]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch #421554: implementation of wxEVT_CONTEXT_MENU
authorJulian Smart <julian@anthemion.co.uk>
Wed, 16 May 2001 11:32:21 +0000 (11:32 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Wed, 16 May 2001 11:32:21 +0000 (11:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10173 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/event.h
src/common/event.cpp
src/msw/window.cpp

index f7bddba9b73a45d2168bfef1204a09c80e3455b8..24cc14c0b4968dbf13260852d5115f3b76247400 100644 (file)
@@ -961,7 +961,6 @@ public:
  wxEVT_MENU_INIT,
  wxEVT_MENU_HIGHLIGHT,
  wxEVT_POPUP_MENU_INIT,
- wxEVT_CONTEXT_MENU,
 */
 
 class WXDLLEXPORT wxMenuEvent : public wxEvent
@@ -1425,6 +1424,37 @@ private:
     DECLARE_DYNAMIC_CLASS(wxHelpEvent)
 };
 
+// A Context event is sent when the user right clicks on a window or
+// presses Shift-F10
+// NOTE : Under windows this is a repackaged WM_CONTETXMENU message
+//        Under other systems it may have to be generated from a right click event
+/*
+ wxEVT_CONTEXT_MENU
+*/
+
+class WXDLLEXPORT wxContextMenuEvent : public wxCommandEvent
+{
+public:
+    wxContextMenuEvent(wxEventType type = wxEVT_NULL,
+                wxWindowID id = 0,
+                const wxPoint& pt = wxDefaultPosition)
+    {
+        m_eventType = type;
+        m_id = id;
+        m_pos = pt;
+    }
+
+    // Position of event (in screen coordinates)
+    const wxPoint& GetPosition() const { return m_pos; }
+    void SetPosition(const wxPoint& pos) { m_pos = pos; }
+
+protected:
+    wxPoint   m_pos;
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxContextMenuEvent)
+};
+
 #endif // wxUSE_GUI
 
 // Idle event
@@ -1705,6 +1735,7 @@ typedef void (wxEvtHandler::*wxWindowDestroyEventFunction)(wxWindowDestroyEvent&
 typedef void (wxEvtHandler::*wxSetCursorEventFunction)(wxSetCursorEvent&);
 typedef void (wxEvtHandler::*wxNotifyEventFunction)(wxNotifyEvent&);
 typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
+typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
 #endif // wxUSE_GUI
 
 // N.B. In GNU-WIN32, you *have* to take the address of a member function
@@ -1935,6 +1966,10 @@ typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
 #define EVT_DETAILED_HELP_RANGE(id1, id2, func) \
  DECLARE_EVENT_TABLE_ENTRY( wxEVT_DETAILED_HELP, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxHelpEventFunction) & func, (wxObject *) NULL ),
 
+// Context Menu Events
+#define EVT_CONTEXT_MENU(func) \
+ DECLARE_EVENT_TABLE_ENTRY(wxEVT_CONTEXT_MENU, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxContextMenuEventFunction) & func, (wxObject *) NULL ),
+
 // ----------------------------------------------------------------------------
 // Global data
 // ----------------------------------------------------------------------------
index 301ae910822019a37c3ab10f1224a5685187139b..061d991d7a4624ef1c7852b368f448ff15705a54 100644 (file)
@@ -83,6 +83,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
     IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
+    IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
 #endif // wxUSE_GUI
 
 const wxEventTable *wxEvtHandler::GetEventTable() const
index b4073d6d240e1cc3fb523b8fde9cf1ed2d3c6d9c..3a91b2ccaba4ee9eee0ad29213f300024f34711f 100644 (file)
@@ -2226,10 +2226,29 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
                 helpEvent.SetEventObject(this);
                 processed = GetEventHandler()->ProcessEvent(helpEvent);
+
             }
             else processed = FALSE;
             break;
         }
+        case WM_CONTEXTMENU:
+        {
+            HWND hWnd = (HWND) wParam;
+            
+            // we don't convert from screen to client coordinates as
+            // the event may be handled by a parent window
+            wxPoint p(LOWORD(lParam), HIWORD(lParam));
+            
+            wxContextMenuEvent contextEvent(wxEVT_CONTEXT_MENU, GetId(), p);
+            GetEventHandler()->ProcessEvent(contextEvent);
+            
+            // set processed to true even if the event is not handled because if we don't
+            // windows will propogate the WM_CONTEXTMENU up the parent window chain, which
+            // we have already done ourselves.
+            processed = true;
+            
+            break;
+        }
 #endif
     }