From: Vadim Zeitlin Date: Mon, 19 Dec 2005 13:46:23 +0000 (+0000) Subject: return a valid bitmap from GetBitmap() even if we created an icon internally X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/333c8697161eb3d9f9e497631c5b24eef01c4d3e?ds=inline return a valid bitmap from GetBitmap() even if we created an icon internally git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 780e5e4a15..82b1a921a1 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -50,24 +50,12 @@ public: virtual void SetIcon(const wxIcon& icon) { SetImage(&icon); } virtual void SetBitmap(const wxBitmap& bitmap) { SetImage(&bitmap); } - // assert failure is provoked by an attempt to get an icon from bitmap or - // vice versa - wxIcon GetIcon() const - { - wxASSERT_MSG( m_isIcon, _T("no icon in this wxStaticBitmap") ); - - return *(wxIcon *)m_image; - } + // can always be used, whether we have a bitmap or an icon in reality + wxBitmap GetBitmap() const; - wxBitmap GetBitmap() const - { - wxASSERT_MSG( !m_isIcon, _T("no bitmap in this wxStaticBitmap") ); - - return *(wxBitmap *)m_image; - } + // can only be used if an icon had been originally used + wxIcon GetIcon() const; - // implementation only from now on - // ------------------------------- protected: virtual wxBorder GetDefaultBorder() const; diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index fbdba6ccc5..ca99580ab0 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -196,6 +196,34 @@ bool wxStaticBitmap::ImageIsOk() const return m_image && m_image->Ok(); } +wxIcon wxStaticBitmap::GetIcon() const +{ + wxCHECK_MSG( m_image, wxIcon(), _T("no image in wxStaticBitmap") ); + + // we can't ask for an icon if all we have is a bitmap + wxCHECK_MSG( m_isIcon, wxIcon(), _T("no icon in this wxStaticBitmap") ); + + return *(wxIcon *)m_image; +} + +wxBitmap wxStaticBitmap::GetBitmap() const +{ + if ( m_isIcon ) + { + // don't fail because we might have replaced the bitmap with icon + // ourselves internally in ConvertImage() to keep the transparency but + // the user code doesn't know about it so it still can use GetBitmap() + // to retrieve the bitmap + return wxBitmap(GetIcon()); + } + else // we have a bitmap + { + wxCHECK_MSG( m_image, wxBitmap(), _T("no image in wxStaticBitmap") ); + + return *(wxBitmap *)m_image; + } +} + void wxStaticBitmap::Free() { delete m_image;