EVT_MENU(TreeTest_Unselect, MyFrame::OnUnselect)
#endif // NO_MULTIPLE_SELECTION
EVT_MENU(TreeTest_Rename, MyFrame::OnRename)
+ EVT_MENU(TreeTest_Count, MyFrame::OnCount)
+ EVT_MENU(TreeTest_CountRec, MyFrame::OnCountRec)
EVT_MENU(TreeTest_Sort, MyFrame::OnSort)
EVT_MENU(TreeTest_SortRev, MyFrame::OnSortRev)
EVT_MENU(TreeTest_Bold, MyFrame::OnSetBold)
EVT_MENU(TreeTest_CollapseAndReset, MyFrame::OnCollapseAndReset)
EVT_MENU(TreeTest_EnsureVisible, MyFrame::OnEnsureVisible)
EVT_MENU(TreeTest_AddItem, MyFrame::OnAddItem)
+ EVT_MENU(TreeTest_InsertItem, MyFrame::OnInsertItem)
EVT_MENU(TreeTest_IncIndent, MyFrame::OnIncIndent)
EVT_MENU(TreeTest_DecIndent, MyFrame::OnDecIndent)
EVT_MENU(TreeTest_IncSpacing, MyFrame::OnIncSpacing)
tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset");
tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_AddItem, "Append a &new item");
+ tree_menu->Append(TreeTest_InsertItem, "&Insert a new item");
tree_menu->Append(TreeTest_Delete, "&Delete this item");
tree_menu->Append(TreeTest_DeleteChildren, "Delete &children");
tree_menu->Append(TreeTest_DeleteAll, "Delete &all items");
tree_menu->AppendSeparator();
+ tree_menu->Append(TreeTest_Count, "Count children of current item");
+ tree_menu->Append(TreeTest_CountRec, "Recursively count children of current item");
+ tree_menu->AppendSeparator();
tree_menu->Append(TreeTest_Sort, "Sort children of current item");
tree_menu->Append(TreeTest_SortRev, "Sort in reversed order");
tree_menu->AppendSeparator();
wxTR_HAS_VARIABLE_ROW_HEIGHT |
#endif
wxSUNKEN_BORDER);
+
+ m_treeCtrl->SetBackgroundColour(wxColour(204, 205, 79));
+
wxTextCtrl *textCtrl = new wxTextCtrl(this, -1, "",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxSUNKEN_BORDER);
(void)m_treeCtrl->EditLabel(item);
}
+void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetSelection();
+
+ CHECK_ITEM( item );
+
+ int i = m_treeCtrl->GetChildrenCount( item, FALSE );
+
+ wxLogMessage(wxT("%d children"), i);
+}
+
+void MyFrame::OnCountRec(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetSelection();
+
+ CHECK_ITEM( item );
+
+ int i = m_treeCtrl->GetChildrenCount( item );
+
+ wxLogMessage(wxT("%d children"), i);
+}
+
void MyFrame::DoSort(bool reverse)
{
wxTreeItemId item = m_treeCtrl->GetSelection();
wxArrayTreeItemIds array;
size_t count = m_treeCtrl->GetSelections(array);
- wxLogMessage(_T("%u items selected"), count);
+ wxLogMessage(wxT("%u items selected"), count);
for ( size_t n = 0; n < count; n++ )
{
m_treeCtrl->DoEnsureVisible();
}
+void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), 1, "2nd item");
+}
+
void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
{
static int s_num = 0;
SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded);
AddItemsRecursively(rootId, numChildren, depth, 0);
+
+ // set some colours/fonts for testing
+ SetItemFont(rootId, *wxITALIC_FONT);
+
+ long cookie;
+ wxTreeItemId id = GetFirstChild(rootId, cookie);
+ SetItemTextColour(id, *wxBLUE);
+
+ id = GetNextChild(rootId, cookie);
+ id = GetNextChild(rootId, cookie);
+ SetItemTextColour(id, *wxRED);
+ SetItemBackgroundColour(id, *wxLIGHT_GREY);
}
void MyTreeCtrl::GetItemsRecursively(const wxTreeItemId& idParent, long cookie)