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.
This commit is contained in:
Vadim Zeitlin 2022-02-05 20:35:46 +01:00
parent bec31f1919
commit 338cd95c2d
8 changed files with 25 additions and 49 deletions

View File

@ -9,8 +9,6 @@
#ifndef _WX_GTKMENUITEM_H_
#define _WX_GTKMENUITEM_H_
#include "wx/bmpbndl.h"
//-----------------------------------------------------------------------------
// wxMenuItem
//-----------------------------------------------------------------------------

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,6 @@
// ----------------------------------------------------------------------------
#include "wx/defs.h"
#include "wx/bmpbndl.h"
#include "wx/vector.h"
// ----------------------------------------------------------------------------

View File

@ -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;
// ----------------------------------------------------------------------------

View File

@ -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)

View File

@ -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);

View File

@ -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)