]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix for wxMemoryDC::GetAsBitmap() not working on Windows.
authorKevin Ollivier <kevino@theolliviers.com>
Mon, 20 Aug 2007 23:26:35 +0000 (23:26 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Mon, 20 Aug 2007 23:26:35 +0000 (23:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48235 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/bitmap.h
include/wx/msw/dcmemory.h
src/msw/bitmap.cpp

index e0740f8832066a872a8071267f5fc010d7216b2b..8c239785afd8444e11ad0a35b334fbe8fbf37c09 100644 (file)
@@ -118,6 +118,10 @@ public:
     // get the given part of bitmap
     wxBitmap GetSubBitmap( const wxRect& rect ) const;
 
+    // NB: This should not be called from user code. It is for wx internal
+    // use only. 
+    wxBitmap GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const;
+
     // copies the contents and mask of the given (colour) icon to the bitmap
     bool CopyFromIcon(const wxIcon& icon,
                       wxBitmapTransparency transp = wxBitmapTransparency_Auto);
index 20f2005856939a734573a929f9079141eac79625..fd2c032c7d98b139dafa146988056f6c696a7c13 100644 (file)
@@ -28,6 +28,9 @@ protected:
     virtual void DoGetSize(int* width, int* height) const;
     virtual void DoSelect(const wxBitmap& bitmap);
 
+    virtual wxBitmap DoGetAsBitmap(const wxRect* subrect) const 
+    { return subrect == NULL ? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmapOfHDC(*subrect, GetHDC() );}
+
     // create DC compatible with the given one or screen if dc == NULL
     bool CreateCompatible(wxDC *dc);
 
index 875fe9ff6aa287c040551cd2ff1043c1b741a080..f3221c6e73caaa8275e464ff1a1c7febb477b6d0 100644 (file)
@@ -1089,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) &&
@@ -1111,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"));
         }