X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/74b31181b345aaaef0c967cc5707bef72ce0a405..0dfef5a8124ac0f1bb2aed6ef5ddfa833e8e2c6e:/samples/treectrl/treetest.cpp diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 873b881083..2bd8bfa646 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -34,10 +34,13 @@ #include "math.h" #ifdef __WXMSW__ + // comment out this line to test multiple selection even under MSW (where + // it looks ugly - but works) #define NO_MULTIPLE_SELECTION - #define NO_VARIABLE_HEIGHT #endif +#define NO_VARIABLE_HEIGHT + #include "treetest.h" // under Windows the icons are in the .rc file @@ -46,6 +49,7 @@ #include "icon2.xpm" #include "icon3.xpm" #include "icon4.xpm" + #include "icon5.xpm" #include "mondrian.xpm" #endif @@ -68,6 +72,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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) @@ -79,6 +85,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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) @@ -147,10 +154,14 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) 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(); @@ -195,6 +206,9 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) 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); @@ -268,6 +282,28 @@ void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) (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(); @@ -293,7 +329,7 @@ void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event)) 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++ ) { @@ -361,6 +397,11 @@ void MyFrame::OnEnsureVisible(wxCommandEvent& event) 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; @@ -534,6 +575,18 @@ void MyTreeCtrl::AddTestItemsToTree(size_t numChildren, 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)