]> git.saurik.com Git - wxWidgets.git/blame - samples/treectrl/treetest.h
Added testing code for PCX Handler (which is still not working
[wxWidgets.git] / samples / treectrl / treetest.h
CommitLineData
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
13class MyApp : public wxApp
14{
15public:
5f939e78 16 bool OnInit();
5a43154b 17};
457814b5 18
5a43154b
VZ
19class MyTreeItemData : public wxTreeItemData
20{
21public:
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
27private:
5f939e78 28 wxString m_desc;
457814b5
JS
29};
30
5a43154b 31class MyTreeCtrl : public wxTreeCtrl
457814b5
JS
32{
33public:
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)
9dfbf520 68 { m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
5f939e78 69 void DoEnsureVisible() { EnsureVisible(m_lastItem); }
e1ee62bd 70
9dfbf520
VZ
71 void DoToggleIcon(const wxTreeItemId& item);
72
e1ee62bd 73protected:
5f939e78 74 virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
e1ee62bd 75
5ea47806
VZ
76 // is this the test item which we use in several event handlers?
77 bool IsTestItem(const wxTreeItemId& item)
78 {
79 // the test item is the first child folder
80 return GetParent(item) == GetRootItem() && !GetPrevSibling(item);
81 }
82
5a43154b 83private:
5f939e78
VZ
84 void AddItemsRecursively(const wxTreeItemId& idParent,
85 size_t nChildren,
86 size_t depth,
87 size_t folder);
88
89 wxImageList *m_imageListNormal;
90 bool m_reverseSort; // flag for OnCompareItems
91 wxTreeItemId m_lastItem; // for OnEnsureVisible()
92
93 // NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
94 // if you want your overloaded OnCompareItems() to be called.
95 // OTOH, if you don't want it you may omit the next line - this will
96 // make default (alphabetical) sorting much faster under wxMSW.
97 DECLARE_DYNAMIC_CLASS(MyTreeCtrl)
98 DECLARE_EVENT_TABLE()
457814b5
JS
99};
100
101// Define a new frame type
102class MyFrame: public wxFrame
019bf128
UU
103{
104public:
5f939e78
VZ
105 // ctor and dtor
106 MyFrame(const wxString& title, int x, int y, int w, int h);
107 virtual ~MyFrame();
f135ff73 108
5f939e78
VZ
109 // menu callbacks
110 void OnQuit(wxCommandEvent& event);
111 void OnAbout(wxCommandEvent& event);
f135ff73 112
5f939e78 113 void OnDump(wxCommandEvent& event);
9dfbf520 114#ifndef NO_MULTIPLE_SELECTION
91b8de8d 115 void OnDumpSelected(wxCommandEvent& event);
9dfbf520
VZ
116 void OnSelect(wxCommandEvent& event);
117 void OnUnselect(wxCommandEvent& event);
118#endif // NO_MULTIPLE_SELECTION
5f939e78
VZ
119 void OnDelete(wxCommandEvent& event);
120 void OnDeleteChildren(wxCommandEvent& event);
121 void OnDeleteAll(wxCommandEvent& event);
122 void OnRecreate(wxCommandEvent& event);
123 void OnCollapseAndReset(wxCommandEvent& event);
add28c55 124
5f939e78
VZ
125 void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
126 void OnClearBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(FALSE); }
f65635b5 127
5f939e78
VZ
128 void OnEnsureVisible(wxCommandEvent& event);
129
130 void OnRename(wxCommandEvent& event);
131 void OnSort(wxCommandEvent& event) { DoSort(); }
132 void OnSortRev(wxCommandEvent& event) { DoSort(TRUE); }
133
134 void OnAddItem(wxCommandEvent& event);
9dfbf520 135
cf724bce
RR
136 void OnIncIndent(wxCommandEvent& event);
137 void OnDecIndent(wxCommandEvent& event);
138
139 void OnIncSpacing(wxCommandEvent& event);
140 void OnDecSpacing(wxCommandEvent& event);
e1ee62bd 141
9dfbf520
VZ
142 void OnToggleIcon(wxCommandEvent& event);
143
f135ff73 144private:
5f939e78 145 void DoSort(bool reverse = FALSE);
e1ee62bd 146
5f939e78 147 MyTreeCtrl *m_treeCtrl;
457814b5 148
5f939e78 149 void DoSetBold(bool bold = TRUE);
add28c55 150
5f939e78 151 DECLARE_EVENT_TABLE()
5a43154b 152};
457814b5 153
5a43154b
VZ
154// menu and control ids
155enum
156{
5f939e78
VZ
157 TreeTest_Quit,
158 TreeTest_About,
159 TreeTest_Dump,
9dfbf520 160 TreeTest_DumpSelected,
5f939e78
VZ
161 TreeTest_Sort,
162 TreeTest_SortRev,
163 TreeTest_Bold,
164 TreeTest_UnBold,
165 TreeTest_Rename,
166 TreeTest_Delete,
167 TreeTest_DeleteChildren,
168 TreeTest_DeleteAll,
169 TreeTest_Recreate,
170 TreeTest_CollapseAndReset,
171 TreeTest_EnsureVisible,
172 TreeTest_AddItem,
cf724bce
RR
173 TreeTest_IncIndent,
174 TreeTest_DecIndent,
175 TreeTest_IncSpacing,
176 TreeTest_DecSpacing,
9dfbf520
VZ
177 TreeTest_ToggleIcon,
178 TreeTest_Select,
179 TreeTest_Unselect,
180 TreeTest_Ctrl = 1000
f65635b5 181};