]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/treectrl/treetest.cpp
Added SWIG patches to allow compiling the generated code with
[wxWidgets.git] / samples / treectrl / treetest.cpp
index fdda0c22d2b212adcb33ceb9a915d9382f0bcf10..40705972a7fc9d2e86eb1290ad0c23a5f72248ba 100644 (file)
@@ -9,11 +9,6 @@
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-  #pragma implementation
-  #pragma interface
-#endif
-
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
@@ -137,14 +132,19 @@ BEGIN_EVENT_TABLE(MyTreeCtrl, wxTreeCtrl)
     EVT_TREE_ITEM_COLLAPSED(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsed)
     EVT_TREE_ITEM_COLLAPSING(TreeTest_Ctrl, MyTreeCtrl::OnItemCollapsing)
 
     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)
 
     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 is the preferred event for creating context menus
+    // on a tree control, because it includes the point of the click or item,
+    // meaning that no additional placement calculations are required.
+    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)
     EVT_RIGHT_DOWN(MyTreeCtrl::OnRMouseDown)
     EVT_RIGHT_UP(MyTreeCtrl::OnRMouseUp)
     EVT_RIGHT_DCLICK(MyTreeCtrl::OnRMouseDClick)
@@ -931,8 +931,6 @@ void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
             case WXK_MENU: key = wxT("MENU"); break;
             case WXK_PAUSE: key = wxT("PAUSE"); break;
             case WXK_CAPITAL: key = wxT("CAPITAL"); break;
             case WXK_MENU: key = wxT("MENU"); break;
             case WXK_PAUSE: key = wxT("PAUSE"); break;
             case WXK_CAPITAL: key = wxT("CAPITAL"); break;
-            case WXK_PRIOR: key = wxT("PRIOR"); break;
-            case WXK_NEXT: key = wxT("NEXT"); break;
             case WXK_END: key = wxT("END"); break;
             case WXK_HOME: key = wxT("HOME"); break;
             case WXK_LEFT: key = wxT("LEFT"); break;
             case WXK_END: key = wxT("END"); break;
             case WXK_HOME: key = wxT("HOME"); break;
             case WXK_LEFT: key = wxT("LEFT"); break;
@@ -1001,7 +999,6 @@ void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)
             case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break;
             case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break;
             case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break;
             case WXK_NUMPAD_UP: key = wxT("NUMPAD_UP"); break;
             case WXK_NUMPAD_RIGHT: key = wxT("NUMPAD_RIGHT"); break;
             case WXK_NUMPAD_DOWN: key = wxT("NUMPAD_DOWN"); break;
-            case WXK_NUMPAD_PRIOR: key = wxT("NUMPAD_PRIOR"); break;
             case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break;
             case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break;
             case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break;
             case WXK_NUMPAD_PAGEUP: key = wxT("NUMPAD_PAGEUP"); break;
             case WXK_NUMPAD_PAGEDOWN: key = wxT("NUMPAD_PAGEDOWN"); break;
             case WXK_NUMPAD_END: key = wxT("NUMPAD_END"); break;
@@ -1171,7 +1168,9 @@ void MyTreeCtrl::OnItemMenu(wxTreeEvent& event)
 void MyTreeCtrl::OnContextMenu(wxContextMenuEvent& event)
 {
     wxPoint pt = event.GetPosition();
 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?)
     wxLogMessage(wxT("OnContextMenu at screen coords (%i, %i)"), pt.x, pt.y);
 
     // check if event was generated by keyboard (MSW-specific?)
@@ -1219,6 +1218,18 @@ void MyTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt)
 #endif // wxUSE_MENUS
 }
 
 #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"));
 void MyTreeCtrl::OnRMouseDown(wxMouseEvent& event)
 {
     wxLogMessage(wxT("Right mouse button down"));