X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4b7f2165565bb33b149baf1272e28f9a61d579d3..a2327a9f80fa3240ab652da8f95a66b5c25576de:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 015b00e732..33651b712f 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -46,6 +46,11 @@ #include "wx/msw/dib.h" #include "wx/image.h" +// missing from mingw32 header +#ifndef CLR_INVALID + #define CLR_INVALID ((COLORREF)-1) +#endif // no CLR_INVALID + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -577,15 +582,15 @@ wxMask::~wxMask() // Create a mask from a mono bitmap (copies the bitmap). bool wxMask::Create(const wxBitmap& bitmap) { + wxCHECK_MSG( bitmap.Ok() && bitmap.GetDepth() == 1, FALSE, + _T("can't create mask from invalid or not monochrome bitmap") ); + if ( m_maskBitmap ) { ::DeleteObject((HBITMAP) m_maskBitmap); m_maskBitmap = 0; } - if (!bitmap.Ok() || bitmap.GetDepth() != 1) - { - return FALSE; - } + m_maskBitmap = (WXHBITMAP) CreateBitmap( bitmap.GetWidth(), bitmap.GetHeight(), @@ -651,20 +656,29 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) wxLogLastError("CreateCompatibleDC"); } - if ( !::SelectObject(srcDC, GetHbitmapOf(bitmap)) ) + bool ok = TRUE; + + HGDIOBJ hbmpSrcOld = ::SelectObject(srcDC, GetHbitmapOf(bitmap)); + if ( !hbmpSrcOld ) { wxLogLastError("SelectObject"); + + ok = FALSE; } - if ( !::SelectObject(destDC, (HBITMAP)m_maskBitmap) ) + + HGDIOBJ hbmpDstOld = ::SelectObject(destDC, (HBITMAP)m_maskBitmap); + if ( !hbmpDstOld ) { wxLogLastError("SelectObject"); + + ok = FALSE; } // this is not very efficient, but I can't think of a better way of doing // it - for ( int w = 0; w < width; w++ ) + for ( int w = 0; ok && (w < width); w++ ) { - for ( int h = 0; h < height; h++ ) + for ( int h = 0; ok && (h < height); h++ ) { COLORREF col = GetPixel(srcDC, w, h); if ( col == CLR_INVALID ) @@ -672,12 +686,9 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) wxLogLastError("GetPixel"); // doesn't make sense to continue - ::SelectObject(srcDC, 0); - ::DeleteDC(srcDC); - ::SelectObject(destDC, 0); - ::DeleteDC(destDC); + ok = FALSE; - return FALSE; + break; } if ( col == maskColour ) @@ -691,12 +702,12 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } } - ::SelectObject(srcDC, 0); + ::SelectObject(srcDC, hbmpSrcOld); ::DeleteDC(srcDC); - ::SelectObject(destDC, 0); + ::SelectObject(destDC, hbmpDstOld); ::DeleteDC(destDC); - return TRUE; + return ok; } // ----------------------------------------------------------------------------