diff --git a/include/wx/window.h b/include/wx/window.h index f07c92d05d..972ef41d58 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1514,6 +1514,9 @@ public: virtual bool SendIdleEvents(wxIdleEvent& event); // Send wxContextMenuEvent and return true if it was processed. + // + // Note that the event may end up being sent to a different window, if this + // window is part of a composite control. bool WXSendContextMenuEvent(const wxPoint& posInScreenCoords); // get the handle of the window for the underlying window system: this diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 828b805ff4..0b744892fd 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -3071,9 +3071,16 @@ wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y) bool wxWindowBase::WXSendContextMenuEvent(const wxPoint& posInScreenCoords) { - wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), posInScreenCoords); - evtCtx.SetEventObject(this); - return HandleWindowEvent(evtCtx); + // When the mouse click happens in a subwindow of a composite control, + // the user-visible event should seem to originate from the main window + // and, notably, use its ID and not the (usually auto-generated and so + // not very useful) ID of the subwindow. + wxWindow* const mainWin = GetMainWindowOfCompositeControl(); + + wxContextMenuEvent + evtCtx(wxEVT_CONTEXT_MENU, mainWin->GetId(), posInScreenCoords); + evtCtx.SetEventObject(mainWin); + return mainWin->HandleWindowEvent(evtCtx); } // methods for drawing the sizers in a visible way: this is currently only