Add common implementations of wxStaticBitmap icon methods

Instead of defining them, slightly differently, in all the non-MSW
ports, define them once in wxStaticBitmapBase.

No real changes, this is just a simplification.
This commit is contained in:
Vadim Zeitlin
2021-10-21 18:15:12 +01:00
parent 5773a8736c
commit b403624f22
11 changed files with 38 additions and 99 deletions

View File

@@ -44,18 +44,6 @@ public:
virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_bitmap; }
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE
{
m_bitmap.CopyFromIcon(icon);
SetInitialSize(GetBitmapSize());
Refresh();
}
#if defined(__WXGTK20__) || defined(__WXMAC__)
// icons and bitmaps are really the same thing in wxGTK and wxMac
wxIcon GetIcon() const wxOVERRIDE { return (const wxIcon &)m_bitmap; }
#endif
virtual void SetScaleMode(ScaleMode scaleMode) wxOVERRIDE
{
m_scaleMode = scaleMode;

View File

@@ -34,18 +34,9 @@ public:
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr));
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE { SetBitmap( icon ); }
virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE;
virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_bitmap; }
// for compatibility with wxMSW
wxIcon GetIcon() const wxOVERRIDE
{
// don't use wxDynamicCast, icons and bitmaps are really the same thing
// in wxGTK
return (const wxIcon &)m_bitmap;
}
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);

View File

@@ -34,18 +34,9 @@ public:
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr));
virtual void SetIcon(const wxIcon& icon) { SetBitmap( icon ); }
virtual void SetBitmap( const wxBitmap& bitmap );
virtual wxBitmap GetBitmap() const { return m_bitmap; }
// for compatibility with wxMSW
wxIcon GetIcon() const
{
// don't use wxDynamicCast, icons and bitmaps are really the same thing
// in wxGTK
return (const wxIcon &)m_bitmap;
}
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);

View File

@@ -48,19 +48,6 @@ public:
wxBitmap GetBitmap() const { return m_messageBitmap; }
// for compatibility with wxMSW
wxIcon GetIcon() const
{
// don't use wxDynamicCast, icons and bitmaps are really the same thing
return *(const wxIcon*)&m_messageBitmap;
}
// for compatibility with wxMSW
void SetIcon(const wxIcon& icon)
{
SetBitmap( icon );
}
// Implementation
virtual void ChangeBackgroundColour();
virtual void ChangeForegroundColour();

View File

@@ -30,18 +30,6 @@ public:
virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_bitmap; }
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE
{
wxBitmap bmp;
bmp.CopyFromIcon(icon);
SetBitmap(bmp);
}
#if defined(__WXGTK20__) || defined(__WXMAC__)
// icons and bitmaps are really the same thing in wxGTK and wxMac
wxIcon GetIcon() const wxOVERRIDE { return (const wxIcon &)m_bitmap; }
#endif
virtual void SetScaleMode(ScaleMode scaleMode) wxOVERRIDE;
virtual ScaleMode GetScaleMode() const wxOVERRIDE { return m_scaleMode; }

View File

@@ -30,10 +30,8 @@ public:
long style = 0,
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr));
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE;
virtual void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE;
virtual wxBitmap GetBitmap() const wxOVERRIDE;
virtual wxIcon GetIcon() const wxOVERRIDE;
virtual QWidget *GetHandle() const wxOVERRIDE;
protected:

View File

@@ -37,15 +37,12 @@ public:
virtual ~wxStaticBitmapBase();
// our interface
virtual void SetIcon(const wxIcon& icon) = 0;
virtual void SetBitmap(const wxBitmap& bitmap) = 0;
virtual wxBitmap GetBitmap() const = 0;
virtual wxIcon GetIcon() const /* = 0 -- should be pure virtual */
{
// stub it out here for now as not all ports implement it (but they
// should)
return wxIcon();
}
virtual void SetIcon(const wxIcon& icon);
virtual wxIcon GetIcon() const;
virtual void SetScaleMode(ScaleMode WXUNUSED(scaleMode)) { }
virtual ScaleMode GetScaleMode() const { return Scale_None; }

View File

@@ -53,11 +53,8 @@ public:
const wxString& name = wxASCII_STR(wxStaticBitmapNameStr));
virtual void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE;
virtual void SetIcon(const wxIcon& icon) wxOVERRIDE;
virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_bitmap; }
wxIcon GetIcon() const wxOVERRIDE;
virtual bool HasTransparentBackground() wxOVERRIDE { return true; }
protected:

View File

@@ -96,4 +96,38 @@ wxSize wxStaticBitmapBase::DoGetBestSize() const
return bmp.IsOk() ? bmp.GetScaledSize() : wxSize(16, 16);
}
// Only wxMSW handles icons and bitmaps differently, in all the other ports
// they are exactly the same thing.
#ifdef wxICON_IS_BITMAP
void wxStaticBitmapBase::SetIcon(const wxIcon& icon)
{
SetBitmap(icon);
}
wxIcon wxStaticBitmapBase::GetIcon() const
{
wxIcon icon;
icon.CopyFromBitmap(GetBitmap());
return icon;
}
#else // !wxICON_IS_BITMAP
// Just provide the stabs for them, they're never used anyhow as they're
// overridden in wxMSW implementation of this class.
void wxStaticBitmapBase::SetIcon(const wxIcon& WXUNUSED(icon))
{
wxFAIL_MSG(wxS("unreachable"));
}
wxIcon wxStaticBitmapBase::GetIcon() const
{
wxFAIL_MSG(wxS("unreachable"));
return wxIcon();
}
#endif // wxICON_IS_BITMAP/!wxICON_IS_BITMAP
#endif // wxUSE_STATBMP

View File

@@ -57,11 +57,6 @@ static void SetPixmap( QLabel *label, const QPixmap *pixMap )
label->setPixmap( *pixMap );
}
void wxStaticBitmap::SetIcon(const wxIcon& icon)
{
SetPixmap( m_qtLabel, icon.GetHandle() );
}
void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
{
SetPixmap( m_qtLabel, bitmap.GetHandle() );
@@ -76,13 +71,6 @@ wxBitmap wxStaticBitmap::GetBitmap() const
return wxBitmap();
}
wxIcon wxStaticBitmap::GetIcon() const
{
wxIcon icon;
icon.CopyFromBitmap( GetBitmap() );
return icon;
}
QWidget *wxStaticBitmap::GetHandle() const
{
return m_qtLabel;

View File

@@ -69,26 +69,6 @@ void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
m_bitmap = bitmap;
}
void wxStaticBitmap::SetIcon(const wxIcon& icon)
{
#ifdef __WXMSW__
m_bitmap.CopyFromIcon(icon);
#else
m_bitmap = (const wxBitmap&)icon;
#endif
}
wxIcon wxStaticBitmap::GetIcon() const
{
wxIcon icon;
#ifdef __WXMSW__
icon.CopyFromBitmap(m_bitmap);
#else
icon = (const wxIcon&)m_bitmap;
#endif
return icon;
}
// ----------------------------------------------------------------------------
// drawing
// ----------------------------------------------------------------------------