]> git.saurik.com Git - wxWidgets.git/blob - samples/treectrl/treetest.h
b08a795631eca5d4216f6fc74214402bdfefcc1d
[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
26 private:
27 wxString m_desc;
28 };
29
30 class MyTreeCtrl : public wxTreeCtrl
31 {
32 public:
33 enum
34 {
35 TreeCtrlIcon_File,
36 TreeCtrlIcon_Folder
37 };
38
39 MyTreeCtrl(wxWindow *parent, const wxWindowID id,
40 const wxPoint& pos, const wxSize& size,
41 long style);
42 virtual ~MyTreeCtrl();
43
44 void OnBeginDrag(wxTreeEvent& event);
45 void OnBeginRDrag(wxTreeEvent& event);
46 void OnBeginLabelEdit(wxTreeEvent& event);
47 void OnEndLabelEdit(wxTreeEvent& event);
48 void OnDeleteItem(wxTreeEvent& event);
49 void OnGetInfo(wxTreeEvent& event);
50 void OnSetInfo(wxTreeEvent& event);
51 void OnItemExpanded(wxTreeEvent& event);
52 void OnItemExpanding(wxTreeEvent& event);
53 void OnItemCollapsed(wxTreeEvent& event);
54 void OnItemCollapsing(wxTreeEvent& event);
55 void OnSelChanged(wxTreeEvent& event);
56 void OnSelChanging(wxTreeEvent& event);
57 void OnTreeKeyDown(wxTreeEvent& event);
58 void OnItemActivated(wxTreeEvent& event);
59
60 void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
61
62 void AddTestItemsToTree(size_t numChildren,
63 size_t depth);
64
65 void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE)
66 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
67
68 protected:
69 virtual int OnCompareItems(const wxTreeItemId& item1,
70 const wxTreeItemId& item2);
71
72 private:
73 void AddItemsRecursively(const wxTreeItemId& idParent,
74 size_t nChildren,
75 size_t depth,
76 size_t folder);
77
78 wxImageList *m_imageListNormal;
79 bool m_reverseSort; // flag for OnCompareItems
80
81 DECLARE_EVENT_TABLE()
82 };
83
84 // Define a new frame type
85 class MyFrame: public wxFrame
86 {
87 public:
88 // ctor and dtor
89 MyFrame(const wxString& title, int x, int y, int w, int h);
90 virtual ~MyFrame();
91
92 // menu callbacks
93 void OnQuit(wxCommandEvent& event);
94 void OnAbout(wxCommandEvent& event);
95 void OnDump(wxCommandEvent& event);
96 void OnDelete(wxCommandEvent& event);
97 void OnDeleteChildren(wxCommandEvent& event);
98 void OnDeleteAll(wxCommandEvent& event);
99 void OnRecreate(wxCommandEvent& event);
100
101 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
102 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
103
104 void OnRename(wxCommandEvent& event);
105 void OnSort(wxCommandEvent& event) { DoSort(); }
106 void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
107
108 private:
109 void DoSort(bool reverse = FALSE);
110
111 MyTreeCtrl *m_treeCtrl;
112
113 void DoSetBold(bool bold = TRUE);
114
115 DECLARE_EVENT_TABLE()
116 };
117
118 // menu and control ids
119 enum
120 {
121 TreeTest_Quit,
122 TreeTest_About,
123 TreeTest_Dump,
124 TreeTest_Sort,
125 TreeTest_SortRev,
126 TreeTest_Bold,
127 TreeTest_UnBold,
128 TreeTest_Rename,
129 TreeTest_Delete,
130 TreeTest_DeleteChildren,
131 TreeTest_DeleteAll,
132 TreeTest_Recreate,
133 TreeTest_Ctrl = 100
134 };
135
136 enum
137 {
138 TreeCtrlIcon_File,
139 TreeCtrlIcon_Folder
140 };