From 0e22e890864e6026758d59a163271714d3708ecd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Aug 2014 15:13:59 +0000 Subject: [PATCH] Fix creation of wxBitmap from monochrome wxIcon or wxCursor in wxMSW. Don't suppose that we always have hbmColor because this is not true for monochrome icons/cursors. Create our own bitmap in this case. Closes #16512. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@77516 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/bitmap.cpp | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index ab1c99876b..8972a92a9c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -607,6 +607,7 @@ wxMSW: - Fix appearance of wxToggleButtons with non default colours (Artur Wieczorek). - Fix drawing on wxDC when using right-to-left layout (Artur Wieczorek). - Fix wxGrid appearance and behaviour in RTL (Artur Wieczorek). +- Fix creating wxBitmap from monochrome wxIcon or wxCursor (Artur Wieczorek). - Add paragraph spacing attributes support to wxTextCtrl (dannchr). - Show new style directory selector even for non existent paths (raychow). - Fix order of radial gradient stops (Alexandru Pana). diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index a58283f8c1..fe8bac5024 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -360,11 +360,24 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon, int w = icon.GetWidth(), h = icon.GetHeight(); - refData->m_width = w; - refData->m_height = h; - refData->m_depth = wxDisplayDepth(); - - refData->m_hBitmap = (WXHBITMAP)iconInfo.hbmColor; + if ( iconInfo.hbmColor ) + { + refData->m_width = w; + refData->m_height = h; + refData->m_depth = wxDisplayDepth(); + refData->m_hBitmap = (WXHBITMAP)iconInfo.hbmColor; + } + else // we only have monochrome icon/cursor + { + // Then we need to create our own empty bitmap, which will be modified + // by the mask below. + wxDIB dib(w, h, wxDisplayDepth()); + if ( dib.IsOk() ) + { + memset(dib.GetData(), 0, wxDIB::GetLineSize(w, dib.GetDepth())*h); + refData->AssignDIB(dib); + } + } switch ( transp ) {