]> git.saurik.com Git - wxWidgets.git/commitdiff
test EVT_TREE_ITEM_RIGHT_CLICK as well
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 6 Apr 2005 22:32:24 +0000 (22:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 6 Apr 2005 22:32:24 +0000 (22:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/treectrl/treetest.cpp

index fdda0c22d2b212adcb33ceb9a915d9382f0bcf10..4f3c978c76ef12d9d9e2d5537f04816320957853 100644 (file)
@@ -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"));