// Test various tree traversal methods. void TreeListCtrlTestCase::Traversal() { // GetParent() tests: wxTreeListItem root = m_treelist->GetRootItem(); CPPUNIT_ASSERT( !m_treelist->GetItemParent(root) ); CPPUNIT_ASSERT_EQUAL( root, m_treelist->GetItemParent(m_code) ); CPPUNIT_ASSERT_EQUAL( m_code, m_treelist->GetItemParent(m_code_osx) ); // GetFirstChild() and GetNextSibling() tests: CPPUNIT_ASSERT_EQUAL( m_code, m_treelist->GetFirstChild(root) ); CPPUNIT_ASSERT_EQUAL ( m_code_osx, m_treelist->GetNextSibling ( m_treelist->GetNextSibling ( m_treelist->GetFirstChild(m_code) ) ) ); // Get{First,Next}Item() test: unsigned numItems = 0; for ( wxTreeListItem item = m_treelist->GetFirstItem(); item.IsOk(); item = m_treelist->GetNextItem(item) ) { numItems++; } CPPUNIT_ASSERT_EQUAL( m_numItems, numItems ); }
void MyFrame::OnDumpSelection(wxCommandEvent& WXUNUSED(event)) { if ( m_treelist->HasFlag(wxTL_MULTIPLE) ) { wxTreeListItems selections; const unsigned numSelected = m_treelist->GetSelections(selections); switch ( numSelected ) { case 0: wxLogMessage("No items selected"); break; case 1: wxLogMessage("Single item selected: %s", DumpItem(selections[0])); break; default: wxLogMessage("%u items selected:", numSelected); for ( unsigned n = 0; n < numSelected; n++ ) { wxLogMessage("\t%s", DumpItem(selections[n])); } } } else // Single selection { wxLogMessage("Selection: %s", DumpItem(m_treelist->GetSelection())); } }
void TreeListCtrlTestCase::Create(long style) { m_treelist = new wxTreeListCtrl(wxTheApp->GetTopWindow(), wxID_ANY, wxDefaultPosition, wxSize(400, 200), style); m_treelist->AppendColumn("Component"); m_treelist->AppendColumn("# Files"); m_treelist->AppendColumn("Size"); // Fill the control with the same data as used in the treelist sample: m_code = AddItem("Code"); AddItem("wxMSW", m_code, "313", "3.94 MiB"); AddItem("wxGTK", m_code, "180", "1.66 MiB"); m_code_osx = AddItem("wxOSX", m_code, "265", "2.36 MiB"); AddItem("Core", m_code_osx, "31", "347 KiB"); AddItem("Carbon", m_code_osx, "91", "1.34 MiB"); m_code_osx_cocoa = AddItem("Cocoa", m_code_osx, "46", "512 KiB"); wxTreeListItem Documentation = AddItem("Documentation"); AddItem("HTML", Documentation, "many"); AddItem("CHM", Documentation, "1"); wxTreeListItem Samples = AddItem("Samples"); AddItem("minimal", Samples, "1", "7 KiB"); AddItem("widgets", Samples, "28", "419 KiB"); m_treelist->Refresh(); m_treelist->Update(); }
void MyFrame::OnCheckHTMLDocs(wxCommandEvent& event) { wxCheckBoxState state; switch ( event.GetId() ) { case Id_Uncheck_HTMLDocs: state = wxCHK_UNCHECKED; break; case Id_Check_HTMLDocs: state = wxCHK_CHECKED; break; case Id_Indet_HTMLDocs: state = wxCHK_UNDETERMINED; break; default: wxFAIL_MSG( "Unknown check state" ); return; } m_treelist->CheckItem(m_itemHTMLDocs, state); }
void MyFrame::OnCheckboxes(wxCommandEvent& event) { long style = m_treelist->GetWindowStyle(); style &= ~(wxTL_CHECKBOX | wxTL_3STATE | wxTL_USER_3STATE); switch ( event.GetId() ) { case Id_NoCheckboxes: break; case Id_Checkboxes2State: style |= wxTL_CHECKBOX; break; case Id_Checkboxes3State: style |= wxTL_3STATE; break; case Id_CheckboxesUser3State: style |= wxTL_USER_3STATE; break; default: wxFAIL_MSG( "Unknown checkbox style" ); return; } RecreateTreeListCtrl(style); }
wxTreeListItem TreeListCtrlTestCase::AddItem(const char *label, wxTreeListItem parent, const char *numFiles, const char *size) { if ( !parent.IsOk() ) parent = m_treelist->GetRootItem(); wxTreeListItem item = m_treelist->AppendItem(parent, label); m_treelist->SetItemText(item, 1, numFiles); m_treelist->SetItemText(item, 2, size); m_numItems++; return item; }
void MyFrame::OnItemChecked(wxTreeListEvent& event) { wxTreeListItem item = event.GetItem(); wxLogMessage("Item \"%s\" toggled, now %s (was %s)", DumpItem(item), CheckedStateString(m_treelist->GetCheckedState(item)), CheckedStateString(event.GetOldCheckedState())); }
void MyFrame::OnSelectionChanged(wxTreeListEvent& event) { const char* msg; if ( m_treelist->HasFlag(wxTL_MULTIPLE) ) msg = "Selection of the \"%s\" item changed."; else msg = "Selection changed, now is \"%s\"."; wxLogMessage(msg, DumpItem(event.GetItem())); }
// Test accessing items text. void TreeListCtrlTestCase::ItemText() { CPPUNIT_ASSERT_EQUAL( "Cocoa", m_treelist->GetItemText(m_code_osx_cocoa) ); CPPUNIT_ASSERT_EQUAL( "46", m_treelist->GetItemText(m_code_osx_cocoa, 1) ); m_treelist->SetItemText(m_code_osx_cocoa, "wxCocoa"); CPPUNIT_ASSERT_EQUAL( "wxCocoa", m_treelist->GetItemText(m_code_osx_cocoa) ); m_treelist->SetItemText(m_code_osx_cocoa, 1, "47"); CPPUNIT_ASSERT_EQUAL( "47", m_treelist->GetItemText(m_code_osx_cocoa, 1) ); }
// Test checking and unchecking items. void TreeListCtrlTestCase::ItemCheck() { CPPUNIT_ASSERT_EQUAL( wxCHK_UNCHECKED, m_treelist->GetCheckedState(m_code) ); m_treelist->CheckItemRecursively(m_code); CPPUNIT_ASSERT_EQUAL( wxCHK_CHECKED, m_treelist->GetCheckedState(m_code) ); CPPUNIT_ASSERT_EQUAL( wxCHK_CHECKED, m_treelist->GetCheckedState(m_code_osx) ); CPPUNIT_ASSERT_EQUAL( wxCHK_CHECKED, m_treelist->GetCheckedState(m_code_osx_cocoa) ); m_treelist->UncheckItem(m_code_osx_cocoa); CPPUNIT_ASSERT_EQUAL( wxCHK_UNCHECKED, m_treelist->GetCheckedState(m_code_osx_cocoa) ); m_treelist->UpdateItemParentStateRecursively(m_code_osx_cocoa); CPPUNIT_ASSERT_EQUAL( wxCHK_UNDETERMINED, m_treelist->GetCheckedState(m_code_osx) ); CPPUNIT_ASSERT_EQUAL( wxCHK_UNDETERMINED, m_treelist->GetCheckedState(m_code) ); m_treelist->CheckItemRecursively(m_code_osx, wxCHK_UNCHECKED); m_treelist->UpdateItemParentStateRecursively(m_code_osx_cocoa); CPPUNIT_ASSERT_EQUAL( wxCHK_UNCHECKED, m_treelist->GetCheckedState(m_code_osx) ); CPPUNIT_ASSERT_EQUAL( wxCHK_UNDETERMINED, m_treelist->GetCheckedState(m_code) ); }
wxString MyFrame::DumpItem(wxTreeListItem item) const { return item.IsOk() ? m_treelist->GetItemText(item) : wxString("NONE"); }
void MyFrame::OnSelectHTMLDocs(wxCommandEvent& WXUNUSED(event)) { m_treelist->Select(m_itemHTMLDocs); }
void MyFrame::OnFlatList(wxCommandEvent& event) { m_isFlat = event.IsChecked(); RecreateTreeListCtrl(m_treelist->GetWindowStyle()); }
void MyFrame::OnMultiSelect(wxCommandEvent& event) { long style = m_treelist->GetWindowStyle(); if ( event.IsChecked() ) style |= wxTL_MULTIPLE; else style &= ~wxTL_MULTIPLE; RecreateTreeListCtrl(style); }
void MyFrame::OnItemContextMenu(wxTreeListEvent& event) { enum { Id_Check_Item, Id_Uncheck_Item, Id_Indet_Item, Id_Check_Recursively, Id_Update_Parent }; wxMenu menu; menu.Append(Id_Check_Item, "&Check item"); menu.Append(Id_Uncheck_Item, "&Uncheck item"); if ( m_treelist->HasFlag(wxTL_3STATE) ) menu.Append(Id_Indet_Item, "Make item &indeterminate"); menu.AppendSeparator(); menu.Append(Id_Check_Recursively, "Check &recursively"); menu.Append(Id_Update_Parent, "Update &parent"); const wxTreeListItem item = event.GetItem(); switch ( m_treelist->GetPopupMenuSelectionFromUser(menu) ) { case Id_Check_Item: m_treelist->CheckItem(item); break; case Id_Uncheck_Item: m_treelist->UncheckItem(item); break; case Id_Indet_Item: m_treelist->CheckItem(item, wxCHK_UNDETERMINED); break; case Id_Check_Recursively: m_treelist->CheckItemRecursively(item); break; case Id_Update_Parent: m_treelist->UpdateItemParentStateRecursively(item); break; default: wxFAIL_MSG( "Unexpected menu selection" ); // Fall through. case wxID_NONE: return; } }