]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: treetest.h | |
3 | // Purpose: wxTreeCtrl sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
5a43154b | 9 | // Licence: wxWindows license |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // Define a new application type | |
5a43154b VZ |
13 | class MyApp : public wxApp |
14 | { | |
15 | public: | |
5f939e78 | 16 | bool OnInit(); |
5a43154b | 17 | }; |
457814b5 | 18 | |
5a43154b VZ |
19 | class MyTreeItemData : public wxTreeItemData |
20 | { | |
21 | public: | |
5f939e78 | 22 | MyTreeItemData(const wxString& desc) : m_desc(desc) { } |
5a43154b | 23 | |
5f939e78 VZ |
24 | void ShowInfo(wxTreeCtrl *tree); |
25 | const char *GetDesc() const { return m_desc.c_str(); } | |
5a43154b VZ |
26 | |
27 | private: | |
5f939e78 | 28 | wxString m_desc; |
457814b5 JS |
29 | }; |
30 | ||
5a43154b | 31 | class MyTreeCtrl : public wxTreeCtrl |
457814b5 JS |
32 | { |
33 | public: | |
5f939e78 VZ |
34 | enum |
35 | { | |
36 | TreeCtrlIcon_File, | |
74b31181 VZ |
37 | TreeCtrlIcon_FileSelected, |
38 | TreeCtrlIcon_Folder, | |
39 | TreeCtrlIcon_FolderSelected, | |
40 | TreeCtrlIcon_FolderOpened | |
5f939e78 VZ |
41 | }; |
42 | ||
43 | MyTreeCtrl() { } | |
44 | MyTreeCtrl(wxWindow *parent, const wxWindowID id, | |
45 | const wxPoint& pos, const wxSize& size, | |
46 | long style); | |
47 | virtual ~MyTreeCtrl(); | |
48 | ||
49 | void OnBeginDrag(wxTreeEvent& event); | |
50 | void OnBeginRDrag(wxTreeEvent& event); | |
51 | void OnBeginLabelEdit(wxTreeEvent& event); | |
52 | void OnEndLabelEdit(wxTreeEvent& event); | |
53 | void OnDeleteItem(wxTreeEvent& event); | |
54 | void OnGetInfo(wxTreeEvent& event); | |
55 | void OnSetInfo(wxTreeEvent& event); | |
56 | void OnItemExpanded(wxTreeEvent& event); | |
57 | void OnItemExpanding(wxTreeEvent& event); | |
58 | void OnItemCollapsed(wxTreeEvent& event); | |
59 | void OnItemCollapsing(wxTreeEvent& event); | |
60 | void OnSelChanged(wxTreeEvent& event); | |
61 | void OnSelChanging(wxTreeEvent& event); | |
62 | void OnTreeKeyDown(wxTreeEvent& event); | |
63 | void OnItemActivated(wxTreeEvent& event); | |
64 | void OnRMouseDClick(wxMouseEvent& event); | |
65 | ||
66 | void GetItemsRecursively(const wxTreeItemId& idParent, long cookie); | |
67 | ||
68 | void AddTestItemsToTree(size_t numChildren, size_t depth); | |
69 | ||
70 | void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE) | |
9dfbf520 | 71 | { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); } |
5f939e78 | 72 | void DoEnsureVisible() { EnsureVisible(m_lastItem); } |
e1ee62bd | 73 | |
9dfbf520 VZ |
74 | void DoToggleIcon(const wxTreeItemId& item); |
75 | ||
e1ee62bd | 76 | protected: |
5f939e78 | 77 | virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2); |
e1ee62bd | 78 | |
5ea47806 VZ |
79 | // is this the test item which we use in several event handlers? |
80 | bool IsTestItem(const wxTreeItemId& item) | |
81 | { | |
82 | // the test item is the first child folder | |
83 | return GetParent(item) == GetRootItem() && !GetPrevSibling(item); | |
84 | } | |
85 | ||
5a43154b | 86 | private: |
5f939e78 VZ |
87 | void AddItemsRecursively(const wxTreeItemId& idParent, |
88 | size_t nChildren, | |
89 | size_t depth, | |
90 | size_t folder); | |
91 | ||
92 | wxImageList *m_imageListNormal; | |
93 | bool m_reverseSort; // flag for OnCompareItems | |
94 | wxTreeItemId m_lastItem; // for OnEnsureVisible() | |
95 | ||
96 | // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() | |
97 | // if you want your overloaded OnCompareItems() to be called. | |
98 | // OTOH, if you don't want it you may omit the next line - this will | |
99 | // make default (alphabetical) sorting much faster under wxMSW. | |
100 | DECLARE_DYNAMIC_CLASS(MyTreeCtrl) | |
101 | DECLARE_EVENT_TABLE() | |
457814b5 JS |
102 | }; |
103 | ||
104 | // Define a new frame type | |
105 | class MyFrame: public wxFrame | |
019bf128 UU |
106 | { |
107 | public: | |
5f939e78 VZ |
108 | // ctor and dtor |
109 | MyFrame(const wxString& title, int x, int y, int w, int h); | |
110 | virtual ~MyFrame(); | |
f135ff73 | 111 | |
5f939e78 VZ |
112 | // menu callbacks |
113 | void OnQuit(wxCommandEvent& event); | |
114 | void OnAbout(wxCommandEvent& event); | |
f135ff73 | 115 | |
5f939e78 | 116 | void OnDump(wxCommandEvent& event); |
9dfbf520 | 117 | #ifndef NO_MULTIPLE_SELECTION |
91b8de8d | 118 | void OnDumpSelected(wxCommandEvent& event); |
9dfbf520 VZ |
119 | void OnSelect(wxCommandEvent& event); |
120 | void OnUnselect(wxCommandEvent& event); | |
121 | #endif // NO_MULTIPLE_SELECTION | |
5f939e78 VZ |
122 | void OnDelete(wxCommandEvent& event); |
123 | void OnDeleteChildren(wxCommandEvent& event); | |
124 | void OnDeleteAll(wxCommandEvent& event); | |
125 | void OnRecreate(wxCommandEvent& event); | |
126 | void OnCollapseAndReset(wxCommandEvent& event); | |
add28c55 | 127 | |
5f939e78 VZ |
128 | void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); } |
129 | void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); } | |
f65635b5 | 130 | |
5f939e78 VZ |
131 | void OnEnsureVisible(wxCommandEvent& event); |
132 | ||
5fd11f09 RR |
133 | void OnCount(wxCommandEvent& event); |
134 | void OnCountRec(wxCommandEvent& event); | |
135 | ||
5f939e78 VZ |
136 | void OnRename(wxCommandEvent& event); |
137 | void OnSort(wxCommandEvent& event) { DoSort(); } | |
138 | void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); } | |
139 | ||
140 | void OnAddItem(wxCommandEvent& event); | |
9dfbf520 | 141 | |
cf724bce RR |
142 | void OnIncIndent(wxCommandEvent& event); |
143 | void OnDecIndent(wxCommandEvent& event); | |
144 | ||
145 | void OnIncSpacing(wxCommandEvent& event); | |
146 | void OnDecSpacing(wxCommandEvent& event); | |
e1ee62bd | 147 | |
9dfbf520 VZ |
148 | void OnToggleIcon(wxCommandEvent& event); |
149 | ||
f135ff73 | 150 | private: |
5f939e78 | 151 | void DoSort(bool reverse = FALSE); |
e1ee62bd | 152 | |
5f939e78 | 153 | MyTreeCtrl *m_treeCtrl; |
457814b5 | 154 | |
5f939e78 | 155 | void DoSetBold(bool bold = TRUE); |
add28c55 | 156 | |
5f939e78 | 157 | DECLARE_EVENT_TABLE() |
5a43154b | 158 | }; |
457814b5 | 159 | |
5a43154b VZ |
160 | // menu and control ids |
161 | enum | |
162 | { | |
5f939e78 VZ |
163 | TreeTest_Quit, |
164 | TreeTest_About, | |
165 | TreeTest_Dump, | |
9dfbf520 | 166 | TreeTest_DumpSelected, |
5fd11f09 RR |
167 | TreeTest_Count, |
168 | TreeTest_CountRec, | |
5f939e78 VZ |
169 | TreeTest_Sort, |
170 | TreeTest_SortRev, | |
171 | TreeTest_Bold, | |
172 | TreeTest_UnBold, | |
173 | TreeTest_Rename, | |
174 | TreeTest_Delete, | |
175 | TreeTest_DeleteChildren, | |
176 | TreeTest_DeleteAll, | |
177 | TreeTest_Recreate, | |
178 | TreeTest_CollapseAndReset, | |
179 | TreeTest_EnsureVisible, | |
180 | TreeTest_AddItem, | |
cf724bce RR |
181 | TreeTest_IncIndent, |
182 | TreeTest_DecIndent, | |
183 | TreeTest_IncSpacing, | |
184 | TreeTest_DecSpacing, | |
9dfbf520 VZ |
185 | TreeTest_ToggleIcon, |
186 | TreeTest_Select, | |
187 | TreeTest_Unselect, | |
188 | TreeTest_Ctrl = 1000 | |
f65635b5 | 189 | }; |