]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dc.cpp
extracted duplicated code from src/*/data.cpp in a common file
[wxWidgets.git] / src / msw / dc.cpp
index 64e2dda0db9d0318d34d99ec4a23aa401558a74c..191d5c33961cb691993506c889eea22f2f30c13e 100644 (file)
@@ -1828,13 +1828,14 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
     if (!GetHDC()) return FALSE;
 #endif
 
+    const wxBitmap& bmpSrc = source->m_selectedBitmap;
+
     wxMask *mask = NULL;
     if ( useMask )
     {
-        const wxBitmap& bmp = source->m_selectedBitmap;
-        mask = bmp.GetMask();
+        mask = bmpSrc.GetMask();
 
-        if ( !(bmp.Ok() && mask && mask->GetMaskBitmap()) )
+        if ( !(bmpSrc.Ok() && mask && mask->GetMaskBitmap()) )
         {
             // don't give assert here because this would break existing
             // programs - just silently ignore useMask parameter
@@ -1998,36 +1999,79 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
     }
     else // no mask, just BitBlt() it
     {
-        // use StretchBlt() if available
-        if ( ::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHBLT )
+        // if we already have a DIB, draw it using StretchDIBits(), otherwise
+        // use StretchBlt() if available and finally fall back to BitBlt()
+        const int caps = ::GetDeviceCaps(GetHdc(), RASTERCAPS);
+        if ( bmpSrc.Ok() && (caps & RC_STRETCHDIB) )
         {
-            StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+            DIBSECTION ds;
+            wxZeroMemory(ds);
 
-            success = ::StretchBlt
-                        (
-                            GetHdc(),
-                            xdest, ydest, width, height,
-                            GetHdcOf(*source),
-                            xsrc, ysrc, width, height,
-                            dwRop
-                        ) != 0;
+            if ( ::GetObject(GetHbitmapOf(bmpSrc),
+                             sizeof(ds),
+                             &ds) == sizeof(ds) )
+            {
+                StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+
+                if ( ::StretchDIBits(GetHdc(),
+                                     xdest, ydest,
+                                     width, height,
+                                     0, 0,
+                                     width, height,
+                                     ds.dsBm.bmBits,
+                                     (LPBITMAPINFO)&ds.dsBmih,
+                                     DIB_RGB_COLORS,
+                                     SRCCOPY
+                                     ) == (int)GDI_ERROR )
+                {
+                    wxLogLastError(wxT("StretchDIBits"));
+                }
+                else
+                {
+                    success = TRUE;
+                }
+            }
         }
-        else
+
+        if ( !success && (caps & RC_STRETCHBLT) )
         {
-            success = ::BitBlt
-                        (
-                            GetHdc(),
-                            xdest, ydest,
-                            (int)width, (int)height,
-                            GetHdcOf(*source),
-                            xsrc, ysrc,
-                            dwRop
-                        ) != 0;
+            StretchBltModeChanger changeMode(GetHdc(), COLORONCOLOR);
+
+            if ( !::StretchBlt
+                    (
+                        GetHdc(),
+                        xdest, ydest, width, height,
+                        GetHdcOf(*source),
+                        xsrc, ysrc, width, height,
+                        dwRop
+                    ) )
+            {
+                wxLogLastError(_T("StretchBlt"));
+            }
+            else
+            {
+                success = TRUE;
+            }
         }
 
         if ( !success )
         {
-            wxLogLastError(wxT("BitBlt/StretchBlt"));
+            if ( !::BitBlt
+                    (
+                        GetHdc(),
+                        xdest, ydest,
+                        (int)width, (int)height,
+                        GetHdcOf(*source),
+                        xsrc, ysrc,
+                        dwRop
+                    ) )
+            {
+                wxLogLastError(_T("BitBlt"));
+            }
+            else
+            {
+                success = TRUE;
+            }
         }
     }
 
@@ -2142,10 +2186,10 @@ wxDCCacheEntry::~wxDCCacheEntry()
 wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h)
 {
     int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
-    wxNode* node = sm_bitmapCache.First();
+    wxNode* node = sm_bitmapCache.GetFirst();
     while (node)
     {
-        wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data();
+        wxDCCacheEntry* entry = (wxDCCacheEntry*) node->GetData();
 
         if (entry->m_depth == depth)
         {
@@ -2163,7 +2207,7 @@ wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h)
             return entry;
         }
 
-        node = node->Next();
+        node = node->GetNext();
     }
     WXHBITMAP hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap((HDC) dc, w, h);
     if ( !hBitmap)
@@ -2178,10 +2222,10 @@ wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h)
 wxDCCacheEntry* wxDC::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc)
 {
     int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
-    wxNode* node = sm_dcCache.First();
+    wxNode* node = sm_dcCache.GetFirst();
     while (node)
     {
-        wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data();
+        wxDCCacheEntry* entry = (wxDCCacheEntry*) node->GetData();
 
         // Don't return the same one as we already have
         if (!notThis || (notThis != entry))
@@ -2192,7 +2236,7 @@ wxDCCacheEntry* wxDC::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc)
             }
         }
 
-        node = node->Next();
+        node = node->GetNext();
     }
     WXHDC hDC = (WXHDC) ::CreateCompatibleDC((HDC) dc);
     if ( !hDC)