]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dc.cpp
OS/2 VisualAge doesn't know about lower case true and false and redefine a for loop...
[wxWidgets.git] / src / os2 / dc.cpp
index 47ef5b4fc2b96c8690eb65f503e7d09b65e9d983..3f0fae3eb12d494423d4b60543b7ccc33e274750 100644 (file)
@@ -204,34 +204,73 @@ void wxDC::SelectOldObjects(WXHDC dc)
 // clipping
 // ---------------------------------------------------------------------------
 
-#define DO_SET_CLIPPING_BOX()                   \
-{                                               \
-    RECT rect;                                  \
-                                                \
-    GetClipBox(GetHdc(), &rect);                \
-                                                \
-    m_clipX1 = (wxCoord) XDEV2LOG(rect.left);   \
-    m_clipY1 = (wxCoord) YDEV2LOG(rect.top);    \
-    m_clipX2 = (wxCoord) XDEV2LOG(rect.right);  \
-    m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
-}
-
-void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y
-                               ,wxCoord width, wxCoord height
-                              )
+#define DO_SET_CLIPPING_BOX()                    \
+{                                                \
+    RECTL rect;                                  \
+                                                 \
+    ::GpiQueryClipBox(m_hPS, &rect);             \
+                                                 \
+    m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft);   \
+    m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop);    \
+    m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight);  \
+    m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
+}
+
+void wxDC::DoSetClippingRegion(
+  wxCoord                           x
+, wxCoord                           y
+, wxCoord                           width
+, wxCoord                           height
+)
 {
-   // TODO
-}
+    RECTL                           vRect;
 
-void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
+    m_clipping    = TRUE;
+    vRect.xLeft   = XLOG2DEV(x);
+    vRect.yTop    = YLOG2DEV(y + height);
+    vRect.xRight  = XLOG2DEV(x + width);
+    vRect.yBottom = YLOG2DEV(y);
+    ::GpiIntersectClipRectangle(m_hPS, &vRect);
+    DO_SET_CLIPPING_BOX()
+} // end of wxDC::DoSetClippingRegion
+
+void wxDC::DoSetClippingRegionAsRegion(
+  const wxRegion&                   rRegion
+)
 {
-   // TODO
-}
+     wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
+     HRGN                           hRgnOld;
+
+     m_clipping = TRUE;
+     ::GpiSetClipRegion( m_hPS
+                        ,(HRGN)rRegion.GetHRGN()
+                        ,&hRgnOld
+                       );
+    DO_SET_CLIPPING_BOX()
+} // end of wxDC::DoSetClippingRegionAsRegion
 
 void wxDC::DestroyClippingRegion(void)
 {
-    // TODO:
-};
+    if (m_clipping && m_hPS)
+    {
+         HRGN                       hRgnOld;
+         RECTL                      vRect;
+
+         // TODO: this should restore the previous clipped region
+         //       so that OnPaint processing works correctly, and
+         //       the update doesn't get destroyed after the first
+         //       DestroyClippingRegion
+         vRect.xLeft   = XLOG2DEV(0);
+         vRect.yTop    = YLOG2DEV(32000);
+         vRect.xRight  = XLOG2DEV(32000);
+         vRect.yBottom = YLOG2DEV(0);
+
+         HRGN                       hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
+
+         ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
+     }
+      m_clipping = FALSE;
+} // end of wxDC::DestroyClippingRegion
 
 // ---------------------------------------------------------------------------
 // query capabilities
