From 338cd95c2d3536f52f8ba1e7d7cfbbc7097f921c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 5 Feb 2022 20:35:46 +0100 Subject: [PATCH] Move GetBitmapFromBundle() to wxMenuItemBase This is just a refactoring to avoid duplicating this function code in all ports and just have it once in the base class. --- include/wx/gtk/menuitem.h | 2 -- include/wx/menuitem.h | 6 ++++++ include/wx/msw/menuitem.h | 4 ---- include/wx/osx/menuitem.h | 1 - src/common/menucmn.cpp | 17 +++++++++++++++++ src/gtk/menu.cpp | 14 +------------- src/msw/menuitem.cpp | 16 ---------------- src/osx/menuitem_osx.cpp | 14 +------------- 8 files changed, 25 insertions(+), 49 deletions(-) diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index dcb7ebc356..b42fa23e92 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -9,8 +9,6 @@ #ifndef _WX_GTKMENUITEM_H_ #define _WX_GTKMENUITEM_H_ -#include "wx/bmpbndl.h" - //----------------------------------------------------------------------------- // wxMenuItem //----------------------------------------------------------------------------- diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 353c28a471..0461b15b48 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -21,6 +21,8 @@ #include "wx/object.h" // base class +#include "wx/bmpbndl.h" + #include "wx/windowid.h" #include "wx/vector.h" @@ -164,6 +166,10 @@ public: } protected: + // Helper function returning the appropriate bitmap from the given bundle + // (which may be invalid, in which case invalid bitmap is returned). + wxBitmap GetBitmapFromBundle(const wxBitmapBundle& bundle) const; + wxWindowIDRef m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR wxMenu *m_parentMenu, // the menu we belong to *m_subMenu; // our sub menu or NULL diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index 5c6b20546b..3fe460e0c1 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -15,8 +15,6 @@ // headers // ---------------------------------------------------------------------------- -#include "wx/bmpbndl.h" - #if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" @@ -134,8 +132,6 @@ private: // common part of all ctors void Init(); - wxBitmap GetBitmapFromBundle(const wxBitmapBundle& bundle) const; - // Return the item position in the menu containing it. // // Returns -1 if the item is not attached to a menu or if we can't find its diff --git a/include/wx/osx/menuitem.h b/include/wx/osx/menuitem.h index 63f207f943..0a6f7bec2f 100644 --- a/include/wx/osx/menuitem.h +++ b/include/wx/osx/menuitem.h @@ -16,7 +16,6 @@ // ---------------------------------------------------------------------------- #include "wx/defs.h" -#include "wx/bmpbndl.h" #include "wx/vector.h" // ---------------------------------------------------------------------------- diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 2694c12ad0..51400664a6 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -344,6 +344,23 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) } #endif +wxBitmap wxMenuItemBase::GetBitmapFromBundle(const wxBitmapBundle& bundle) const +{ + wxBitmap bmp; + if ( bundle.IsOk() ) + { + if ( m_parentMenu && m_parentMenu->GetWindow() ) + { + bmp = bundle.GetBitmapFor(m_parentMenu->GetWindow()); + } + else + { + bmp = bundle.GetBitmap(wxDefaultSize); + } + } + return bmp; +} + bool wxMenuBase::ms_locked = true; // ---------------------------------------------------------------------------- diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 1548873222..36566fde60 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -768,19 +768,7 @@ void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) wxBitmap wxMenuItem::GetBitmap() const { - wxBitmap bmp; - if ( m_bitmap.IsOk() ) - { - if ( m_parentMenu && m_parentMenu->GetWindow() ) - { - bmp = m_bitmap.GetBitmapFor(m_parentMenu->GetWindow()); - } - else - { - bmp = m_bitmap.GetBitmap(wxDefaultSize); - } - } - return bmp; + return GetBitmapFromBundle(m_bitmap); } void wxMenuItem::SetupBitmaps(wxWindow *win) diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index d40a433142..300d1f3e93 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -688,22 +688,6 @@ void wxMenuItem::SetItemLabel(const wxString& txt) } } -wxBitmap wxMenuItem::GetBitmapFromBundle(const wxBitmapBundle& bundle) const -{ - if (bundle.IsOk()) - { - if (m_parentMenu && m_parentMenu->GetWindow()) - { - return bundle.GetBitmapFor(m_parentMenu->GetWindow()); - } - else - { - return bundle.GetBitmap(wxDefaultSize); - } - } - return wxNullBitmap; -} - wxBitmap wxMenuItem::GetBitmap(bool bChecked) const { wxBitmap bmp = GetBitmapFromBundle(bChecked ? m_bmpChecked : m_bmpUnchecked); diff --git a/src/osx/menuitem_osx.cpp b/src/osx/menuitem_osx.cpp index a1bb0e75f0..d153910135 100644 --- a/src/osx/menuitem_osx.cpp +++ b/src/osx/menuitem_osx.cpp @@ -77,19 +77,7 @@ void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) wxBitmap wxMenuItem::GetBitmap() const { - wxBitmap bmp; - if ( m_bitmap.IsOk() ) - { - if (m_parentMenu && m_parentMenu->GetWindow()) - { - bmp = m_bitmap.GetBitmapFor(m_parentMenu->GetWindow()); - } - else - { - bmp = m_bitmap.GetBitmap(wxDefaultSize); - } - } - return bmp; + return GetBitmapFromBundle(m_bitmap); } void wxMenuItem::Enable(bool bDoEnable)