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
This commit is contained in:
Vadim Zeitlin
2005-12-19 13:46:23 +00:00
parent 62bdd4db0e
commit 333c869716
2 changed files with 32 additions and 16 deletions

View File

@@ -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") );
// can always be used, whether we have a bitmap or an icon in reality
wxBitmap GetBitmap() const;
return *(wxIcon *)m_image;
}
// can only be used if an icon had been originally used
wxIcon GetIcon() const;
wxBitmap GetBitmap() const
{
wxASSERT_MSG( !m_isIcon, _T("no bitmap in this wxStaticBitmap") );
return *(wxBitmap *)m_image;
}
// implementation only from now on
// -------------------------------
protected:
virtual wxBorder GetDefaultBorder() const;

View File

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