]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/bitmap.cpp
don't keep dangling m_prevRadio pointer (2nd part of patch 1836644)
[wxWidgets.git] / src / msw / bitmap.cpp
index 773ed64d579aa060bd5b75dc54d8c366991ab215..f3221c6e73caaa8275e464ff1a1c7febb477b6d0 100644 (file)
@@ -289,9 +289,8 @@ wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const
     return m_refData;
 }
 
-#ifdef __WIN32__
-
-bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
+bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon,
+                                    wxBitmapTransparency transp)
 {
 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
     // it may be either HICON or HCURSOR
@@ -317,31 +316,51 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
 
     refData->m_hBitmap = (WXHBITMAP)iconInfo.hbmColor;
 
+    switch ( transp )
+    {
+        default:
+            wxFAIL_MSG( _T("unknown wxBitmapTransparency value") );
+
+        case wxBitmapTransparency_None:
+            // nothing to do, refData->m_hasAlpha is false by default
+            break;
+
+        case wxBitmapTransparency_Auto:
 #if wxUSE_WXDIB
-    // If the icon is 32 bits per pixel then it may have alpha channel data,
-    // although there are some icons that are 32 bpp but have no alpha... So
-    // convert to a DIB and manually check the 4th byte for each pixel.
-    BITMAP bm;
-    if ( ::GetObject(iconInfo.hbmColor, sizeof(BITMAP), (LPVOID)&bm)
-         && bm.bmBitsPixel == 32)
-    {
-        wxDIB dib(iconInfo.hbmColor);
-        if (dib.IsOk())
-        {
-            unsigned char* pixels = dib.GetData();
-            for (int idx=0; idx<w*h*4; idx+=4)
+            // If the icon is 32 bits per pixel then it may have alpha channel
+            // data, although there are some icons that are 32 bpp but have no
+            // alpha... So convert to a DIB and manually check the 4th byte for
+            // each pixel.
             {
-                if (pixels[idx+3] != 0)
+                BITMAP bm;
+                if ( ::GetObject(iconInfo.hbmColor, sizeof(bm), &bm) &&
+                        (bm.bmBitsPixel == 32) )
                 {
-                    // If there is an alpha byte that is non-zero then set the
-                    // alpha flag and bail out of the loop.
-                    refData->m_hasAlpha = true;
-                    break;
+                    wxDIB dib(iconInfo.hbmColor);
+                    if (dib.IsOk())
+                    {
+                        const unsigned char* pixels = dib.GetData();
+                        for (int idx = 0; idx < w*h*4; idx+=4)
+                        {
+                            if (pixels[idx+3] != 0)
+                            {
+                                // If there is an alpha byte that is non-zero
+                                // then set the alpha flag and stop checking
+                                refData->m_hasAlpha = true;
+                                break;
+                            }
+                        }
+                    }
                 }
             }
-        }
+            break;
+#endif // wxUSE_WXDIB
+
+        case wxBitmapTransparency_Always:
+            refData->m_hasAlpha = true;
+            break;
     }
-#endif
+
     if ( !refData->m_hasAlpha )
     {
         // the mask returned by GetIconInfo() is inverted compared to the usual
@@ -353,32 +372,32 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
     ::DeleteObject(iconInfo.hbmMask);
 
     return true;
-#else
+#else // __WXMICROWIN__ || __WXWINCE__
     wxUnusedVar(icon);
+    wxUnusedVar(transp);
+
     return false;
-#endif
+#endif // !__WXWINCE__/__WXWINCE__
 }
 
-#endif // Win32
-
-bool wxBitmap::CopyFromCursor(const wxCursor& cursor)
+bool wxBitmap::CopyFromCursor(const wxCursor& cursor, wxBitmapTransparency transp)
 {
     UnRef();
 
     if ( !cursor.Ok() )
         return false;
 
-    return CopyFromIconOrCursor(cursor);
+    return CopyFromIconOrCursor(cursor, transp);
 }
 
-bool wxBitmap::CopyFromIcon(const wxIcon& icon)
+bool wxBitmap::CopyFromIcon(const wxIcon& icon, wxBitmapTransparency transp)
 {
     UnRef();
 
     if ( !icon.Ok() )
         return false;
 
-    return CopyFromIconOrCursor(icon);
+    return CopyFromIconOrCursor(icon, transp);
 }
 
 #ifndef NEVER_USE_DIB
@@ -1070,8 +1089,14 @@ bool wxBitmap::SaveFile(const wxString& filename,
 // ----------------------------------------------------------------------------
 // sub bitmap extraction
 // ----------------------------------------------------------------------------
+wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect ) const
+{
+        MemoryHDC dcSrc;
+        SelectInHDC selectSrc(dcSrc, GetHbitmap());
+        return GetSubBitmapOfHDC( rect, (WXHDC)dcSrc );
+}
 
-wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
+wxBitmap wxBitmap::GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const
 {
     wxCHECK_MSG( Ok() &&
                  (rect.x >= 0) && (rect.y >= 0) &&
@@ -1092,16 +1117,15 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
               dcDst;
 
     {
-        SelectInHDC selectSrc(dcSrc, GetHbitmap()),
-                    selectDst(dcDst, GetHbitmapOf(ret));
-
-        if ( !selectSrc || !selectDst )
+        SelectInHDC selectDst(dcDst, GetHbitmapOf(ret));
+               
+        if ( !selectDst )
         {
-            wxLogLastError(_T("SelectObjct(hBitmap)"));
+            wxLogLastError(_T("SelectObject(destBitmap)"));
         }
 
         if ( !::BitBlt(dcDst, 0, 0, rect.width, rect.height,
-                       dcSrc, rect.x, rect.y, SRCCOPY) )
+                       (HDC)hdc, rect.x, rect.y, SRCCOPY) )
         {
             wxLogLastError(_T("BitBlt"));
         }