File: GUI_Main_Tree.cpp

package info (click to toggle)
mediainfo 20.09-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,732 kB
  • sloc: cpp: 15,682; objc: 2,760; sh: 1,343; xml: 926; python: 259; perl: 207; makefile: 173
file content (155 lines) | stat: -rw-r--r-- 4,915 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//---------------------------------------------------------------------------
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
#include "GUI/WxWidgets/GUI_Main_Tree.h"
#include "Common/Core.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
BEGIN_EVENT_TABLE(GUI_Main_Tree, wxTreeCtrl)
    EVT_TREE_ITEM_EXPANDING (26983, GUI_Main_Tree::OnItemExpanding)
    EVT_TREE_ITEM_COLLAPSING(26983, GUI_Main_Tree::OnItemCollapsing)
END_EVENT_TABLE()
//---------------------------------------------------------------------------

//***************************************************************************
// Constructor/Destructor
//***************************************************************************

//---------------------------------------------------------------------------
GUI_Main_Tree::GUI_Main_Tree(Core* Core_, wxWindow* parent)
        : wxTreeCtrl(parent, 26983, wxPoint(0, 0), wxSize(parent->GetClientSize().GetWidth()-0, parent->GetClientSize().GetHeight()-0)),
        GUI_Main_Common_Core(Core_)
{
    //Update
    GUI_Refresh();
}

//---------------------------------------------------------------------------
GUI_Main_Tree::~GUI_Main_Tree()
{
    Hide();

    DeleteAllItems();
    TextPos.clear();
}

//***************************************************************************
// Actions
//***************************************************************************

//---------------------------------------------------------------------------
void GUI_Main_Tree::GUI_Refresh()
{
    Hide();

    //Retrieving info
    Text=C->Inform_Get();

    //Clear
    DeleteAllItems();
    TextPos.clear();

    //Showing
    if (!Text.empty())
    {
        SetWindowStyle(wxTR_HIDE_ROOT);
        wxTreeItemId RootID=AddRoot(wxT("Root"));
        TextPos[RootID.m_pItem]=(size_t)-1;
        Item_Show(RootID);
    }

    Show();
}

void GUI_Main_Tree::GUI_Resize()
{
    SetSize(0, 0, GetParent()->GetClientSize().GetWidth()-0, GetParent()->GetClientSize().GetHeight()-0);
}

//---------------------------------------------------------------------------
void GUI_Main_Tree::Item_Show(const wxTreeItemId &Item)
{
    DeleteChildren(Item);

    //Finding size of the file offset string
    size_t Offset=Text.find(__T(' '))+1;
    if (!Offset || Offset>64+1)
        return;

    wxTreeItemId ItemID;
    //wxFont Font(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
    //wxFont Font(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
    size_t Level=0;
    size_t Pos1=TextPos[Item.m_pItem];
    size_t Pos2=0;
    size_t LevelBase;
    if (Pos1!=(size_t)-1)
    {
        //Not the root level
        LevelBase=Text.find_first_not_of(__T(' '), Pos1+Offset)-(Pos1+Offset);
        Pos1=Text.find(__T('\n'), Pos1)+1;
    }
    else
    {
        //Root level
        LevelBase=(size_t)-1;
        Pos1=0;
    }
    while (Pos2!=(size_t)-1)
    {
        Pos2=Text.find(__T('\n'), Pos1); //Pos to the next line
        #ifdef WIN32
            #define SIZE 1
        #else
            #define SIZE 0
        #endif
        Level=Text.find_first_not_of(__T(' '), Pos1+Offset)-(Pos1+Offset);
        if (Level==LevelBase+1)
        {
            //Showing line
            String Line=Text.substr(Pos1, Pos2-Pos1-SIZE);
            if (Line.size()>11 && Line[Offset]==__T(' '))
            {
                Line.erase(Offset, Level);
            }
            if (!Line.empty())
            {
                ItemID=AppendItem(Item, Line.c_str());
                TextPos[ItemID.m_pItem]=Pos1;
                //SetItemFont(ItemID, Font);
            }
        }
        else if (Level==LevelBase+2)
            SetItemHasChildren(ItemID); //SubLevel elements detected, we are showing the availability of childrens
        else if (Level<=LevelBase && LevelBase!=(size_t)-1) //This is an upper level, finnished (except for root level, there is no upper level)
            Pos2=(size_t)-1;
        Pos1=Pos2+1;
    }
}

//***************************************************************************
// Events
//***************************************************************************

void GUI_Main_Tree::OnItemExpanding(wxTreeEvent& event)
{
    Item_Show(event.GetItem());
}

void GUI_Main_Tree::OnItemCollapsing(wxTreeEvent& event)
{
    //CollapseAndReset(event.GetItem());
    //SetItemHasChildren(event.GetItem());
}