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. This is a backport of r75785, r75794 and r75923 from trunk. Closes #2609. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75924 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/app.h"
|
||||||
#include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
|
#include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
|
||||||
#include "wx/window.h"
|
#include "wx/window.h"
|
||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
@@ -87,7 +88,8 @@ bool wxImageList::Create(int width, int height, bool mask, int initial)
|
|||||||
flags |= ILC_COLOR32;
|
flags |= ILC_COLOR32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( mask )
|
// For comctl32.dll < 6 always use masks as it doesn't support alpha.
|
||||||
|
if ( mask || wxApp::GetComCtl32Version() < 600 )
|
||||||
flags |= ILC_MASK;
|
flags |= ILC_MASK;
|
||||||
|
|
||||||
// Grow by 1, I guess this is reasonable behaviour most of the time
|
// Grow by 1, I guess this is reasonable behaviour most of the time
|
||||||
@@ -140,6 +142,7 @@ bool wxImageList::GetSize(int WXUNUSED(index), int &width, int &height) const
|
|||||||
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
||||||
{
|
{
|
||||||
HBITMAP hbmp;
|
HBITMAP hbmp;
|
||||||
|
bool useMask;
|
||||||
|
|
||||||
#if wxUSE_WXDIB && wxUSE_IMAGE
|
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
// wxBitmap normally stores alpha in pre-multiplied format but
|
// wxBitmap normally stores alpha in pre-multiplied format but
|
||||||
@@ -150,15 +153,35 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask)
|
|||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
// 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);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
{
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
hbmp = GetHbitmapOf(bitmap);
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
|
||||||
AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask));
|
// Use mask only if we don't have alpha, the bitmap isn't drawn correctly
|
||||||
|
// if we use both.
|
||||||
|
AutoHBITMAP hbmpMask;
|
||||||
|
if ( useMask )
|
||||||
|
hbmpMask.Init(GetMaskForImage(bitmap, mask));
|
||||||
|
|
||||||
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask);
|
||||||
if ( index == -1 )
|
if ( index == -1 )
|
||||||
@@ -181,8 +204,14 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour)
|
|||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
if ( wxApp::GetComCtl32Version() < 600 )
|
||||||
|
{
|
||||||
|
img.ClearAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
hbmpRelease.Init(hbmp);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -220,21 +249,38 @@ bool wxImageList::Replace(int index,
|
|||||||
const wxBitmap& mask)
|
const wxBitmap& mask)
|
||||||
{
|
{
|
||||||
HBITMAP hbmp;
|
HBITMAP hbmp;
|
||||||
|
bool useMask;
|
||||||
|
|
||||||
#if wxUSE_WXDIB && wxUSE_IMAGE
|
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
// See the comment in Add() above.
|
// See the comment in Add() above.
|
||||||
AutoHBITMAP hbmpRelease;
|
AutoHBITMAP hbmpRelease;
|
||||||
if ( bitmap.HasAlpha() )
|
if ( bitmap.HasAlpha() )
|
||||||
{
|
{
|
||||||
hbmp = wxDIB(bitmap.ConvertToImage(),
|
wxImage img = bitmap.ConvertToImage();
|
||||||
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
|
||||||
|
if ( wxApp::GetComCtl32Version() < 600 )
|
||||||
|
{
|
||||||
|
img.ClearAlpha();
|
||||||
|
useMask = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
useMask = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
hbmpRelease.Init(hbmp);
|
hbmpRelease.Init(hbmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
{
|
||||||
hbmp = GetHbitmapOf(bitmap);
|
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) )
|
if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) )
|
||||||
{
|
{
|
||||||
|
@@ -663,7 +663,10 @@ void wxToolBar::CreateDisabledImageList()
|
|||||||
(
|
(
|
||||||
sizeBitmap.x,
|
sizeBitmap.x,
|
||||||
sizeBitmap.y,
|
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()
|
GetToolsCount()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user