]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dc.cpp
Don't do the wx cleanup if wxPython didn't do the initialization.
[wxWidgets.git] / src / os2 / dc.cpp
index c0f1fefcd4c7e747bd837345e85cb19c04b8c93b..cb5f93929421b86d5edd382c5d4cda0d329dd900 100644 (file)
@@ -23,6 +23,7 @@
     #include "wx/log.h"
     #include "wx/icon.h"
     #include "wx/msgdlg.h"
+    #include "wx/module.h"
 #endif
 
 #include "wx/dcprint.h"
@@ -204,7 +205,7 @@ wxDCCacheEntry* wxDC::FindBitmapInCache(
 , int                               nHeight
 )
 {
-    int                             nDepth = 24 // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
+    int                             nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
     wxNode*                         pNode = m_svBitmapCache.First();
     BITMAPINFOHEADER2               vBmpHdr;
 
@@ -541,10 +542,22 @@ int wxDC::GetDepth() const
 
 void wxDC::Clear()
 {
+    //
+    // If this is a canvas DC then just fill with the background color
+    // Otherwise purge the whole thing
+    //
+    if (m_pCanvas)
+    {
+        RECTL                       vRect;
+
+        ::GpiQueryClipBox(m_hPS, &vRect);
+        ::WinFillRect(m_hPS, &vRect, ::GpiQueryBackColor(m_hPS));
+    }
+    else
     ::GpiErase(m_hPS);
 } // end of wxDC::Clear
 
-void wxDC::DoFloodFill(
+bool wxDC::DoFloodFill(
   wxCoord                           vX
 , wxCoord                           vY
 , const wxColour&                   rCol
@@ -564,6 +577,8 @@ void wxDC::DoFloodFill(
         lOptions = FF_SURFACE;
 
     ::GpiFloodFill(m_hPS, lOptions, lColor);
+    
+    return TRUE;
 } // end of wxDC::DoFloodFill
 
 bool wxDC::DoGetPixel(
@@ -1185,16 +1200,48 @@ void wxDC::DoDrawBitmap(
 , bool                              bUseMask
 )
 {
-    POINTL                          vPoint = {vX, vY};
+    if (!bUseMask && !IsKindOf(CLASSINFO(wxPrinterDC)))
+    {
+        HBITMAP                         hBitmap =  (HBITMAP)rBmp.GetHBITMAP();
+        wxBitmap                        vNewBitmap( rBmp.GetWidth()
+                                                   ,rBmp.GetHeight()
+                                                   ,rBmp.GetDepth()
+                                                  );
+        HBITMAP                         hBitmapOld = ::GpiSetBitmap((HPS)GetHPS(), vNewBitmap.GetHBITMAP());
+        LONG                            lOldTextground = ::GpiQueryColor((HPS)GetHPS());
+        LONG                            lOldBackground = ::GpiQueryBackColor((HPS)GetHPS());
+
+        if (m_textForegroundColour.Ok())
+        {
+            ::GpiSetColor( (HPS)GetHPS()
+                           ,m_textForegroundColour.GetPixel()
+                          );
+        }
+        if (m_textBackgroundColour.Ok())
+        {
+            ::GpiSetBackColor( (HPS)GetHPS()
+                              ,m_textBackgroundColour.GetPixel()
+                             );
+        }
 
-    ::WinDrawBitmap( GetHPS()
-                    ,(HBITMAP)GetHbitmapOf(rBmp)
-                    ,NULL
-                    ,&vPoint
-                    ,0L
-                    ,0L
-                    ,DBM_NORMAL
-                   );
+        vY = OS2Y(vY,rBmp.GetHeight());
+
+        POINTL                      vPoint[4] = { vX, vY + rBmp.GetHeight()
+                                                 ,vX + rBmp.GetWidth(), vY
+                                                 ,0, 0
+                                                 ,rBmp.GetWidth(), rBmp.GetHeight()
+                                                };
+        ::GpiWCBitBlt( (HPS)GetHPS()
+                      ,hBitmap
+                      ,4
+                      ,vPoint
+                      ,ROP_SRCCOPY
+                      ,BBO_IGNORE
+                     );
+        ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld);
+        ::GpiSetColor((HPS)GetHPS(), lOldTextground);
+        ::GpiSetBackColor((HPS)GetHPS(), lOldBackground);
+    }
 } // end of wxDC::DoDrawBitmap
 
 void wxDC::DoDrawText(
@@ -1353,6 +1400,52 @@ void wxDC::DoDrawRotatedText(
 // set GDI objects
 // ---------------------------------------------------------------------------
 
+void wxDC::DoSelectPalette(
+  bool                              bRealize
+)
+{
+    //
+    // Set the old object temporarily, in case the assignment deletes an object
+    // that's not yet selected out.
+    //
+    if (m_hOldPalette)
+    {
+        m_hOldPalette = 0;
+    }
+
+    if (m_palette.Ok())
+    {
+        HPALETTE                    hOldPal;
+
+        hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
+        if (!m_hOldPalette)
+            m_hOldPalette = (WXHPALETTE)hOldPal;
+    }
+} // end of wxDC::DoSelectPalette
+
+void wxDC::InitializePalette()
+{
+    if (wxDisplayDepth() <= 8 )
+    {
+        //
+        // Look for any window or parent that has a custom palette. If any has
+        // one then we need to use it in drawing operations
+        //
+        wxWindow*                   pWin = m_pCanvas->GetAncestorWithCustomPalette();
+
+        m_hasCustomPalette = pWin && pWin->HasCustomPalette();
+        if (m_hasCustomPalette)
+        {
+            m_palette = pWin->GetPalette();
+
+            //
+            // turn on PM translation for this palette
+            //
+            DoSelectPalette();
+        }
+    }
+} // end of wxDC::InitializePalette
+
 void wxDC::SetPalette(
   const wxPalette&                  rPalette
 )
@@ -1795,8 +1888,8 @@ void wxDC::SetMapMode(
         ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
         ::GpiSetPS(m_hPS, &vSize, ulOptions);
     }
-    m_nWindowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT);
-    m_nWindowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT);
+    m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
+    m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
     // ????
 }; // end of wxDC::SetMapMode
 
@@ -1884,7 +1977,8 @@ wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
 
 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
 {
-    return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
+       // axis orientation is not taken into account for conversion of a distance
+    return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
 }
 
 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
@@ -1894,7 +1988,8 @@ wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
 
 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
 {
-    return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
+       // axis orientation is not taken into account for conversion of a distance
+    return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
 }
 
 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
@@ -1904,7 +1999,8 @@ wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
 
 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
 {
-    return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
+       // axis orientation is not taken into account for conversion of a distance
+    return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
 }
 
 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
@@ -1914,7 +2010,8 @@ wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
 
 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
 {
-    return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
+       // axis orientation is not taken into account for conversion of a distance
+    return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
 }
 
 // ---------------------------------------------------------------------------