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