From 53b6806b50f8c60d25b4e58bed45105c52566c44 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 16 Feb 2016 21:23:10 +0100 Subject: [PATCH 1/2] Fixed adding 32-bit icons with transparency to wxImageList. ComCtl32 prior to 6.0 doesn't support images with alpha channel so if we have 32-bit icon with transparency we need to convert it to a wxBitmap and then add this bitmap to wxImageList. If required, bitmap with alpha channel will be converted to the mask in wxImageList::Add. --- src/msw/imaglist.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index 0b216d5b39..460de7f0c5 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -230,6 +230,19 @@ int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour) // Adds a bitmap and mask from an icon. int wxImageList::Add(const wxIcon& icon) { + // ComCtl32 prior 6.0 doesn't support images with alpha + // channel so if we have 32-bit icon with transparency + // we need to add it as a wxBitmap via dedicated method + // where alpha channel will be converted to the mask. + if ( wxApp::GetComCtl32Version() < 600 ) + { + wxBitmap bmp(icon); + if ( bmp.HasAlpha() ) + { + return Add(bmp); + } + } + int index = ImageList_AddIcon(GetHImageList(), GetHiconOf(icon)); if ( index == -1 ) { @@ -292,6 +305,19 @@ bool wxImageList::Replace(int index, // Replaces a bitmap and mask from an icon. bool wxImageList::Replace(int i, const wxIcon& icon) { + // ComCtl32 prior 6.0 doesn't support images with alpha + // channel so if we have 32-bit icon with transparency + // we need to replace it as a wxBitmap via dedicated method + // where alpha channel will be converted to the mask. + if ( wxApp::GetComCtl32Version() < 600 ) + { + wxBitmap bmp(icon); + if ( bmp.HasAlpha() ) + { + return Replace(i, bmp); + } + } + bool ok = ImageList_ReplaceIcon(GetHImageList(), i, GetHiconOf(icon)) != -1; if ( !ok ) { From 43fe885eb756dd721cd4e06825e054ec89baf170 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 16 Feb 2016 21:36:44 +0100 Subject: [PATCH 2/2] Fixed displaying text labels after assigning wxImageList to wxListCtrl. For ComCtl32 prior to 6.0 all text labels in wxListCtrl need to be re-assigned when new wxImageList is set in order to position them correctly within the control. --- src/msw/listctrl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index dfc8128eb6..3c0675eb7b 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1341,6 +1341,18 @@ void wxListCtrl::SetImageList(wxImageList *imageList, int which) m_ownsImageListState = false; } (void) ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); + + // For ComCtl32 prior 6.0 we need to re-assign all existing + // text labels in order to position them correctly. + if ( wxApp::GetComCtl32Version() < 600 ) + { + const int n = GetItemCount(); + for( int i = 0; i < n; i++ ) + { + wxString text = GetItemText(i); + SetItemText(i, text); + } + } } void wxListCtrl::AssignImageList(wxImageList *imageList, int which)