1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // Define a new application type
13 class MyApp
: public wxApp
19 class MyTreeItemData
: public wxTreeItemData
22 MyTreeItemData(const wxString
& desc
) : m_desc(desc
) { }
24 void ShowInfo(wxTreeCtrl
*tree
);
25 const char *GetDesc() const { return m_desc
.c_str(); }
31 class MyTreeCtrl
: public wxTreeCtrl
41 MyTreeCtrl(wxWindow
*parent
, const wxWindowID id
,
42 const wxPoint
& pos
, const wxSize
& size
,
44 virtual ~MyTreeCtrl();
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
);
63 void GetItemsRecursively(const wxTreeItemId
& idParent
, long cookie
);
65 void AddTestItemsToTree(size_t numChildren
, size_t depth
);
67 void DoSortChildren(const wxTreeItemId
& item
, bool reverse
= FALSE
)
68 { m_reverseSort
= reverse
; wxTreeCtrl::SortChildren(item
); }
69 void DoEnsureVisible() { EnsureVisible(m_lastItem
); }
71 void DoToggleIcon(const wxTreeItemId
& item
);
74 virtual int OnCompareItems(const wxTreeItemId
& i1
, const wxTreeItemId
& i2
);
76 // is this the test item which we use in several event handlers?
77 bool IsTestItem(const wxTreeItemId
& item
)
79 // the test item is the first child folder
80 return GetParent(item
) == GetRootItem() && !GetPrevSibling(item
);
84 void AddItemsRecursively(const wxTreeItemId
& idParent
,
89 wxImageList
*m_imageListNormal
;
90 bool m_reverseSort
; // flag for OnCompareItems
91 wxTreeItemId m_lastItem
; // for OnEnsureVisible()
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
)
101 // Define a new frame type
102 class MyFrame
: public wxFrame
106 MyFrame(const wxString
& title
, int x
, int y
, int w
, int h
);
110 void OnQuit(wxCommandEvent
& event
);
111 void OnAbout(wxCommandEvent
& event
);
113 void OnDump(wxCommandEvent
& event
);
114 #ifndef NO_MULTIPLE_SELECTION
115 void OnDumpSelected(wxCommandEvent
& event
);
116 void OnSelect(wxCommandEvent
& event
);
117 void OnUnselect(wxCommandEvent
& event
);
118 #endif // NO_MULTIPLE_SELECTION
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
);
125 void OnSetBold(wxCommandEvent
& WXUNUSED(event
)) { DoSetBold(TRUE
); }
126 void OnClearBold(wxCommandEvent
& WXUNUSED(event
)) { DoSetBold(FALSE
); }
128 void OnEnsureVisible(wxCommandEvent
& event
);
130 void OnRename(wxCommandEvent
& event
);
131 void OnSort(wxCommandEvent
& event
) { DoSort(); }
132 void OnSortRev(wxCommandEvent
& event
) { DoSort(TRUE
); }
134 void OnAddItem(wxCommandEvent
& event
);
136 void OnIncIndent(wxCommandEvent
& event
);
137 void OnDecIndent(wxCommandEvent
& event
);
139 void OnIncSpacing(wxCommandEvent
& event
);
140 void OnDecSpacing(wxCommandEvent
& event
);
142 void OnToggleIcon(wxCommandEvent
& event
);
145 void DoSort(bool reverse
= FALSE
);
147 MyTreeCtrl
*m_treeCtrl
;
149 void DoSetBold(bool bold
= TRUE
);
151 DECLARE_EVENT_TABLE()
154 // menu and control ids
160 TreeTest_DumpSelected
,
167 TreeTest_DeleteChildren
,
170 TreeTest_CollapseAndReset
,
171 TreeTest_EnsureVisible
,