X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/527343602e91d60c65fb7589a6ddcf4683930c78..d01ad2f5a76ca1c18227e8ded100b8c667213662:/samples/treectrl/treetest.cpp diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 73a7bb62f9..307b3de575 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -64,6 +64,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) MENU_LINK(Quit) MENU_LINK(About) + MENU_LINK(ClearLog) MENU_LINK(TogButtons) MENU_LINK(TogTwist) @@ -110,6 +111,13 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) MENU_LINK(DecSpacing) MENU_LINK(ToggleIcon) MENU_LINK(SelectRoot) + + MENU_LINK(ShowFirstVisible) +#ifdef wxHAS_LAST_VISIBLE + MENU_LINK(ShowLastVisible) +#endif // wxHAS_LAST_VISIBLE + MENU_LINK(ShowNextVisible) + MENU_LINK(ShowPrevVisible) #undef MENU_LINK END_EVENT_TABLE() @@ -139,7 +147,7 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown) EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, MyTreeCtrl::OnItemActivated) - // so many differents ways to handle right mouse button clicks... + // so many different ways to handle right mouse button clicks... EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu) // EVT_TREE_ITEM_MENU is the preferred event for creating context menus // on a tree control, because it includes the point of the click or item, @@ -193,6 +201,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) *tree_menu = new wxMenu, *item_menu = new wxMenu; + file_menu->Append(TreeTest_ClearLog, wxT("&Clear log\tCtrl-L")); + file_menu->AppendSeparator(); file_menu->Append(TreeTest_About, wxT("&About...")); file_menu->AppendSeparator(); file_menu->Append(TreeTest_Quit, wxT("E&xit\tAlt-X")); @@ -208,7 +218,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) style_menu->AppendCheckItem(TreeTest_TogFullHighlight, wxT("Toggle &full row highlight")); style_menu->AppendCheckItem(TreeTest_TogEdit, wxT("Toggle &edit mode")); #ifndef NO_MULTIPLE_SELECTION - style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode")); + style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode\tCtrl-S")); #endif // NO_MULTIPLE_SELECTION style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges")); style_menu->AppendCheckItem(TreeTest_ToggleAlternateImages, wxT("Toggle alternate images")); @@ -251,6 +261,13 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) item_menu->Append(TreeTest_ClearBold, wxT("Make item ¬ bold")); item_menu->AppendSeparator(); item_menu->Append(TreeTest_ToggleIcon, wxT("Toggle the item's &icon")); + item_menu->AppendSeparator(); + item_menu->Append(TreeTest_ShowFirstVisible, wxT("Show &first visible")); +#ifdef wxHAS_LAST_VISIBLE + item_menu->Append(TreeTest_ShowLastVisible, wxT("Show &last visible")); +#endif // wxHAS_LAST_VISIBLE + item_menu->Append(TreeTest_ShowNextVisible, wxT("Show &next visible")); + item_menu->Append(TreeTest_ShowPrevVisible, wxT("Show &previous visible")); #ifndef NO_MULTIPLE_SELECTION item_menu->AppendSeparator(); @@ -400,12 +417,11 @@ void MyFrame::Resize() { wxSize size = GetClientSize(); m_treeCtrl->SetSize(0, 0, size.x, size.y -#if !wxUSE_LOG - ); -#else +#if wxUSE_LOG *2/3); - m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3); + m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3 #endif + ); } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -421,6 +437,11 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) wxOK | wxICON_INFORMATION, this); } +void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) +{ + m_textCtrl->Clear(); +} + void MyFrame::OnRename(wxCommandEvent& WXUNUSED(event)) { wxTreeItemId item = m_treeCtrl->GetSelection(); @@ -694,6 +715,38 @@ void MyFrame::OnToggleIcon(wxCommandEvent& WXUNUSED(event)) m_treeCtrl->DoToggleIcon(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::DoShowNextOrPrev(TreeFunc1_t pfn, const wxString& label) +{ + wxTreeItemId item = m_treeCtrl->GetSelection(); + + CHECK_ITEM( item ); + + if ( !m_treeCtrl->IsVisible(item) ) + { + wxLogMessage("The selected item must be visible."); + return; + } + + item = (m_treeCtrl->*pfn)(item); + + if ( !item.IsOk() ) + wxLogMessage("There is no %s item", label); + else + wxLogMessage("The %s item is \"%s\"", + label, m_treeCtrl->GetItemText(item)); +} + void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event)) { wxColour col = wxGetColourFromUser(this, m_treeCtrl->GetForegroundColour());