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.
This commit is contained in:
Vadim Zeitlin 2022-06-15 01:26:07 +01:00
parent 7f3baa9abf
commit c0dbe808a6
12 changed files with 37 additions and 60 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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