]> git.saurik.com Git - wxWidgets.git/blob - samples/treectrl/treetest.h
removed datacmn, not a base file any more
[wxWidgets.git] / samples / treectrl / treetest.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treectrl.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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #define USE_GENERIC_TREECTRL 0
13
14 #if USE_GENERIC_TREECTRL
15 #include "wx/generic/treectlg.h"
16 #ifndef wxTreeCtrl
17 #define wxTreeCtrl wxGenericTreeCtrl
18 #define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
19 #endif
20 #endif
21
22 // Define a new application type
23 class MyApp : public wxApp
24 {
25 public:
26 MyApp() { m_showImages = TRUE; m_showButtons = FALSE; }
27
28 bool OnInit();
29
30 void SetShowImages(bool show) { m_showImages = show; }
31 bool ShowImages() const { return m_showImages; }
32
33 void SetShowButtons(bool show) { m_showButtons = show; }
34 bool ShowButtons() const { return m_showButtons; }
35
36 private:
37 bool m_showImages, m_showButtons;
38 };
39
40 class MyTreeItemData : public wxTreeItemData
41 {
42 public:
43 MyTreeItemData(const wxString& desc) : m_desc(desc) { }
44
45 void ShowInfo(wxTreeCtrl *tree);
46 const wxChar *GetDesc() const { return m_desc.c_str(); }
47
48 private:
49 wxString m_desc;
50 };
51
52 class MyTreeCtrl : public wxTreeCtrl
53 {
54 public:
55 enum
56 {
57 TreeCtrlIcon_File,
58 TreeCtrlIcon_FileSelected,
59 TreeCtrlIcon_Folder,
60 TreeCtrlIcon_FolderSelected,
61 TreeCtrlIcon_FolderOpened
62 };
63
64 MyTreeCtrl() { }
65 MyTreeCtrl(wxWindow *parent, const wxWindowID id,
66 const wxPoint& pos, const wxSize& size,
67 long style);
68 virtual ~MyTreeCtrl();
69
70 void OnBeginDrag(wxTreeEvent& event);
71 void OnBeginRDrag(wxTreeEvent& event);
72 void OnEndDrag(wxTreeEvent& event);
73 void OnBeginLabelEdit(wxTreeEvent& event);
74 void OnEndLabelEdit(wxTreeEvent& event);
75 void OnDeleteItem(wxTreeEvent& event);
76 void OnRMouseUp(wxMouseEvent& event);
77 void OnGetInfo(wxTreeEvent& event);
78 void OnTreeRMouseClick(wxTreeEvent& event);
79 void OnItemRightClick(wxTreeEvent& event);
80 void OnSetInfo(wxTreeEvent& event);
81 void OnItemExpanded(wxTreeEvent& event);
82 void OnItemExpanding(wxTreeEvent& event);
83 void OnItemCollapsed(wxTreeEvent& event);
84 void OnItemCollapsing(wxTreeEvent& event);
85 void OnSelChanged(wxTreeEvent& event);
86 void OnSelChanging(wxTreeEvent& event);
87 void OnTreeKeyDown(wxTreeEvent& event);
88 void OnItemActivated(wxTreeEvent& event);
89 void OnRMouseDClick(wxMouseEvent& event);
90
91 void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
92
93 void CreateImageList(int size = 16);
94 void CreateButtonsImageList(int size = 11);
95
96 void AddTestItemsToTree(size_t numChildren, size_t depth);
97
98 void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE)
99 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
100 void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }
101
102 void DoToggleIcon(const wxTreeItemId& item);
103
104 void ShowMenu(wxTreeItemId id, const wxPoint& pt);
105
106 int ImageSize(void) const { return m_imageSize; }
107
108 void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
109
110 protected:
111 virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
112
113 // is this the test item which we use in several event handlers?
114 bool IsTestItem(const wxTreeItemId& item)
115 {
116 // the test item is the first child folder
117 return GetItemParent(item) == GetRootItem() && !GetPrevSibling(item);
118 }
119
120 private:
121 void AddItemsRecursively(const wxTreeItemId& idParent,
122 size_t nChildren,
123 size_t depth,
124 size_t folder);
125
126 int m_imageSize; // current size of images
127 bool m_reverseSort; // flag for OnCompareItems
128 wxTreeItemId m_lastItem, // for OnEnsureVisible()
129 m_draggedItem; // item being dragged right now
130
131 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
132 // if you want your overloaded OnCompareItems() to be called.
133 // OTOH, if you don't want it you may omit the next line - this will
134 // make default (alphabetical) sorting much faster under wxMSW.
135 DECLARE_DYNAMIC_CLASS(MyTreeCtrl)
136 DECLARE_EVENT_TABLE()
137 };
138
139 // Define a new frame type
140 class MyFrame: public wxFrame
141 {
142 public:
143 // ctor and dtor
144 MyFrame(const wxString& title, int x, int y, int w, int h);
145 virtual ~MyFrame();
146
147 // menu callbacks
148 void OnQuit(wxCommandEvent& event);
149 void OnAbout(wxCommandEvent& event);
150
151 void OnTogButtons(wxCommandEvent& event)
152 { TogStyle(event.GetId(), wxTR_HAS_BUTTONS); }
153 void OnTogTwist(wxCommandEvent& event)
154 { TogStyle(event.GetId(), wxTR_TWIST_BUTTONS); }
155 void OnTogLines(wxCommandEvent& event)
156 { TogStyle(event.GetId(), wxTR_NO_LINES); }
157 void OnTogEdit(wxCommandEvent& event)
158 { TogStyle(event.GetId(), wxTR_EDIT_LABELS); }
159 void OnTogHideRoot(wxCommandEvent& event)
160 { TogStyle(event.GetId(), wxTR_HIDE_ROOT); }
161 void OnTogRootLines(wxCommandEvent& event)
162 { TogStyle(event.GetId(), wxTR_LINES_AT_ROOT); }
163 void OnTogBorder(wxCommandEvent& event)
164 { TogStyle(event.GetId(), wxTR_ROW_LINES); }
165 void OnTogFullHighlight(wxCommandEvent& event)
166 { TogStyle(event.GetId(), wxTR_FULL_ROW_HIGHLIGHT); }
167
168 void OnResetStyle(wxCommandEvent& WXUNUSED(event))
169 { CreateTreeWithDefStyle(); }
170
171 void OnSetFgColour(wxCommandEvent& event);
172 void OnSetBgColour(wxCommandEvent& event);
173
174 void OnDump(wxCommandEvent& event);
175 #ifndef NO_MULTIPLE_SELECTION
176 void OnDumpSelected(wxCommandEvent& event);
177 void OnSelect(wxCommandEvent& event);
178 void OnUnselect(wxCommandEvent& event);
179 void OnToggleSel(wxCommandEvent& event);
180 #endif // NO_MULTIPLE_SELECTION
181 void OnDelete(wxCommandEvent& event);
182 void OnDeleteChildren(wxCommandEvent& event);
183 void OnDeleteAll(wxCommandEvent& event);
184
185 void OnRecreate(wxCommandEvent& event);
186 void OnToggleButtons(wxCommandEvent& event);
187 void OnToggleImages(wxCommandEvent& event);
188 void OnSetImageSize(wxCommandEvent& event);
189 void OnCollapseAndReset(wxCommandEvent& event);
190
191 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
192 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
193
194 void OnEnsureVisible(wxCommandEvent& event);
195
196 void OnCount(wxCommandEvent& event);
197 void OnCountRec(wxCommandEvent& event);
198
199 void OnRename(wxCommandEvent& event);
200 void OnSort(wxCommandEvent& event) { DoSort(); }
201 void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
202
203 void OnAddItem(wxCommandEvent& event);
204 void OnInsertItem(wxCommandEvent& event);
205
206 void OnIncIndent(wxCommandEvent& event);
207 void OnDecIndent(wxCommandEvent& event);
208
209 void OnIncSpacing(wxCommandEvent& event);
210 void OnDecSpacing(wxCommandEvent& event);
211
212 void OnToggleIcon(wxCommandEvent& event);
213
214 void OnSize(wxSizeEvent& event);
215
216 private:
217 void TogStyle(int id, long flag);
218
219 void DoSort(bool reverse = FALSE);
220
221 void Resize();
222
223 void CreateTreeWithDefStyle();
224 void CreateTree(long style);
225
226 MyTreeCtrl *m_treeCtrl;
227 wxTextCtrl *m_textCtrl;
228
229 void DoSetBold(bool bold = TRUE);
230
231 DECLARE_EVENT_TABLE()
232 };
233
234 // menu and control ids
235 enum
236 {
237 TreeTest_Quit,
238 TreeTest_About,
239 TreeTest_TogButtons,
240 TreeTest_TogTwist,
241 TreeTest_TogLines,
242 TreeTest_TogEdit,
243 TreeTest_TogHideRoot,
244 TreeTest_TogRootLines,
245 TreeTest_TogBorder,
246 TreeTest_TogFullHighlight,
247 TreeTest_SetFgColour,
248 TreeTest_SetBgColour,
249 TreeTest_ResetStyle,
250 TreeTest_Dump,
251 TreeTest_DumpSelected,
252 TreeTest_Count,
253 TreeTest_CountRec,
254 TreeTest_Sort,
255 TreeTest_SortRev,
256 TreeTest_SetBold,
257 TreeTest_ClearBold,
258 TreeTest_Rename,
259 TreeTest_Delete,
260 TreeTest_DeleteChildren,
261 TreeTest_DeleteAll,
262 TreeTest_Recreate,
263 TreeTest_ToggleImages,
264 TreeTest_ToggleButtons,
265 TreeTest_SetImageSize,
266 TreeTest_ToggleSel,
267 TreeTest_CollapseAndReset,
268 TreeTest_EnsureVisible,
269 TreeTest_AddItem,
270 TreeTest_InsertItem,
271 TreeTest_IncIndent,
272 TreeTest_DecIndent,
273 TreeTest_IncSpacing,
274 TreeTest_DecSpacing,
275 TreeTest_ToggleIcon,
276 TreeTest_Select,
277 TreeTest_Unselect,
278 TreeTest_Ctrl = 1000
279 };