diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index fdda0c22d2..4f3c978c76 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -137,14 +137,16 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl) EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed) EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing) - EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu) - EVT_TREE_ITEM_MENU(TreeTest_Ctrl, MyTreeCtrl::OnItemMenu) - EVT_TREE_SEL_CHANGED(TreeTest_Ctrl, MyTreeCtrl::OnSelChanged) EVT_TREE_SEL_CHANGING(TreeTest_Ctrl, MyTreeCtrl::OnSelChanging) 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... + EVT_CONTEXT_MENU(MyTreeCtrl::OnContextMenu) + EVT_TREE_ITEM_MENU(TreeTest_Ctrl, MyTreeCtrl::OnItemMenu) + EVT_TREE_ITEM_RIGHT_CLICK(TreeTest_Ctrl, MyTreeCtrl::OnItemRClick) + EVT_RIGHT_DOWN(MyTreeCtrl::OnRMouseDown) EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp) EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick) @@ -1171,7 +1173,9 @@ void MyTreeCtrl::OnItemMenu(wxTreeEvent& event) void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event) { wxPoint pt = event.GetPosition(); - wxTreeItemId item = GetSelection(); + wxTreeItemId item; + if ( !HasFlag(wxTR_MULTIPLE) ) + item = GetSelection(); wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y); // check if event was generated by keyboard (MSW-specific?) @@ -1219,6 +1223,18 @@ void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt) #endif // wxUSE_MENUS } +void MyTreeCtrl::OnItemRClick(wxTreeEvent& event) +{ + wxTreeItemId itemId = event.GetItem(); + MyTreeItemData *item = itemId.IsOk() ? (MyTreeItemData *)GetItemData(itemId) + : NULL; + + wxLogMessage(wxT("Item \"%s\" right clicked"), item ? item->GetDesc() + : _T("")); + + event.Skip(); +} + void MyTreeCtrl::OnRMouseDown(wxMouseEvent& event) { wxLogMessage(wxT("Right mouse button down"));