X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/484523cf522b02385cd47c432d50d117940b46b9..4bc1afd502a0f6f31bddb349a63f41a828f54ded:/samples/treectrl/treectrl.cpp?ds=sidebyside diff --git a/samples/treectrl/treectrl.cpp b/samples/treectrl/treectrl.cpp index cb30f162d0..2bb7c13e98 100644 --- a/samples/treectrl/treectrl.cpp +++ b/samples/treectrl/treectrl.cpp @@ -117,6 +117,9 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) EVT_TREE_ITEM_EXPANDING(TreeTest_Ctrl, MyTreeCtrl::OnItemExpanding) EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed) EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing) + EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRightClick) + + EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp) EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged) EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging) EVT_TREE_KEY_DOWN(TreeTest_Ctrl, MyTreeCtrl::OnTreeKeyDown) @@ -215,7 +218,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h) m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl, wxDefaultPosition, wxDefaultSize, - wxTR_HAS_BUTTONS | + wxTR_HAS_BUTTONS | // wxTR_NO_LINES | wxTR_EDIT_LABELS | #ifndef NO_VARIABLE_HEIGHT wxTR_HAS_VARIABLE_ROW_HEIGHT | @@ -841,6 +844,36 @@ void MyTreeCtrl::OnItemActivated(wxTreeEvent& event) wxLogMessage("OnItemActivated"); } +void MyTreeCtrl::OnItemRightClick(wxTreeEvent& event) +{ + ShowMenu(event.GetItem(), event.GetPoint()); +} + +void MyTreeCtrl::OnRMouseUp(wxMouseEvent& event) +{ + wxPoint pt = event.GetPosition(); + ShowMenu(HitTest(pt), pt); +} + +void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt) +{ + wxString title; + if ( id.IsOk() ) + { + title << _T("Menu for ") << GetItemText(id); + } + else + { + title = _T("Menu for no particular item"); + } + + wxMenu menu(title); + menu.Append(TreeTest_About, _T("&About...")); + menu.Append(TreeTest_Dump, _T("&Dump")); + + PopupMenu(&menu, pt); +} + void MyTreeCtrl::OnRMouseDClick(wxMouseEvent& event) { wxTreeItemId id = HitTest(event.GetPosition());