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