Fix transparency in toolbar buttons when not using comctl32.dll v6.
Old versions of comctl32.dll don't support alpha in the toolbar image list, so use the masks only for them. Closes #2609. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75785 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -87,7 +87,8 @@ bool wxImageList::Create(int width, int height, bool mask, int initial)
|
||||
flags |= ILC_COLOR32;
|
||||
#endif
|
||||
|
||||
if ( mask )
|
||||
// For comctl32.dll < 6 always use masks as it doesn't support alpha.
|
||||
if ( mask || wxApp::GetComCtl32Version() < 600 )
|
||||
flags |= ILC_MASK;
|
||||
|
||||
// Grow by 1, I guess this is reasonable behaviour most of the time
|
||||
@@ -148,20 +149,37 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
||||
// course, very inefficient but it's better than wrong appearance so we do
|
||||
// this for now until a better way can be found.
|
||||
AutoHBITMAP hbmpRelease;
|
||||
bool useMask;
|
||||
if ( bitmap.HasAlpha() )
|
||||
{
|
||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
|
||||
// For comctl32.dll < 6 remove alpha channel from image
|
||||
// to prevent possible interferences with the mask.
|
||||
if ( wxApp::GetComCtl32Version() < 600 )
|
||||
{
|
||||
img.ClearAlpha();
|
||||
useMask = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
useMask = false;
|
||||
}
|
||||
|
||||
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
hbmpRelease.Init(hbmp);
|
||||
}
|
||||
else
|
||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||
{
|
||||
hbmp = GetHbitmapOf(bitmap);
|
||||
useMask = true;
|
||||
}
|
||||
|
||||
// Use mask only if we don't have alpha, the bitmap isn't drawn correctly
|
||||
// if we use both.
|
||||
AutoHBITMAP hbmpMask;
|
||||
if ( !bitmap.HasAlpha() )
|
||||
if ( useMask )
|
||||
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
||||
|
||||
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
||||
@@ -185,8 +203,14 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
|
||||
AutoHBITMAP hbmpRelease;
|
||||
if ( bitmap.HasAlpha() )
|
||||
{
|
||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
|
||||
if ( wxApp::GetComCtl32Version() < 600 )
|
||||
{
|
||||
img.ClearAlpha();
|
||||
}
|
||||
|
||||
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
hbmpRelease.Init(hbmp);
|
||||
}
|
||||
else
|
||||
@@ -224,21 +248,38 @@ bool wxImageList::Replace(int index,
|
||||
const wxBitmap& mask)
|
||||
{
|
||||
HBITMAP hbmp;
|
||||
bool useMask;
|
||||
|
||||
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||
// See the comment in Add() above.
|
||||
AutoHBITMAP hbmpRelease;
|
||||
if ( bitmap.HasAlpha() )
|
||||
{
|
||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
wxImage img = bitmap.ConvertToImage();
|
||||
|
||||
if ( wxApp::GetComCtl32Version() < 600 )
|
||||
{
|
||||
img.ClearAlpha();
|
||||
useMask = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
useMask = false;
|
||||
}
|
||||
|
||||
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||
hbmpRelease.Init(hbmp);
|
||||
}
|
||||
else
|
||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||
{
|
||||
hbmp = GetHbitmapOf(bitmap);
|
||||
useMask = true;
|
||||
}
|
||||
|
||||
AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));
|
||||
AutoHBITMAP hbmpMask;
|
||||
if ( useMask )
|
||||
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
||||
|
||||
if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
|
||||
{
|
||||
|
@@ -663,7 +663,10 @@ void wxToolBar::CreateDisabledImageList()
|
||||
(
|
||||
sizeBitmap.x,
|
||||
sizeBitmap.y,
|
||||
bmpDisabled.GetMask() != NULL,
|
||||
// Don't use mask if we have alpha
|
||||
// (wxImageList will fall back to
|
||||
// mask if alpha not supported)
|
||||
!bmpDisabled.HasAlpha(),
|
||||
GetToolsCount()
|
||||
);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user