diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 6c54109a8e..153e0a4f07 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -247,6 +247,9 @@ protected: // the paragraph styles globally. bool MSWSetParaFormat(const wxTextAttr& attr, long from, long to); + // Send wxEVT_CONTEXT_MENU event from here if the control doesn't do it on + // its own. + void OnRightUp(wxMouseEvent& event); // we're using RICHEDIT (and not simple EDIT) control if this field is not // 0, it also gives the version of the RICHEDIT control being used diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index e055f1a31d..90c96676b1 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -563,7 +563,16 @@ bool wxTextCtrl::MSWCreateText(const wxString& value, if ( m_verRichEdit >= 4 ) { wxTextCtrlOleCallback *cb = new wxTextCtrlOleCallback(this); - contextMenuConnected = ::SendMessage(GetHwnd(), EM_SETOLECALLBACK, 0, (LPARAM)cb) != 0; + if ( ::SendMessage(GetHwnd(), EM_SETOLECALLBACK, 0, (LPARAM)cb) ) + { + // If we succeeded in setting up the callback, we don't need to + // connect to wxEVT_CONTEXT_MENU to show the menu ourselves, + // but we do need to connect to wxEVT_RIGHT_UP to generate + // wxContextMenuEvent ourselves as we're not going to get it + // from the control which consumes it. + contextMenuConnected = true; + Bind(wxEVT_RIGHT_UP, &wxTextCtrl::OnRightUp, this); + } } #endif if ( !contextMenuConnected ) @@ -2405,6 +2414,16 @@ void wxTextCtrl::OnSetFocus(wxFocusEvent& event) // the rest of the file only deals with the rich edit controls #if wxUSE_RICHEDIT +void wxTextCtrl::OnRightUp(wxMouseEvent& eventMouse) +{ + wxContextMenuEvent eventMenu(wxEVT_CONTEXT_MENU, + GetId(), + ClientToScreen(eventMouse.GetPosition())); + + if ( !ProcessWindowEvent(eventMenu) ) + eventMouse.Skip(); +} + void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) { if (IsRich())