1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/colordlg.h"
25 #include "wx/numdlg.h"
27 #include "wx/artprov.h"
29 #include "wx/imaglist.h"
30 #include "wx/treectrl.h"
34 // this is not supported by native control
35 #define NO_VARIABLE_HEIGHT
47 #include "../sample.xpm"
50 // verify that the item is ok and insult the user if it is not
51 #define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
52 wxMessageBox(wxT("Please select some item first!"), \
53 wxT("Tree sample error"), \
54 wxOK | wxICON_EXCLAMATION, \
59 #define MENU_LINK(name) EVT_MENU(TreeTest_##name, MyFrame::On##name)
61 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
62 EVT_IDLE(MyFrame::OnIdle
)
63 EVT_SIZE(MyFrame::OnSize
)
73 MENU_LINK(TogHideRoot
)
74 MENU_LINK(TogRootLines
)
76 MENU_LINK(TogFullHighlight
)
77 MENU_LINK(SetFgColour
)
78 MENU_LINK(SetBgColour
)
83 #ifndef NO_MULTIPLE_SELECTION
84 MENU_LINK(DumpSelected
)
88 #endif // NO_MULTIPLE_SELECTION
97 MENU_LINK(DeleteChildren
)
100 MENU_LINK(ToggleImages
)
101 MENU_LINK(ToggleAlternateImages
)
102 MENU_LINK(ToggleButtons
)
103 MENU_LINK(SetImageSize
)
104 MENU_LINK(CollapseAndReset
)
105 MENU_LINK(EnsureVisible
)
107 MENU_LINK(InsertItem
)
110 MENU_LINK(IncSpacing
)
111 MENU_LINK(DecSpacing
)
112 MENU_LINK(ToggleIcon
)
113 MENU_LINK(SelectRoot
)
118 #if USE_GENERIC_TREECTRL
119 BEGIN_EVENT_TABLE(MyTreeCtrl
, wxGenericTreeCtrl
)
121 BEGIN_EVENT_TABLE(MyTreeCtrl
, wxTreeCtrl
)
123 EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl
, MyTreeCtrl::OnBeginDrag
)
124 EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl
, MyTreeCtrl::OnBeginRDrag
)
125 EVT_TREE_END_DRAG(TreeTest_Ctrl
, MyTreeCtrl::OnEndDrag
)
126 EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl
, MyTreeCtrl::OnBeginLabelEdit
)
127 EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl
, MyTreeCtrl::OnEndLabelEdit
)
128 EVT_TREE_DELETE_ITEM(TreeTest_Ctrl
, MyTreeCtrl::OnDeleteItem
)
129 #if 0 // there are so many of those that logging them causes flicker
130 EVT_TREE_GET_INFO(TreeTest_Ctrl
, MyTreeCtrl::OnGetInfo
)
132 EVT_TREE_SET_INFO(TreeTest_Ctrl
, MyTreeCtrl::OnSetInfo
)
133 EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl
, MyTreeCtrl::OnItemExpanded
)
134 EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl
, MyTreeCtrl::OnItemExpanding
)
135 EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl
, MyTreeCtrl::OnItemCollapsed
)
136 EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl
, MyTreeCtrl::OnItemCollapsing
)
138 EVT_TREE_SEL_CHANGED(TreeTest_Ctrl
, MyTreeCtrl::OnSelChanged
)
139 EVT_TREE_SEL_CHANGING(TreeTest_Ctrl
, MyTreeCtrl::OnSelChanging
)
140 EVT_TREE_KEY_DOWN(TreeTest_Ctrl
, MyTreeCtrl::OnTreeKeyDown
)
141 EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl
, MyTreeCtrl::OnItemActivated
)
143 // so many differents ways to handle right mouse button clicks...
144 EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu
)
145 // EVT_TREE_ITEM_MENU is the preferred event for creating context menus
146 // on a tree control, because it includes the point of the click or item,
147 // meaning that no additional placement calculations are required.
148 EVT_TREE_ITEM_MENU(TreeTest_Ctrl
, MyTreeCtrl::OnItemMenu
)
149 EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl
, MyTreeCtrl::OnItemRClick
)
151 EVT_RIGHT_DOWN(MyTreeCtrl::OnRMouseDown
)
152 EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp
)
153 EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick
)
160 if ( !wxApp::OnInit() )
163 // Create the main frame window
164 MyFrame
*frame
= new MyFrame(wxT("wxTreeCtrl Test"), 50, 50, 450, 600);
174 // My frame constructor
175 MyFrame::MyFrame(const wxString
& title
, int x
, int y
, int w
, int h
)
176 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
)),
182 // This reduces flicker effects - even better would be to define
183 // OnEraseBackground to do nothing. When the tree control's scrollbars are
184 // show or hidden, the frame is sent a background erase event.
185 SetBackgroundColour(wxColour(255, 255, 255));
188 SetIcon(wxICON(sample
));
192 wxMenu
*file_menu
= new wxMenu
,
193 *style_menu
= new wxMenu
,
194 *tree_menu
= new wxMenu
,
195 *item_menu
= new wxMenu
;
197 file_menu
->Append(TreeTest_ClearLog
, wxT("&Clear log\tCtrl-L"));
198 file_menu
->AppendSeparator();
199 file_menu
->Append(TreeTest_About
, wxT("&About..."));
200 file_menu
->AppendSeparator();
201 file_menu
->Append(TreeTest_Quit
, wxT("E&xit\tAlt-X"));
203 style_menu
->AppendCheckItem(TreeTest_TogButtons
, wxT("Toggle &normal buttons"));
204 style_menu
->AppendCheckItem(TreeTest_TogTwist
, wxT("Toggle &twister buttons"));
205 style_menu
->AppendCheckItem(TreeTest_ToggleButtons
, wxT("Toggle image &buttons"));
206 style_menu
->AppendSeparator();
207 style_menu
->AppendCheckItem(TreeTest_TogLines
, wxT("Toggle &connecting lines"));
208 style_menu
->AppendCheckItem(TreeTest_TogRootLines
, wxT("Toggle &lines at root"));
209 style_menu
->AppendCheckItem(TreeTest_TogHideRoot
, wxT("Toggle &hidden root"));
210 style_menu
->AppendCheckItem(TreeTest_TogBorder
, wxT("Toggle &item border"));
211 style_menu
->AppendCheckItem(TreeTest_TogFullHighlight
, wxT("Toggle &full row highlight"));
212 style_menu
->AppendCheckItem(TreeTest_TogEdit
, wxT("Toggle &edit mode"));
213 #ifndef NO_MULTIPLE_SELECTION
214 style_menu
->AppendCheckItem(TreeTest_ToggleSel
, wxT("Toggle &selection mode\tCtrl-S"));
215 #endif // NO_MULTIPLE_SELECTION
216 style_menu
->AppendCheckItem(TreeTest_ToggleImages
, wxT("Toggle show ima&ges"));
217 style_menu
->AppendCheckItem(TreeTest_ToggleAlternateImages
, wxT("Toggle alternate images"));
218 style_menu
->Append(TreeTest_SetImageSize
, wxT("Set image si&ze..."));
219 style_menu
->AppendSeparator();
220 style_menu
->Append(TreeTest_SetFgColour
, wxT("Set &foreground colour..."));
221 style_menu
->Append(TreeTest_SetBgColour
, wxT("Set &background colour..."));
222 style_menu
->AppendSeparator();
223 style_menu
->Append(TreeTest_ResetStyle
, wxT("&Reset to default\tF10"));
225 tree_menu
->Append(TreeTest_Recreate
, wxT("&Recreate the tree"));
226 tree_menu
->Append(TreeTest_CollapseAndReset
, wxT("C&ollapse and reset"));
227 tree_menu
->AppendSeparator();
228 tree_menu
->Append(TreeTest_AddItem
, wxT("Append a &new item"));
229 tree_menu
->Append(TreeTest_InsertItem
, wxT("&Insert a new item"));
230 tree_menu
->Append(TreeTest_Delete
, wxT("&Delete this item"));
231 tree_menu
->Append(TreeTest_DeleteChildren
, wxT("Delete &children"));
232 tree_menu
->Append(TreeTest_DeleteAll
, wxT("Delete &all items"));
233 tree_menu
->Append(TreeTest_SelectRoot
, wxT("Select root item"));
234 tree_menu
->AppendSeparator();
235 tree_menu
->Append(TreeTest_Count
, wxT("Count children of current item"));
236 tree_menu
->Append(TreeTest_CountRec
, wxT("Recursively count children of current item"));
237 tree_menu
->AppendSeparator();
238 tree_menu
->Append(TreeTest_Sort
, wxT("Sort children of current item"));
239 tree_menu
->Append(TreeTest_SortRev
, wxT("Sort in reversed order"));
240 tree_menu
->AppendSeparator();
241 tree_menu
->Append(TreeTest_EnsureVisible
, wxT("Make the last item &visible"));
242 tree_menu
->AppendSeparator();
243 tree_menu
->Append(TreeTest_IncIndent
, wxT("Add 5 points to indentation\tAlt-I"));
244 tree_menu
->Append(TreeTest_DecIndent
, wxT("Reduce indentation by 5 points\tAlt-R"));
245 tree_menu
->AppendSeparator();
246 tree_menu
->Append(TreeTest_IncSpacing
, wxT("Add 5 points to spacing\tCtrl-I"));
247 tree_menu
->Append(TreeTest_DecSpacing
, wxT("Reduce spacing by 5 points\tCtrl-R"));
249 item_menu
->Append(TreeTest_Dump
, wxT("&Dump item children"));
250 item_menu
->Append(TreeTest_Rename
, wxT("&Rename item..."));
252 item_menu
->AppendSeparator();
253 item_menu
->Append(TreeTest_SetBold
, wxT("Make item &bold"));
254 item_menu
->Append(TreeTest_ClearBold
, wxT("Make item ¬ bold"));
255 item_menu
->AppendSeparator();
256 item_menu
->Append(TreeTest_ToggleIcon
, wxT("Toggle the item's &icon"));
258 #ifndef NO_MULTIPLE_SELECTION
259 item_menu
->AppendSeparator();
260 item_menu
->Append(TreeTest_DumpSelected
, wxT("Dump selected items\tAlt-D"));
261 item_menu
->Append(TreeTest_Select
, wxT("Select current item\tAlt-S"));
262 item_menu
->Append(TreeTest_Unselect
, wxT("Unselect everything\tAlt-U"));
263 #endif // NO_MULTIPLE_SELECTION
265 wxMenuBar
*menu_bar
= new wxMenuBar
;
266 menu_bar
->Append(file_menu
, wxT("&File"));
267 menu_bar
->Append(style_menu
, wxT("&Style"));
268 menu_bar
->Append(tree_menu
, wxT("&Tree"));
269 menu_bar
->Append(item_menu
, wxT("&Item"));
270 SetMenuBar(menu_bar
);
271 #endif // wxUSE_MENUS
273 m_panel
= new wxPanel(this);
276 // create the controls
277 m_textCtrl
= new wxTextCtrl(m_panel
, wxID_ANY
, wxT(""),
278 wxDefaultPosition
, wxDefaultSize
,
279 wxTE_MULTILINE
| wxSUNKEN_BORDER
);
282 CreateTreeWithDefStyle();
284 menu_bar
->Check(TreeTest_ToggleImages
, true);
285 menu_bar
->Check(TreeTest_ToggleAlternateImages
, false);
288 // create a status bar
290 #endif // wxUSE_STATUSBAR
294 // For some reason, we get a memcpy crash in wxLogStream::DoLogStream
295 // on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
296 delete wxLog::SetActiveTarget(new wxLogStderr
);
298 // set our text control as the log target
299 wxLogTextCtrl
*logWindow
= new wxLogTextCtrl(m_textCtrl
);
300 delete wxLog::SetActiveTarget(logWindow
);
308 delete wxLog::SetActiveTarget(NULL
);
312 void MyFrame::CreateTreeWithDefStyle()
314 long style
= wxTR_DEFAULT_STYLE
|
315 #ifndef NO_VARIABLE_HEIGHT
316 wxTR_HAS_VARIABLE_ROW_HEIGHT
|
320 CreateTree(style
| wxSUNKEN_BORDER
);
322 // as we don't know what wxTR_DEFAULT_STYLE could contain, test for
324 wxMenuBar
*mbar
= GetMenuBar();
325 mbar
->Check(TreeTest_TogButtons
, (style
& wxTR_HAS_BUTTONS
) != 0);
326 mbar
->Check(TreeTest_TogButtons
, (style
& wxTR_TWIST_BUTTONS
) != 0);
327 mbar
->Check(TreeTest_TogLines
, (style
& wxTR_NO_LINES
) == 0);
328 mbar
->Check(TreeTest_TogRootLines
, (style
& wxTR_LINES_AT_ROOT
) != 0);
329 mbar
->Check(TreeTest_TogHideRoot
, (style
& wxTR_HIDE_ROOT
) != 0);
330 mbar
->Check(TreeTest_TogEdit
, (style
& wxTR_EDIT_LABELS
) != 0);
331 mbar
->Check(TreeTest_TogBorder
, (style
& wxTR_ROW_LINES
) != 0);
332 mbar
->Check(TreeTest_TogFullHighlight
, (style
& wxTR_FULL_ROW_HIGHLIGHT
) != 0);
335 void MyFrame::CreateTree(long style
)
337 m_treeCtrl
= new MyTreeCtrl(m_panel
, TreeTest_Ctrl
,
338 wxDefaultPosition
, wxDefaultSize
,
341 GetMenuBar()->Enable(TreeTest_SelectRoot
, !(style
& wxTR_HIDE_ROOT
));
346 void MyFrame::TogStyle(int id
, long flag
)
348 long style
= m_treeCtrl
->GetWindowStyle() ^ flag
;
350 // most treectrl styles can't be changed on the fly using the native
351 // control and the tree must be recreated
353 m_treeCtrl
->SetWindowStyle(style
);
359 GetMenuBar()->Check(id
, (style
& flag
) != 0);
362 void MyFrame::OnIdle(wxIdleEvent
& event
)
367 wxTreeItemId idRoot
= m_treeCtrl
->GetRootItem();
371 wxTreeItemId idLast
= m_treeCtrl
->GetLastChild(idRoot
);
372 status
= wxString::Format(
373 _T("Root/last item is %svisible/%svisible"),
374 m_treeCtrl
->IsVisible(idRoot
) ? _T("") : _T("not "),
375 idLast
.IsOk() && m_treeCtrl
->IsVisible(idLast
)
376 ? _T("") : _T("not "));
379 status
= _T("No root item");
381 SetStatusText(status
, 1);
383 #endif // wxUSE_STATUSBAR
388 void MyFrame::OnSize(wxSizeEvent
& event
)
402 void MyFrame::Resize()
404 wxSize size
= GetClientSize();
405 m_treeCtrl
->SetSize(0, 0, size
.x
, size
.y
408 m_textCtrl
->SetSize(0, 2*size
.y
/3, size
.x
, size
.y
/3
413 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
418 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
420 wxMessageBox(wxT("Tree test sample\n")
421 wxT("(c) Julian Smart 1997, Vadim Zeitlin 1998"),
422 wxT("About tree test"),
423 wxOK
| wxICON_INFORMATION
, this);
426 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
431 void MyFrame::OnRename(wxCommandEvent
& WXUNUSED(event
))
433 wxTreeItemId item
= m_treeCtrl
->GetSelection();
437 // old code - now we edit in place
439 static wxString s_text
;
440 s_text
= wxGetTextFromUser(wxT("New name: "), wxT("Tree sample question"),
442 if ( !s_text
.empty() )
444 m_treeCtrl
->SetItemText(item
, s_text
);
448 // TODO demonstrate creating a custom edit control...
449 (void)m_treeCtrl
->EditLabel(item
);
452 void MyFrame::OnCount(wxCommandEvent
& WXUNUSED(event
))
454 wxTreeItemId item
= m_treeCtrl
->GetSelection();
458 int i
= m_treeCtrl
->GetChildrenCount( item
, false );
460 wxLogMessage(wxT("%d children"), i
);
463 void MyFrame::OnCountRec(wxCommandEvent
& WXUNUSED(event
))
465 wxTreeItemId item
= m_treeCtrl
->GetSelection();
469 int i
= m_treeCtrl
->GetChildrenCount( item
);
471 wxLogMessage(wxT("%d children"), i
);
474 void MyFrame::DoSort(bool reverse
)
476 wxTreeItemId item
= m_treeCtrl
->GetSelection();
480 m_treeCtrl
->DoSortChildren(item
, reverse
);
483 void MyFrame::OnHighlight(wxCommandEvent
& WXUNUSED(event
))
485 wxTreeItemId id
= m_treeCtrl
->GetSelection();
490 if ( !m_treeCtrl
->GetBoundingRect(id
, r
, true /* text, not full row */) )
492 wxLogMessage(_T("Failed to get bounding item rect"));
496 wxClientDC
dc(m_treeCtrl
);
498 dc
.SetPen(*wxTRANSPARENT_PEN
);
500 m_treeCtrl
->Update();
503 void MyFrame::OnDump(wxCommandEvent
& WXUNUSED(event
))
505 wxTreeItemId root
= m_treeCtrl
->GetSelection();
509 m_treeCtrl
->GetItemsRecursively(root
);
512 #ifndef NO_MULTIPLE_SELECTION
514 void MyFrame::OnToggleSel(wxCommandEvent
& event
)
516 TogStyle(event
.GetId(), wxTR_MULTIPLE
);
519 void MyFrame::OnDumpSelected(wxCommandEvent
& WXUNUSED(event
))
521 wxArrayTreeItemIds array
;
523 size_t count
= m_treeCtrl
->GetSelections(array
);
524 wxLogMessage(wxT("%u items selected"), unsigned(count
));
526 for ( size_t n
= 0; n
< count
; n
++ )
528 wxLogMessage(wxT("\t%s"), m_treeCtrl
->GetItemText(array
.Item(n
)).c_str());
532 void MyFrame::OnSelect(wxCommandEvent
& WXUNUSED(event
))
534 m_treeCtrl
->SelectItem(m_treeCtrl
->GetSelection());
537 void MyFrame::OnSelectRoot(wxCommandEvent
& WXUNUSED(event
))
539 if ( !m_treeCtrl
->HasFlag(wxTR_HIDE_ROOT
) )
540 m_treeCtrl
->SelectItem(m_treeCtrl
->GetRootItem());
543 void MyFrame::OnUnselect(wxCommandEvent
& WXUNUSED(event
))
545 m_treeCtrl
->UnselectAll();
548 #endif // NO_MULTIPLE_SELECTION
550 void MyFrame::DoSetBold(bool bold
)
552 wxTreeItemId item
= m_treeCtrl
->GetSelection();
556 m_treeCtrl
->SetItemBold(item
, bold
);
559 void MyFrame::OnDelete(wxCommandEvent
& WXUNUSED(event
))
561 wxTreeItemId item
= m_treeCtrl
->GetSelection();
565 m_treeCtrl
->Delete(item
);
568 void MyFrame::OnDeleteChildren(wxCommandEvent
& WXUNUSED(event
))
570 wxTreeItemId item
= m_treeCtrl
->GetSelection();
574 m_treeCtrl
->DeleteChildren(item
);
577 void MyFrame::OnDeleteAll(wxCommandEvent
& WXUNUSED(event
))
579 m_treeCtrl
->DeleteAllItems();
582 void MyFrame::OnRecreate(wxCommandEvent
& event
)
585 m_treeCtrl
->AddTestItemsToTree(5, 2);
588 void MyFrame::OnSetImageSize(wxCommandEvent
& WXUNUSED(event
))
590 int size
= wxGetNumberFromUser(wxT("Enter the size for the images to use"),
592 wxT("TreeCtrl sample"),
593 m_treeCtrl
->ImageSize());
597 m_treeCtrl
->CreateImageList(size
);
598 wxGetApp().SetShowImages(true);
601 void MyFrame::OnToggleImages(wxCommandEvent
& WXUNUSED(event
))
603 if ( wxGetApp().ShowImages() )
605 m_treeCtrl
->CreateImageList(-1);
606 wxGetApp().SetShowImages(false);
610 m_treeCtrl
->CreateImageList(0);
611 wxGetApp().SetShowImages(true);
615 void MyFrame::OnToggleAlternateImages(wxCommandEvent
& WXUNUSED(event
))
617 bool alternateImages
= m_treeCtrl
->AlternateImages();
619 m_treeCtrl
->SetAlternateImages(!alternateImages
);
620 m_treeCtrl
->CreateImageList(0);
623 void MyFrame::OnToggleButtons(wxCommandEvent
& WXUNUSED(event
))
625 #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
626 if ( wxGetApp().ShowButtons() )
628 m_treeCtrl
->CreateButtonsImageList(-1);
629 wxGetApp().SetShowButtons(false);
633 m_treeCtrl
->CreateButtonsImageList(15);
634 wxGetApp().SetShowButtons(true);
639 void MyFrame::OnCollapseAndReset(wxCommandEvent
& WXUNUSED(event
))
641 m_treeCtrl
->CollapseAndReset(m_treeCtrl
->GetRootItem());
644 void MyFrame::OnEnsureVisible(wxCommandEvent
& WXUNUSED(event
))
646 m_treeCtrl
->DoEnsureVisible();
649 void MyFrame::OnInsertItem(wxCommandEvent
& WXUNUSED(event
))
651 int image
= wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File
: -1;
652 m_treeCtrl
->InsertItem(m_treeCtrl
->GetRootItem(), image
, wxT("2nd item"));
655 void MyFrame::OnAddItem(wxCommandEvent
& WXUNUSED(event
))
657 static int s_num
= 0;
660 text
.Printf(wxT("Item #%d"), ++s_num
);
662 m_treeCtrl
->AppendItem(m_treeCtrl
->GetRootItem(),
664 MyTreeCtrl::TreeCtrlIcon_File */ );
667 void MyFrame::OnIncIndent(wxCommandEvent
& WXUNUSED(event
))
669 unsigned int indent
= m_treeCtrl
->GetIndent();
671 m_treeCtrl
->SetIndent( indent
+5 );
674 void MyFrame::OnDecIndent(wxCommandEvent
& WXUNUSED(event
))
676 unsigned int indent
= m_treeCtrl
->GetIndent();
678 m_treeCtrl
->SetIndent( indent
-5 );
681 void MyFrame::OnIncSpacing(wxCommandEvent
& WXUNUSED(event
))
683 unsigned int indent
= m_treeCtrl
->GetSpacing();
685 m_treeCtrl
->SetSpacing( indent
+5 );
688 void MyFrame::OnDecSpacing(wxCommandEvent
& WXUNUSED(event
))
690 unsigned int indent
= m_treeCtrl
->GetSpacing();
692 m_treeCtrl
->SetSpacing( indent
-5 );
695 void MyFrame::OnToggleIcon(wxCommandEvent
& WXUNUSED(event
))
697 wxTreeItemId item
= m_treeCtrl
->GetSelection();
701 m_treeCtrl
->DoToggleIcon(item
);
704 void MyFrame::OnSetFgColour(wxCommandEvent
& WXUNUSED(event
))
706 wxColour col
= wxGetColourFromUser(this, m_treeCtrl
->GetForegroundColour());
708 m_treeCtrl
->SetForegroundColour(col
);
711 void MyFrame::OnSetBgColour(wxCommandEvent
& WXUNUSED(event
))
713 wxColour col
= wxGetColourFromUser(this, m_treeCtrl
->GetBackgroundColour());
715 m_treeCtrl
->SetBackgroundColour(col
);
718 // MyTreeCtrl implementation
719 #if USE_GENERIC_TREECTRL
720 IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl
, wxGenericTreeCtrl
)
722 IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl
, wxTreeCtrl
)
725 MyTreeCtrl::MyTreeCtrl(wxWindow
*parent
, const wxWindowID id
,
726 const wxPoint
& pos
, const wxSize
& size
,
728 : wxTreeCtrl(parent
, id
, pos
, size
, style
),
729 m_alternateImages(false)
731 m_reverseSort
= false;
735 // Add some items to the tree
736 AddTestItemsToTree(5, 2);
739 void MyTreeCtrl::CreateImageList(int size
)
751 // Make an image list containing small icons
752 wxImageList
*images
= new wxImageList(size
, size
, true);
754 // should correspond to TreeCtrlIcon_xxx enum
758 if (m_alternateImages
)
760 icons
[TreeCtrlIcon_File
] = wxIcon(icon1_xpm
);
761 icons
[TreeCtrlIcon_FileSelected
] = wxIcon(icon2_xpm
);
762 icons
[TreeCtrlIcon_Folder
] = wxIcon(icon3_xpm
);
763 icons
[TreeCtrlIcon_FolderSelected
] = wxIcon(icon4_xpm
);
764 icons
[TreeCtrlIcon_FolderOpened
] = wxIcon(icon5_xpm
);
768 wxSize
iconSize(size
, size
);
770 icons
[TreeCtrlIcon_File
] =
771 icons
[TreeCtrlIcon_FileSelected
] = wxArtProvider::GetIcon(wxART_NORMAL_FILE
, wxART_LIST
, iconSize
);
772 icons
[TreeCtrlIcon_Folder
] =
773 icons
[TreeCtrlIcon_FolderSelected
] =
774 icons
[TreeCtrlIcon_FolderOpened
] = wxArtProvider::GetIcon(wxART_FOLDER
, wxART_LIST
, iconSize
);
777 for ( size_t i
= 0; i
< WXSIZEOF(icons
); i
++ )
779 int sizeOrig
= icons
[0].GetWidth();
780 if ( size
== sizeOrig
)
782 images
->Add(icons
[i
]);
786 images
->Add(wxBitmap(wxBitmap(icons
[i
]).ConvertToImage().Rescale(size
, size
)));
790 AssignImageList(images
);
793 #if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
794 void MyTreeCtrl::CreateButtonsImageList(int size
)
798 SetButtonsImageList(NULL
);
802 // Make an image list containing small icons
803 wxImageList
*images
= new wxImageList(size
, size
, true);
805 // should correspond to TreeCtrlIcon_xxx enum
809 if (m_alternateImages
)
811 icons
[0] = wxIcon(icon3_xpm
); // closed
812 icons
[1] = wxIcon(icon3_xpm
); // closed, selected
813 icons
[2] = wxIcon(icon5_xpm
); // open
814 icons
[3] = wxIcon(icon5_xpm
); // open, selected
818 wxSize
iconSize(size
, size
);
821 icons
[1] = wxArtProvider::GetIcon(wxART_FOLDER
, wxART_LIST
, iconSize
); // closed, selected
823 icons
[3] = wxArtProvider::GetIcon(wxART_FOLDER_OPEN
, wxART_LIST
, iconSize
);// open, selected
826 for ( size_t i
= 0; i
< WXSIZEOF(icons
); i
++ )
828 int sizeOrig
= icons
[i
].GetWidth();
829 if ( size
== sizeOrig
)
831 images
->Add(icons
[i
]);
835 images
->Add(wxBitmap(wxBitmap(icons
[i
]).ConvertToImage().Rescale(size
, size
)));
839 AssignButtonsImageList(images
);
841 void MyTreeCtrl::CreateButtonsImageList(int WXUNUSED(size
))
846 int MyTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
847 const wxTreeItemId
& item2
)
851 // just exchange 1st and 2nd items
852 return wxTreeCtrl::OnCompareItems(item2
, item1
);
856 return wxTreeCtrl::OnCompareItems(item1
, item2
);
860 void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId
& idParent
,
867 bool hasChildren
= depth
> 1;
870 for ( size_t n
= 0; n
< numChildren
; n
++ )
872 // at depth 1 elements won't have any more children
874 str
.Printf(wxT("%s child %u"), wxT("Folder"), unsigned(n
+ 1));
876 str
.Printf(wxT("%s child %u.%u"), wxT("File"), unsigned(folder
), unsigned(n
+ 1));
878 // here we pass to AppendItem() normal and selected item images (we
879 // suppose that selected image follows the normal one in the enum)
881 if ( wxGetApp().ShowImages() )
883 image
= depth
== 1 ? TreeCtrlIcon_File
: TreeCtrlIcon_Folder
;
884 imageSel
= image
+ 1;
888 image
= imageSel
= -1;
890 wxTreeItemId id
= AppendItem(idParent
, str
, image
, imageSel
,
891 new MyTreeItemData(str
));
893 // and now we also set the expanded one (only for the folders)
894 if ( hasChildren
&& wxGetApp().ShowImages() )
896 SetItemImage(id
, TreeCtrlIcon_FolderOpened
,
897 wxTreeItemIcon_Expanded
);
900 // remember the last child for OnEnsureVisible()
901 if ( !hasChildren
&& n
== numChildren
- 1 )
906 AddItemsRecursively(id
, numChildren
, depth
- 1, n
+ 1);
912 void MyTreeCtrl::AddTestItemsToTree(size_t numChildren
,
915 int image
= wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_Folder
: -1;
916 wxTreeItemId rootId
= AddRoot(wxT("Root"),
918 new MyTreeItemData(wxT("Root item")));
919 if ( !HasFlag(wxTR_HIDE_ROOT
) && image
!= -1 )
921 SetItemImage(rootId
, TreeCtrlIcon_FolderOpened
, wxTreeItemIcon_Expanded
);
924 AddItemsRecursively(rootId
, numChildren
, depth
, 0);
926 // set some colours/fonts for testing
927 if ( !HasFlag(wxTR_HIDE_ROOT
) )
928 SetItemFont(rootId
, *wxITALIC_FONT
);
930 wxTreeItemIdValue cookie
;
931 wxTreeItemId id
= GetFirstChild(rootId
, cookie
);
932 SetItemTextColour(id
, *wxBLUE
);
934 id
= GetNextChild(rootId
, cookie
);
935 id
= GetNextChild(rootId
, cookie
);
936 SetItemTextColour(id
, *wxRED
);
937 SetItemBackgroundColour(id
, *wxLIGHT_GREY
);
940 void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId
& idParent
,
941 wxTreeItemIdValue cookie
)
946 id
= GetFirstChild(idParent
, cookie
);
948 id
= GetNextChild(idParent
, cookie
);
953 wxString text
= GetItemText(id
);
956 if (ItemHasChildren(id
))
957 GetItemsRecursively(id
);
959 GetItemsRecursively(idParent
, cookie
);
962 void MyTreeCtrl::DoToggleIcon(const wxTreeItemId
& item
)
964 int image
= (GetItemImage(item
) == TreeCtrlIcon_Folder
)
966 : TreeCtrlIcon_Folder
;
967 SetItemImage(item
, image
, wxTreeItemIcon_Normal
);
969 image
= (GetItemImage(item
) == TreeCtrlIcon_FolderSelected
)
970 ? TreeCtrlIcon_FileSelected
971 : TreeCtrlIcon_FolderSelected
;
972 SetItemImage(item
, image
, wxTreeItemIcon_Selected
);
975 void MyTreeCtrl::LogEvent(const wxChar
*name
, const wxTreeEvent
& event
)
977 wxTreeItemId item
= event
.GetItem();
980 text
<< _T('"') << GetItemText(item
).c_str() << _T('"');
982 text
= _T("invalid item");
983 wxLogMessage(wxT("%s(%s)"), name
, text
.c_str());
987 #define TREE_EVENT_HANDLER(name) \
988 void MyTreeCtrl::name(wxTreeEvent& event) \
990 LogEvent(_T(#name), event); \
991 SetLastItem(wxTreeItemId()); \
995 TREE_EVENT_HANDLER(OnBeginRDrag
)
996 TREE_EVENT_HANDLER(OnDeleteItem
)
997 TREE_EVENT_HANDLER(OnGetInfo
)
998 TREE_EVENT_HANDLER(OnSetInfo
)
999 TREE_EVENT_HANDLER(OnItemExpanded
)
1000 TREE_EVENT_HANDLER(OnItemExpanding
)
1001 TREE_EVENT_HANDLER(OnItemCollapsed
)
1002 TREE_EVENT_HANDLER(OnSelChanged
)
1003 TREE_EVENT_HANDLER(OnSelChanging
)
1005 #undef TREE_EVENT_HANDLER
1007 void LogKeyEvent(const wxChar
*name
, const wxKeyEvent
& event
)
1010 long keycode
= event
.GetKeyCode();
1014 case WXK_BACK
: key
= wxT("BACK"); break;
1015 case WXK_TAB
: key
= wxT("TAB"); break;
1016 case WXK_RETURN
: key
= wxT("RETURN"); break;
1017 case WXK_ESCAPE
: key
= wxT("ESCAPE"); break;
1018 case WXK_SPACE
: key
= wxT("SPACE"); break;
1019 case WXK_DELETE
: key
= wxT("DELETE"); break;
1020 case WXK_START
: key
= wxT("START"); break;
1021 case WXK_LBUTTON
: key
= wxT("LBUTTON"); break;
1022 case WXK_RBUTTON
: key
= wxT("RBUTTON"); break;
1023 case WXK_CANCEL
: key
= wxT("CANCEL"); break;
1024 case WXK_MBUTTON
: key
= wxT("MBUTTON"); break;
1025 case WXK_CLEAR
: key
= wxT("CLEAR"); break;
1026 case WXK_SHIFT
: key
= wxT("SHIFT"); break;
1027 case WXK_ALT
: key
= wxT("ALT"); break;
1028 case WXK_CONTROL
: key
= wxT("CONTROL"); break;
1029 case WXK_MENU
: key
= wxT("MENU"); break;
1030 case WXK_PAUSE
: key
= wxT("PAUSE"); break;
1031 case WXK_CAPITAL
: key
= wxT("CAPITAL"); break;
1032 case WXK_END
: key
= wxT("END"); break;
1033 case WXK_HOME
: key
= wxT("HOME"); break;
1034 case WXK_LEFT
: key
= wxT("LEFT"); break;
1035 case WXK_UP
: key
= wxT("UP"); break;
1036 case WXK_RIGHT
: key
= wxT("RIGHT"); break;
1037 case WXK_DOWN
: key
= wxT("DOWN"); break;
1038 case WXK_SELECT
: key
= wxT("SELECT"); break;
1039 case WXK_PRINT
: key
= wxT("PRINT"); break;
1040 case WXK_EXECUTE
: key
= wxT("EXECUTE"); break;
1041 case WXK_SNAPSHOT
: key
= wxT("SNAPSHOT"); break;
1042 case WXK_INSERT
: key
= wxT("INSERT"); break;
1043 case WXK_HELP
: key
= wxT("HELP"); break;
1044 case WXK_NUMPAD0
: key
= wxT("NUMPAD0"); break;
1045 case WXK_NUMPAD1
: key
= wxT("NUMPAD1"); break;
1046 case WXK_NUMPAD2
: key
= wxT("NUMPAD2"); break;
1047 case WXK_NUMPAD3
: key
= wxT("NUMPAD3"); break;
1048 case WXK_NUMPAD4
: key
= wxT("NUMPAD4"); break;
1049 case WXK_NUMPAD5
: key
= wxT("NUMPAD5"); break;
1050 case WXK_NUMPAD6
: key
= wxT("NUMPAD6"); break;
1051 case WXK_NUMPAD7
: key
= wxT("NUMPAD7"); break;
1052 case WXK_NUMPAD8
: key
= wxT("NUMPAD8"); break;
1053 case WXK_NUMPAD9
: key
= wxT("NUMPAD9"); break;
1054 case WXK_MULTIPLY
: key
= wxT("MULTIPLY"); break;
1055 case WXK_ADD
: key
= wxT("ADD"); break;
1056 case WXK_SEPARATOR
: key
= wxT("SEPARATOR"); break;
1057 case WXK_SUBTRACT
: key
= wxT("SUBTRACT"); break;
1058 case WXK_DECIMAL
: key
= wxT("DECIMAL"); break;
1059 case WXK_DIVIDE
: key
= wxT("DIVIDE"); break;
1060 case WXK_F1
: key
= wxT("F1"); break;
1061 case WXK_F2
: key
= wxT("F2"); break;
1062 case WXK_F3
: key
= wxT("F3"); break;
1063 case WXK_F4
: key
= wxT("F4"); break;
1064 case WXK_F5
: key
= wxT("F5"); break;
1065 case WXK_F6
: key
= wxT("F6"); break;
1066 case WXK_F7
: key
= wxT("F7"); break;
1067 case WXK_F8
: key
= wxT("F8"); break;
1068 case WXK_F9
: key
= wxT("F9"); break;
1069 case WXK_F10
: key
= wxT("F10"); break;
1070 case WXK_F11
: key
= wxT("F11"); break;
1071 case WXK_F12
: key
= wxT("F12"); break;
1072 case WXK_F13
: key
= wxT("F13"); break;
1073 case WXK_F14
: key
= wxT("F14"); break;
1074 case WXK_F15
: key
= wxT("F15"); break;
1075 case WXK_F16
: key
= wxT("F16"); break;
1076 case WXK_F17
: key
= wxT("F17"); break;
1077 case WXK_F18
: key
= wxT("F18"); break;
1078 case WXK_F19
: key
= wxT("F19"); break;
1079 case WXK_F20
: key
= wxT("F20"); break;
1080 case WXK_F21
: key
= wxT("F21"); break;
1081 case WXK_F22
: key
= wxT("F22"); break;
1082 case WXK_F23
: key
= wxT("F23"); break;
1083 case WXK_F24
: key
= wxT("F24"); break;
1084 case WXK_NUMLOCK
: key
= wxT("NUMLOCK"); break;
1085 case WXK_SCROLL
: key
= wxT("SCROLL"); break;
1086 case WXK_PAGEUP
: key
= wxT("PAGEUP"); break;
1087 case WXK_PAGEDOWN
: key
= wxT("PAGEDOWN"); break;
1088 case WXK_NUMPAD_SPACE
: key
= wxT("NUMPAD_SPACE"); break;
1089 case WXK_NUMPAD_TAB
: key
= wxT("NUMPAD_TAB"); break;
1090 case WXK_NUMPAD_ENTER
: key
= wxT("NUMPAD_ENTER"); break;
1091 case WXK_NUMPAD_F1
: key
= wxT("NUMPAD_F1"); break;
1092 case WXK_NUMPAD_F2
: key
= wxT("NUMPAD_F2"); break;
1093 case WXK_NUMPAD_F3
: key
= wxT("NUMPAD_F3"); break;
1094 case WXK_NUMPAD_F4
: key
= wxT("NUMPAD_F4"); break;
1095 case WXK_NUMPAD_HOME
: key
= wxT("NUMPAD_HOME"); break;
1096 case WXK_NUMPAD_LEFT
: key
= wxT("NUMPAD_LEFT"); break;
1097 case WXK_NUMPAD_UP
: key
= wxT("NUMPAD_UP"); break;
1098 case WXK_NUMPAD_RIGHT
: key
= wxT("NUMPAD_RIGHT"); break;
1099 case WXK_NUMPAD_DOWN
: key
= wxT("NUMPAD_DOWN"); break;
1100 case WXK_NUMPAD_PAGEUP
: key
= wxT("NUMPAD_PAGEUP"); break;
1101 case WXK_NUMPAD_PAGEDOWN
: key
= wxT("NUMPAD_PAGEDOWN"); break;
1102 case WXK_NUMPAD_END
: key
= wxT("NUMPAD_END"); break;
1103 case WXK_NUMPAD_BEGIN
: key
= wxT("NUMPAD_BEGIN"); break;
1104 case WXK_NUMPAD_INSERT
: key
= wxT("NUMPAD_INSERT"); break;
1105 case WXK_NUMPAD_DELETE
: key
= wxT("NUMPAD_DELETE"); break;
1106 case WXK_NUMPAD_EQUAL
: key
= wxT("NUMPAD_EQUAL"); break;
1107 case WXK_NUMPAD_MULTIPLY
: key
= wxT("NUMPAD_MULTIPLY"); break;
1108 case WXK_NUMPAD_ADD
: key
= wxT("NUMPAD_ADD"); break;
1109 case WXK_NUMPAD_SEPARATOR
: key
= wxT("NUMPAD_SEPARATOR"); break;
1110 case WXK_NUMPAD_SUBTRACT
: key
= wxT("NUMPAD_SUBTRACT"); break;
1111 case WXK_NUMPAD_DECIMAL
: key
= wxT("NUMPAD_DECIMAL"); break;
1115 if ( keycode
< 128 && wxIsprint((int)keycode
) )
1116 key
.Printf(wxT("'%c'"), (char)keycode
);
1117 else if ( keycode
> 0 && keycode
< 27 )
1118 key
.Printf(_("Ctrl-%c"), wxT('A') + keycode
- 1);
1120 key
.Printf(wxT("unknown (%ld)"), keycode
);
1125 wxLogMessage( wxT("%s event: %s (flags = %c%c%c%c)"),
1128 event
.ControlDown() ? wxT('C') : wxT('-'),
1129 event
.AltDown() ? wxT('A') : wxT('-'),
1130 event
.ShiftDown() ? wxT('S') : wxT('-'),
1131 event
.MetaDown() ? wxT('M') : wxT('-'));
1134 void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent
& event
)
1136 LogKeyEvent(wxT("Tree key down "), event
.GetKeyEvent());
1141 void MyTreeCtrl::OnBeginDrag(wxTreeEvent
& event
)
1143 // need to explicitly allow drag
1144 if ( event
.GetItem() != GetRootItem() )
1146 m_draggedItem
= event
.GetItem();
1148 wxPoint clientpt
= event
.GetPoint();
1149 wxPoint screenpt
= ClientToScreen(clientpt
);
1151 wxLogMessage(wxT("OnBeginDrag: started dragging %s at screen coords (%i,%i)"),
1152 GetItemText(m_draggedItem
).c_str(),
1153 screenpt
.x
, screenpt
.y
);
1159 wxLogMessage(wxT("OnBeginDrag: this item can't be dragged."));
1163 void MyTreeCtrl::OnEndDrag(wxTreeEvent
& event
)
1165 wxTreeItemId itemSrc
= m_draggedItem
,
1166 itemDst
= event
.GetItem();
1167 m_draggedItem
= (wxTreeItemId
)0l;
1169 // where to copy the item?
1170 if ( itemDst
.IsOk() && !ItemHasChildren(itemDst
) )
1172 // copy to the parent then
1173 itemDst
= GetItemParent(itemDst
);
1176 if ( !itemDst
.IsOk() )
1178 wxLogMessage(wxT("OnEndDrag: can't drop here."));
1183 wxString text
= GetItemText(itemSrc
);
1184 wxLogMessage(wxT("OnEndDrag: '%s' copied to '%s'."),
1185 text
.c_str(), GetItemText(itemDst
).c_str());
1187 // just do append here - we could also insert it just before/after the item
1188 // on which it was dropped, but this requires slightly more work... we also
1189 // completely ignore the client data and icon of the old item but could
1190 // copy them as well.
1192 // Finally, we only copy one item here but we might copy the entire tree if
1193 // we were dragging a folder.
1194 int image
= wxGetApp().ShowImages() ? TreeCtrlIcon_File
: -1;
1195 AppendItem(itemDst
, text
, image
);
1198 void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent
& event
)
1200 wxLogMessage(wxT("OnBeginLabelEdit"));
1202 // for testing, prevent this item's label editing
1203 wxTreeItemId itemId
= event
.GetItem();
1204 if ( IsTestItem(itemId
) )
1206 wxMessageBox(wxT("You can't edit this item."));
1210 else if ( itemId
== GetRootItem() )
1212 // test that it is possible to change the text of the item being edited
1213 SetItemText(itemId
, _T("Editing root item"));
1217 void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent
& event
)
1219 wxLogMessage(wxT("OnEndLabelEdit"));
1221 // don't allow anything except letters in the labels
1222 if ( !event
.GetLabel().IsWord() )
1224 wxMessageBox(wxT("The new label should be a single word."));
1230 void MyTreeCtrl::OnItemCollapsing(wxTreeEvent
& event
)
1232 wxLogMessage(wxT("OnItemCollapsing"));
1234 // for testing, prevent the user from collapsing the first child folder
1235 wxTreeItemId itemId
= event
.GetItem();
1236 if ( IsTestItem(itemId
) )
1238 wxMessageBox(wxT("You can't collapse this item."));
1244 void MyTreeCtrl::OnItemActivated(wxTreeEvent
& event
)
1246 // show some info about this item
1247 wxTreeItemId itemId
= event
.GetItem();
1248 MyTreeItemData
*item
= (MyTreeItemData
*)GetItemData(itemId
);
1252 item
->ShowInfo(this);
1255 wxLogMessage(wxT("OnItemActivated"));
1258 void MyTreeCtrl::OnItemMenu(wxTreeEvent
& event
)
1260 wxTreeItemId itemId
= event
.GetItem();
1261 MyTreeItemData
*item
= itemId
.IsOk() ? (MyTreeItemData
*)GetItemData(itemId
)
1263 wxPoint clientpt
= event
.GetPoint();
1264 wxPoint screenpt
= ClientToScreen(clientpt
);
1266 wxLogMessage(wxT("OnItemMenu for item \"%s\" at screen coords (%i, %i)"),
1267 item
? item
->GetDesc() : _T(""), screenpt
.x
, screenpt
.y
);
1269 ShowMenu(itemId
, clientpt
);
1273 void MyTreeCtrl::OnContextMenu(wxContextMenuEvent
& event
)
1275 wxPoint pt
= event
.GetPosition();
1277 wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt
.x
, pt
.y
);
1280 void MyTreeCtrl::ShowMenu(wxTreeItemId id
, const wxPoint
& pt
)
1285 title
<< wxT("Menu for ") << GetItemText(id
);
1289 title
= wxT("Menu for no particular item");
1294 menu
.Append(TreeTest_About
, wxT("&About..."));
1295 menu
.AppendSeparator();
1296 menu
.Append(TreeTest_Highlight
, wxT("&Highlight item"));
1297 menu
.Append(TreeTest_Dump
, wxT("&Dump"));
1299 PopupMenu(&menu
, pt
);
1300 #endif // wxUSE_MENUS
1303 void MyTreeCtrl::OnItemRClick(wxTreeEvent
& event
)
1305 wxTreeItemId itemId
= event
.GetItem();
1306 MyTreeItemData
*item
= itemId
.IsOk() ? (MyTreeItemData
*)GetItemData(itemId
)
1309 wxLogMessage(wxT("Item \"%s\" right clicked"), item
? item
->GetDesc()
1315 void MyTreeCtrl::OnRMouseDown(wxMouseEvent
& event
)
1317 wxLogMessage(wxT("Right mouse button down"));
1322 void MyTreeCtrl::OnRMouseUp(wxMouseEvent
& event
)
1324 wxLogMessage(wxT("Right mouse button up"));
1329 void MyTreeCtrl::OnRMouseDClick(wxMouseEvent
& event
)
1331 wxTreeItemId id
= HitTest(event
.GetPosition());
1333 wxLogMessage(wxT("No item under mouse"));
1336 MyTreeItemData
*item
= (MyTreeItemData
*)GetItemData(id
);
1338 wxLogMessage(wxT("Item '%s' under mouse"), item
->GetDesc());
1344 static inline const wxChar
*Bool2String(bool b
)
1346 return b
? wxT("") : wxT("not ");
1349 void MyTreeItemData::ShowInfo(wxTreeCtrl
*tree
)
1351 wxLogMessage(wxT("Item '%s': %sselected, %sexpanded, %sbold,\n")
1352 wxT("%u children (%u immediately under this item)."),
1354 Bool2String(tree
->IsSelected(GetId())),
1355 Bool2String(tree
->IsExpanded(GetId())),
1356 Bool2String(tree
->IsBold(GetId())),
1357 unsigned(tree
->GetChildrenCount(GetId())),
1358 unsigned(tree
->GetChildrenCount(GetId(), false)));