Add wxIcon::CreateFromHICON() to wxMSW.
Provide a public method properly assigning an HICON to wxIcon, instead of asking people to call SetHICON() and SetSize(). Closes #15023. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73489 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -647,6 +647,7 @@ wxMSW:
|
|||||||
- Fix changing labels of menu items with bitmaps (Daniel Hyams).
|
- Fix changing labels of menu items with bitmaps (Daniel Hyams).
|
||||||
- Fix appearance of multiline coloured wxCheckBox (Catalin Raceanu).
|
- Fix appearance of multiline coloured wxCheckBox (Catalin Raceanu).
|
||||||
- Allow creating wxCursor from ANI files (Catalin Raceanu).
|
- Allow creating wxCursor from ANI files (Catalin Raceanu).
|
||||||
|
- Add wxIcon::CreateFromHICON() (troelsk).
|
||||||
|
|
||||||
wxOSX/Cocoa:
|
wxOSX/Cocoa:
|
||||||
|
|
||||||
|
@@ -65,6 +65,8 @@ public:
|
|||||||
wxBitmapType type = wxICON_DEFAULT_TYPE,
|
wxBitmapType type = wxICON_DEFAULT_TYPE,
|
||||||
int desiredWidth = -1, int desiredHeight = -1);
|
int desiredWidth = -1, int desiredHeight = -1);
|
||||||
|
|
||||||
|
bool CreateFromHICON(WXHICON icon);
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; }
|
wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; }
|
||||||
|
|
||||||
|
@@ -179,6 +179,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~wxIcon();
|
virtual ~wxIcon();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Attach a Windows icon handle.
|
||||||
|
|
||||||
|
This wxMSW-specific method allows to assign a native Windows @c HICON
|
||||||
|
(which must be castes to @c WXHICON opaque handle type) to wxIcon.
|
||||||
|
Notice that this means that the @c HICON will be destroyed by wxIcon
|
||||||
|
when it is destroyed.
|
||||||
|
|
||||||
|
@return @true if successful.
|
||||||
|
|
||||||
|
@onlyfor{wxmsw}
|
||||||
|
|
||||||
|
@since 2.9.5
|
||||||
|
*/
|
||||||
|
bool CreateFromHICON(WXHICON icon);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns disabled (dimmed) version of the icon.
|
Returns disabled (dimmed) version of the icon.
|
||||||
|
|
||||||
|
@@ -432,9 +432,6 @@ bool wxICOFileHandler::LoadIcon(wxIcon *icon,
|
|||||||
{
|
{
|
||||||
icon->UnRef();
|
icon->UnRef();
|
||||||
|
|
||||||
// actual size
|
|
||||||
wxSize size;
|
|
||||||
|
|
||||||
HICON hicon = NULL;
|
HICON hicon = NULL;
|
||||||
|
|
||||||
// Parse the filename: it may be of the form "filename;n" in order to
|
// Parse the filename: it may be of the form "filename;n" in order to
|
||||||
@@ -515,25 +512,23 @@ bool wxICOFileHandler::LoadIcon(wxIcon *icon,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = wxGetHiconSize(hicon);
|
if ( !icon->CreateFromHICON(hicon) )
|
||||||
|
return false;
|
||||||
|
|
||||||
if ( (desiredWidth != -1 && desiredWidth != size.x) ||
|
if ( (desiredWidth != -1 && desiredWidth != icon->GetWidth()) ||
|
||||||
(desiredHeight != -1 && desiredHeight != size.y) )
|
(desiredHeight != -1 && desiredHeight != icon->GetHeight()) )
|
||||||
{
|
{
|
||||||
wxLogTrace(wxT("iconload"),
|
wxLogTrace(wxT("iconload"),
|
||||||
wxT("Returning false from wxICOFileHandler::Load because of the size mismatch: actual (%d, %d), requested (%d, %d)"),
|
wxT("Returning false from wxICOFileHandler::Load because of the size mismatch: actual (%d, %d), requested (%d, %d)"),
|
||||||
size.x, size.y,
|
icon->GetWidth(), icon->GetHeight(),
|
||||||
desiredWidth, desiredHeight);
|
desiredWidth, desiredHeight);
|
||||||
|
|
||||||
::DestroyIcon(hicon);
|
icon->UnRef();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
icon->SetHICON((WXHICON)hicon);
|
return true;
|
||||||
icon->SetSize(size.x, size.y);
|
|
||||||
|
|
||||||
return icon->IsOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
|
bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
|
||||||
@@ -593,12 +588,7 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxSize size = wxGetHiconSize(hicon);
|
return icon->CreateFromHICON((WXHICON)hicon);
|
||||||
icon->SetSize(size.x, size.y);
|
|
||||||
|
|
||||||
icon->SetHICON((WXHICON)hicon);
|
|
||||||
|
|
||||||
return icon->IsOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_PNG_RESOURCE_HANDLER
|
#if wxUSE_PNG_RESOURCE_HANDLER
|
||||||
|
@@ -156,3 +156,14 @@ bool wxIcon::LoadFile(const wxString& filename,
|
|||||||
|
|
||||||
return handler->Load(this, filename, type, desiredWidth, desiredHeight);
|
return handler->Load(this, filename, type, desiredWidth, desiredHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxIcon::CreateFromHICON(WXHICON icon)
|
||||||
|
{
|
||||||
|
SetHICON(icon);
|
||||||
|
if ( !IsOk() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SetSize(wxGetHiconSize(icon));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user