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