]> git.saurik.com Git - wxWidgets.git/blob - samples/treectrl/treetest.h
fixed (rare but fatal) bug in wxWindowDisabler
[wxWidgets.git] / samples / treectrl / treetest.h
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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // Define a new application type
13 class MyApp : public wxApp
14 {
15 public:
16 MyApp() { m_showImages = TRUE; }
17
18 bool OnInit();
19
20 void SetShowImages(bool show) { m_showImages = show; }
21 bool ShowImages() const { return m_showImages; }
22
23 private:
24 bool m_showImages;
25 };
26
27 class MyTreeItemData : public wxTreeItemData
28 {
29 public:
30 MyTreeItemData(const wxString& desc) : m_desc(desc) { }
31
32 void ShowInfo(wxTreeCtrl *tree);
33 const char *GetDesc() const { return m_desc.c_str(); }
34
35 private:
36 wxString m_desc;
37 };
38
39 class MyTreeCtrl : public wxTreeCtrl
40 {
41 public:
42 enum
43 {
44 TreeCtrlIcon_File,
45 TreeCtrlIcon_FileSelected,
46 TreeCtrlIcon_Folder,
47 TreeCtrlIcon_FolderSelected,
48 TreeCtrlIcon_FolderOpened
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);
59 void OnEndDrag(wxTreeEvent& event);
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
77 void CreateImageList(int size = 16);
78
79 void AddTestItemsToTree(size_t numChildren, size_t depth);
80
81 void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE)
82 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
83 void DoEnsureVisible() { EnsureVisible(m_lastItem); }
84
85 void DoToggleIcon(const wxTreeItemId& item);
86
87 protected:
88 virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
89
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
97 private:
98 void AddItemsRecursively(const wxTreeItemId& idParent,
99 size_t nChildren,
100 size_t depth,
101 size_t folder);
102
103 wxImageList *m_imageListNormal;
104 bool m_reverseSort; // flag for OnCompareItems
105 wxTreeItemId m_lastItem, // for OnEnsureVisible()
106 m_draggedItem; // item being dragged right now
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()
114 };
115
116 // Define a new frame type
117 class MyFrame: public wxFrame
118 {
119 public:
120 // ctor and dtor
121 MyFrame(const wxString& title, int x, int y, int w, int h);
122 virtual ~MyFrame();
123
124 // menu callbacks
125 void OnQuit(wxCommandEvent& event);
126 void OnAbout(wxCommandEvent& event);
127
128 void OnDump(wxCommandEvent& event);
129 #ifndef NO_MULTIPLE_SELECTION
130 void OnDumpSelected(wxCommandEvent& event);
131 void OnSelect(wxCommandEvent& event);
132 void OnUnselect(wxCommandEvent& event);
133 void OnToggleSel(wxCommandEvent& event);
134 #endif // NO_MULTIPLE_SELECTION
135 void OnDelete(wxCommandEvent& event);
136 void OnDeleteChildren(wxCommandEvent& event);
137 void OnDeleteAll(wxCommandEvent& event);
138
139 void OnRecreate(wxCommandEvent& event);
140 void OnToggleImages(wxCommandEvent& event);
141 void OnSetImageSize(wxCommandEvent& event);
142 void OnCollapseAndReset(wxCommandEvent& event);
143
144 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
145 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
146
147 void OnEnsureVisible(wxCommandEvent& event);
148
149 void OnCount(wxCommandEvent& event);
150 void OnCountRec(wxCommandEvent& event);
151
152 void OnRename(wxCommandEvent& event);
153 void OnSort(wxCommandEvent& event) { DoSort(); }
154 void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
155
156 void OnAddItem(wxCommandEvent& event);
157 void OnInsertItem(wxCommandEvent& event);
158
159 void OnIncIndent(wxCommandEvent& event);
160 void OnDecIndent(wxCommandEvent& event);
161
162 void OnIncSpacing(wxCommandEvent& event);
163 void OnDecSpacing(wxCommandEvent& event);
164
165 void OnToggleIcon(wxCommandEvent& event);
166
167 void OnSize(wxSizeEvent& event);
168
169 private:
170 void DoSort(bool reverse = FALSE);
171
172 void Resize(const wxSize& size);
173
174 MyTreeCtrl *m_treeCtrl;
175 wxTextCtrl *m_textCtrl;
176
177 void DoSetBold(bool bold = TRUE);
178
179 DECLARE_EVENT_TABLE()
180 };
181
182 // menu and control ids
183 enum
184 {
185 TreeTest_Quit,
186 TreeTest_About,
187 TreeTest_Dump,
188 TreeTest_DumpSelected,
189 TreeTest_Count,
190 TreeTest_CountRec,
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,
200 TreeTest_ToggleImages,
201 TreeTest_SetImageSize,
202 TreeTest_ToggleSel,
203 TreeTest_CollapseAndReset,
204 TreeTest_EnsureVisible,
205 TreeTest_AddItem,
206 TreeTest_InsertItem,
207 TreeTest_IncIndent,
208 TreeTest_DecIndent,
209 TreeTest_IncSpacing,
210 TreeTest_DecSpacing,
211 TreeTest_ToggleIcon,
212 TreeTest_Select,
213 TreeTest_Unselect,
214 TreeTest_Ctrl = 1000
215 };