From 78f30e3e566fbd82faae84f212908490ae85af69 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Jun 2022 21:16:29 +0200 Subject: [PATCH 1/7] Document that clang is required for building wxOSX Due to the use of Apple-specific extensions in the SDK headers, gcc can't be used to compile wxOSX any more. Closes #22519. --- docs/doxygen/mainpages/introduction.h | 4 ++-- docs/doxygen/mainpages/platdetails.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/doxygen/mainpages/introduction.h b/docs/doxygen/mainpages/introduction.h index f1529d786d..02f115413b 100644 --- a/docs/doxygen/mainpages/introduction.h +++ b/docs/doxygen/mainpages/introduction.h @@ -91,8 +91,8 @@ NetBSD, Solaris, AIX, ...) and require GTK+ 2.6 or later or GTK+ 3.x. The primary supported compiler is GNU g++. @li wxOSX/Cocoa: This is the native port for Apple computers. wxOSX/Cocoa -supports 32 or 64 bit Intel Macs running macOS 10.10 or later. The port can be -built either with g++ or clang. +supports 32 or 64 bit Intel Macs running macOS 10.10 or later. The port can +currently be only built using Apple clang. Other platforms (e.g. iOS - with a minimum requirement of iOS 13), compilers (Sun CC, HP-UX aCC, IBM xlC or SGI mipsPro under Unix) and ports (wxQT, wxGTK1, diff --git a/docs/doxygen/mainpages/platdetails.h b/docs/doxygen/mainpages/platdetails.h index 309a330258..3356b7bc43 100644 --- a/docs/doxygen/mainpages/platdetails.h +++ b/docs/doxygen/mainpages/platdetails.h @@ -54,6 +54,10 @@ wxOSX/Cocoa is the port of wxWidgets for the macOS platform. It requires a minimum SDK 10.11, Xcode 7.2.1 or greater (runs under 10.10.5 and higher), and supports x86_64 (but not i386) and ARM builds and deploying under 10.10. +Note that Apple clang must be used to build wxOSX, due to the use of +Apple-specific extensions ("blocks") in the macOS SDK headers, and hence the +applications using it must be built using clang as well. + @subpage plat_osx_install "Build and Install Instructions" From 7f3baa9abf3865c4925ef8b86137b2521da5777d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Jun 2022 18:27:07 +0100 Subject: [PATCH 2/7] Rename wxMenuItem::m_bmpChecked to m_bitmap in wxMSW and wxUniv These two ports were the only ones to use something other than m_bitmap for wxBitmapBundle storing the item bitmap, rename it for consistency with the other ports and to allow moving this field into the base class in the upcoming commit. No real changes. --- include/wx/msw/menuitem.h | 2 +- include/wx/univ/menuitem.h | 4 ++-- src/msw/menuitem.cpp | 8 ++++---- src/univ/menu.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index 3fe460e0c1..4523d9c38a 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -139,7 +139,7 @@ private: int MSGetMenuItemPos() const; // item bitmaps - wxBitmapBundle m_bmpChecked, // bitmap to put near the item + wxBitmapBundle m_bitmap, // bitmap to put near the item m_bmpUnchecked; // (checked is used also for 'uncheckable' items) #if wxUSE_OWNER_DRAWN wxBitmapBundle m_bmpDisabled; diff --git a/include/wx/univ/menuitem.h b/include/wx/univ/menuitem.h index d2b3717cd4..19178f3cf4 100644 --- a/include/wx/univ/menuitem.h +++ b/include/wx/univ/menuitem.h @@ -41,7 +41,7 @@ public: const wxBitmapBundle& bmpUnchecked = wxBitmapBundle()); void SetBitmap(const wxBitmapBundle& bmp) { SetBitmaps(bmp); } wxBitmap GetBitmap(bool checked = true) const - { return GetBitmapFromBundle(checked ? m_bmpChecked : m_bmpUnchecked); } + { return GetBitmapFromBundle(checked ? m_bitmap : m_bmpUnchecked); } void SetDisabledBitmap( const wxBitmapBundle& bmpDisabled ) { m_bmpDisabled = bmpDisabled; } @@ -93,7 +93,7 @@ protected: void UpdateAccelInfo(); // the bitmaps (may be invalid, then they're not used) - wxBitmapBundle m_bmpChecked, + wxBitmapBundle m_bitmap, m_bmpUnchecked, m_bmpDisabled; diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 300d1f3e93..d00557c7f9 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -690,7 +690,7 @@ void wxMenuItem::SetItemLabel(const wxString& txt) wxBitmap wxMenuItem::GetBitmap(bool bChecked) const { - wxBitmap bmp = GetBitmapFromBundle(bChecked ? m_bmpChecked : m_bmpUnchecked); + wxBitmap bmp = GetBitmapFromBundle(bChecked ? m_bitmap : m_bmpUnchecked); #if wxUSE_IMAGE if ( bmp.IsOk() && !bmp.HasAlpha() && wxGetWinVersion() >= wxWinVersion_Vista) { @@ -712,7 +712,7 @@ wxBitmap wxMenuItem::GetDisabledBitmap() const void wxMenuItem::DoSetBitmap(const wxBitmapBundle& bmpNew, bool bChecked) { - wxBitmapBundle& bmp = bChecked ? m_bmpChecked : m_bmpUnchecked; + wxBitmapBundle& bmp = bChecked ? m_bitmap : m_bmpUnchecked; if ( bmp.IsSameAs(bmpNew) ) return; bmp = bmpNew; @@ -863,7 +863,7 @@ bool wxMenuItem::OnMeasureItem(size_t *width, size_t *height) *width += imgWidth + data->CheckBgMargin.GetTotalX(); } - if ( m_bmpChecked.IsOk() || m_bmpUnchecked.IsOk() ) + if ( m_bitmap.IsOk() || m_bmpUnchecked.IsOk() ) { // get size of bitmap always return valid value (0 for invalid bitmap), // so we don't needed check if bitmap is valid ;) @@ -1087,7 +1087,7 @@ bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc, - data->CheckBgMargin.cyBottomHeight - data->CheckMargin.cyBottomHeight); - if ( IsCheckable() && !m_bmpChecked.IsOk() ) + if ( IsCheckable() && !m_bitmap.IsOk() ) { if ( stat & wxODChecked ) { diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index 21718a9ba9..d6d019c68b 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -1616,7 +1616,7 @@ void wxMenuItem::SetCheckable(bool checkable) void wxMenuItem::SetBitmaps(const wxBitmapBundle& bmpChecked, const wxBitmapBundle& bmpUnchecked) { - m_bmpChecked = bmpChecked; + m_bitmap = bmpChecked; m_bmpUnchecked = bmpUnchecked; NotifyMenu(); From c0dbe808a6090180b684bf68b26a7ef685ef54f3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Jun 2022 01:26:07 +0100 Subject: [PATCH 3/7] Move SetBitmap() and GetBitmap() to wxMenuItemBase Ensure that all derived classes have these functions and let them to avoid defining them if they can just use the default implementation, which was the case for most ports. Also move m_bitmap to the base class from the derived ones. No real changes. --- include/wx/gtk/menuitem.h | 3 --- include/wx/gtk1/menuitem.h | 3 --- include/wx/menuitem.h | 6 ++++++ include/wx/motif/menuitem.h | 7 ------- include/wx/msw/menuitem.h | 20 +++++++++++++++----- include/wx/osx/menuitem.h | 5 ----- include/wx/qt/menuitem.h | 4 +--- include/wx/univ/menuitem.h | 9 +++++---- src/common/menucmn.cpp | 10 ++++++++++ src/gtk/menu.cpp | 15 --------------- src/gtk1/menu.cpp | 5 ----- src/osx/menuitem_osx.cpp | 10 ---------- 12 files changed, 37 insertions(+), 60 deletions(-) diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index b42fa23e92..2b2d3beee9 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -29,8 +29,6 @@ public: virtual void Enable( bool enable = true ) wxOVERRIDE; virtual void Check( bool check = true ) wxOVERRIDE; virtual bool IsChecked() const wxOVERRIDE; - virtual void SetBitmap(const wxBitmapBundle& bitmap); - virtual wxBitmap GetBitmap() const; void SetupBitmaps(wxWindow *win); #if wxUSE_ACCEL @@ -60,7 +58,6 @@ public: #endif private: - wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any GtkWidget *m_menuItem; // GtkMenuItem wxDECLARE_DYNAMIC_CLASS(wxMenuItem); diff --git a/include/wx/gtk1/menuitem.h b/include/wx/gtk1/menuitem.h index 7ae48cedb7..d5ef40392d 100644 --- a/include/wx/gtk1/menuitem.h +++ b/include/wx/gtk1/menuitem.h @@ -32,8 +32,6 @@ public: virtual void Enable( bool enable = TRUE ); virtual void Check( bool check = TRUE ); virtual bool IsChecked() const; - virtual void SetBitmap(const wxBitmapBundle& bitmap) { m_bitmap = bitmap; } - virtual wxBitmap GetBitmap() const; #if wxUSE_ACCEL virtual wxAcceleratorEntry *GetAccel() const; @@ -65,7 +63,6 @@ private: void DoSetText(const wxString& text); wxString m_hotKey; - wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any GtkWidget *m_menuItem; // GtkMenuItem GtkWidget* m_labelWidget; // Label widget diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 0461b15b48..70965abc2b 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -115,6 +115,11 @@ public: void SetHelp(const wxString& str); const wxString& GetHelp() const { return m_help; } + // bitmap-related functions + + virtual void SetBitmap(const wxBitmapBundle& bmp); + virtual wxBitmap GetBitmap() const; + #if wxUSE_ACCEL // extract the accelerator from the given menu string, return NULL if none // found @@ -175,6 +180,7 @@ protected: *m_subMenu; // our sub menu or NULL wxString m_text, // label of the item m_help; // the help string for the item + wxBitmapBundle m_bitmap; // item bitmap, may be invalid wxItemKind m_kind; // separator/normal/check/radio item? bool m_isChecked; // is checked? bool m_isEnabled; // is enabled? diff --git a/include/wx/motif/menuitem.h b/include/wx/motif/menuitem.h index 3e539a44d7..664ad64680 100644 --- a/include/wx/motif/menuitem.h +++ b/include/wx/motif/menuitem.h @@ -35,12 +35,6 @@ public: virtual void SetItemLabel(const wxString& label); virtual void Enable(bool enable = true); virtual void Check(bool check = true); - // included SetBitmap and GetBitmap as copied from the GTK include file - // I'm not sure if this works but it silences the linker in the - // menu sample. - // JJ - virtual void SetBitmap(const wxBitmapBundle& bitmap) { m_bitmap = bitmap; } - virtual wxBitmap GetBitmap() const { return GetBitmapFromBundle(m_bitmap); } // implementation from now on void CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu, @@ -59,7 +53,6 @@ private: WXWidget m_buttonWidget; wxMenuBar* m_menuBar; wxMenu* m_topMenu; // Top-level menu e.g. popup-menu - wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any wxDECLARE_DYNAMIC_CLASS(wxMenuItem); }; diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index 4523d9c38a..1e8bf02e5e 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -78,14 +78,25 @@ public: DoSetBitmap(bmpUnchecked, false); } - void SetBitmap(const wxBitmapBundle& bmp, bool bChecked = true) + virtual void SetBitmap(const wxBitmapBundle& bmp) wxOVERRIDE { - DoSetBitmap(bmp, bChecked); + DoSetBitmap(bmp, true); + } + + virtual wxBitmap GetBitmap() const wxOVERRIDE + { + return GetBitmap(true); } void SetupBitmaps(); - wxBitmap GetBitmap(bool bChecked = true) const; + // The functions taking bChecked are wxMSW-specific. + void SetBitmap(const wxBitmapBundle& bmp, bool bChecked) + { + DoSetBitmap(bmp, bChecked); + } + + wxBitmap GetBitmap(bool bChecked) const; #if wxUSE_OWNER_DRAWN void SetDisabledBitmap(const wxBitmapBundle& bmpDisabled) @@ -139,8 +150,7 @@ private: int MSGetMenuItemPos() const; // item bitmaps - wxBitmapBundle m_bitmap, // bitmap to put near the item - m_bmpUnchecked; // (checked is used also for 'uncheckable' items) + wxBitmapBundle m_bmpUnchecked; // (used only for checkable items) #if wxUSE_OWNER_DRAWN wxBitmapBundle m_bmpDisabled; #endif // wxUSE_OWNER_DRAWN diff --git a/include/wx/osx/menuitem.h b/include/wx/osx/menuitem.h index 0a6f7bec2f..7b29f950c9 100644 --- a/include/wx/osx/menuitem.h +++ b/include/wx/osx/menuitem.h @@ -48,9 +48,6 @@ public: void RemoveHiddenItems(); #endif // wxUSE_ACCEL - virtual void SetBitmap(const wxBitmapBundle& bitmap) ; - virtual wxBitmap GetBitmap() const; - // Implementation only from now on. @@ -63,8 +60,6 @@ public: private: void UncheckRadio() ; - wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any - wxMenuItemImpl* m_peer; #if wxUSE_ACCEL diff --git a/include/wx/qt/menuitem.h b/include/wx/qt/menuitem.h index 63d59ffce9..80887b5783 100644 --- a/include/wx/qt/menuitem.h +++ b/include/wx/qt/menuitem.h @@ -35,8 +35,7 @@ public: virtual void Check(bool check = true) wxOVERRIDE; virtual bool IsChecked() const wxOVERRIDE; - virtual void SetBitmap(const wxBitmapBundle& bitmap); - virtual wxBitmap GetBitmap() const { return GetBitmapFromBundle(m_bitmap); } + virtual void SetBitmap(const wxBitmapBundle& bitmap) wxOVERRIDE; virtual QAction *GetHandle() const; @@ -44,7 +43,6 @@ public: private: // Qt is using an action instead of a menu item. wxQtAction *m_qtAction; - wxBitmapBundle m_bitmap; wxDECLARE_DYNAMIC_CLASS( wxMenuItem ); }; diff --git a/include/wx/univ/menuitem.h b/include/wx/univ/menuitem.h index 19178f3cf4..75627490ee 100644 --- a/include/wx/univ/menuitem.h +++ b/include/wx/univ/menuitem.h @@ -39,9 +39,11 @@ public: // hopefully void SetBitmaps(const wxBitmapBundle& bmpChecked, const wxBitmapBundle& bmpUnchecked = wxBitmapBundle()); - void SetBitmap(const wxBitmapBundle& bmp) { SetBitmaps(bmp); } - wxBitmap GetBitmap(bool checked = true) const + virtual void SetBitmap(const wxBitmapBundle& bmp) wxOVERRIDE { SetBitmaps(bmp); } + wxBitmap GetBitmap(bool checked) const { return GetBitmapFromBundle(checked ? m_bitmap : m_bmpUnchecked); } + virtual wxBitmap GetBitmap() const wxOVERRIDE + { return GetBitmap(true); } void SetDisabledBitmap( const wxBitmapBundle& bmpDisabled ) { m_bmpDisabled = bmpDisabled; } @@ -93,8 +95,7 @@ protected: void UpdateAccelInfo(); // the bitmaps (may be invalid, then they're not used) - wxBitmapBundle m_bitmap, - m_bmpUnchecked, + wxBitmapBundle m_bmpUnchecked, m_bmpDisabled; // the positions of the first and last items of the radio group this item diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 51400664a6..5e755c8a69 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -344,6 +344,16 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) } #endif +void wxMenuItemBase::SetBitmap(const wxBitmapBundle& bmp) +{ + m_bitmap = bmp; +} + +wxBitmap wxMenuItemBase::GetBitmap() const +{ + return GetBitmapFromBundle(m_bitmap); +} + wxBitmap wxMenuItemBase::GetBitmapFromBundle(const wxBitmapBundle& bundle) const { wxBitmap bmp; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 36566fde60..480f1d0690 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -756,21 +756,6 @@ void wxMenuItem::ClearExtraAccels() #endif // wxUSE_ACCEL -void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) -{ - if (m_kind == wxITEM_NORMAL) - m_bitmap = bitmap; - else - { - wxFAIL_MSG("only normal menu items can have bitmaps"); - } -} - -wxBitmap wxMenuItem::GetBitmap() const -{ - return GetBitmapFromBundle(m_bitmap); -} - void wxMenuItem::SetupBitmaps(wxWindow *win) { #ifndef __WXGTK4__ diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 048a17fa1a..1bb69dd1f2 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -870,11 +870,6 @@ wxAcceleratorEntry *wxMenuItem::GetAccel() const #endif // wxUSE_ACCEL -wxBitmap wxMenuItem::GetBitmap() const -{ - return GetBitmapFromBundle(m_bitmap); -} - void wxMenuItem::Check( bool check ) { wxCHECK_RET( m_menuItem, wxT("invalid menu item") ); diff --git a/src/osx/menuitem_osx.cpp b/src/osx/menuitem_osx.cpp index d153910135..39b839d0e3 100644 --- a/src/osx/menuitem_osx.cpp +++ b/src/osx/menuitem_osx.cpp @@ -70,16 +70,6 @@ wxMenuItem::~wxMenuItem() // change item state // ----------------- -void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) -{ - m_bitmap = bitmap; -} - -wxBitmap wxMenuItem::GetBitmap() const -{ - return GetBitmapFromBundle(m_bitmap); -} - void wxMenuItem::Enable(bool bDoEnable) { if (( m_isEnabled != bDoEnable From d0b32e71f5548254fb268a085ef3d6faec9d4936 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Jun 2022 01:59:53 +0100 Subject: [PATCH 4/7] Document wxMSW-specific wxMenuItem methods separately Also remove obsolete note about having to call SetBitmap() before appending the item to the menu as this is not true any longer since quite some time. --- interface/wx/menuitem.h | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/interface/wx/menuitem.h b/interface/wx/menuitem.h index 9802b0ff43..710dc1ed04 100644 --- a/interface/wx/menuitem.h +++ b/interface/wx/menuitem.h @@ -160,12 +160,17 @@ public: */ wxColour& GetBackgroundColour() const; + /** + Returns the item bitmap. + */ + wxBitmap GetBitmap() const; + /** Returns the checked or unchecked bitmap. - The @c checked parameter is only available in wxMSW. + This overload only exists in wxMSW, avoid using it in portable code. */ - virtual wxBitmap GetBitmap(bool checked = true) const; + wxBitmap GetBitmap(bool checked) const; /** Returns the bitmap used for disabled items. @@ -351,23 +356,26 @@ public: /** Sets the bitmap for the menu item. - It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap) if - @a checked is @true (default value) or SetBitmaps(wxNullBitmap, bmp) - otherwise. - - SetBitmap() must be called before the item is appended to the menu, - i.e. appending the item without a bitmap and setting one later is not - guaranteed to work. But the bitmap can be changed or reset later if it - had been set up initially. - Notice that GTK+ uses a global setting called @c gtk-menu-images to determine if the images should be shown in the menus at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no images will be shown, consistently with the native behaviour. - - @onlyfor{wxmsw,wxosx,wxgtk} */ - virtual void SetBitmap(const wxBitmapBundle& bmp, bool checked = true); + void SetBitmap(const wxBitmapBundle& bmp); + + /** + Sets the checked or unchecked bitmap for the menu item. + + It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap) if + @a checked is @true or SetBitmaps(wxNullBitmap, bmp) otherwise. + + Note that different bitmaps for checked and unchecked item states are + not supported in most ports, while setting just a single bitmap using + the overload above is supported in all of them. + + @onlyfor{wxmsw} + */ + void SetBitmap(const wxBitmapBundle& bmp, bool checked); /** Sets the checked/unchecked bitmaps for the menu item. From 5f8b9000787d8e32b8702841a0d92af508d1ee23 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Jun 2022 02:01:53 +0100 Subject: [PATCH 5/7] Add wxMenuItem::GetBitmapBundle() This is needed to e.g. allow cloning a wxMenuItem fully without losing any of its data. --- include/wx/menuitem.h | 4 ++++ interface/wx/menuitem.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 70965abc2b..2a6608761d 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -118,6 +118,10 @@ public: // bitmap-related functions virtual void SetBitmap(const wxBitmapBundle& bmp); + wxBitmapBundle GetBitmapBundle() const { return m_bitmap; } + + // This method only exists for compatibility, prefer using + // GetBitmapBundle() in the new code. virtual wxBitmap GetBitmap() const; #if wxUSE_ACCEL diff --git a/interface/wx/menuitem.h b/interface/wx/menuitem.h index 710dc1ed04..71f07b81c5 100644 --- a/interface/wx/menuitem.h +++ b/interface/wx/menuitem.h @@ -162,6 +162,9 @@ public: /** Returns the item bitmap. + + This method exists only for compatibility, please use GetBitmapBundle() + in the new code. */ wxBitmap GetBitmap() const; @@ -172,6 +175,18 @@ public: */ wxBitmap GetBitmap(bool checked) const; + /** + Returns the bitmap bundle containing the bitmap used for this item. + + The returned bundle is invalid, i.e. empty, if no bitmap is associated + with the item. + + @see SetBitmap() + + @since 3.2.0 + */ + wxBitmapBundle GetBitmapBundle() const; + /** Returns the bitmap used for disabled items. From 37950c1421073cb3f98f272a4ed28e1b18c05b66 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Jun 2022 01:48:31 +0100 Subject: [PATCH 6/7] Make changing popup menu items in wxEVT_MENU_OPEN work again Set up popup menu bitmaps after executing wxEVT_MENU_OPEN handler, so that any changes to the menu item bitmaps done in it are taken into account, as this only happens when SetupBitmaps() is called. Closes #22530. --- src/msw/window.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 18b629285a..74cbe59275 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2368,8 +2368,6 @@ static void wxYieldForCommandsOnly() bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y) { - menu->SetupBitmaps(); - wxPoint pt; if ( x == wxDefaultCoord && y == wxDefaultCoord ) { @@ -2450,7 +2448,16 @@ wxWindowMSW::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu) { wxMenuEvent event(evtType, menu && !menu->IsAttached() ? wxID_ANY : 0, menu); - return wxMenu::ProcessMenuEvent(menu, event, this); + const bool processed = wxMenu::ProcessMenuEvent(menu, event, this); + + if ( menu && evtType == wxEVT_MENU_OPEN ) + { + // Do this after possibly executing the user-defined wxEVT_MENU_OPEN + // handler which could have modified the bitmaps. + menu->SetupBitmaps(); + } + + return processed; } bool wxWindowMSW::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu) From f0ec9974a52f9be2ca6cae99f4d117412c4bf4dc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Jun 2022 01:50:00 +0100 Subject: [PATCH 7/7] Remove the now unnecessary calls to SetupBitmaps() After the changes of the previous commit, calling SetupBitmaps() preemptively is not necessary any more, as it's called in any case just before showing the menu, so remove the calls to it to simplify the code and even make it slightly faster (at the cost of slowing it down before opening the menu, but this needs to be done in any case to avoid reintroducing the problem fixed by the parent commit). --- include/wx/msw/menu.h | 14 -------------- src/msw/menu.cpp | 33 --------------------------------- 2 files changed, 47 deletions(-) diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index c372d7490f..9a7635acbc 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -69,10 +69,6 @@ public: // containing this position. bool MSWGetRadioGroupRange(int pos, int *start, int *end) const; -#if wxUSE_MENUBAR - virtual void Attach(wxMenuBarBase *menubar) wxOVERRIDE; -#endif - void SetupBitmaps(); #if wxUSE_ACCEL @@ -226,16 +222,6 @@ protected: // common part of all ctors void Init(); - void SetupBitmaps(); - - void OnDPIChanged(wxDPIChangedEvent& event) - { - // need to reset bitmaps - SetupBitmaps(); - - event.Skip(); - } - WXHMENU m_hMenu; // Return the MSW position for a wxMenu which is sometimes different from diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index ce99d0f685..49be7d433f 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -305,19 +305,6 @@ bool wxMenu::MSWGetRadioGroupRange(int pos, int *start, int *end) const return m_radioData && m_radioData->GetGroupRange(pos, start, end); } -#if wxUSE_MENUBAR -void wxMenu::Attach(wxMenuBarBase* menubar) -{ - wxMenuBase::Attach(menubar); - - if (menubar->IsAttached()) - { - // menubar is already attached, we need to call SetupBitmaps - SetupBitmaps(); - } -} -#endif - void wxMenu::SetupBitmaps() { for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst(); @@ -611,14 +598,6 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) // if we're already attached to the menubar, we must update it if ( IsAttached() && GetMenuBar()->IsAttached() ) { - if ( pItem->IsSubMenu() ) - { - pItem->GetSubMenu()->SetupBitmaps(); - } - if ( !pItem->IsSeparator() ) - { - pItem->SetupBitmaps(); - } GetMenuBar()->Refresh(); } @@ -1259,14 +1238,6 @@ void wxMenuBar::RebuildAccelTable() #endif // wxUSE_ACCEL -void wxMenuBar::SetupBitmaps() -{ - for ( wxMenuList::const_iterator it = m_menus.begin(); it != m_menus.end(); ++it ) - { - (*it)->SetupBitmaps(); - } -} - void wxMenuBar::Attach(wxFrame *frame) { wxMenuBarBase::Attach(frame); @@ -1274,10 +1245,6 @@ void wxMenuBar::Attach(wxFrame *frame) #if wxUSE_ACCEL RebuildAccelTable(); #endif // wxUSE_ACCEL - - SetupBitmaps(); - - frame->Bind(wxEVT_DPI_CHANGED, &wxMenuBar::OnDPIChanged, this); } void wxMenuBar::Detach()