1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTreeCtrl sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
31 #include "wx/imaglist.h"
32 #include "wx/treectrl.h"
37 // comment out this line to test multiple selection even under MSW (where
38 // it looks ugly - but works)
39 #define NO_MULTIPLE_SELECTION
42 #define NO_VARIABLE_HEIGHT
46 // under Windows the icons are in the .rc file
53 #include "mondrian.xpm"
56 // verify that the item is ok and insult the user if it is not
57 #define CHECK_ITEM( item ) if ( !item.IsOk() ) { \
58 wxMessageBox("Please select some item first!", \
59 "Tree sample error", \
60 wxOK | wxICON_EXCLAMATION, \
65 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
66 EVT_MENU(TreeTest_Quit
, MyFrame::OnQuit
)
67 EVT_MENU(TreeTest_About
, MyFrame::OnAbout
)
68 EVT_MENU(TreeTest_Dump
, MyFrame::OnDump
)
69 #ifndef NO_MULTIPLE_SELECTION
70 EVT_MENU(TreeTest_DumpSelected
, MyFrame::OnDumpSelected
)
71 EVT_MENU(TreeTest_Select
, MyFrame::OnSelect
)
72 EVT_MENU(TreeTest_Unselect
, MyFrame::OnUnselect
)
73 #endif // NO_MULTIPLE_SELECTION
74 EVT_MENU(TreeTest_Rename
, MyFrame::OnRename
)
75 EVT_MENU(TreeTest_Count
, MyFrame::OnCount
)
76 EVT_MENU(TreeTest_CountRec
, MyFrame::OnCountRec
)
77 EVT_MENU(TreeTest_Sort
, MyFrame::OnSort
)
78 EVT_MENU(TreeTest_SortRev
, MyFrame::OnSortRev
)
79 EVT_MENU(TreeTest_Bold
, MyFrame::OnSetBold
)
80 EVT_MENU(TreeTest_UnBold
, MyFrame::OnClearBold
)
81 EVT_MENU(TreeTest_Delete
, MyFrame::OnDelete
)
82 EVT_MENU(TreeTest_DeleteChildren
, MyFrame::OnDeleteChildren
)
83 EVT_MENU(TreeTest_DeleteAll
, MyFrame::OnDeleteAll
)
84 EVT_MENU(TreeTest_Recreate
, MyFrame::OnRecreate
)
85 EVT_MENU(TreeTest_CollapseAndReset
, MyFrame::OnCollapseAndReset
)
86 EVT_MENU(TreeTest_EnsureVisible
, MyFrame::OnEnsureVisible
)
87 EVT_MENU(TreeTest_AddItem
, MyFrame::OnAddItem
)
88 EVT_MENU(TreeTest_InsertItem
, MyFrame::OnInsertItem
)
89 EVT_MENU(TreeTest_IncIndent
, MyFrame::OnIncIndent
)
90 EVT_MENU(TreeTest_DecIndent
, MyFrame::OnDecIndent
)
91 EVT_MENU(TreeTest_IncSpacing
, MyFrame::OnIncSpacing
)
92 EVT_MENU(TreeTest_DecSpacing
, MyFrame::OnDecSpacing
)
93 EVT_MENU(TreeTest_ToggleIcon
, MyFrame::OnToggleIcon
)
96 BEGIN_EVENT_TABLE(MyTreeCtrl
, wxTreeCtrl
)
97 EVT_TREE_BEGIN_DRAG(TreeTest_Ctrl
, MyTreeCtrl::OnBeginDrag
)
98 EVT_TREE_BEGIN_RDRAG(TreeTest_Ctrl
, MyTreeCtrl::OnBeginRDrag
)
99 EVT_TREE_BEGIN_LABEL_EDIT(TreeTest_Ctrl
, MyTreeCtrl::OnBeginLabelEdit
)
100 EVT_TREE_END_LABEL_EDIT(TreeTest_Ctrl
, MyTreeCtrl::OnEndLabelEdit
)
101 EVT_TREE_DELETE_ITEM(TreeTest_Ctrl
, MyTreeCtrl::OnDeleteItem
)
102 #if 0 // there are so many of those that logging them causes flicker
103 EVT_TREE_GET_INFO(TreeTest_Ctrl
, MyTreeCtrl::OnGetInfo
)
105 EVT_TREE_SET_INFO(TreeTest_Ctrl
, MyTreeCtrl::OnSetInfo
)
106 EVT_TREE_ITEM_EXPANDED(TreeTest_Ctrl
, MyTreeCtrl::OnItemExpanded
)
107 EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl
, MyTreeCtrl::OnItemExpanding
)
108 EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl
, MyTreeCtrl::OnItemCollapsed
)
109 EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl
, MyTreeCtrl::OnItemCollapsing
)
110 EVT_TREE_SEL_CHANGED(TreeTest_Ctrl
, MyTreeCtrl::OnSelChanged
)
111 EVT_TREE_SEL_CHANGING(TreeTest_Ctrl
, MyTreeCtrl::OnSelChanging
)
112 EVT_TREE_KEY_DOWN(TreeTest_Ctrl
, MyTreeCtrl::OnTreeKeyDown
)
113 EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl
, MyTreeCtrl::OnItemActivated
)
114 EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick
)
121 // Create the main frame window
122 MyFrame
*frame
= new MyFrame("wxTreeCtrl Test", 50, 50, 450, 340);
132 // My frame constructor
133 MyFrame::MyFrame(const wxString
& title
, int x
, int y
, int w
, int h
)
134 : wxFrame((wxFrame
*)NULL
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
136 // This reduces flicker effects - even better would be to define
137 // OnEraseBackground to do nothing. When the tree control's scrollbars are
138 // show or hidden, the frame is sent a background erase event.
139 SetBackgroundColour(wxColour(255, 255, 255));
142 SetIcon(wxICON(mondrian
));
145 wxMenu
*file_menu
= new wxMenu
,
146 *tree_menu
= new wxMenu
,
147 *item_menu
= new wxMenu
;
149 file_menu
->Append(TreeTest_About
, "&About...");
150 file_menu
->AppendSeparator();
151 file_menu
->Append(TreeTest_Quit
, "E&xit");
153 tree_menu
->Append(TreeTest_Recreate
, "&Recreate the tree");
154 tree_menu
->Append(TreeTest_CollapseAndReset
, "C&ollapse and reset");
155 tree_menu
->AppendSeparator();
156 tree_menu
->Append(TreeTest_AddItem
, "Append a &new item");
157 tree_menu
->Append(TreeTest_InsertItem
, "&Insert a new item");
158 tree_menu
->Append(TreeTest_Delete
, "&Delete this item");
159 tree_menu
->Append(TreeTest_DeleteChildren
, "Delete &children");
160 tree_menu
->Append(TreeTest_DeleteAll
, "Delete &all items");
161 tree_menu
->AppendSeparator();
162 tree_menu
->Append(TreeTest_Count
, "Count children of current item");
163 tree_menu
->Append(TreeTest_CountRec
, "Recursively count children of current item");
164 tree_menu
->AppendSeparator();
165 tree_menu
->Append(TreeTest_Sort
, "Sort children of current item");
166 tree_menu
->Append(TreeTest_SortRev
, "Sort in reversed order");
167 tree_menu
->AppendSeparator();
168 tree_menu
->Append(TreeTest_EnsureVisible
, "Make the last item &visible");
169 tree_menu
->AppendSeparator();
170 tree_menu
->Append(TreeTest_IncIndent
, "Add 5 points to indentation\tAlt-I");
171 tree_menu
->Append(TreeTest_DecIndent
, "Reduce indentation by 5 points\tAlt-R");
172 tree_menu
->AppendSeparator();
173 tree_menu
->Append(TreeTest_IncSpacing
, "Add 5 points to spacing\tCtrl-I");
174 tree_menu
->Append(TreeTest_DecSpacing
, "Reduce spacing by 5 points\tCtrl-R");
176 item_menu
->Append(TreeTest_Dump
, "&Dump item children");
177 item_menu
->Append(TreeTest_Rename
, "&Rename item...");
179 item_menu
->AppendSeparator();
180 item_menu
->Append(TreeTest_Bold
, "Make item &bold");
181 item_menu
->Append(TreeTest_UnBold
, "Make item ¬ bold");
182 item_menu
->AppendSeparator();
183 item_menu
->Append(TreeTest_ToggleIcon
, "Toggle the items &icon");
185 #ifndef NO_MULTIPLE_SELECTION
186 item_menu
->AppendSeparator();
187 item_menu
->Append(TreeTest_DumpSelected
, "Dump selected items\tAlt-D");
188 item_menu
->Append(TreeTest_Select
, "Select current item\tAlt-S");
189 item_menu
->Append(TreeTest_Unselect
, "Unselect everything\tAlt-U");
192 wxMenuBar
*menu_bar
= new wxMenuBar
;
193 menu_bar
->Append(file_menu
, "&File");
194 menu_bar
->Append(tree_menu
, "&Tree");
195 menu_bar
->Append(item_menu
, "&Item");
196 SetMenuBar(menu_bar
);
198 m_treeCtrl
= new MyTreeCtrl(this, TreeTest_Ctrl
,
199 wxDefaultPosition
, wxDefaultSize
,
202 #ifndef NO_MULTIPLE_SELECTION
205 #ifndef NO_VARIABLE_HEIGHT
206 wxTR_HAS_VARIABLE_ROW_HEIGHT
|
210 m_treeCtrl
->SetBackgroundColour(wxColour(204, 205, 79));
212 wxTextCtrl
*textCtrl
= new wxTextCtrl(this, -1, "",
213 wxDefaultPosition
, wxDefaultSize
,
214 wxTE_MULTILINE
| wxSUNKEN_BORDER
);
216 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
217 c
->top
.SameAs(this, wxTop
);
218 c
->left
.SameAs(this, wxLeft
);
219 c
->right
.SameAs(this, wxRight
);
220 c
->height
.PercentOf(this, wxHeight
, 66);
221 m_treeCtrl
->SetConstraints(c
);
223 c
= new wxLayoutConstraints
;
224 c
->top
.Below(m_treeCtrl
);
225 c
->left
.SameAs(this, wxLeft
);
226 c
->right
.SameAs(this, wxRight
);
227 c
->bottom
.SameAs(this, wxBottom
);
228 textCtrl
->SetConstraints(c
);
231 // create a status bar with 3 panes
233 SetStatusText("", 0);
236 // For some reason, we get a memcpy crash in wxLogStream::DoLogStream
237 // on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
238 delete wxLog::SetActiveTarget(new wxLogStderr
);
240 // set our text control as the log target
241 wxLogTextCtrl
*logWindow
= new wxLogTextCtrl(textCtrl
);
242 delete wxLog::SetActiveTarget(logWindow
);
248 delete wxLog::SetActiveTarget(NULL
);
251 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
256 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
258 wxMessageBox("Tree test sample\n"
259 "(c) Julian Smart 1997, Vadim Zeitlin 1998",
261 wxOK
| wxICON_INFORMATION
, this);
264 void MyFrame::OnRename(wxCommandEvent
& WXUNUSED(event
))
266 wxTreeItemId item
= m_treeCtrl
->GetSelection();
270 // old code - now we edit in place
272 static wxString s_text
;
273 s_text
= wxGetTextFromUser("New name: ", "Tree sample question",
275 if ( !s_text
.IsEmpty() )
277 m_treeCtrl
->SetItemText(item
, s_text
);
281 // TODO demonstrate creating a custom edit control...
282 (void)m_treeCtrl
->EditLabel(item
);
285 void MyFrame::OnCount(wxCommandEvent
& WXUNUSED(event
))
287 wxTreeItemId item
= m_treeCtrl
->GetSelection();
291 int i
= m_treeCtrl
->GetChildrenCount( item
, FALSE
);
293 wxLogMessage(wxT("%d children"), i
);
296 void MyFrame::OnCountRec(wxCommandEvent
& WXUNUSED(event
))
298 wxTreeItemId item
= m_treeCtrl
->GetSelection();
302 int i
= m_treeCtrl
->GetChildrenCount( item
);
304 wxLogMessage(wxT("%d children"), i
);
307 void MyFrame::DoSort(bool reverse
)
309 wxTreeItemId item
= m_treeCtrl
->GetSelection();
313 m_treeCtrl
->DoSortChildren(item
, reverse
);
316 void MyFrame::OnDump(wxCommandEvent
& WXUNUSED(event
))
318 wxTreeItemId root
= m_treeCtrl
->GetSelection();
322 m_treeCtrl
->GetItemsRecursively(root
, -1);
325 #ifndef NO_MULTIPLE_SELECTION
327 void MyFrame::OnDumpSelected(wxCommandEvent
& WXUNUSED(event
))
329 wxArrayTreeItemIds array
;
331 size_t count
= m_treeCtrl
->GetSelections(array
);
332 wxLogMessage(wxT("%u items selected"), count
);
334 for ( size_t n
= 0; n
< count
; n
++ )
336 wxLogMessage("\t%s", m_treeCtrl
->GetItemText(array
.Item(n
)).c_str());
340 void MyFrame::OnSelect(wxCommandEvent
& event
)
342 m_treeCtrl
->SelectItem(m_treeCtrl
->GetSelection());
345 void MyFrame::OnUnselect(wxCommandEvent
& event
)
347 m_treeCtrl
->UnselectAll();
350 #endif // NO_MULTIPLE_SELECTION
352 void MyFrame::DoSetBold(bool bold
)
354 wxTreeItemId item
= m_treeCtrl
->GetSelection();
358 m_treeCtrl
->SetItemBold(item
, bold
);
361 void MyFrame::OnDelete(wxCommandEvent
& WXUNUSED(event
))
363 wxTreeItemId item
= m_treeCtrl
->GetSelection();
367 m_treeCtrl
->Delete(item
);
370 void MyFrame::OnDeleteChildren(wxCommandEvent
& WXUNUSED(event
))
372 wxTreeItemId item
= m_treeCtrl
->GetSelection();
376 m_treeCtrl
->DeleteChildren(item
);
379 void MyFrame::OnDeleteAll(wxCommandEvent
& WXUNUSED(event
))
381 m_treeCtrl
->DeleteAllItems();
384 void MyFrame::OnRecreate(wxCommandEvent
& event
)
387 m_treeCtrl
->AddTestItemsToTree(3, 2);
390 void MyFrame::OnCollapseAndReset(wxCommandEvent
& event
)
392 m_treeCtrl
->CollapseAndReset(m_treeCtrl
->GetRootItem());
395 void MyFrame::OnEnsureVisible(wxCommandEvent
& event
)
397 m_treeCtrl
->DoEnsureVisible();
400 void MyFrame::OnInsertItem(wxCommandEvent
& WXUNUSED(event
))
402 m_treeCtrl
->InsertItem(m_treeCtrl
->GetRootItem(), 1, "2nd item");
405 void MyFrame::OnAddItem(wxCommandEvent
& WXUNUSED(event
))
407 static int s_num
= 0;
410 text
.Printf("Item #%d", ++s_num
);
412 m_treeCtrl
->AppendItem(m_treeCtrl
->GetRootItem(),
414 MyTreeCtrl::TreeCtrlIcon_File */ );
417 void MyFrame::OnIncIndent(wxCommandEvent
& WXUNUSED(event
))
419 unsigned int indent
= m_treeCtrl
->GetIndent();
421 m_treeCtrl
->SetIndent( indent
+5 );
424 void MyFrame::OnDecIndent(wxCommandEvent
& WXUNUSED(event
))
426 unsigned int indent
= m_treeCtrl
->GetIndent();
428 m_treeCtrl
->SetIndent( indent
-5 );
431 void MyFrame::OnIncSpacing(wxCommandEvent
& WXUNUSED(event
))
433 unsigned int indent
= m_treeCtrl
->GetSpacing();
435 m_treeCtrl
->SetSpacing( indent
+5 );
438 void MyFrame::OnDecSpacing(wxCommandEvent
& WXUNUSED(event
))
440 unsigned int indent
= m_treeCtrl
->GetSpacing();
442 m_treeCtrl
->SetSpacing( indent
-5 );
445 void MyFrame::OnToggleIcon(wxCommandEvent
& WXUNUSED(event
))
447 wxTreeItemId item
= m_treeCtrl
->GetSelection();
451 m_treeCtrl
->DoToggleIcon(item
);
454 // MyTreeCtrl implementation
455 IMPLEMENT_DYNAMIC_CLASS(MyTreeCtrl
, wxTreeCtrl
)
457 MyTreeCtrl::MyTreeCtrl(wxWindow
*parent
, const wxWindowID id
,
458 const wxPoint
& pos
, const wxSize
& size
,
460 : wxTreeCtrl(parent
, id
, pos
, size
, style
)
462 #ifndef NO_VARIABLE_HEIGHT
464 wxImage::AddHandler(new wxJPEGHandler
);
467 image
.LoadFile(wxString("horse.jpg"), wxBITMAP_TYPE_JPEG
);
471 m_reverseSort
= FALSE
;
473 // Make an image list containing small icons
474 m_imageListNormal
= new wxImageList(16, 16, TRUE
);
476 // should correspond to TreeCtrlIcon_xxx enum
477 #if defined(__WXMSW__) && defined(__WIN16__)
478 // This is required in 16-bit Windows mode only because we can't load a specific (16x16)
479 // icon image, so it comes out stretched
480 # ifndef NO_VARIABLE_HEIGHT
481 m_imageListNormal
->Add(image
.ConvertToBitmap());
483 m_imageListNormal
->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE
));
485 m_imageListNormal
->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE
));
486 m_imageListNormal
->Add(wxBitmap("bitmap3", wxBITMAP_TYPE_BMP_RESOURCE
));
487 m_imageListNormal
->Add(wxBitmap("bitmap4", wxBITMAP_TYPE_BMP_RESOURCE
));
488 m_imageListNormal
->Add(wxBitmap("bitmap5", wxBITMAP_TYPE_BMP_RESOURCE
));
490 # ifndef NO_VARIABLE_HEIGHT
491 m_imageListNormal
->Add(image
.ConvertToBitmap());
493 m_imageListNormal
->Add(wxICON(icon1
));
495 m_imageListNormal
->Add(wxICON(icon2
));
496 m_imageListNormal
->Add(wxICON(icon3
));
497 m_imageListNormal
->Add(wxICON(icon4
));
498 m_imageListNormal
->Add(wxICON(icon5
));
501 SetImageList(m_imageListNormal
);
503 // Add some items to the tree
504 AddTestItemsToTree(3, 2);
507 MyTreeCtrl::~MyTreeCtrl()
509 delete m_imageListNormal
;
512 int MyTreeCtrl::OnCompareItems(const wxTreeItemId
& item1
,
513 const wxTreeItemId
& item2
)
517 // just exchange 1st and 2nd items
518 return wxTreeCtrl::OnCompareItems(item2
, item1
);
522 return wxTreeCtrl::OnCompareItems(item1
, item2
);
526 void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId
& idParent
,
533 bool hasChildren
= depth
> 1;
536 for ( size_t n
= 0; n
< numChildren
; n
++ )
538 // at depth 1 elements won't have any more children
540 str
.Printf("%s child %d", "Folder", n
+ 1);
542 str
.Printf("%s child %d.%d", "File", folder
, n
+ 1);
544 // here we pass to AppendItem() normal and selected item images (we
545 // suppose that selected image follows the normal one in the enum)
546 int image
= depth
== 1 ? TreeCtrlIcon_File
: TreeCtrlIcon_Folder
;
547 wxTreeItemId id
= AppendItem(idParent
, str
, image
, image
+ 1,
548 new MyTreeItemData(str
));
550 // and now we also set the expanded one (only for the folders)
553 SetItemImage(id
, TreeCtrlIcon_FolderOpened
,
554 wxTreeItemIcon_Expanded
);
557 // remember the last child for OnEnsureVisible()
558 if ( !hasChildren
&& n
== numChildren
- 1 )
563 AddItemsRecursively(id
, numChildren
, depth
- 1, n
+ 1);
569 void MyTreeCtrl::AddTestItemsToTree(size_t numChildren
,
572 wxTreeItemId rootId
= AddRoot("Root",
573 TreeCtrlIcon_Folder
, TreeCtrlIcon_Folder
,
574 new MyTreeItemData("Root item"));
575 SetItemImage(rootId
, TreeCtrlIcon_FolderOpened
, wxTreeItemIcon_Expanded
);
577 AddItemsRecursively(rootId
, numChildren
, depth
, 0);
579 // set some colours/fonts for testing
580 SetItemFont(rootId
, *wxITALIC_FONT
);
583 wxTreeItemId id
= GetFirstChild(rootId
, cookie
);
584 SetItemTextColour(id
, *wxBLUE
);
586 id
= GetNextChild(rootId
, cookie
);
587 id
= GetNextChild(rootId
, cookie
);
588 SetItemTextColour(id
, *wxRED
);
589 SetItemBackgroundColour(id
, *wxLIGHT_GREY
);
592 void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId
& idParent
, long cookie
)
597 id
= GetFirstChild(idParent
, cookie
);
599 id
= GetNextChild(idParent
, cookie
);
604 wxString text
= GetItemText(id
);
607 if (ItemHasChildren(id
))
608 GetItemsRecursively(id
,-1);
610 GetItemsRecursively(idParent
, cookie
);
613 void MyTreeCtrl::DoToggleIcon(const wxTreeItemId
& item
)
615 int image
= GetItemImage(item
) == TreeCtrlIcon_Folder
? TreeCtrlIcon_File
616 : TreeCtrlIcon_Folder
;
618 SetItemImage(item
, image
);
623 #define TREE_EVENT_HANDLER(name) \
624 void MyTreeCtrl::name(wxTreeEvent& WXUNUSED(event)) \
626 wxLogMessage(#name); \
629 TREE_EVENT_HANDLER(OnBeginDrag
)
630 TREE_EVENT_HANDLER(OnBeginRDrag
)
631 TREE_EVENT_HANDLER(OnDeleteItem
)
632 TREE_EVENT_HANDLER(OnGetInfo
)
633 TREE_EVENT_HANDLER(OnSetInfo
)
634 TREE_EVENT_HANDLER(OnItemExpanded
)
635 TREE_EVENT_HANDLER(OnItemExpanding
)
636 TREE_EVENT_HANDLER(OnItemCollapsed
)
637 TREE_EVENT_HANDLER(OnSelChanged
)
638 TREE_EVENT_HANDLER(OnSelChanging
)
640 #undef TREE_EVENT_HANDLER
642 void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent
& event
)
644 wxLogMessage("OnBeginLabelEdit");
646 // for testing, prevent this items label editing
647 wxTreeItemId itemId
= event
.GetItem();
648 if ( IsTestItem(itemId
) )
650 wxMessageBox("You can't edit this item.");
656 void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent
& event
)
658 wxLogMessage("OnEndLabelEdit");
660 // don't allow anything except letters in the labels
661 if ( !event
.GetLabel().IsWord() )
663 wxMessageBox("The label should contain only letters.");
669 void MyTreeCtrl::OnItemCollapsing(wxTreeEvent
& event
)
671 wxLogMessage("OnItemCollapsing");
673 // for testing, prevent the user from collapsing the first child folder
674 wxTreeItemId itemId
= event
.GetItem();
675 if ( IsTestItem(itemId
) )
677 wxMessageBox("You can't collapse this item.");
683 void MyTreeCtrl::OnTreeKeyDown(wxTreeEvent
&WXUNUSED(event
))
685 wxLogMessage("OnTreeKeyDown");
688 void MyTreeCtrl::OnItemActivated(wxTreeEvent
&WXUNUSED(event
))
690 // show some info about this item
691 wxTreeItemId itemId
= GetSelection();
692 MyTreeItemData
*item
= (MyTreeItemData
*)GetItemData(itemId
);
696 item
->ShowInfo(this);
699 wxLogMessage("OnItemActivated");
702 void MyTreeCtrl::OnRMouseDClick(wxMouseEvent
& event
)
704 wxTreeItemId id
= HitTest(event
.GetPosition());
706 wxLogMessage("No item under mouse");
709 MyTreeItemData
*item
= (MyTreeItemData
*)GetItemData(id
);
711 wxLogMessage("Item '%s' under mouse", item
->GetDesc());
715 static inline const char *Bool2String(bool b
)
717 return b
? "" : "not ";
720 void MyTreeItemData::ShowInfo(wxTreeCtrl
*tree
)
722 wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
723 "%u children (%u immediately under this item).",
725 Bool2String(tree
->IsSelected(GetId())),
726 Bool2String(tree
->IsExpanded(GetId())),
727 Bool2String(tree
->IsBold(GetId())),
728 tree
->GetChildrenCount(GetId()),
729 tree
->GetChildrenCount(GetId(), FALSE
));