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:
Artur Wieczorek
2018-09-11 21:50:22 +02:00
parent 97f73acddb
commit 5115fe31ef
3 changed files with 25 additions and 11 deletions

View File

@@ -71,6 +71,7 @@ public:
void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); } void SetHICON(WXHICON icon) { SetHandle((WXHANDLE)icon); }
WXHICON GetHICON() const { return (WXHICON)GetHandle(); } 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): // create from bitmap (which should have a mask unless it's monochrome):
// there shouldn't be any implicit bitmap -> icon conversion (i.e. no // there shouldn't be any implicit bitmap -> icon conversion (i.e. no

View File

@@ -118,8 +118,7 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
} }
else else
{ {
SetHICON((WXHICON)hicon); InitFromHICON((WXHICON)hicon, bmp.GetWidth(), bmp.GetHeight());
SetSize(bmp.GetWidth(), bmp.GetHeight());
} }
} }
@@ -154,11 +153,26 @@ bool wxIcon::LoadFile(const wxString& filename,
bool wxIcon::CreateFromHICON(WXHICON icon) bool wxIcon::CreateFromHICON(WXHICON icon)
{ {
SetHICON(icon); wxSize size = wxGetHiconSize(icon);
if ( !IsOk() ) return InitFromHICON(icon, size.GetWidth(), size.GetHeight());
return false; }
SetSize(wxGetHiconSize(icon)); bool wxIcon::InitFromHICON(WXHICON icon, int width, int height)
{
return true; #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();
} }

View File

@@ -461,11 +461,10 @@ wxIcon wxImageList::GetIcon(int index) const
if (hIcon) if (hIcon)
{ {
wxIcon icon; wxIcon icon;
icon.SetHICON((WXHICON)hIcon);
int iconW, iconH; int iconW, iconH;
GetSize(index, iconW, iconH); GetSize(index, iconW, iconH);
icon.SetSize(iconW, iconH); icon.InitFromHICON((WXHICON)hIcon, iconW, iconH);
return icon; return icon;
} }