From b403624f22d07dd57325bab2dc3263fcd45fa94c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 2021 18:15:12 +0100 Subject: [PATCH] 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. --- include/wx/generic/statbmpg.h | 12 ------------ include/wx/gtk/statbmp.h | 9 --------- include/wx/gtk1/statbmp.h | 9 --------- include/wx/motif/statbmp.h | 13 ------------- include/wx/osx/statbmp.h | 12 ------------ include/wx/qt/statbmp.h | 2 -- include/wx/statbmp.h | 11 ++++------- include/wx/univ/statbmp.h | 3 --- src/common/statbmpcmn.cpp | 34 ++++++++++++++++++++++++++++++++++ src/qt/statbmp.cpp | 12 ------------ src/univ/statbmp.cpp | 20 -------------------- 11 files changed, 38 insertions(+), 99 deletions(-) diff --git a/include/wx/generic/statbmpg.h b/include/wx/generic/statbmpg.h index abf7340878..bb49ba93bc 100644 --- a/include/wx/generic/statbmpg.h +++ b/include/wx/generic/statbmpg.h @@ -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; diff --git a/include/wx/gtk/statbmp.h b/include/wx/gtk/statbmp.h index 28b116134c..f45d170800 100644 --- a/include/wx/gtk/statbmp.h +++ b/include/wx/gtk/statbmp.h @@ -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); diff --git a/include/wx/gtk1/statbmp.h b/include/wx/gtk1/statbmp.h index 3c9eaad0d2..5e28a49234 100644 --- a/include/wx/gtk1/statbmp.h +++ b/include/wx/gtk1/statbmp.h @@ -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); diff --git a/include/wx/motif/statbmp.h b/include/wx/motif/statbmp.h index 4d0bbf09df..0cdfd7022a 100644 --- a/include/wx/motif/statbmp.h +++ b/include/wx/motif/statbmp.h @@ -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(); diff --git a/include/wx/osx/statbmp.h b/include/wx/osx/statbmp.h index 93d5cf836e..51d9545a08 100644 --- a/include/wx/osx/statbmp.h +++ b/include/wx/osx/statbmp.h @@ -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; } diff --git a/include/wx/qt/statbmp.h b/include/wx/qt/statbmp.h index d4210c5ff6..d376463a73 100644 --- a/include/wx/qt/statbmp.h +++ b/include/wx/qt/statbmp.h @@ -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: diff --git a/include/wx/statbmp.h b/include/wx/statbmp.h index ea888cd501..3192ba0e25 100644 --- a/include/wx/statbmp.h +++ b/include/wx/statbmp.h @@ -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; } diff --git a/include/wx/univ/statbmp.h b/include/wx/univ/statbmp.h index 38d8a545d6..4c0e27e844 100644 --- a/include/wx/univ/statbmp.h +++ b/include/wx/univ/statbmp.h @@ -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: diff --git a/src/common/statbmpcmn.cpp b/src/common/statbmpcmn.cpp index d2c4f8c26b..f9824dad94 100644 --- a/src/common/statbmpcmn.cpp +++ b/src/common/statbmpcmn.cpp @@ -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 diff --git a/src/qt/statbmp.cpp b/src/qt/statbmp.cpp index d27a57672f..56d09461e4 100644 --- a/src/qt/statbmp.cpp +++ b/src/qt/statbmp.cpp @@ -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; diff --git a/src/univ/statbmp.cpp b/src/univ/statbmp.cpp index f763772e18..dc6a590d65 100644 --- a/src/univ/statbmp.cpp +++ b/src/univ/statbmp.cpp @@ -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 // ----------------------------------------------------------------------------