Return the best-sized icons from wxWindowsArtProvider
Use SHDefExtractIcon() to retrieve the most appropriately-sized icon instead of always getting either the small or the large icon and then scaling it ourselves to make it of the right size. This results in incomparably better results for large icon sizes, e.g. 256*256, as can be seen in the artprov sample.
This commit is contained in:
committed by
Vadim Zeitlin
parent
880b2b0a46
commit
8698d69c77
@@ -180,38 +180,37 @@ wxBitmap wxWindowsArtProvider::CreateBitmap(const wxArtID& id,
|
||||
{
|
||||
WinStruct<SHSTOCKICONINFO> sii;
|
||||
|
||||
UINT uFlags = SHGSI_ICON;
|
||||
if ( size != wxDefaultSize )
|
||||
{
|
||||
if ( size.x <= 16 )
|
||||
uFlags |= SHGSI_SMALLICON;
|
||||
else if ( size.x >= 64 )
|
||||
uFlags |= SHGSI_LARGEICON;
|
||||
}
|
||||
UINT uFlags = SHGSI_ICONLOCATION | SHGSI_SYSICONINDEX;
|
||||
|
||||
HRESULT res = MSW_SHGetStockIconInfo(stockIconId, uFlags, &sii);
|
||||
if ( res == S_OK )
|
||||
{
|
||||
wxIcon icon;
|
||||
icon.CreateFromHICON( (WXHICON)sii.hIcon );
|
||||
const wxSize
|
||||
sizeNeeded = size.IsFullySpecified()
|
||||
? size
|
||||
: wxArtProvider::GetNativeSizeHint(client);
|
||||
|
||||
bitmap = wxBitmap(icon);
|
||||
::DestroyIcon(sii.hIcon);
|
||||
|
||||
if ( bitmap.IsOk() )
|
||||
HICON hIcon = NULL;
|
||||
res = SHDefExtractIcon(sii.szPath, sii.iIcon, 0,
|
||||
&hIcon, NULL, sizeNeeded.x);
|
||||
if ( res == S_OK )
|
||||
{
|
||||
const wxSize
|
||||
sizeNeeded = size.IsFullySpecified()
|
||||
? size
|
||||
: wxArtProvider::GetNativeSizeHint(client);
|
||||
wxIcon icon;
|
||||
icon.CreateFromHICON((WXHICON)hIcon);
|
||||
|
||||
if ( sizeNeeded.IsFullySpecified() &&
|
||||
bitmap.GetSize() != sizeNeeded )
|
||||
bitmap = wxBitmap(icon);
|
||||
::DestroyIcon(hIcon);
|
||||
|
||||
if ( bitmap.IsOk() )
|
||||
{
|
||||
wxArtProvider::RescaleBitmap(bitmap, sizeNeeded);
|
||||
}
|
||||
if ( sizeNeeded.IsFullySpecified() &&
|
||||
bitmap.GetSize() != sizeNeeded )
|
||||
{
|
||||
wxArtProvider::RescaleBitmap(bitmap, sizeNeeded);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user