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