@@ -300,7 +339,7 @@ bool wxDC::DoGetPixel(
     vPoint.x = vX;
     vPoint.y = vY;
     lColor = ::GpiSetPel(m_hPS, &vPoint);
-    *pCol = lColor;
+    pCol->Set((unsigned long)lColor);
     if(lColor>= 0)
         return(TRUE);
     else
@@ -325,7 +364,6 @@ void wxDC::DoDrawLine(
     vPoint[0].y = vY1;
     vPoint[1].x = vX2;
     vPoint[1].y = vY2;
-    // ::GpiSetColor(m_hPS,CLR_RED); //DEbug
     ::GpiMove(m_hPS, &vPoint[0]);
     ::GpiLine(m_hPS, &vPoint[1]);
 }
@@ -592,7 +630,7 @@ void wxDC::DoDrawRectangle(
     vPoint[0].x = vX;
     vPoint[0].y = vY;
     vPoint[1].x = vX + vWidth;
-    vPoint[1].y = vY - vHeight;      //mustdie !!! ??
+    vPoint[1].y = vY - vHeight;
     ::GpiMove(m_hPS, &vPoint[0]);
     lColor       = m_brush.GetColour().GetPixel();
     lBorderColor = m_pen.GetColour().GetPixel();
@@ -604,8 +642,7 @@ void wxDC::DoDrawRectangle(
         if(m_brush.GetStyle() == wxTRANSPARENT)
             lControl = DRO_OUTLINE;
 
-//EK    ::GpiSetColor(m_hPS,lBorderColor);
-        ::GpiSetColor(m_hPS,CLR_GREEN);
+        ::GpiSetColor(m_hPS, CLR_GREEN);
         ::GpiBox( m_hPS       // handle to a presentation space
                  ,lControl   // draw the box outline ? or ?
                  ,&vPoint[1]  // address of the corner
@@ -962,66 +999,29 @@ void wxDC::SetPen(
     if (!m_pen.Ok())
         return;
 
-    int                             nWidth = m_pen.GetWidth();
+    if (m_hOldPen)
+        m_hOldPen = 0L;
+    m_pen = rPen;
 
-    if (nWidth <= 0)
-    {
-        nWidth = 1;
-    }
-    else
+    if (!m_pen.Ok())
     {
-        double                      dW = 0.5 +
-                                       ( fabs((double) XLOG2DEVREL(nWidth)) +
-                                         fabs((double) YLOG2DEVREL(nWidth))
-                                       ) / 2.0;
-        nWidth = (int)dW;
+        if (m_hOldPen)
+        {
+            m_pen.SetPS((HPS)m_hOldPen);
+        }
+        m_hOldPen = 0L;
     }
-    wxColour                        vColor = m_pen.GetColour();
-
-    ::GpiSetColor( m_hPS
-                  ,vColor.GetPixel()
-                 ); //DEbug ??
 
-    int                             nLinetype;
-    int                             nStyle = m_pen.GetStyle();
-
-    nLinetype = LINETYPE_DEFAULT;
-    switch(nStyle)
+    if (m_pen.Ok())
     {
-        case wxDOT:
-            nLinetype = LINETYPE_DOT;
-            break;
-
-        case wxLONG_DASH:
-            nLinetype = LINETYPE_LONGDASH;
-            break;
-
-        case wxSHORT_DASH:
-            nLinetype = LINETYPE_SHORTDASH;
-            break;
-
-        case wxDOT_DASH:
-            nLinetype = LINETYPE_DASHDOT;
-            break;
-
-        case wxTRANSPARENT:
-            nLinetype = LINETYPE_INVISIBLE;
-            break;
-
-        case wxSOLID:
-            nLinetype = LINETYPE_SOLID;
-            break;
+        if (m_pen.GetResourceHandle())
+        {
+            m_pen.SetPS(m_hPS);
+            if (!m_hOldPen)
+                m_hOldPen = m_pen.GetPS();
+        }
     }
-    ::GpiSetLineType( m_hPS
-                     ,nLinetype
-                    );
 
-    nWidth =  m_pen.GetWidth();
-    ::GpiSetLineWidth( m_hPS
-                      ,MAKEFIXED( nWidth
-                                 ,0
-                                )
-                     );
 }
 
 void wxDC::SetBrush(
@@ -1215,7 +1215,18 @@ void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
 
 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
 {
-    // TODO:
+    RECTL                           vRect;
+
+    ::GpiQueryPageViewport( m_hPS
+                           ,&vRect
+                          );
+    vRect.xLeft += x;
+    vRect.xRight += x;
+    vRect.yBottom -= y;
+    vRect.yTop -= y;
+    ::GpiSetPageViewport( m_hPS
+                         ,&vRect
+                        );
 };
 
 // ---------------------------------------------------------------------------