Set HICON and its parameters in one call
To avoid separate calls to SetSize() function after calling SetHICON() use newly implemented InitFromHICON() function which allows set HICON together with its parameters in one call.
This commit is contained in:
@@ -71,6 +71,7 @@ public:
|
||||
|
||||
void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); }
|
||||
WXHICON GetHICON() const { return (WXHICON)GetHandle(); }
|
||||
bool InitFromHICON(WXHICON icon, int width, int height);
|
||||
|
||||
// create from bitmap (which should have a mask unless it's monochrome):
|
||||
// there shouldn't be any implicit bitmap -> icon conversion (i.e. no
|
||||
|
@@ -118,8 +118,7 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
|
||||
}
|
||||
else
|
||||
{
|
||||
SetHICON((WXHICON)hicon);
|
||||
SetSize(bmp.GetWidth(), bmp.GetHeight());
|
||||
InitFromHICON((WXHICON)hicon, bmp.GetWidth(), bmp.GetHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,11 +153,26 @@ bool wxIcon::LoadFile(const wxString& filename,
|
||||
|
||||
bool wxIcon::CreateFromHICON(WXHICON icon)
|
||||
{
|
||||
SetHICON(icon);
|
||||
if ( !IsOk() )
|
||||
return false;
|
||||
|
||||
SetSize(wxGetHiconSize(icon));
|
||||
|
||||
return true;
|
||||
wxSize size = wxGetHiconSize(icon);
|
||||
return InitFromHICON(icon, size.GetWidth(), size.GetHeight());
|
||||
}
|
||||
|
||||
bool wxIcon::InitFromHICON(WXHICON icon, int width, int height)
|
||||
{
|
||||
#if wxDEBUG_LEVEL >= 2
|
||||
if ( icon != NULL )
|
||||
{
|
||||
wxSize size = wxGetHiconSize(icon);
|
||||
wxASSERT_MSG(size.GetWidth() == width && size.GetHeight() == height,
|
||||
wxS("Inconsistent icon parameters"));
|
||||
}
|
||||
#endif // wxDEBUG_LEVEL >= 2
|
||||
|
||||
AllocExclusive();
|
||||
|
||||
GetGDIImageData()->m_handle = (WXHANDLE)icon;
|
||||
GetGDIImageData()->m_width = width;
|
||||
GetGDIImageData()->m_height = height;
|
||||
|
||||
return IsOk();
|
||||
}
|
||||
|
@@ -461,11 +461,10 @@ wxIcon wxImageList::GetIcon(int index) const
|
||||
if (hIcon)
|
||||
{
|
||||
wxIcon icon;
|
||||
icon.SetHICON((WXHICON)hIcon);
|
||||
|
||||
int iconW, iconH;
|
||||
GetSize(index, iconW, iconH);
|
||||
icon.SetSize(iconW, iconH);
|
||||
icon.InitFromHICON((WXHICON)hIcon, iconW, iconH);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
Reference in New Issue
Block a user