]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/treectrl/treetest.h
Add copy constructor, DateTimeFromDateTime
[wxWidgets.git] / samples / treectrl / treetest.h
... / ...
CommitLineData
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
23class MyApp : public wxApp
24{
25public:
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
36private:
37 bool m_showImages, m_showButtons;
38};
39
40class MyTreeItemData : public wxTreeItemData
41{
42public:
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
48private:
49 wxString m_desc;
50};
51
52class MyTreeCtrl : public wxTreeCtrl
53{
54public:
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 OnContextMenu(wxContextMenuEvent& event);
77 void OnItemMenu(wxTreeEvent& event);
78 void OnGetInfo(wxTreeEvent& event);
79 void OnSetInfo(wxTreeEvent& event);
80 void OnItemExpanded(wxTreeEvent& event);
81 void OnItemExpanding(wxTreeEvent& event);
82 void OnItemCollapsed(wxTreeEvent& event);
83 void OnItemCollapsing(wxTreeEvent& event);
84 void OnSelChanged(wxTreeEvent& event);
85 void OnSelChanging(wxTreeEvent& event);
86 void OnTreeKeyDown(wxTreeEvent& event);
87 void OnItemActivated(wxTreeEvent& event);
88 void OnItemRClick(wxTreeEvent& event);
89
90 void OnRMouseDown(wxMouseEvent& event);
91 void OnRMouseUp(wxMouseEvent& event);
92 void OnRMouseDClick(wxMouseEvent& event);
93
94 void GetItemsRecursively(const wxTreeItemId& idParent,
95 wxTreeItemIdValue cookie = 0);
96
97 void CreateImageList(int size = 16);
98 void CreateButtonsImageList(int size = 11);
99
100 void AddTestItemsToTree(size_t numChildren, size_t depth);
101
102 void DoSortChildren(const wxTreeItemId& item, bool reverse = false)
103 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
104 void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }
105
106 void DoToggleIcon(const wxTreeItemId& item);
107
108 void ShowMenu(wxTreeItemId id, const wxPoint& pt);
109
110 int ImageSize(void) const { return m_imageSize; }
111
112 void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
113
114protected:
115 virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
116
117 // is this the test item which we use in several event handlers?
118 bool IsTestItem(const wxTreeItemId& item)
119 {
120 // the test item is the first child folder
121 return GetItemParent(item) == GetRootItem() && !GetPrevSibling(item);
122 }
123
124private:
125 void AddItemsRecursively(const wxTreeItemId& idParent,
126 size_t nChildren,
127 size_t depth,
128 size_t folder);
129
130 int m_imageSize; // current size of images
131 bool m_reverseSort; // flag for OnCompareItems
132 wxTreeItemId m_lastItem, // for OnEnsureVisible()
133 m_draggedItem; // item being dragged right now
134
135 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
136 // if you want your overloaded OnCompareItems() to be called.
137 // OTOH, if you don't want it you may omit the next line - this will
138 // make default (alphabetical) sorting much faster under wxMSW.
139 DECLARE_DYNAMIC_CLASS(MyTreeCtrl)
140 DECLARE_EVENT_TABLE()
141};
142
143// Define a new frame type
144class MyFrame: public wxFrame
145{
146public:
147 // ctor and dtor
148 MyFrame(const wxString& title, int x, int y, int w, int h);
149 virtual ~MyFrame();
150
151 // menu callbacks
152 void OnQuit(wxCommandEvent& event);
153 void OnAbout(wxCommandEvent& event);
154
155 void OnTogButtons(wxCommandEvent& event)
156 { TogStyle(event.GetId(), wxTR_HAS_BUTTONS); }
157 void OnTogTwist(wxCommandEvent& event)
158 { TogStyle(event.GetId(), wxTR_TWIST_BUTTONS); }
159 void OnTogLines(wxCommandEvent& event)
160 { TogStyle(event.GetId(), wxTR_NO_LINES); }
161 void OnTogEdit(wxCommandEvent& event)
162 { TogStyle(event.GetId(), wxTR_EDIT_LABELS); }
163 void OnTogHideRoot(wxCommandEvent& event)
164 { TogStyle(event.GetId(), wxTR_HIDE_ROOT); }
165 void OnTogRootLines(wxCommandEvent& event)
166 { TogStyle(event.GetId(), wxTR_LINES_AT_ROOT); }
167 void OnTogBorder(wxCommandEvent& event)
168 { TogStyle(event.GetId(), wxTR_ROW_LINES); }
169 void OnTogFullHighlight(wxCommandEvent& event)
170 { TogStyle(event.GetId(), wxTR_FULL_ROW_HIGHLIGHT); }
171
172 void OnResetStyle(wxCommandEvent& WXUNUSED(event))
173 { CreateTreeWithDefStyle(); }
174
175 void OnSetFgColour(wxCommandEvent& event);
176 void OnSetBgColour(wxCommandEvent& event);
177
178 void OnDump(wxCommandEvent& event);
179#ifndef NO_MULTIPLE_SELECTION
180 void OnDumpSelected(wxCommandEvent& event);
181 void OnSelect(wxCommandEvent& event);
182 void OnUnselect(wxCommandEvent& event);
183 void OnToggleSel(wxCommandEvent& event);
184#endif // NO_MULTIPLE_SELECTION
185 void OnSelectRoot(wxCommandEvent& event);
186 void OnDelete(wxCommandEvent& event);
187 void OnDeleteChildren(wxCommandEvent& event);
188 void OnDeleteAll(wxCommandEvent& event);
189
190 void OnRecreate(wxCommandEvent& event);
191 void OnToggleButtons(wxCommandEvent& event);
192 void OnToggleImages(wxCommandEvent& event);
193 void OnSetImageSize(wxCommandEvent& event);
194 void OnCollapseAndReset(wxCommandEvent& event);
195
196 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(true); }
197 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(false); }
198
199 void OnEnsureVisible(wxCommandEvent& event);
200
201 void OnCount(wxCommandEvent& event);
202 void OnCountRec(wxCommandEvent& event);
203
204 void OnRename(wxCommandEvent& event);
205 void OnSort(wxCommandEvent& WXUNUSED(event)) { DoSort(); }
206 void OnSortRev(wxCommandEvent& WXUNUSED(event)) { DoSort(true); }
207
208 void OnAddItem(wxCommandEvent& event);
209 void OnInsertItem(wxCommandEvent& event);
210
211 void OnIncIndent(wxCommandEvent& event);
212 void OnDecIndent(wxCommandEvent& event);
213
214 void OnIncSpacing(wxCommandEvent& event);
215 void OnDecSpacing(wxCommandEvent& event);
216
217 void OnToggleIcon(wxCommandEvent& event);
218
219 void OnIdle(wxIdleEvent& event);
220 void OnSize(wxSizeEvent& event);
221
222private:
223 void TogStyle(int id, long flag);
224
225 void DoSort(bool reverse = false);
226
227 void Resize();
228
229 void CreateTreeWithDefStyle();
230 void CreateTree(long style);
231
232 MyTreeCtrl *m_treeCtrl;
233#if wxUSE_LOG
234 wxTextCtrl *m_textCtrl;
235#endif // wxUSE_LOG
236
237 void DoSetBold(bool bold = true);
238
239 DECLARE_EVENT_TABLE()
240};
241
242// menu and control ids
243enum
244{
245 TreeTest_Quit = wxID_EXIT,
246 TreeTest_About = wxID_ABOUT,
247 TreeTest_TogButtons = wxID_HIGHEST,
248 TreeTest_TogTwist,
249 TreeTest_TogLines,
250 TreeTest_TogEdit,
251 TreeTest_TogHideRoot,
252 TreeTest_TogRootLines,
253 TreeTest_TogBorder,
254 TreeTest_TogFullHighlight,
255 TreeTest_SetFgColour,
256 TreeTest_SetBgColour,
257 TreeTest_ResetStyle,
258 TreeTest_Dump,
259 TreeTest_DumpSelected,
260 TreeTest_Count,
261 TreeTest_CountRec,
262 TreeTest_Sort,
263 TreeTest_SortRev,
264 TreeTest_SetBold,
265 TreeTest_ClearBold,
266 TreeTest_Rename,
267 TreeTest_Delete,
268 TreeTest_DeleteChildren,
269 TreeTest_DeleteAll,
270 TreeTest_Recreate,
271 TreeTest_ToggleImages,
272 TreeTest_ToggleButtons,
273 TreeTest_SetImageSize,
274 TreeTest_ToggleSel,
275 TreeTest_CollapseAndReset,
276 TreeTest_EnsureVisible,
277 TreeTest_AddItem,
278 TreeTest_InsertItem,
279 TreeTest_IncIndent,
280 TreeTest_DecIndent,
281 TreeTest_IncSpacing,
282 TreeTest_DecSpacing,
283 TreeTest_ToggleIcon,
284 TreeTest_Select,
285 TreeTest_Unselect,
286 TreeTest_SelectRoot,
287 TreeTest_Ctrl = 1000
288};