From 616e7c88422bca5c5fa549e53836dd1b8e952a61 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Mar 2022 17:28:06 +0100 Subject: [PATCH] Update menu bitmaps when invoking window is set in wxOSX Changing invoking window always needs to update the bitmaps because the scale factor may need to be changed if this window is on a different display, using different scaling, so do it automatically whenever SetInvokingWindow() is called instead of having to remember to call SetupBitmaps() manually everywhere SetInvokingWindow() is. This required making the base class function virtual, but allows to get rid of SetupBitmaps() call in wxWindow::DoPopupMenu(), as it can now rely on this being already done by wxWindowBase::PopupMenu(). --- include/wx/menu.h | 2 +- include/wx/osx/menu.h | 2 ++ src/osx/menu_osx.cpp | 8 ++++++++ src/osx/window_osx.cpp | 2 -- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/wx/menu.h b/include/wx/menu.h index b0877afc98..22360496bf 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -261,7 +261,7 @@ public: // // NB: avoid calling SetInvokingWindow() directly if possible, use // wxMenuInvokingWindowSetter class below instead - void SetInvokingWindow(wxWindow *win); + virtual void SetInvokingWindow(wxWindow *win); wxWindow *GetInvokingWindow() const { return m_invokingWindow; } // the window associated with this menu: this is the invoking window for diff --git a/include/wx/osx/menu.h b/include/wx/osx/menu.h index 26544dc415..96e3515b2a 100644 --- a/include/wx/osx/menu.h +++ b/include/wx/osx/menu.h @@ -36,6 +36,8 @@ public: virtual void SetTitle(const wxString& title) wxOVERRIDE; + virtual void SetInvokingWindow(wxWindow* win) wxOVERRIDE; + bool ProcessCommand(wxCommandEvent& event); // get the menu handle diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index ec05d0aa8c..cf6b26ff21 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -421,6 +421,14 @@ void wxMenu::Attach(wxMenuBarBase *menubar) } #endif +void wxMenu::SetInvokingWindow(wxWindow* win) +{ + wxMenuBase::SetInvokingWindow(win); + + if ( win ) + SetupBitmaps(); +} + void wxMenu::SetupBitmaps() { for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst(); diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 4792406b22..99cbfe1c7c 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -871,8 +871,6 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) { #ifndef __WXUNIVERSAL__ - menu->SetupBitmaps(); - if ( x == wxDefaultCoord && y == wxDefaultCoord ) { wxPoint mouse = wxGetMousePosition();