]> git.saurik.com Git - wxWidgets.git/blob - samples/treectrl/treetest.h
Found a few situations where the most recent
[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 bool OnInit();
17 };
18
19 class MyTreeItemData : public wxTreeItemData
20 {
21 public:
22 MyTreeItemData(const wxString& desc) : m_desc(desc) { }
23
24 void ShowInfo(wxTreeCtrl *tree);
25 const char *GetDesc() const { return m_desc.c_str(); }
26
27 private:
28 wxString m_desc;
29 };
30
31 class MyTreeCtrl : public wxTreeCtrl
32 {
33 public:
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)
68 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
69 void DoEnsureVisible() { EnsureVisible(m_lastItem); }
70
71 protected:
72 virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
73
74 private:
75 void AddItemsRecursively(const wxTreeItemId& idParent,
76 size_t nChildren,
77 size_t depth,
78 size_t folder);
79
80 wxImageList *m_imageListNormal;
81 bool m_reverseSort; // flag for OnCompareItems
82 wxTreeItemId m_lastItem; // for OnEnsureVisible()
83
84 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
85 // if you want your overloaded OnCompareItems() to be called.
86 // OTOH, if you don't want it you may omit the next line - this will
87 // make default (alphabetical) sorting much faster under wxMSW.
88 DECLARE_DYNAMIC_CLASS(MyTreeCtrl)
89 DECLARE_EVENT_TABLE()
90 };
91
92 // Define a new frame type
93 class MyFrame: public wxFrame
94 {
95 public:
96 // ctor and dtor
97 MyFrame(const wxString& title, int x, int y, int w, int h);
98 virtual ~MyFrame();
99
100 // menu callbacks
101 void OnQuit(wxCommandEvent& event);
102 void OnAbout(wxCommandEvent& event);
103
104 void OnDump(wxCommandEvent& event);
105 void OnDelete(wxCommandEvent& event);
106 void OnDeleteChildren(wxCommandEvent& event);
107 void OnDeleteAll(wxCommandEvent& event);
108 void OnRecreate(wxCommandEvent& event);
109 void OnCollapseAndReset(wxCommandEvent& event);
110
111 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
112 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
113
114 void OnEnsureVisible(wxCommandEvent& event);
115
116 void OnRename(wxCommandEvent& event);
117 void OnSort(wxCommandEvent& event) { DoSort(); }
118 void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
119
120 void OnAddItem(wxCommandEvent& event);
121
122 void OnIncIndent(wxCommandEvent& event);
123 void OnDecIndent(wxCommandEvent& event);
124
125 void OnIncSpacing(wxCommandEvent& event);
126 void OnDecSpacing(wxCommandEvent& event);
127
128 private:
129 void DoSort(bool reverse = FALSE);
130
131 MyTreeCtrl *m_treeCtrl;
132
133 void DoSetBold(bool bold = TRUE);
134
135 DECLARE_EVENT_TABLE()
136 };
137
138 // menu and control ids
139 enum
140 {
141 TreeTest_Quit,
142 TreeTest_About,
143 TreeTest_Dump,
144 TreeTest_Sort,
145 TreeTest_SortRev,
146 TreeTest_Bold,
147 TreeTest_UnBold,
148 TreeTest_Rename,
149 TreeTest_Delete,
150 TreeTest_DeleteChildren,
151 TreeTest_DeleteAll,
152 TreeTest_Recreate,
153 TreeTest_CollapseAndReset,
154 TreeTest_EnsureVisible,
155 TreeTest_AddItem,
156 TreeTest_IncIndent,
157 TreeTest_DecIndent,
158 TreeTest_IncSpacing,
159 TreeTest_DecSpacing,
160 TreeTest_Ctrl = 100
161 };