+ wxMessageBox(wxT("Tree test sample\n")
+ wxT("(c) Julian Smart 1997, Vadim Zeitlin 1998"),
+ wxT("About tree test"),
+ wxOK | wxICON_INFORMATION, this);
+}
+
+void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event))
+{
+ m_textCtrl->Clear();
+}
+
+void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ // old code - now we edit in place
+#if 0
+ static wxString s_text;
+ s_text = wxGetTextFromUser(wxT("New name: "), wxT("Tree sample question"),
+ s_text, this);
+ if ( !s_text.empty() )
+ {
+ m_treeCtrl->SetItemText(item, s_text);
+ }
+#endif // 0
+
+ // TODO demonstrate creating a custom edit control...
+ (void)m_treeCtrl->EditLabel(item);
+}
+
+void MyFrame::OnCount(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ 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->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ int i = m_treeCtrl->GetChildrenCount( item );
+
+ wxLogMessage(wxT("%d children"), i);
+}
+
+void MyFrame::DoSort(bool reverse)
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->DoSortChildren(item, reverse);
+}
+
+void MyFrame::OnHighlight(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId id = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( id );
+
+ wxRect r;
+ if ( !m_treeCtrl->GetBoundingRect(id, r, true /* text, not full row */) )
+ {
+ wxLogMessage(wxT("Failed to get bounding item rect"));
+ return;
+ }
+
+ wxClientDC dc(m_treeCtrl);
+ dc.SetBrush(*wxRED);
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.DrawRectangle(r);
+ m_treeCtrl->Update();
+}
+
+void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId root = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( root );
+
+ m_treeCtrl->GetItemsRecursively(root);
+}
+
+#ifndef NO_MULTIPLE_SELECTION
+
+void MyFrame::OnToggleSel(wxCommandEvent& event)
+{
+ TogStyle(event.GetId(), wxTR_MULTIPLE);
+}
+
+void MyFrame::OnDumpSelected(wxCommandEvent& WXUNUSED(event))
+{
+ wxArrayTreeItemIds array;
+
+ size_t count = m_treeCtrl->GetSelections(array);
+ wxLogMessage(wxT("%u items selected"), unsigned(count));
+
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxLogMessage(wxT("\t%s"), m_treeCtrl->GetItemText(array.Item(n)).c_str());
+ }
+}
+
+void MyFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->SelectItem(m_treeCtrl->GetFocusedItem());
+}
+
+void MyFrame::OnSelectRoot(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !m_treeCtrl->HasFlag(wxTR_HIDE_ROOT) )
+ m_treeCtrl->SelectItem(m_treeCtrl->GetRootItem());
+}
+
+void MyFrame::OnSetFocusedRoot(wxCommandEvent& WXUNUSED(event))
+{
+ if ( !m_treeCtrl->HasFlag(wxTR_HIDE_ROOT) )
+ m_treeCtrl->SetFocusedItem(m_treeCtrl->GetRootItem());
+}
+
+void MyFrame::OnClearFocused(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->ClearFocusedItem();
+}
+
+void MyFrame::OnUnselect(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->UnselectAll();
+}
+
+void MyFrame::OnSelectChildren(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+ if ( !item.IsOk() )
+ item = m_treeCtrl->GetRootItem();
+
+ m_treeCtrl->SelectChildren(item);
+}
+
+#endif // NO_MULTIPLE_SELECTION
+
+void MyFrame::DoSetBold(bool bold)
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->SetItemBold(item, bold);
+}
+
+void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->Delete(item);
+}
+
+void MyFrame::OnDeleteChildren(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->DeleteChildren(item);
+}
+
+void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->DeleteAllItems();
+}
+
+void MyFrame::OnRecreate(wxCommandEvent& event)
+{
+ OnDeleteAll(event);
+ m_treeCtrl->AddTestItemsToTree(NUM_CHILDREN_PER_LEVEL, NUM_LEVELS);
+}
+
+void MyFrame::OnSetImageSize(wxCommandEvent& WXUNUSED(event))
+{
+ int size = wxGetNumberFromUser(wxT("Enter the size for the images to use"),
+ wxT("Size: "),
+ wxT("TreeCtrl sample"),
+ m_treeCtrl->ImageSize());
+ if ( size == -1 )
+ return;
+
+ m_treeCtrl->CreateImageList(size);
+ wxGetApp().SetShowImages(true);
+}
+
+void MyFrame::OnToggleImages(wxCommandEvent& WXUNUSED(event))
+{
+ if ( wxGetApp().ShowImages() )
+ {
+ m_treeCtrl->CreateImageList(-1);
+ wxGetApp().SetShowImages(false);
+ }
+ else
+ {
+ m_treeCtrl->CreateImageList(0);
+ wxGetApp().SetShowImages(true);
+ }
+}
+
+void MyFrame::OnToggleStates(wxCommandEvent& WXUNUSED(event))
+{
+ if ( wxGetApp().ShowStates() )
+ {
+ m_treeCtrl->CreateStateImageList(true);
+ wxGetApp().SetShowStates(false);
+ }
+ else
+ {
+ m_treeCtrl->CreateStateImageList(false);
+ wxGetApp().SetShowStates(true);
+ }
+}
+
+void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event))
+{
+ bool alternateImages = m_treeCtrl->AlternateImages();
+
+ m_treeCtrl->SetAlternateImages(!alternateImages);
+ m_treeCtrl->CreateImageList(0);
+}
+
+void MyFrame::OnToggleAlternateStates(wxCommandEvent& WXUNUSED(event))
+{
+ bool alternateStates = m_treeCtrl->AlternateStates();
+
+ m_treeCtrl->SetAlternateStates(!alternateStates);
+ m_treeCtrl->CreateStateImageList();
+
+ // normal states < alternate states
+ // so we must reset broken states
+ if ( alternateStates )
+ m_treeCtrl->ResetBrokenStateImages();
+}
+
+void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event))
+{
+#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
+ if ( wxGetApp().ShowButtons() )
+ {
+ m_treeCtrl->CreateButtonsImageList(-1);
+ wxGetApp().SetShowButtons(false);
+ }
+ else
+ {
+ m_treeCtrl->CreateButtonsImageList(15);
+ wxGetApp().SetShowButtons(true);
+ }
+#endif
+}
+
+void MyFrame::OnCollapseAndReset(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->CollapseAndReset(m_treeCtrl->GetRootItem());
+}
+
+void MyFrame::OnEnsureVisible(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->DoEnsureVisible();
+}
+
+void MyFrame::OnSetFocus(wxCommandEvent& WXUNUSED(event))
+{
+ m_treeCtrl->SetFocus();
+}
+
+void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
+{
+ int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File : -1;
+ m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), image, wxT("2nd item"));
+}
+
+void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
+{
+ static int s_num = 0;
+
+ wxString text;
+ text.Printf(wxT("Item #%d"), ++s_num);
+
+ m_treeCtrl->AppendItem(m_treeCtrl->GetRootItem(),
+ text /*,
+ MyTreeCtrl::TreeCtrlIcon_File */ );
+}
+
+void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
+{
+ unsigned int indent = m_treeCtrl->GetIndent();
+ if (indent < 100)
+ m_treeCtrl->SetIndent( indent+5 );
+}
+
+void MyFrame::OnDecIndent(wxCommandEvent& WXUNUSED(event))
+{
+ unsigned int indent = m_treeCtrl->GetIndent();
+ if (indent > 10)
+ m_treeCtrl->SetIndent( indent-5 );
+}
+
+void MyFrame::OnIncSpacing(wxCommandEvent& WXUNUSED(event))
+{
+ unsigned int indent = m_treeCtrl->GetSpacing();
+ if (indent < 100)
+ {
+ m_treeCtrl->SetSpacing( indent+5 );
+ m_treeCtrl->Refresh();
+ }
+}
+
+void MyFrame::OnDecSpacing(wxCommandEvent& WXUNUSED(event))
+{
+ unsigned int indent = m_treeCtrl->GetSpacing();
+ if (indent > 10)
+ {
+ m_treeCtrl->SetSpacing( indent-5 );
+ m_treeCtrl->Refresh();
+ }
+}
+
+void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->DoToggleIcon(item);
+}
+
+void MyFrame::OnToggleState(wxCommandEvent& WXUNUSED(event))
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->DoToggleState(item);
+}
+
+void MyFrame::DoShowFirstOrLast(TreeFunc0_t pfn, const wxString& label)
+{
+ const wxTreeItemId item = (m_treeCtrl->*pfn)();
+
+ if ( !item.IsOk() )
+ {
+ wxLogMessage("There is no %s item", label);
+ }
+ else
+ {
+ wxLogMessage("The %s item is \"%s\"",
+ label, m_treeCtrl->GetItemText(item));
+ }
+}
+
+void MyFrame::DoShowRelativeItem(TreeFunc1_t pfn, const wxString& label)
+{
+ wxTreeItemId item = m_treeCtrl->GetFocusedItem();
+
+ CHECK_ITEM( item );
+
+ if ((pfn == (TreeFunc1_t) &wxTreeCtrl::GetPrevVisible
+ || pfn == (TreeFunc1_t) &wxTreeCtrl::GetNextVisible)
+ && !m_treeCtrl->IsVisible(item))
+ {
+ wxLogMessage("The selected item must be visible.");
+ return;
+ }
+
+ wxTreeItemId new_item = (m_treeCtrl->*pfn)(item);
+
+ if ( !new_item.IsOk() )
+ {
+ wxLogMessage("There is no %s item", label);
+ }
+ else
+ {
+ wxLogMessage("The %s item is \"%s\"",
+ label, m_treeCtrl->GetItemText(new_item));
+ }
+}
+
+void MyFrame::OnScrollTo(wxCommandEvent& WXUNUSED(event))
+{
+ // scroll to the last but one top level child
+ wxTreeItemId item = m_treeCtrl->GetPrevSibling(
+ m_treeCtrl->GetLastChild(
+ m_treeCtrl->GetRootItem()));
+ CHECK_ITEM( item );
+
+ m_treeCtrl->ScrollTo(item);
+}
+
+void MyFrame::OnSelectLast(wxCommandEvent& WXUNUSED(event))
+{
+ // select the very last item of the tree
+ wxTreeItemId item = m_treeCtrl->GetRootItem();
+ for ( ;; )
+ {
+ wxTreeItemId itemChild = m_treeCtrl->GetLastChild(item);
+ if ( !itemChild.IsOk() )
+ break;
+
+ item = itemChild;
+ }
+
+ CHECK_ITEM( item );
+
+ m_treeCtrl->SelectItem(item);
+}
+
+void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
+{
+ wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour());
+ if ( col.IsOk() )
+ m_treeCtrl->SetForegroundColour(col);
+}