]> git.saurik.com Git - wxWidgets.git/blame - samples/treectrl/treetest.cpp
fix sizing of extra control
[wxWidgets.git] / samples / treectrl / treetest.cpp
CommitLineData
457814b5 1/////////////////////////////////////////////////////////////////////////////
ec312631 2// Name: treetest.cpp
457814b5
JS
3// Purpose: wxTreeCtrl sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
3a5a2f56 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
457814b5
JS
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
b2c82287 16 #pragma hdrstop
457814b5
JS
17#endif
18
19#ifndef WX_PRECOMP
b2c82287
WS
20 #include "wx/wx.h"
21 #include "wx/log.h"
457814b5
JS
22#endif
23
75cd9288 24#include "wx/colordlg.h"
e4f3eb42 25#include "wx/numdlg.h"
3a5a2f56 26
52734360 27#include "wx/artprov.h"
91b8de8d 28#include "wx/image.h"
3a5a2f56 29#include "wx/imaglist.h"
457814b5 30#include "wx/treectrl.h"
b713f891 31#include "wx/math.h"
4754ab16 32#include "wx/renderer.h"
cf724bce 33
2c8e4738
VZ
34#ifdef __WIN32__
35 // this is not supported by native control
7cc8c988 36 #define NO_VARIABLE_HEIGHT
74b31181 37#endif
91b8de8d 38
ec312631 39#include "treetest.h"
9dfbf520 40
6f4aae60
CE
41#include "icon1.xpm"
42#include "icon2.xpm"
43#include "icon3.xpm"
44#include "icon4.xpm"
45#include "icon5.xpm"
dacaa6f1 46
4754ab16
RR
47#include "state1.xpm"
48#include "state2.xpm"
49#include "state3.xpm"
50#include "state4.xpm"
51#include "state5.xpm"
52
b2c82287
WS
53#ifndef __WXMSW__
54 #include "../sample.xpm"
dacaa6f1 55#endif
6f4aae60 56
e1ee62bd 57// verify that the item is ok and insult the user if it is not
4693b20c
MB
58#define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
59 wxMessageBox(wxT("Please select some item first!"), \
60 wxT("Tree sample error"), \
61 wxOK | wxICON_EXCLAMATION, \
62 this); \
63 return; \
5f939e78
VZ
64 }
65
d88a2485
VZ
66#define MENU_LINK(name) EVT_MENU(TreeTest_##name, MyFrame::On##name)
67
457814b5 68BEGIN_EVENT_TABLE(MyFrame, wxFrame)
a67c5664 69 EVT_IDLE(MyFrame::OnIdle)
7cc8c988
VZ
70 EVT_SIZE(MyFrame::OnSize)
71
618a5e38
RR
72 MENU_LINK(Quit)
73 MENU_LINK(About)
f87a111f 74 MENU_LINK(ClearLog)
11ab1dfb 75
618a5e38
RR
76 MENU_LINK(TogButtons)
77 MENU_LINK(TogTwist)
78 MENU_LINK(TogLines)
79 MENU_LINK(TogEdit)
80 MENU_LINK(TogHideRoot)
81 MENU_LINK(TogRootLines)
82 MENU_LINK(TogBorder)
33984936 83 MENU_LINK(TogFullHighlight)
d88a2485
VZ
84 MENU_LINK(SetFgColour)
85 MENU_LINK(SetBgColour)
11ab1dfb
VZ
86 MENU_LINK(ResetStyle)
87
e525c4ff 88 MENU_LINK(Highlight)
618a5e38 89 MENU_LINK(Dump)
9dfbf520 90#ifndef NO_MULTIPLE_SELECTION
618a5e38
RR
91 MENU_LINK(DumpSelected)
92 MENU_LINK(Select)
93 MENU_LINK(Unselect)
94 MENU_LINK(ToggleSel)
9dfbf520 95#endif // NO_MULTIPLE_SELECTION
618a5e38
RR
96 MENU_LINK(Rename)
97 MENU_LINK(Count)
98 MENU_LINK(CountRec)
99 MENU_LINK(Sort)
100 MENU_LINK(SortRev)
101 MENU_LINK(SetBold)
102 MENU_LINK(ClearBold)
103 MENU_LINK(Delete)
104 MENU_LINK(DeleteChildren)
105 MENU_LINK(DeleteAll)
106 MENU_LINK(Recreate)
107 MENU_LINK(ToggleImages)
4754ab16 108 MENU_LINK(ToggleStates)
52734360 109 MENU_LINK(ToggleAlternateImages)
4754ab16 110 MENU_LINK(ToggleAlternateStates)
618a5e38
RR
111 MENU_LINK(ToggleButtons)
112 MENU_LINK(SetImageSize)
113 MENU_LINK(CollapseAndReset)
114 MENU_LINK(EnsureVisible)
115 MENU_LINK(AddItem)
116 MENU_LINK(InsertItem)
117 MENU_LINK(IncIndent)
118 MENU_LINK(DecIndent)
119 MENU_LINK(IncSpacing)
120 MENU_LINK(DecSpacing)
121 MENU_LINK(ToggleIcon)
4754ab16 122 MENU_LINK(ToggleState)
dc631754 123 MENU_LINK(SelectRoot)
f73eddd2
VZ
124
125 MENU_LINK(ShowFirstVisible)
126#ifdef wxHAS_LAST_VISIBLE
127 MENU_LINK(ShowLastVisible)
128#endif // wxHAS_LAST_VISIBLE
129 MENU_LINK(ShowNextVisible)
130 MENU_LINK(ShowPrevVisible)
618a5e38
RR
131#undef MENU_LINK
132
457814b5
JS
133END_EVENT_TABLE()
134
484523cf
JS
135#if USE_GENERIC_TREECTRL
136BEGIN_EVENT_TABLE(MyTreeCtrl, wxGenericTreeCtrl)
137#else
457814b5 138BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
484523cf 139#endif
5f939e78
VZ
140 EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginDrag)
141 EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl, MyTreeCtrl::OnBeginRDrag)
5888ef1e 142 EVT_TREE_END_DRAG(TreeTest_Ctrl, MyTreeCtrl::OnEndDrag)
5f939e78
VZ
143 EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnBeginLabelEdit)
144 EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl, MyTreeCtrl::OnEndLabelEdit)
145 EVT_TREE_DELETE_ITEM(TreeTest_Ctrl, MyTreeCtrl::OnDeleteItem)
74b31181 146#if 0 // there are so many of those that logging them causes flicker
5f939e78 147 EVT_TREE_GET_INFO(TreeTest_Ctrl, MyTreeCtrl::OnGetInfo)
74b31181 148#endif
5f939e78
VZ
149 EVT_TREE_SET_INFO(TreeTest_Ctrl, MyTreeCtrl::OnSetInfo)
150 EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanded)
151 EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding)
152 EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
153 EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
e3d0aa77 154
5f939e78
VZ
155 EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged)
156 EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging)
157 EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown)
158 EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated)
4754ab16 159 EVT_TREE_STATE_IMAGE_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemStateClick)
c545c230 160
f73eddd2 161 // so many different ways to handle right mouse button clicks...
5fd60e08 162 EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu)
9489a535
KH
163 // EVT_TREE_ITEM_MENU is the preferred event for creating context menus
164 // on a tree control, because it includes the point of the click or item,
165 // meaning that no additional placement calculations are required.
5fd60e08
VZ
166 EVT_TREE_ITEM_MENU(TreeTest_Ctrl, MyTreeCtrl::OnItemMenu)
167 EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRClick)
168
c545c230
VZ
169 EVT_RIGHT_DOWN(MyTreeCtrl::OnRMouseDown)
170 EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp)
5f939e78 171 EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick)
457814b5
JS
172END_EVENT_TABLE()
173
174IMPLEMENT_APP(MyApp)
175
c89a6106 176bool MyApp::OnInit()
457814b5 177{
45e6e6f8
VZ
178 if ( !wxApp::OnInit() )
179 return false;
180
5f939e78 181 // Create the main frame window
4693b20c 182 MyFrame *frame = new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
457814b5 183
5f939e78 184 // Show the frame
9013f513 185 frame->Show(true);
5f939e78 186 SetTopWindow(frame);
457814b5 187
9013f513 188 return true;
3a5a2f56 189}
457814b5 190
457814b5 191
3a5a2f56
VZ
192// My frame constructor
193MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
9013f513 194 : wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
b29903d4
WS
195 m_treeCtrl(NULL)
196#if wxUSE_LOG
197 , m_textCtrl(NULL)
198#endif // wxUSE_LOG
3a5a2f56 199{
5f939e78
VZ
200 // This reduces flicker effects - even better would be to define
201 // OnEraseBackground to do nothing. When the tree control's scrollbars are
202 // show or hidden, the frame is sent a background erase event.
203 SetBackgroundColour(wxColour(255, 255, 255));
204
205 // Give it an icon
b2c82287 206 SetIcon(wxICON(sample));
5f939e78 207
801bb685 208#if wxUSE_MENUS
5f939e78
VZ
209 // Make a menubar
210 wxMenu *file_menu = new wxMenu,
618a5e38 211 *style_menu = new wxMenu,
5f939e78
VZ
212 *tree_menu = new wxMenu,
213 *item_menu = new wxMenu;
214
f87a111f
VZ
215 file_menu->Append(TreeTest_ClearLog, wxT("&Clear log\tCtrl-L"));
216 file_menu->AppendSeparator();
4693b20c 217 file_menu->Append(TreeTest_About, wxT("&About..."));
5f939e78 218 file_menu->AppendSeparator();
4693b20c 219 file_menu->Append(TreeTest_Quit, wxT("E&xit\tAlt-X"));
5f939e78 220
2153bf89
DS
221 style_menu->AppendCheckItem(TreeTest_TogButtons, wxT("Toggle &normal buttons"));
222 style_menu->AppendCheckItem(TreeTest_TogTwist, wxT("Toggle &twister buttons"));
223 style_menu->AppendCheckItem(TreeTest_ToggleButtons, wxT("Toggle image &buttons"));
618a5e38 224 style_menu->AppendSeparator();
2153bf89
DS
225 style_menu->AppendCheckItem(TreeTest_TogLines, wxT("Toggle &connecting lines"));
226 style_menu->AppendCheckItem(TreeTest_TogRootLines, wxT("Toggle &lines at root"));
227 style_menu->AppendCheckItem(TreeTest_TogHideRoot, wxT("Toggle &hidden root"));
228 style_menu->AppendCheckItem(TreeTest_TogBorder, wxT("Toggle &item border"));
229 style_menu->AppendCheckItem(TreeTest_TogFullHighlight, wxT("Toggle &full row highlight"));
230 style_menu->AppendCheckItem(TreeTest_TogEdit, wxT("Toggle &edit mode"));
7cc8c988 231#ifndef NO_MULTIPLE_SELECTION
f87a111f 232 style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode\tCtrl-S"));
7cc8c988 233#endif // NO_MULTIPLE_SELECTION
2153bf89 234 style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
4754ab16 235 style_menu->AppendCheckItem(TreeTest_ToggleStates, wxT("Toggle show st&ates"));
52734360 236 style_menu->AppendCheckItem(TreeTest_ToggleAlternateImages, wxT("Toggle alternate images"));
4754ab16 237 style_menu->AppendCheckItem(TreeTest_ToggleAlternateStates, wxT("Toggle alternate state images"));
4693b20c 238 style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze..."));
d88a2485
VZ
239 style_menu->AppendSeparator();
240 style_menu->Append(TreeTest_SetFgColour, wxT("Set &foreground colour..."));
241 style_menu->Append(TreeTest_SetBgColour, wxT("Set &background colour..."));
11ab1dfb
VZ
242 style_menu->AppendSeparator();
243 style_menu->Append(TreeTest_ResetStyle, wxT("&Reset to default\tF10"));
618a5e38 244
3acd4349
VS
245 tree_menu->Append(TreeTest_Recreate, wxT("&Recreate the tree"));
246 tree_menu->Append(TreeTest_CollapseAndReset, wxT("C&ollapse and reset"));
5f939e78 247 tree_menu->AppendSeparator();
3acd4349
VS
248 tree_menu->Append(TreeTest_AddItem, wxT("Append a &new item"));
249 tree_menu->Append(TreeTest_InsertItem, wxT("&Insert a new item"));
250 tree_menu->Append(TreeTest_Delete, wxT("&Delete this item"));
251 tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
252 tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
dc631754 253 tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
5f939e78 254 tree_menu->AppendSeparator();
3acd4349
VS
255 tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
256 tree_menu->Append(TreeTest_CountRec, wxT("Recursively count children of current item"));
5fd11f09 257 tree_menu->AppendSeparator();
3acd4349
VS
258 tree_menu->Append(TreeTest_Sort, wxT("Sort children of current item"));
259 tree_menu->Append(TreeTest_SortRev, wxT("Sort in reversed order"));
5f939e78 260 tree_menu->AppendSeparator();
3acd4349 261 tree_menu->Append(TreeTest_EnsureVisible, wxT("Make the last item &visible"));
cf724bce 262 tree_menu->AppendSeparator();
3acd4349
VS
263 tree_menu->Append(TreeTest_IncIndent, wxT("Add 5 points to indentation\tAlt-I"));
264 tree_menu->Append(TreeTest_DecIndent, wxT("Reduce indentation by 5 points\tAlt-R"));
cf724bce 265 tree_menu->AppendSeparator();
3acd4349
VS
266 tree_menu->Append(TreeTest_IncSpacing, wxT("Add 5 points to spacing\tCtrl-I"));
267 tree_menu->Append(TreeTest_DecSpacing, wxT("Reduce spacing by 5 points\tCtrl-R"));
5f939e78 268
3acd4349
VS
269 item_menu->Append(TreeTest_Dump, wxT("&Dump item children"));
270 item_menu->Append(TreeTest_Rename, wxT("&Rename item..."));
91b8de8d 271
5f939e78 272 item_menu->AppendSeparator();
3acd4349
VS
273 item_menu->Append(TreeTest_SetBold, wxT("Make item &bold"));
274 item_menu->Append(TreeTest_ClearBold, wxT("Make item &not bold"));
9dfbf520 275 item_menu->AppendSeparator();
3acd4349 276 item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon"));
4754ab16 277 item_menu->Append(TreeTest_ToggleState, wxT("Toggle the item's &state"));
f73eddd2
VZ
278 item_menu->AppendSeparator();
279 item_menu->Append(TreeTest_ShowFirstVisible, wxT("Show &first visible"));
280#ifdef wxHAS_LAST_VISIBLE
281 item_menu->Append(TreeTest_ShowLastVisible, wxT("Show &last visible"));
282#endif // wxHAS_LAST_VISIBLE
283 item_menu->Append(TreeTest_ShowNextVisible, wxT("Show &next visible"));
284 item_menu->Append(TreeTest_ShowPrevVisible, wxT("Show &previous visible"));
9dfbf520
VZ
285
286#ifndef NO_MULTIPLE_SELECTION
287 item_menu->AppendSeparator();
3acd4349
VS
288 item_menu->Append(TreeTest_DumpSelected, wxT("Dump selected items\tAlt-D"));
289 item_menu->Append(TreeTest_Select, wxT("Select current item\tAlt-S"));
290 item_menu->Append(TreeTest_Unselect, wxT("Unselect everything\tAlt-U"));
7cc8c988 291#endif // NO_MULTIPLE_SELECTION
5f939e78
VZ
292
293 wxMenuBar *menu_bar = new wxMenuBar;
3acd4349
VS
294 menu_bar->Append(file_menu, wxT("&File"));
295 menu_bar->Append(style_menu, wxT("&Style"));
296 menu_bar->Append(tree_menu, wxT("&Tree"));
297 menu_bar->Append(item_menu, wxT("&Item"));
5f939e78 298 SetMenuBar(menu_bar);
801bb685 299#endif // wxUSE_MENUS
2c8e4738 300
998cee67
VZ
301 m_panel = new wxPanel(this);
302
b29903d4 303#if wxUSE_LOG
11ab1dfb 304 // create the controls
998cee67 305 m_textCtrl = new wxTextCtrl(m_panel, wxID_ANY, wxT(""),
5f939e78
VZ
306 wxDefaultPosition, wxDefaultSize,
307 wxTE_MULTILINE | wxSUNKEN_BORDER);
b29903d4 308#endif // wxUSE_LOG
5f939e78 309
11ab1dfb
VZ
310 CreateTreeWithDefStyle();
311
9013f513 312 menu_bar->Check(TreeTest_ToggleImages, true);
4754ab16 313 menu_bar->Check(TreeTest_ToggleStates, true);
52734360 314 menu_bar->Check(TreeTest_ToggleAlternateImages, false);
4754ab16 315 menu_bar->Check(TreeTest_ToggleAlternateStates, false);
11ab1dfb 316
a67c5664
VZ
317#if wxUSE_STATUSBAR
318 // create a status bar
319 CreateStatusBar(2);
320#endif // wxUSE_STATUSBAR
3a5a2f56 321
b29903d4 322#if wxUSE_LOG
a367b9b3 323#ifdef __WXMOTIF__
5f939e78
VZ
324 // For some reason, we get a memcpy crash in wxLogStream::DoLogStream
325 // on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
326 delete wxLog::SetActiveTarget(new wxLogStderr);
a367b9b3 327#else
5f939e78 328 // set our text control as the log target
7cc8c988 329 wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
5f939e78 330 delete wxLog::SetActiveTarget(logWindow);
a367b9b3 331#endif
b29903d4 332#endif // wxUSE_LOG
457814b5
JS
333}
334
c89a6106 335MyFrame::~MyFrame()
457814b5 336{
b29903d4 337#if wxUSE_LOG
5f939e78 338 delete wxLog::SetActiveTarget(NULL);
b29903d4 339#endif // wxUSE_LOG
457814b5
JS
340}
341
11ab1dfb
VZ
342void MyFrame::CreateTreeWithDefStyle()
343{
344 long style = wxTR_DEFAULT_STYLE |
345#ifndef NO_VARIABLE_HEIGHT
346 wxTR_HAS_VARIABLE_ROW_HEIGHT |
347#endif
348 wxTR_EDIT_LABELS;
349
350 CreateTree(style | wxSUNKEN_BORDER);
351
352 // as we don't know what wxTR_DEFAULT_STYLE could contain, test for
353 // everything
354 wxMenuBar *mbar = GetMenuBar();
355 mbar->Check(TreeTest_TogButtons, (style & wxTR_HAS_BUTTONS) != 0);
356 mbar->Check(TreeTest_TogButtons, (style & wxTR_TWIST_BUTTONS) != 0);
357 mbar->Check(TreeTest_TogLines, (style & wxTR_NO_LINES) == 0);
358 mbar->Check(TreeTest_TogRootLines, (style & wxTR_LINES_AT_ROOT) != 0);
359 mbar->Check(TreeTest_TogHideRoot, (style & wxTR_HIDE_ROOT) != 0);
360 mbar->Check(TreeTest_TogEdit, (style & wxTR_EDIT_LABELS) != 0);
361 mbar->Check(TreeTest_TogBorder, (style & wxTR_ROW_LINES) != 0);
362 mbar->Check(TreeTest_TogFullHighlight, (style & wxTR_FULL_ROW_HIGHLIGHT) != 0);
363}
364
365void MyFrame::CreateTree(long style)
366{
998cee67 367 m_treeCtrl = new MyTreeCtrl(m_panel, TreeTest_Ctrl,
11ab1dfb
VZ
368 wxDefaultPosition, wxDefaultSize,
369 style);
c6a6bbbf
VZ
370
371 GetMenuBar()->Enable(TreeTest_SelectRoot, !(style & wxTR_HIDE_ROOT));
372
11ab1dfb
VZ
373 Resize();
374}
375
376void MyFrame::TogStyle(int id, long flag)
618a5e38 377{
11ab1dfb
VZ
378 long style = m_treeCtrl->GetWindowStyle() ^ flag;
379
380 // most treectrl styles can't be changed on the fly using the native
381 // control and the tree must be recreated
382#ifndef __WXMSW__
383 m_treeCtrl->SetWindowStyle(style);
384#else // MSW
385 delete m_treeCtrl;
386 CreateTree(style);
387#endif // !MSW/MSW
388
389 GetMenuBar()->Check(id, (style & flag) != 0);
618a5e38
RR
390}
391
a67c5664
VZ
392void MyFrame::OnIdle(wxIdleEvent& event)
393{
394#if wxUSE_STATUSBAR
e4a8a172
VZ
395 if ( m_treeCtrl )
396 {
397 wxTreeItemId idRoot = m_treeCtrl->GetRootItem();
98123913
PC
398 wxString status;
399 if (idRoot.IsOk())
400 {
401 wxTreeItemId idLast = m_treeCtrl->GetLastChild(idRoot);
402 status = wxString::Format(
403 _T("Root/last item is %svisible/%svisible"),
404 m_treeCtrl->IsVisible(idRoot) ? _T("") : _T("not "),
405 idLast.IsOk() && m_treeCtrl->IsVisible(idLast)
406 ? _T("") : _T("not "));
407 }
408 else
409 status = _T("No root item");
410
411 SetStatusText(status, 1);
e4a8a172 412 }
a67c5664
VZ
413#endif // wxUSE_STATUSBAR
414
415 event.Skip();
416}
417
7cc8c988
VZ
418void MyFrame::OnSize(wxSizeEvent& event)
419{
925e9792 420 if ( m_treeCtrl
b29903d4 421#if wxUSE_LOG
925e9792 422 && m_textCtrl
b29903d4
WS
423#endif // wxUSE_LOG
424 )
7cc8c988 425 {
11ab1dfb 426 Resize();
7cc8c988
VZ
427 }
428
429 event.Skip();
430}
431
11ab1dfb 432void MyFrame::Resize()
7cc8c988 433{
11ab1dfb 434 wxSize size = GetClientSize();
b29903d4 435 m_treeCtrl->SetSize(0, 0, size.x, size.y
f87a111f 436#if wxUSE_LOG
b29903d4 437 *2/3);
f87a111f 438 m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3
b29903d4 439#endif
f87a111f 440 );
7cc8c988
VZ
441}
442
3a5a2f56 443void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 444{
9013f513 445 Close(true);
457814b5
JS
446}
447
3a5a2f56 448void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
457814b5 449{
3acd4349
VS
450 wxMessageBox(wxT("Tree test sample\n")
451 wxT("(c) Julian Smart 1997, Vadim Zeitlin 1998"),
452 wxT("About tree test"),
5f939e78 453 wxOK | wxICON_INFORMATION, this);
e1ee62bd
VZ
454}
455
f87a111f
VZ
456void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
457{
458 m_textCtrl->Clear();
459}
460
e1ee62bd
VZ
461void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
462{
5f939e78 463 wxTreeItemId item = m_treeCtrl->GetSelection();
e1ee62bd 464
5f939e78 465 CHECK_ITEM( item );
e1ee62bd 466
5ea47806
VZ
467 // old code - now we edit in place
468#if 0
5f939e78 469 static wxString s_text;
3acd4349 470 s_text = wxGetTextFromUser(wxT("New name: "), wxT("Tree sample question"),
5f939e78 471 s_text, this);
b713f891 472 if ( !s_text.empty() )
5f939e78
VZ
473 {
474 m_treeCtrl->SetItemText(item, s_text);
475 }
5ea47806
VZ
476#endif // 0
477
478 // TODO demonstrate creating a custom edit control...
479 (void)m_treeCtrl->EditLabel(item);
e1ee62bd
VZ
480}
481
5fd11f09
RR
482void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event))
483{
484 wxTreeItemId item = m_treeCtrl->GetSelection();
485
486 CHECK_ITEM( item );
487
9013f513 488 int i = m_treeCtrl->GetChildrenCount( item, false );
75c74ca0 489
247e5b16 490 wxLogMessage(wxT("%d children"), i);
5fd11f09
RR
491}
492
493void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event))
494{
495 wxTreeItemId item = m_treeCtrl->GetSelection();
496
497 CHECK_ITEM( item );
498
499 int i = m_treeCtrl->GetChildrenCount( item );
75c74ca0 500
247e5b16 501 wxLogMessage(wxT("%d children"), i);
5fd11f09
RR
502}
503
e1ee62bd
VZ
504void MyFrame::DoSort(bool reverse)
505{
5f939e78 506 wxTreeItemId item = m_treeCtrl->GetSelection();
e1ee62bd 507
5f939e78 508 CHECK_ITEM( item );
457814b5 509
5f939e78 510 m_treeCtrl->DoSortChildren(item, reverse);
457814b5
JS
511}
512
e525c4ff
VZ
513void MyFrame::OnHighlight(wxCommandEvent& WXUNUSED(event))
514{
515 wxTreeItemId id = m_treeCtrl->GetSelection();
516
517 CHECK_ITEM( id );
518
519 wxRect r;
520 if ( !m_treeCtrl->GetBoundingRect(id, r, true /* text, not full row */) )
521 {
522 wxLogMessage(_T("Failed to get bounding item rect"));
523 return;
524 }
525
526 wxClientDC dc(m_treeCtrl);
527 dc.SetBrush(*wxRED);
528 dc.SetPen(*wxTRANSPARENT_PEN);
529 dc.DrawRectangle(r);
530 m_treeCtrl->Update();
531}
532
4832f7c0
VZ
533void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
534{
5f939e78 535 wxTreeItemId root = m_treeCtrl->GetSelection();
e1ee62bd 536
5f939e78 537 CHECK_ITEM( root );
e1ee62bd 538
2d75caaa 539 m_treeCtrl->GetItemsRecursively(root);
4832f7c0
VZ
540}
541
9dfbf520
VZ
542#ifndef NO_MULTIPLE_SELECTION
543
11ab1dfb 544void MyFrame::OnToggleSel(wxCommandEvent& event)
7cc8c988 545{
11ab1dfb 546 TogStyle(event.GetId(), wxTR_MULTIPLE);
7cc8c988
VZ
547}
548
91b8de8d
RR
549void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
550{
9dfbf520 551 wxArrayTreeItemIds array;
91b8de8d 552
9dfbf520 553 size_t count = m_treeCtrl->GetSelections(array);
b143cf70 554 wxLogMessage(wxT("%u items selected"), unsigned(count));
91b8de8d 555
9dfbf520
VZ
556 for ( size_t n = 0; n < count; n++ )
557 {
4693b20c 558 wxLogMessage(wxT("\t%s"), m_treeCtrl->GetItemText(array.Item(n)).c_str());
9dfbf520
VZ
559 }
560}
561
256b8649 562void MyFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
9dfbf520
VZ
563{
564 m_treeCtrl->SelectItem(m_treeCtrl->GetSelection());
565}
566
dc631754
VZ
567void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event))
568{
c6a6bbbf
VZ
569 if ( !m_treeCtrl->HasFlag(wxTR_HIDE_ROOT) )
570 m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
dc631754
VZ
571}
572
256b8649 573void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
9dfbf520
VZ
574{
575 m_treeCtrl->UnselectAll();
91b8de8d
RR
576}
577
9dfbf520
VZ
578#endif // NO_MULTIPLE_SELECTION
579
add28c55
VZ
580void MyFrame::DoSetBold(bool bold)
581{
5f939e78 582 wxTreeItemId item = m_treeCtrl->GetSelection();
e1ee62bd 583
5f939e78 584 CHECK_ITEM( item );
e1ee62bd 585
5f939e78 586 m_treeCtrl->SetItemBold(item, bold);
add28c55
VZ
587}
588
ff5bf259
VZ
589void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
590{
5f939e78 591 wxTreeItemId item = m_treeCtrl->GetSelection();
e1ee62bd 592
5f939e78 593 CHECK_ITEM( item );
e1ee62bd 594
5f939e78 595 m_treeCtrl->Delete(item);
ff5bf259
VZ
596}
597
372edb9d
VZ
598void MyFrame::OnDeleteChildren(wxCommandEvent& WXUNUSED(event))
599{
5f939e78 600 wxTreeItemId item = m_treeCtrl->GetSelection();
e1ee62bd 601
5f939e78 602 CHECK_ITEM( item );
e1ee62bd 603
5f939e78 604 m_treeCtrl->DeleteChildren(item);
372edb9d
VZ
605}
606
ff5bf259
VZ
607void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
608{
5f939e78 609 m_treeCtrl->DeleteAllItems();
ff5bf259
VZ
610}
611
612void MyFrame::OnRecreate(wxCommandEvent& event)
613{
5f939e78 614 OnDeleteAll(event);
618a5e38 615 m_treeCtrl->AddTestItemsToTree(5, 2);
ff5bf259
VZ
616}
617
256b8649 618void MyFrame::OnSetImageSize(wxCommandEvent& WXUNUSED(event))
2c8e4738 619{
3acd4349
VS
620 int size = wxGetNumberFromUser(wxT("Enter the size for the images to use"),
621 wxT("Size: "),
622 wxT("TreeCtrl sample"),
618a5e38 623 m_treeCtrl->ImageSize());
2c8e4738
VZ
624 if ( size == -1 )
625 return;
626
618a5e38 627 m_treeCtrl->CreateImageList(size);
9013f513 628 wxGetApp().SetShowImages(true);
2c8e4738
VZ
629}
630
256b8649 631void MyFrame::OnToggleImages(wxCommandEvent& WXUNUSED(event))
2c8e4738 632{
f6bcfd97
BP
633 if ( wxGetApp().ShowImages() )
634 {
635 m_treeCtrl->CreateImageList(-1);
9013f513 636 wxGetApp().SetShowImages(false);
f6bcfd97
BP
637 }
638 else
639 {
618a5e38 640 m_treeCtrl->CreateImageList(0);
9013f513 641 wxGetApp().SetShowImages(true);
f6bcfd97 642 }
618a5e38 643}
2c8e4738 644
4754ab16
RR
645void MyFrame::OnToggleStates(wxCommandEvent& WXUNUSED(event))
646{
647 if ( wxGetApp().ShowStates() )
648 {
649 m_treeCtrl->CreateStateImageList(true);
650 wxGetApp().SetShowStates(false);
651 }
652 else
653 {
654 m_treeCtrl->CreateStateImageList(false);
655 wxGetApp().SetShowStates(true);
656 }
657}
658
52734360
VZ
659void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event))
660{
661 bool alternateImages = m_treeCtrl->AlternateImages();
662
663 m_treeCtrl->SetAlternateImages(!alternateImages);
664 m_treeCtrl->CreateImageList(0);
665}
666
4754ab16
RR
667void MyFrame::OnToggleAlternateStates(wxCommandEvent& WXUNUSED(event))
668{
669 bool alternateStates = m_treeCtrl->AlternateStates();
670
671 m_treeCtrl->SetAlternateStates(!alternateStates);
672 m_treeCtrl->CreateStateImageList();
673}
674
256b8649 675void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event))
618a5e38 676{
a3e377a3 677#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
618a5e38
RR
678 if ( wxGetApp().ShowButtons() )
679 {
680 m_treeCtrl->CreateButtonsImageList(-1);
9013f513 681 wxGetApp().SetShowButtons(false);
618a5e38
RR
682 }
683 else
684 {
685 m_treeCtrl->CreateButtonsImageList(15);
9013f513 686 wxGetApp().SetShowButtons(true);
618a5e38 687 }
a3e377a3 688#endif
2c8e4738
VZ
689}
690
256b8649 691void MyFrame::OnCollapseAndReset(wxCommandEvent& WXUNUSED(event))
dd3646fd 692{
5f939e78 693 m_treeCtrl->CollapseAndReset(m_treeCtrl->GetRootItem());
dd3646fd
VZ
694}
695
256b8649 696void MyFrame::OnEnsureVisible(wxCommandEvent& WXUNUSED(event))
f65635b5
VZ
697{
698 m_treeCtrl->DoEnsureVisible();
699}
700
75c74ca0
VZ
701void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
702{
2c8e4738 703 int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File : -1;
3acd4349 704 m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), image, wxT("2nd item"));
75c74ca0
VZ
705}
706
5f939e78
VZ
707void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
708{
709 static int s_num = 0;
710
711 wxString text;
4693b20c 712 text.Printf(wxT("Item #%d"), ++s_num);
5f939e78
VZ
713
714 m_treeCtrl->AppendItem(m_treeCtrl->GetRootItem(),
112c5086
RR
715 text /*,
716 MyTreeCtrl::TreeCtrlIcon_File */ );
5f939e78
VZ
717}
718
cf724bce
RR
719void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
720{
721 unsigned int indent = m_treeCtrl->GetIndent();
722 if (indent < 100)
723 m_treeCtrl->SetIndent( indent+5 );
724}
725
726void MyFrame::OnDecIndent(wxCommandEvent& WXUNUSED(event))
727{
728 unsigned int indent = m_treeCtrl->GetIndent();
729 if (indent > 10)
730 m_treeCtrl->SetIndent( indent-5 );
731}
732
733void MyFrame::OnIncSpacing(wxCommandEvent& WXUNUSED(event))
734{
735 unsigned int indent = m_treeCtrl->GetSpacing();
736 if (indent < 100)
737 m_treeCtrl->SetSpacing( indent+5 );
738}
739
740void MyFrame::OnDecSpacing(wxCommandEvent& WXUNUSED(event))
741{
742 unsigned int indent = m_treeCtrl->GetSpacing();
743 if (indent > 10)
744 m_treeCtrl->SetSpacing( indent-5 );
745}
746
9dfbf520
VZ
747void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event))
748{
749 wxTreeItemId item = m_treeCtrl->GetSelection();
750
751 CHECK_ITEM( item );
752
753 m_treeCtrl->DoToggleIcon(item);
754}
755
4754ab16
RR
756void MyFrame::OnToggleState(wxCommandEvent& WXUNUSED(event))
757{
758 wxTreeItemId item = m_treeCtrl->GetSelection();
759
760 CHECK_ITEM( item );
761
762 m_treeCtrl->DoToggleState(item);
763}
764
f73eddd2
VZ
765void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label)
766{
767 const wxTreeItemId item = (m_treeCtrl->*pfn)();
768
769 if ( !item.IsOk() )
770 wxLogMessage("There is no %s item", label);
771 else
772 wxLogMessage("The %s item is \"%s\"",
773 label, m_treeCtrl->GetItemText(item));
774}
775
776void MyFrame::DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label)
777{
778 wxTreeItemId item = m_treeCtrl->GetSelection();
779
780 CHECK_ITEM( item );
781
782 if ( !m_treeCtrl->IsVisible(item) )
783 {
784 wxLogMessage("The selected item must be visible.");
785 return;
786 }
787
788 item = (m_treeCtrl->*pfn)(item);
789
790 if ( !item.IsOk() )
791 wxLogMessage("There is no %s item", label);
792 else
793 wxLogMessage("The %s item is \"%s\"",
794 label, m_treeCtrl->GetItemText(item));
795}
796
d88a2485
VZ
797void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
798{
799 wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour());
800 if ( col.Ok() )
801 m_treeCtrl->SetForegroundColour(col);
802}
803
804void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
805{
806 wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetBackgroundColour());
807 if ( col.Ok() )
808 m_treeCtrl->SetBackgroundColour(col);
809}
810
3a5a2f56 811// MyTreeCtrl implementation
484523cf
JS
812#if USE_GENERIC_TREECTRL
813IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxGenericTreeCtrl)
814#else
23fd5130 815IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl, wxTreeCtrl)
484523cf 816#endif
23fd5130 817
3a5a2f56
VZ
818MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
819 const wxPoint& pos, const wxSize& size,
820 long style)
52734360 821 : wxTreeCtrl(parent, id, pos, size, style),
4754ab16
RR
822 m_alternateImages(false),
823 m_alternateStates(false)
457814b5 824{
9013f513 825 m_reverseSort = false;
91b8de8d 826
2c8e4738 827 CreateImageList();
4754ab16 828 CreateStateImageList();
91b8de8d 829
2c8e4738 830 // Add some items to the tree
618a5e38 831 AddTestItemsToTree(5, 2);
2c8e4738
VZ
832}
833
834void MyTreeCtrl::CreateImageList(int size)
835{
2c8e4738
VZ
836 if ( size == -1 )
837 {
618a5e38
RR
838 SetImageList(NULL);
839 return;
2c8e4738 840 }
618a5e38
RR
841 if ( size == 0 )
842 size = m_imageSize;
f6bcfd97 843 else
618a5e38
RR
844 m_imageSize = size;
845
846 // Make an image list containing small icons
9013f513 847 wxImageList *images = new wxImageList(size, size, true);
e1ee62bd 848
618a5e38 849 // should correspond to TreeCtrlIcon_xxx enum
618a5e38
RR
850 wxBusyCursor wait;
851 wxIcon icons[5];
618a5e38 852
52734360
VZ
853 if (m_alternateImages)
854 {
855 icons[TreeCtrlIcon_File] = wxIcon(icon1_xpm);
856 icons[TreeCtrlIcon_FileSelected] = wxIcon(icon2_xpm);
857 icons[TreeCtrlIcon_Folder] = wxIcon(icon3_xpm);
858 icons[TreeCtrlIcon_FolderSelected] = wxIcon(icon4_xpm);
859 icons[TreeCtrlIcon_FolderOpened] = wxIcon(icon5_xpm);
860 }
861 else
862 {
863 wxSize iconSize(size, size);
864
865 icons[TreeCtrlIcon_File] =
866 icons[TreeCtrlIcon_FileSelected] = wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_LIST, iconSize);
867 icons[TreeCtrlIcon_Folder] =
868 icons[TreeCtrlIcon_FolderSelected] =
869 icons[TreeCtrlIcon_FolderOpened] = wxArtProvider::GetIcon(wxART_FOLDER, wxART_LIST, iconSize);
870 }
871
618a5e38
RR
872 for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
873 {
52734360 874 int sizeOrig = icons[0].GetWidth();
618a5e38 875 if ( size == sizeOrig )
2c8e4738 876 {
618a5e38 877 images->Add(icons[i]);
2c8e4738 878 }
618a5e38
RR
879 else
880 {
9f24e0b5 881 images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
618a5e38
RR
882 }
883 }
618a5e38
RR
884
885 AssignImageList(images);
886}
887
4754ab16
RR
888void MyTreeCtrl::CreateStateImageList(bool del)
889{
890 if ( del )
891 {
892 SetStateImageList(NULL);
893 return;
894 }
895
896 wxImageList *states;
897 wxBusyCursor wait;
898
899 if (m_alternateStates)
900 {
901 wxIcon icons[5];
902 icons[0] = wxIcon(state1_xpm); // yellow
903 icons[1] = wxIcon(state2_xpm); // green
904 icons[2] = wxIcon(state3_xpm); // red
905 icons[3] = wxIcon(state4_xpm); // blue
906 icons[4] = wxIcon(state5_xpm); // black
907
908 int width = icons[0].GetWidth(),
909 height = icons[0].GetHeight();
910
911 // Make an state image list containing small icons
912 states = new wxImageList(width, height, true);
913
914 for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
915 states->Add(icons[i]);
916 }
917 else
918 {
f95dc4d6 919#if 0
4754ab16
RR
920 int width = ::GetSystemMetrics(SM_CXMENUCHECK),
921 height = ::GetSystemMetrics(SM_CYMENUCHECK);
f95dc4d6
RR
922#else
923 int width = 16;
924 int height = 16;
925#endif
4754ab16
RR
926
927 // make an state checkbox image list
928 states = new wxImageList(width, height, true);
929
930 wxBitmap checkBmp(width, height);
931 wxRect rect (0, 0, width, height);
932
933 wxRendererNative& renderer = wxRendererNative::Get();
934
935 // create no checked image
936 {
937 // first create bitmap in a memory DC
938 wxMemoryDC memDC(checkBmp);
f95dc4d6 939 memDC.Clear();
4754ab16
RR
940 // then draw a check mark into it
941 renderer.DrawCheckBox(this, memDC, rect, 0);
942 } // select checkBmp out of memDC
943
944 states->Add(checkBmp);
945
946 // create checked image
947 {
948 wxMemoryDC memDC(checkBmp);
949 renderer.DrawCheckBox(this, memDC, rect, wxCONTROL_CHECKED);
950 }
951
952 states->Add(checkBmp);
953 }
954
955 AssignStateImageList(states);
956}
957
256b8649 958#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
618a5e38
RR
959void MyTreeCtrl::CreateButtonsImageList(int size)
960{
961 if ( size == -1 )
962 {
963 SetButtonsImageList(NULL);
964 return;
965 }
966
967 // Make an image list containing small icons
9013f513 968 wxImageList *images = new wxImageList(size, size, true);
618a5e38
RR
969
970 // should correspond to TreeCtrlIcon_xxx enum
618a5e38
RR
971 wxBusyCursor wait;
972 wxIcon icons[4];
618a5e38 973
52734360
VZ
974 if (m_alternateImages)
975 {
976 icons[0] = wxIcon(icon3_xpm); // closed
977 icons[1] = wxIcon(icon3_xpm); // closed, selected
978 icons[2] = wxIcon(icon5_xpm); // open
979 icons[3] = wxIcon(icon5_xpm); // open, selected
980 }
981 else
982 {
983 wxSize iconSize(size, size);
984
985 icons[0] = // closed
986 icons[1] = wxArtProvider::GetIcon(wxART_FOLDER, wxART_LIST, iconSize); // closed, selected
987 icons[2] = // open
988 icons[3] = wxArtProvider::GetIcon(wxART_FOLDER_OPEN, wxART_LIST, iconSize);// open, selected
989 }
990
991 for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
618a5e38
RR
992 {
993 int sizeOrig = icons[i].GetWidth();
994 if ( size == sizeOrig )
995 {
996 images->Add(icons[i]);
997 }
998 else
999 {
8dda7c0c 1000 images->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
618a5e38 1001 }
2c8e4738 1002 }
457814b5 1003
618a5e38 1004 AssignButtonsImageList(images);
256b8649
JS
1005#else
1006void MyTreeCtrl::CreateButtonsImageList(int WXUNUSED(size))
1007{
a3e377a3 1008#endif
457814b5
JS
1009}
1010
e1ee62bd
VZ
1011int MyTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
1012 const wxTreeItemId& item2)
1013{
5f939e78
VZ
1014 if ( m_reverseSort )
1015 {
1016 // just exchange 1st and 2nd items
1017 return wxTreeCtrl::OnCompareItems(item2, item1);
1018 }
1019 else
1020 {
1021 return wxTreeCtrl::OnCompareItems(item1, item2);
1022 }
e1ee62bd
VZ
1023}
1024
3a5a2f56
VZ
1025void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
1026 size_t numChildren,
4832f7c0
VZ
1027 size_t depth,
1028 size_t folder)
457814b5 1029{
f65635b5 1030 if ( depth > 0 )
3a5a2f56 1031 {
74b31181
VZ
1032 bool hasChildren = depth > 1;
1033
f65635b5
VZ
1034 wxString str;
1035 for ( size_t n = 0; n < numChildren; n++ )
1036 {
1037 // at depth 1 elements won't have any more children
74b31181 1038 if ( hasChildren )
b143cf70 1039 str.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n + 1));
74b31181 1040 else
b143cf70 1041 str.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder), unsigned(n + 1));
f65635b5 1042
74b31181
VZ
1043 // here we pass to AppendItem() normal and selected item images (we
1044 // suppose that selected image follows the normal one in the enum)
2c8e4738
VZ
1045 int image, imageSel;
1046 if ( wxGetApp().ShowImages() )
1047 {
1048 image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
1049 imageSel = image + 1;
1050 }
1051 else
1052 {
1053 image = imageSel = -1;
1054 }
1055 wxTreeItemId id = AppendItem(idParent, str, image, imageSel,
f65635b5
VZ
1056 new MyTreeItemData(str));
1057
4754ab16
RR
1058 if ( wxGetApp().ShowStates() )
1059 SetItemState(id, 0);
1060
74b31181 1061 // and now we also set the expanded one (only for the folders)
2c8e4738 1062 if ( hasChildren && wxGetApp().ShowImages() )
74b31181
VZ
1063 {
1064 SetItemImage(id, TreeCtrlIcon_FolderOpened,
1065 wxTreeItemIcon_Expanded);
1066 }
1067
f65635b5 1068 // remember the last child for OnEnsureVisible()
74b31181 1069 if ( !hasChildren && n == numChildren - 1 )
f65635b5
VZ
1070 {
1071 m_lastItem = id;
1072 }
1073
1074 AddItemsRecursively(id, numChildren, depth - 1, n + 1);
1075 }
3a5a2f56 1076 }
f65635b5 1077 //else: done!
457814b5
JS
1078}
1079
3a5a2f56
VZ
1080void MyTreeCtrl::AddTestItemsToTree(size_t numChildren,
1081 size_t depth)
457814b5 1082{
2c8e4738 1083 int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_Folder : -1;
3acd4349 1084 wxTreeItemId rootId = AddRoot(wxT("Root"),
2c8e4738 1085 image, image,
3acd4349 1086 new MyTreeItemData(wxT("Root item")));
c6a6bbbf 1087 if ( !HasFlag(wxTR_HIDE_ROOT) && image != -1 )
2c8e4738
VZ
1088 {
1089 SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded);
1090 }
457814b5 1091
5f939e78 1092 AddItemsRecursively(rootId, numChildren, depth, 0);
9ec64fa7
VZ
1093
1094 // set some colours/fonts for testing
c6a6bbbf
VZ
1095 if ( !HasFlag(wxTR_HIDE_ROOT) )
1096 SetItemFont(rootId, *wxITALIC_FONT);
9ec64fa7 1097
2d75caaa 1098 wxTreeItemIdValue cookie;
9ec64fa7
VZ
1099 wxTreeItemId id = GetFirstChild(rootId, cookie);
1100 SetItemTextColour(id, *wxBLUE);
1101
1102 id = GetNextChild(rootId, cookie);
1103 id = GetNextChild(rootId, cookie);
1104 SetItemTextColour(id, *wxRED);
1105 SetItemBackgroundColour(id, *wxLIGHT_GREY);
4832f7c0
VZ
1106}
1107
2d75caaa
VZ
1108void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent,
1109 wxTreeItemIdValue cookie)
4832f7c0 1110{
5f939e78 1111 wxTreeItemId id;
4832f7c0 1112
2d75caaa 1113 if ( !cookie )
5f939e78
VZ
1114 id = GetFirstChild(idParent, cookie);
1115 else
1116 id = GetNextChild(idParent, cookie);
4832f7c0 1117
2d75caaa 1118 if ( !id.IsOk() )
5f939e78 1119 return;
4832f7c0 1120
9dfbf520 1121 wxString text = GetItemText(id);
5f939e78 1122 wxLogMessage(text);
4832f7c0 1123
5f939e78 1124 if (ItemHasChildren(id))
2d75caaa 1125 GetItemsRecursively(id);
4832f7c0 1126
5f939e78 1127 GetItemsRecursively(idParent, cookie);
457814b5
JS
1128}
1129
9dfbf520
VZ
1130void MyTreeCtrl::DoToggleIcon(const wxTreeItemId& item)
1131{
8c7da4a6 1132 int image = GetItemImage(item) == TreeCtrlIcon_Folder
0c36b36e
VS
1133 ? TreeCtrlIcon_File
1134 : TreeCtrlIcon_Folder;
1135 SetItemImage(item, image, wxTreeItemIcon_Normal);
1136
ec8bb924 1137 image = GetItemImage(item, wxTreeItemIcon_Selected) == TreeCtrlIcon_FolderSelected
0c36b36e
VS
1138 ? TreeCtrlIcon_FileSelected
1139 : TreeCtrlIcon_FolderSelected;
1140 SetItemImage(item, image, wxTreeItemIcon_Selected);
9dfbf520
VZ
1141}
1142
4754ab16
RR
1143void MyTreeCtrl::DoToggleState(const wxTreeItemId& item)
1144{
1145 if ( m_alternateStates )
1146 {
1147 // sets random state unlike current
1148 int state = GetItemState(item);
1149 int nState;
1150
1151 srand (time(NULL));
1152 do {
1153 nState = rand() % GetStateImageList()->GetImageCount();
1154 } while (nState == state);
1155
1156 SetItemState(item, nState);
1157 }
1158 else
1159 {
1160 // we have only 2 checkbox states, so next state will be reversed
1161 SetItemState(item, wxTREE_ITEMSTATE_NEXT);
1162 }
1163}
1164
5c2603c2
VZ
1165void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event)
1166{
1167 wxTreeItemId item = event.GetItem();
1168 wxString text;
1169 if ( item.IsOk() )
1170 text << _T('"') << GetItemText(item).c_str() << _T('"');
1171 else
1172 text = _T("invalid item");
1173 wxLogMessage(wxT("%s(%s)"), name, text.c_str());
1174}
4832f7c0 1175
3a5a2f56 1176// avoid repetition
4693b20c
MB
1177#define TREE_EVENT_HANDLER(name) \
1178void MyTreeCtrl::name(wxTreeEvent& event) \
1179{ \
5c2603c2 1180 LogEvent(_T(#name), event); \
1cf1238d 1181 SetLastItem(wxTreeItemId()); \
4693b20c 1182 event.Skip(); \
5f939e78 1183}
457814b5 1184
3a5a2f56 1185TREE_EVENT_HANDLER(OnBeginRDrag)
3a5a2f56
VZ
1186TREE_EVENT_HANDLER(OnDeleteItem)
1187TREE_EVENT_HANDLER(OnGetInfo)
1188TREE_EVENT_HANDLER(OnSetInfo)
1189TREE_EVENT_HANDLER(OnItemExpanded)
1190TREE_EVENT_HANDLER(OnItemExpanding)
1191TREE_EVENT_HANDLER(OnItemCollapsed)
1192TREE_EVENT_HANDLER(OnSelChanged)
1193TREE_EVENT_HANDLER(OnSelChanging)
1194
1195#undef TREE_EVENT_HANDLER
1196
1944ad76
VZ
1197void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
1198{
1199 wxString key;
0c6099b7 1200 long keycode = event.GetKeyCode();
1944ad76 1201 {
0c6099b7 1202 switch ( keycode )
1944ad76 1203 {
0c6099b7
RN
1204 case WXK_BACK: key = wxT("BACK"); break;
1205 case WXK_TAB: key = wxT("TAB"); break;
1206 case WXK_RETURN: key = wxT("RETURN"); break;
1207 case WXK_ESCAPE: key = wxT("ESCAPE"); break;
1208 case WXK_SPACE: key = wxT("SPACE"); break;
1209 case WXK_DELETE: key = wxT("DELETE"); break;
1210 case WXK_START: key = wxT("START"); break;
1211 case WXK_LBUTTON: key = wxT("LBUTTON"); break;
1212 case WXK_RBUTTON: key = wxT("RBUTTON"); break;
1213 case WXK_CANCEL: key = wxT("CANCEL"); break;
1214 case WXK_MBUTTON: key = wxT("MBUTTON"); break;
1215 case WXK_CLEAR: key = wxT("CLEAR"); break;
1216 case WXK_SHIFT: key = wxT("SHIFT"); break;
1217 case WXK_ALT: key = wxT("ALT"); break;
1218 case WXK_CONTROL: key = wxT("CONTROL"); break;
1219 case WXK_MENU: key = wxT("MENU"); break;
1220 case WXK_PAUSE: key = wxT("PAUSE"); break;
1221 case WXK_CAPITAL: key = wxT("CAPITAL"); break;
0c6099b7
RN
1222 case WXK_END: key = wxT("END"); break;
1223 case WXK_HOME: key = wxT("HOME"); break;
1224 case WXK_LEFT: key = wxT("LEFT"); break;
1225 case WXK_UP: key = wxT("UP"); break;
1226 case WXK_RIGHT: key = wxT("RIGHT"); break;
1227 case WXK_DOWN: key = wxT("DOWN"); break;
1228 case WXK_SELECT: key = wxT("SELECT"); break;
1229 case WXK_PRINT: key = wxT("PRINT"); break;
1230 case WXK_EXECUTE: key = wxT("EXECUTE"); break;
1231 case WXK_SNAPSHOT: key = wxT("SNAPSHOT"); break;
1232 case WXK_INSERT: key = wxT("INSERT"); break;
1233 case WXK_HELP: key = wxT("HELP"); break;
1234 case WXK_NUMPAD0: key = wxT("NUMPAD0"); break;
1235 case WXK_NUMPAD1: key = wxT("NUMPAD1"); break;
1236 case WXK_NUMPAD2: key = wxT("NUMPAD2"); break;
1237 case WXK_NUMPAD3: key = wxT("NUMPAD3"); break;
1238 case WXK_NUMPAD4: key = wxT("NUMPAD4"); break;
1239 case WXK_NUMPAD5: key = wxT("NUMPAD5"); break;
1240 case WXK_NUMPAD6: key = wxT("NUMPAD6"); break;
1241 case WXK_NUMPAD7: key = wxT("NUMPAD7"); break;
1242 case WXK_NUMPAD8: key = wxT("NUMPAD8"); break;
1243 case WXK_NUMPAD9: key = wxT("NUMPAD9"); break;
1244 case WXK_MULTIPLY: key = wxT("MULTIPLY"); break;
1245 case WXK_ADD: key = wxT("ADD"); break;
1246 case WXK_SEPARATOR: key = wxT("SEPARATOR"); break;
1247 case WXK_SUBTRACT: key = wxT("SUBTRACT"); break;
1248 case WXK_DECIMAL: key = wxT("DECIMAL"); break;
1249 case WXK_DIVIDE: key = wxT("DIVIDE"); break;
1250 case WXK_F1: key = wxT("F1"); break;
1251 case WXK_F2: key = wxT("F2"); break;
1252 case WXK_F3: key = wxT("F3"); break;
1253 case WXK_F4: key = wxT("F4"); break;
1254 case WXK_F5: key = wxT("F5"); break;
1255 case WXK_F6: key = wxT("F6"); break;
1256 case WXK_F7: key = wxT("F7"); break;
1257 case WXK_F8: key = wxT("F8"); break;
1258 case WXK_F9: key = wxT("F9"); break;
1259 case WXK_F10: key = wxT("F10"); break;
1260 case WXK_F11: key = wxT("F11"); break;
1261 case WXK_F12: key = wxT("F12"); break;
1262 case WXK_F13: key = wxT("F13"); break;
1263 case WXK_F14: key = wxT("F14"); break;
1264 case WXK_F15: key = wxT("F15"); break;
1265 case WXK_F16: key = wxT("F16"); break;
1266 case WXK_F17: key = wxT("F17"); break;
1267 case WXK_F18: key = wxT("F18"); break;
1268 case WXK_F19: key = wxT("F19"); break;
1269 case WXK_F20: key = wxT("F20"); break;
1270 case WXK_F21: key = wxT("F21"); break;
1271 case WXK_F22: key = wxT("F22"); break;
1272 case WXK_F23: key = wxT("F23"); break;
1273 case WXK_F24: key = wxT("F24"); break;
1274 case WXK_NUMLOCK: key = wxT("NUMLOCK"); break;
1275 case WXK_SCROLL: key = wxT("SCROLL"); break;
1276 case WXK_PAGEUP: key = wxT("PAGEUP"); break;
1277 case WXK_PAGEDOWN: key = wxT("PAGEDOWN"); break;
1278 case WXK_NUMPAD_SPACE: key = wxT("NUMPAD_SPACE"); break;
1279 case WXK_NUMPAD_TAB: key = wxT("NUMPAD_TAB"); break;
1280 case WXK_NUMPAD_ENTER: key = wxT("NUMPAD_ENTER"); break;
1281 case WXK_NUMPAD_F1: key = wxT("NUMPAD_F1"); break;
1282 case WXK_NUMPAD_F2: key = wxT("NUMPAD_F2"); break;
1283 case WXK_NUMPAD_F3: key = wxT("NUMPAD_F3"); break;
1284 case WXK_NUMPAD_F4: key = wxT("NUMPAD_F4"); break;
1285 case WXK_NUMPAD_HOME: key = wxT("NUMPAD_HOME"); break;
1286 case WXK_NUMPAD_LEFT: key = wxT("NUMPAD_LEFT"); break;
1287 case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break;
1288 case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break;
1289 case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break;
0c6099b7
RN
1290 case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break;
1291 case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break;
1292 case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break;
1293 case WXK_NUMPAD_BEGIN: key = wxT("NUMPAD_BEGIN"); break;
1294 case WXK_NUMPAD_INSERT: key = wxT("NUMPAD_INSERT"); break;
1295 case WXK_NUMPAD_DELETE: key = wxT("NUMPAD_DELETE"); break;
1296 case WXK_NUMPAD_EQUAL: key = wxT("NUMPAD_EQUAL"); break;
1297 case WXK_NUMPAD_MULTIPLY: key = wxT("NUMPAD_MULTIPLY"); break;
1298 case WXK_NUMPAD_ADD: key = wxT("NUMPAD_ADD"); break;
1299 case WXK_NUMPAD_SEPARATOR: key = wxT("NUMPAD_SEPARATOR"); break;
1300 case WXK_NUMPAD_SUBTRACT: key = wxT("NUMPAD_SUBTRACT"); break;
1301 case WXK_NUMPAD_DECIMAL: key = wxT("NUMPAD_DECIMAL"); break;
1302
1303 default:
1304 {
bee09d36 1305 if ( keycode < 128 && wxIsprint((int)keycode) )
0c6099b7
RN
1306 key.Printf(wxT("'%c'"), (char)keycode);
1307 else if ( keycode > 0 && keycode < 27 )
1308 key.Printf(_("Ctrl-%c"), wxT('A') + keycode - 1);
1309 else
1310 key.Printf(wxT("unknown (%ld)"), keycode);
1311 }
1944ad76
VZ
1312 }
1313 }
1314
3acd4349 1315 wxLogMessage( wxT("%s event: %s (flags = %c%c%c%c)"),
1944ad76
VZ
1316 name,
1317 key.c_str(),
3acd4349
VS
1318 event.ControlDown() ? wxT('C') : wxT('-'),
1319 event.AltDown() ? wxT('A') : wxT('-'),
1320 event.ShiftDown() ? wxT('S') : wxT('-'),
1321 event.MetaDown() ? wxT('M') : wxT('-'));
1944ad76
VZ
1322}
1323
1324void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent& event)
1325{
3acd4349 1326 LogKeyEvent(wxT("Tree key down "), event.GetKeyEvent());
1944ad76
VZ
1327
1328 event.Skip();
1329}
1330
5888ef1e
VZ
1331void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
1332{
1333 // need to explicitly allow drag
1334 if ( event.GetItem() != GetRootItem() )
1335 {
1336 m_draggedItem = event.GetItem();
1337
8f6dc819
VZ
1338 wxPoint clientpt = event.GetPoint();
1339 wxPoint screenpt = ClientToScreen(clientpt);
1340
1341 wxLogMessage(wxT("OnBeginDrag: started dragging %s at screen coords (%i,%i)"),
1342 GetItemText(m_draggedItem).c_str(),
1343 screenpt.x, screenpt.y);
5888ef1e
VZ
1344
1345 event.Allow();
1346 }
1347 else
1348 {
4693b20c 1349 wxLogMessage(wxT("OnBeginDrag: this item can't be dragged."));
5888ef1e
VZ
1350 }
1351}
1352
1353void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
1354{
1355 wxTreeItemId itemSrc = m_draggedItem,
1356 itemDst = event.GetItem();
e97320d4 1357 m_draggedItem = (wxTreeItemId)0l;
5888ef1e
VZ
1358
1359 // where to copy the item?
1360 if ( itemDst.IsOk() && !ItemHasChildren(itemDst) )
1361 {
1362 // copy to the parent then
99006e44 1363 itemDst = GetItemParent(itemDst);
5888ef1e
VZ
1364 }
1365
1366 if ( !itemDst.IsOk() )
1367 {
4693b20c 1368 wxLogMessage(wxT("OnEndDrag: can't drop here."));
5888ef1e
VZ
1369
1370 return;
1371 }
1372
1373 wxString text = GetItemText(itemSrc);
4693b20c 1374 wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."),
5888ef1e
VZ
1375 text.c_str(), GetItemText(itemDst).c_str());
1376
1377 // just do append here - we could also insert it just before/after the item
1378 // on which it was dropped, but this requires slightly more work... we also
1379 // completely ignore the client data and icon of the old item but could
1380 // copy them as well.
1381 //
1382 // Finally, we only copy one item here but we might copy the entire tree if
1383 // we were dragging a folder.
2c8e4738 1384 int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1;
4754ab16
RR
1385 wxTreeItemId id = AppendItem(itemDst, text, image);
1386
1387 if ( wxGetApp().ShowStates() )
1388 SetItemState(id, GetItemState(itemSrc));
5888ef1e
VZ
1389}
1390
5ea47806
VZ
1391void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)
1392{
4693b20c 1393 wxLogMessage(wxT("OnBeginLabelEdit"));
5ea47806 1394
618a5e38 1395 // for testing, prevent this item's label editing
5ea47806
VZ
1396 wxTreeItemId itemId = event.GetItem();
1397 if ( IsTestItem(itemId) )
1398 {
4693b20c 1399 wxMessageBox(wxT("You can't edit this item."));
5ea47806
VZ
1400
1401 event.Veto();
1402 }
646a8a4d
VZ
1403 else if ( itemId == GetRootItem() )
1404 {
1405 // test that it is possible to change the text of the item being edited
1406 SetItemText(itemId, _T("Editing root item"));
1407 }
5ea47806
VZ
1408}
1409
1410void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
1411{
4693b20c 1412 wxLogMessage(wxT("OnEndLabelEdit"));
5ea47806
VZ
1413
1414 // don't allow anything except letters in the labels
1415 if ( !event.GetLabel().IsWord() )
1416 {
9602d7ae 1417 wxMessageBox(wxT("The new label should be a single word."));
5ea47806
VZ
1418
1419 event.Veto();
1420 }
1421}
1422
3a5a2f56 1423void MyTreeCtrl::OnItemCollapsing(wxTreeEvent& event)
457814b5 1424{
4693b20c 1425 wxLogMessage(wxT("OnItemCollapsing"));
f135ff73 1426
5f939e78
VZ
1427 // for testing, prevent the user from collapsing the first child folder
1428 wxTreeItemId itemId = event.GetItem();
5ea47806 1429 if ( IsTestItem(itemId) )
5f939e78 1430 {
4693b20c 1431 wxMessageBox(wxT("You can't collapse this item."));
457814b5 1432
5f939e78
VZ
1433 event.Veto();
1434 }
457814b5
JS
1435}
1436
477350ce 1437void MyTreeCtrl::OnItemActivated(wxTreeEvent& event)
457814b5 1438{
5f939e78 1439 // show some info about this item
477350ce 1440 wxTreeItemId itemId = event.GetItem();
5f939e78 1441 MyTreeItemData *item = (MyTreeItemData *)GetItemData(itemId);
457814b5 1442
5f939e78
VZ
1443 if ( item != NULL )
1444 {
1445 item->ShowInfo(this);
1446 }
457814b5 1447
4693b20c 1448 wxLogMessage(wxT("OnItemActivated"));
5f939e78
VZ
1449}
1450
4754ab16
RR
1451void MyTreeCtrl::OnItemStateClick(wxTreeEvent& event)
1452{
1453 // toggle item state
1454 wxTreeItemId itemId = event.GetItem();
1455 DoToggleState(itemId);
1456
1457 wxLogMessage(wxT("Item \"%s\" state changed to %d"),
1458 GetItemText(itemId), GetItemState(itemId));
1459}
1460
ef46ef23
VZ
1461void MyTreeCtrl::OnItemMenu(wxTreeEvent& event)
1462{
1463 wxTreeItemId itemId = event.GetItem();
1464 MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
1465 : NULL;
8f6dc819
VZ
1466 wxPoint clientpt = event.GetPoint();
1467 wxPoint screenpt = ClientToScreen(clientpt);
ef46ef23 1468
4754ab16 1469 wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"),
8f6dc819 1470 item ? item->GetDesc() : _T(""), screenpt.x, screenpt.y);
ef46ef23 1471
8f6dc819 1472 ShowMenu(itemId, clientpt);
ef46ef23
VZ
1473 event.Skip();
1474}
1475
ae8c4b33 1476void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event)
e3d0aa77
VZ
1477{
1478 wxPoint pt = event.GetPosition();
925e9792 1479
8f6dc819 1480 wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y);
e3d0aa77
VZ
1481}
1482
1483void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
1484{
1485 wxString title;
1486 if ( id.IsOk() )
1487 {
3acd4349 1488 title << wxT("Menu for ") << GetItemText(id);
e3d0aa77
VZ
1489 }
1490 else
1491 {
3acd4349 1492 title = wxT("Menu for no particular item");
e3d0aa77
VZ
1493 }
1494
801bb685 1495#if wxUSE_MENUS
e3d0aa77 1496 wxMenu menu(title);
3acd4349 1497 menu.Append(TreeTest_About, wxT("&About..."));
e525c4ff
VZ
1498 menu.AppendSeparator();
1499 menu.Append(TreeTest_Highlight, wxT("&Highlight item"));
3acd4349 1500 menu.Append(TreeTest_Dump, wxT("&Dump"));
e3d0aa77
VZ
1501
1502 PopupMenu(&menu, pt);
801bb685 1503#endif // wxUSE_MENUS
e3d0aa77
VZ
1504}
1505
5fd60e08
VZ
1506void MyTreeCtrl::OnItemRClick(wxTreeEvent& event)
1507{
1508 wxTreeItemId itemId = event.GetItem();
1509 MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId)
1510 : NULL;
1511
1512 wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc()
1513 : _T(""));
1514
1515 event.Skip();
1516}
1517
c545c230
VZ
1518void MyTreeCtrl::OnRMouseDown(wxMouseEvent& event)
1519{
1520 wxLogMessage(wxT("Right mouse button down"));
1521
1522 event.Skip();
1523}
1524
1525void MyTreeCtrl::OnRMouseUp(wxMouseEvent& event)
1526{
1527 wxLogMessage(wxT("Right mouse button up"));
1528
1529 event.Skip();
1530}
1531
5f939e78
VZ
1532void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event)
1533{
1534 wxTreeItemId id = HitTest(event.GetPosition());
1535 if ( !id )
4693b20c 1536 wxLogMessage(wxT("No item under mouse"));
5f939e78
VZ
1537 else
1538 {
1539 MyTreeItemData *item = (MyTreeItemData *)GetItemData(id);
1540 if ( item )
4693b20c 1541 wxLogMessage(wxT("Item '%s' under mouse"), item->GetDesc());
5f939e78 1542 }
c545c230
VZ
1543
1544 event.Skip();
457814b5
JS
1545}
1546
4693b20c 1547static inline const wxChar *Bool2String(bool b)
457814b5 1548{
4693b20c 1549 return b ? wxT("") : wxT("not ");
457814b5
JS
1550}
1551
9769e589 1552void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
457814b5 1553{
4693b20c
MB
1554 wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n")
1555 wxT("%u children (%u immediately under this item)."),
5f939e78
VZ
1556 m_desc.c_str(),
1557 Bool2String(tree->IsSelected(GetId())),
1558 Bool2String(tree->IsExpanded(GetId())),
1559 Bool2String(tree->IsBold(GetId())),
b143cf70
PC
1560 unsigned(tree->GetChildrenCount(GetId())),
1561 unsigned(tree->GetChildrenCount(GetId(), false)));
457814b5 1562}