]>
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, | |
37 | TreeCtrlIcon_Folder | |
38 | }; | |
39 | ||
40 | MyTreeCtrl() { } | |
41 | MyTreeCtrl(wxWindow *parent, const wxWindowID id, | |
42 | const wxPoint& pos, const wxSize& size, | |
43 | long style); | |
44 | virtual ~MyTreeCtrl(); | |
45 | ||
46 | void OnBeginDrag(wxTreeEvent& event); | |
47 | void OnBeginRDrag(wxTreeEvent& event); | |
48 | void OnBeginLabelEdit(wxTreeEvent& event); | |
49 | void OnEndLabelEdit(wxTreeEvent& event); | |
50 | void OnDeleteItem(wxTreeEvent& event); | |
51 | void OnGetInfo(wxTreeEvent& event); | |
52 | void OnSetInfo(wxTreeEvent& event); | |
53 | void OnItemExpanded(wxTreeEvent& event); | |
54 | void OnItemExpanding(wxTreeEvent& event); | |
55 | void OnItemCollapsed(wxTreeEvent& event); | |
56 | void OnItemCollapsing(wxTreeEvent& event); | |
57 | void OnSelChanged(wxTreeEvent& event); | |
58 | void OnSelChanging(wxTreeEvent& event); | |
59 | void OnTreeKeyDown(wxTreeEvent& event); | |
60 | void OnItemActivated(wxTreeEvent& event); | |
61 | void OnRMouseDClick(wxMouseEvent& event); | |
62 | ||
63 | void GetItemsRecursively(const wxTreeItemId& idParent, long cookie); | |
64 | ||
65 | void AddTestItemsToTree(size_t numChildren, size_t depth); | |
66 | ||
67 | void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE) | |
e1ee62bd | 68 | { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); } |
5f939e78 | 69 | void DoEnsureVisible() { EnsureVisible(m_lastItem); } |
e1ee62bd VZ |
70 | |
71 | protected: | |
5f939e78 | 72 | virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2); |
e1ee62bd | 73 | |
5ea47806 VZ |
74 | // is this the test item which we use in several event handlers? |
75 | bool IsTestItem(const wxTreeItemId& item) | |
76 | { | |
77 | // the test item is the first child folder | |
78 | return GetParent(item) == GetRootItem() && !GetPrevSibling(item); | |
79 | } | |
80 | ||
5a43154b | 81 | private: |
5f939e78 VZ |
82 | void AddItemsRecursively(const wxTreeItemId& idParent, |
83 | size_t nChildren, | |
84 | size_t depth, | |
85 | size_t folder); | |
86 | ||
87 | wxImageList *m_imageListNormal; | |
88 | bool m_reverseSort; // flag for OnCompareItems | |
89 | wxTreeItemId m_lastItem; // for OnEnsureVisible() | |
90 | ||
91 | // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS() | |
92 | // if you want your overloaded OnCompareItems() to be called. | |
93 | // OTOH, if you don't want it you may omit the next line - this will | |
94 | // make default (alphabetical) sorting much faster under wxMSW. | |
95 | DECLARE_DYNAMIC_CLASS(MyTreeCtrl) | |
96 | DECLARE_EVENT_TABLE() | |
457814b5 JS |
97 | }; |
98 | ||
99 | // Define a new frame type | |
100 | class MyFrame: public wxFrame | |
019bf128 UU |
101 | { |
102 | public: | |
5f939e78 VZ |
103 | // ctor and dtor |
104 | MyFrame(const wxString& title, int x, int y, int w, int h); | |
105 | virtual ~MyFrame(); | |
f135ff73 | 106 | |
5f939e78 VZ |
107 | // menu callbacks |
108 | void OnQuit(wxCommandEvent& event); | |
109 | void OnAbout(wxCommandEvent& event); | |
f135ff73 | 110 | |
5f939e78 | 111 | void OnDump(wxCommandEvent& event); |
91b8de8d | 112 | void OnDumpSelected(wxCommandEvent& event); |
5f939e78 VZ |
113 | void OnDelete(wxCommandEvent& event); |
114 | void OnDeleteChildren(wxCommandEvent& event); | |
115 | void OnDeleteAll(wxCommandEvent& event); | |
116 | void OnRecreate(wxCommandEvent& event); | |
117 | void OnCollapseAndReset(wxCommandEvent& event); | |
add28c55 | 118 | |
5f939e78 VZ |
119 | void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); } |
120 | void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); } | |
f65635b5 | 121 | |
5f939e78 VZ |
122 | void OnEnsureVisible(wxCommandEvent& event); |
123 | ||
124 | void OnRename(wxCommandEvent& event); | |
125 | void OnSort(wxCommandEvent& event) { DoSort(); } | |
126 | void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); } | |
127 | ||
128 | void OnAddItem(wxCommandEvent& event); | |
cf724bce RR |
129 | |
130 | void OnIncIndent(wxCommandEvent& event); | |
131 | void OnDecIndent(wxCommandEvent& event); | |
132 | ||
133 | void OnIncSpacing(wxCommandEvent& event); | |
134 | void OnDecSpacing(wxCommandEvent& event); | |
e1ee62bd | 135 | |
f135ff73 | 136 | private: |
5f939e78 | 137 | void DoSort(bool reverse = FALSE); |
e1ee62bd | 138 | |
5f939e78 | 139 | MyTreeCtrl *m_treeCtrl; |
457814b5 | 140 | |
5f939e78 | 141 | void DoSetBold(bool bold = TRUE); |
add28c55 | 142 | |
5f939e78 | 143 | DECLARE_EVENT_TABLE() |
5a43154b | 144 | }; |
457814b5 | 145 | |
5a43154b VZ |
146 | // menu and control ids |
147 | enum | |
148 | { | |
5f939e78 VZ |
149 | TreeTest_Quit, |
150 | TreeTest_About, | |
151 | TreeTest_Dump, | |
91b8de8d | 152 | TreeTest_Dump_Selected, |
5f939e78 VZ |
153 | TreeTest_Sort, |
154 | TreeTest_SortRev, | |
155 | TreeTest_Bold, | |
156 | TreeTest_UnBold, | |
157 | TreeTest_Rename, | |
158 | TreeTest_Delete, | |
159 | TreeTest_DeleteChildren, | |
160 | TreeTest_DeleteAll, | |
161 | TreeTest_Recreate, | |
162 | TreeTest_CollapseAndReset, | |
163 | TreeTest_EnsureVisible, | |
164 | TreeTest_AddItem, | |
cf724bce RR |
165 | TreeTest_IncIndent, |
166 | TreeTest_DecIndent, | |
167 | TreeTest_IncSpacing, | |
168 | TreeTest_DecSpacing, | |
5f939e78 | 169 | TreeTest_Ctrl = 100 |
f65635b5 | 170 | }; |