]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dcclient.cpp
Fix splitting message into title in body in MSW wxProgressDialog.
[wxWidgets.git] / src / os2 / dcclient.cpp
index 925d9609ee1771b240d3b41f8196b63cdcf3dfc1..ce890dab9e8badf7d9378332a28deb03b4ce91ea 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
-// Name:        dcclient.cpp
+// Name:        src/os2/dcclient.cpp
 // Purpose:     wxClientDC class
-// Author:      AUTHOR
+// Author:      David Webster
 // Modified by:
-// Created:     01/02/97
+// Created:     09/21/99
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
-// Licence:    wxWindows licence
+// Copyright:   (c) David Webster
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "dcclient.h"
-#endif
-
-#include "wx/dcclient.h"
-#include "wx/dcmemory.h"
-#include "wx/region.h"
-#include <math.h>
+// ===========================================================================
+// declarations
+// ===========================================================================
 
-//-----------------------------------------------------------------------------
-// constants
-//-----------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
 
-#define RAD2DEG 57.2957795131
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
 
-//-----------------------------------------------------------------------------
-// wxPaintDC
-//-----------------------------------------------------------------------------
+#include "wx/dcclient.h"
+#include "wx/os2/dcclient.h"
 
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
-IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
-IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
+#ifndef WX_PRECOMP
+    #include "wx/string.h"
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/window.h"
 #endif
 
-/*
- * wxWindowDC
- */
+#include "wx/os2/private.h"
 
-wxWindowDC::wxWindowDC(void)
-{
-};
+// ----------------------------------------------------------------------------
+// array/list types
+// ----------------------------------------------------------------------------
 
-wxWindowDC::wxWindowDC( wxWindow *window )
+struct WXDLLEXPORT wxPaintDCInfo
 {
-};
+    wxPaintDCInfo( wxWindow* pWin
+                  ,wxPaintDCImpl*     pDC
+                 )
+    {
+        m_hWnd = pWin->GetHWND();
+        m_hDC = pDC->GetHDC();
+        m_nCount = 1;
+    }
 
-wxWindowDC::~wxWindowDC(void)
-{
-};
+    WXHWND                          m_hWnd;   // window for this DC
+    WXHDC                           m_hDC;    // the DC handle
+    size_t                          m_nCount; // usage count
+}; // end of wxPaintDCInfot
 
-void wxWindowDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1), 
-  const wxColour& WXUNUSED(col), int WXUNUSED(style) )
-{
-};
+#include "wx/arrimpl.cpp"
 
-bool wxWindowDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
-{
-  return FALSE;
-};
+WX_DEFINE_OBJARRAY(wxArrayDCInfo);
 
-void wxWindowDC::DrawLine( long x1, long y1, long x2, long y2 )
-{
-  if (!Ok()) return;
-  
-};
+// ----------------------------------------------------------------------------
+// global variables
+// ----------------------------------------------------------------------------
 
-void wxWindowDC::CrossHair( long x, long y )
-{
-  if (!Ok()) return;
-  
-};
+static RECT        g_paintStruct;
 
-void wxWindowDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc )
-{
-  if (!Ok()) return;
-  
-  long xx1 = XLOG2DEV(x1); 
-  long yy1 = YLOG2DEV(y1);
-  long xx2 = XLOG2DEV(x2); 
-  long yy2 = YLOG2DEV(y2);
-  long xxc = XLOG2DEV((long)xc); 
-  long yyc = YLOG2DEV((long)yc);
-  double dx = xx1 - xxc; 
-  double dy = yy1 - yyc;
-  double radius = sqrt(dx*dx+dy*dy);
-  long   r      = (long)radius;
-  double radius1, radius2;
-
-  if (xx1 == xx2 && yy1 == yy2) 
-  {
-    radius1 = 0.0;
-    radius2 = 360.0;
-  } 
-  else 
-  if (radius == 0.0) 
-  {
-    radius1 = radius2 = 0.0;
-  } 
-  else 
-  {
-    radius1 = (xx1 - xxc == 0) ?
-           (yy1 - yyc < 0) ? 90.0 : -90.0 :
-           -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
-    radius2 = (xx2 - xxc == 0) ?
-           (yy2 - yyc < 0) ? 90.0 : -90.0 :
-           -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
-  };
-  long alpha1 = long(radius1 * 64.0);
-  long alpha2 = long((radius2 - radius1) * 64.0);
-  while (alpha2 <= 0) alpha2 += 360*64;
-  while (alpha1 > 360*64) alpha1 -= 360*64;
-
-  if (m_brush.GetStyle() != wxTRANSPARENT) {};
-    
-  if (m_pen.GetStyle() != wxTRANSPARENT) {};
-  
-};
-
-void wxWindowDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea )
-{
-  if (!Ok()) return;
-  
-  long xx = XLOG2DEV(x);    
-  long yy = YLOG2DEV(y);
-  long ww = m_signX * XLOG2DEVREL(width); 
-  long hh = m_signY * YLOG2DEVREL(height);
-  
-  // CMB: handle -ve width and/or height
-  if (ww < 0) { ww = -ww; xx = xx - ww; }
-  if (hh < 0) { hh = -hh; yy = yy - hh; }
-  
-  long start = long(sa * 64.0);
-  long end = long(ea * 64.0);
-  if (m_brush.GetStyle() != wxTRANSPARENT) {};
-  
-  if (m_pen.GetStyle() != wxTRANSPARENT) {};
-};
-
-void wxWindowDC::DrawPoint( long x, long y )
-{
-  if (!Ok()) return;
-  
-  if (m_pen.GetStyle() != wxTRANSPARENT) {};
-};
+#ifdef wxHAS_PAINT_DEBUG
+    // a global variable which we check to verify that wxPaintDC are only
+    // created in resopnse to WM_PAINT message - doing this from elsewhere is a
+    // common programming error among wxWidgets programmers and might lead to
+    // very subtle and difficult to debug refresh/repaint bugs.
+    int g_isPainting = 0;
+#endif // wxHAS_PAINT_DEBUG
 
-void wxWindowDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset )
-{
-  if (!Ok()) return;
-  
-  if (m_pen.GetStyle() == wxTRANSPARENT) return;
-  
-  for (int i = 0; i < n-1; i++)
-  {
-    long x1 = XLOG2DEV(points[i].x + xoffset);
-    long x2 = XLOG2DEV(points[i+1].x + xoffset);
-    long y1 = YLOG2DEV(points[i].y + yoffset);     // oh, what a waste
-    long y2 = YLOG2DEV(points[i+1].y + yoffset);
-  };
-};
-
-void wxWindowDC::DrawLines( wxList *points, long xoffset, long yoffset )
-{
-  if (!Ok()) return;
-  
-  if (m_pen.GetStyle() == wxTRANSPARENT) return;
-  
-  wxNode *node = points->First();
-  while (node->Next())
-  {
-    wxPoint *point = (wxPoint*)node->Data();
-    wxPoint *npoint = (wxPoint*)node->Next()->Data();
-    long x1 = XLOG2DEV(point->x + xoffset);
-    long x2 = XLOG2DEV(npoint->x + xoffset);
-    long y1 = YLOG2DEV(point->y + yoffset);    // and again...
-    long y2 = YLOG2DEV(npoint->y + yoffset);
-    node = node->Next();
-  };
-};
-
-void wxWindowDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[], 
-  long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
-{
-  if (!Ok()) return;
-};
+// ===========================================================================
+// implementation
+// ===========================================================================
 
-void wxWindowDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset), 
-                             long WXUNUSED(yoffset), int WXUNUSED(fillStyle) )
-{
-  if (!Ok()) return;
-};
+// ----------------------------------------------------------------------------
+// wxWindowDCImpl
+// ----------------------------------------------------------------------------
 
-void wxWindowDC::DrawRectangle( long x, long y, long width, long height )
-{
-  if (!Ok()) return;
-
-  long xx = XLOG2DEV(x);
-  long yy = YLOG2DEV(y);
-  long ww = m_signX * XLOG2DEVREL(width);
-  long hh = m_signY * YLOG2DEVREL(height);
-    
-  // CMB: draw nothing if transformed w or h is 0
-  if (ww == 0 || hh == 0) return;
-
-  // CMB: handle -ve width and/or height
-  if (ww < 0) { ww = -ww; xx = xx - ww; }
-  if (hh < 0) { hh = -hh; yy = yy - hh; }
-
-  if (m_brush.GetStyle() != wxTRANSPARENT) {};
-    
-  if (m_pen.GetStyle() != wxTRANSPARENT) {};
-};
-
-void wxWindowDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius )
-{
-  if (!Ok()) return;
-  
-  if (radius < 0.0) radius = - radius * ((width < height) ? width : height);
-  
-  long xx = XLOG2DEV(x);    
-  long yy = YLOG2DEV(y);
-  long ww = m_signX * XLOG2DEVREL(width); 
-  long hh = m_signY * YLOG2DEVREL(height);
-  long rr = XLOG2DEVREL((long)radius);
-
-  // CMB: handle -ve width and/or height
-  if (ww < 0) { ww = -ww; xx = xx - ww; }
-  if (hh < 0) { hh = -hh; yy = yy - hh; }
-
-  // CMB: if radius is zero use DrawRectangle() instead to avoid
-  // X drawing errors with small radii
-  if (rr == 0)
-  {
-    DrawRectangle( x, y, width, height );
-    return;
-  }
-
-  // CMB: draw nothing if transformed w or h is 0
-  if (ww == 0 || hh == 0) return;
-
-  // CMB: adjust size if outline is drawn otherwise the result is
-  // 1 pixel too wide and high
-  if (m_pen.GetStyle() != wxTRANSPARENT)
-  {
-    ww--;
-    hh--;
-  }
-
-  // CMB: ensure dd is not larger than rectangle otherwise we
-  // get an hour glass shape
-  long dd = 2 * rr;
-  if (dd > ww) dd = ww;
-  if (dd > hh) dd = hh;
-  rr = dd / 2;
-
-  if (m_brush.GetStyle() != wxTRANSPARENT)
-  {
-  };
-  
-  if (m_pen.GetStyle() != wxTRANSPARENT)
-  {
-  };
-};
-
-void wxWindowDC::DrawEllipse( long x, long y, long width, long height )
-{
-  if (!Ok()) return;
-  
-  long xx = XLOG2DEV(x);    
-  long yy = YLOG2DEV(y);
-  long ww = m_signX * XLOG2DEVREL(width); 
-  long hh = m_signY * YLOG2DEVREL(height);
-
-  // CMB: handle -ve width and/or height
-  if (ww < 0) { ww = -ww; xx = xx - ww; }
-  if (hh < 0) { hh = -hh; yy = yy - hh; }
-  
-  if (m_brush.GetStyle() != wxTRANSPARENT) {};
-  
-  if (m_pen.GetStyle() != wxTRANSPARENT) {};
-};
-
-bool wxWindowDC::CanDrawBitmap(void) const
-{
-  return TRUE;
-};
+IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxPMDCImpl)
 
-void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
-{
-  if (!Ok()) return;
-  
-  if (!icon.Ok()) return;
-  
-  int xx = XLOG2DEV(x);
-  int yy = YLOG2DEV(y);
-  
-};
-
-bool wxWindowDC::Blit( long xdest, long ydest, long width, long height,
-       wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) )
+wxWindowDCImpl::wxWindowDCImpl( wxDC *owner ) :
+   wxPMDCImpl( owner )
 {
-  if (!Ok()) return FALSE;
-  
-  // CMB 20/5/98: add blitting of bitmaps
-  if (source->IsKindOf(CLASSINFO(wxMemoryDC)))
-  {
-    wxMemoryDC* srcDC = (wxMemoryDC*)source;
-    /*
-     GdkBitmap* bmap = srcDC->m_selected.GetBitmap();
-    if (bmap)
+    m_PageSize.cx = m_PageSize.cy = 0;
+}
+
+wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow* pTheCanvas) :
+   wxPMDCImpl( owner )
+{
+    ERRORID                         vError;
+    wxString                        sError;
+    int                             nWidth, nHeight;
+
+    m_pCanvas = pTheCanvas;
+    DoGetSize(&nWidth, &nHeight);
+    m_PageSize.cx = nWidth;
+    m_PageSize.cy = nHeight;
+    m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(pTheCanvas) );
+
+    //
+    // default under PM is that Window and Client DC's are the same
+    // so we offer a separate Presentation Space to use for the
+    // entire window.  Otherwise, calling BeginPaint will just create
+    // chached-micro client presentation space
+    //
+     m_hPS = ::GpiCreatePS( vHabmain
+                           ,m_hDC
+                           ,&m_PageSize
+                           ,PU_PELS | GPIF_LONG | GPIA_ASSOC
+                          );
+    if (!m_hPS)
     {
-      gdk_draw_bitmap (
-          m_window,
-          m_textGC,
-          bmap,
-          source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc),
-          XLOG2DEV(xdest), YLOG2DEV(ydest),
-          source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height)
-          );
-      return TRUE;
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError(wxT("Unable to create presentation space. Error: %s\n"), sError.c_str());
     }
-    */
-  }
-
-  return TRUE;
-};
-
-void wxWindowDC::DrawText( const wxString &text, long x, long y, bool
-WXUNUSED(use16) )
-{
-  if (!Ok()) return;
-
-};
-
-
+    ::GpiAssociate(m_hPS, NULLHANDLE);
+    ::GpiAssociate(m_hPS, m_hDC);
+
+    //
+    // Set the wxWidgets color table
+    //
+    if (!::GpiCreateLogColorTable( m_hPS
+                                  ,0L
+                                  ,LCOLF_CONSECRGB
+                                  ,0L
+                                  ,(LONG)wxTheColourDatabase->m_nSize
+                                  ,(PLONG)wxTheColourDatabase->m_palTable
+                                 ))
+    {
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError(wxT("Unable to set current color table (3). Error: %s\n"), sError.c_str());
+    }
+    ::GpiCreateLogColorTable( m_hPS
+                             ,0L
+                             ,LCOLF_RGB
+                             ,0L
+                             ,0L
+                             ,NULL
+                            );
+    ::WinQueryWindowRect( GetWinHwnd(m_pCanvas)
+                         ,&m_vRclPaint
+                        );
+    InitDC();
+} // end of wxWindowDCImpl::wxWindowDCImpl
+
+void wxWindowDCImpl::InitDC()
+{
+
+    //
+    // The background mode is only used for text background and is set in
+    // DrawText() to OPAQUE as required, otherwise always TRANSPARENT,
+    //
+    ::GpiSetBackMix(GetHPS(), BM_LEAVEALONE);
+
+    //
+    // Default bg colour is pne of the window
+    //
+    SetBackground(wxBrush(m_pCanvas->GetBackgroundColour(), wxSOLID));
+
+    m_pen.SetColour(*wxBLACK);
+    m_brush.SetColour(*wxWHITE);
+    // since we are a window dc we need to grab the palette from the window
+#if wxUSE_PALETTE
+    InitializePalette();
+#endif
+    wxFont* pFont = new wxFont( 10, wxMODERN, wxNORMAL, wxBOLD );
+    SetFont(*pFont);
+    delete pFont;
+    //
+    // OS/2 default vertical character alignment needs to match the other OS's
+    //
+    ::GpiSetTextAlignment((HPS)GetHPS(), TA_NORMAL_HORIZ, TA_BOTTOM);
 
-bool wxWindowDC::CanGetTextExtent(void) const
-{
-  return TRUE;
-};
+} // end of wxWindowDCImpl::InitDC
 
-void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height,
-                     long *WXUNUSED(descent), long *WXUNUSED(externalLeading),
-                     wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) )
+void wxWindowDCImpl::DoGetSize(
+  int*                              pnWidth
+, int*                              pnHeight
+) const
 {
-  if (!Ok()) return;
-  
-};
+    wxCHECK_RET( m_pCanvas, wxT("wxWindowDC without a window?") );
+    m_pCanvas->GetSize( pnWidth
+                       ,pnHeight
+                      );
+} // end of wxWindowDCImpl::DoGetSize
 
-long wxWindowDC::GetCharWidth(void)
-{
-  if (!Ok()) return 0;
-  return 0;
-};
+// ----------------------------------------------------------------------------
+// wxClientDC
+// ----------------------------------------------------------------------------
 
-long wxWindowDC::GetCharHeight(void)
-{
-  if (!Ok()) return 0;
-  return 0;
-};
+IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl)
 
-void wxWindowDC::Clear(void)
+wxClientDCImpl::wxClientDCImpl( wxDC *owner ) :
+   wxWindowDCImpl( owner )
 {
-  if (!Ok()) return;
-  
-};
-
-void wxWindowDC::SetFont( const wxFont &font )
-{
-  if (!Ok()) return;
-  
-  m_font = font;
-};
+    m_pCanvas = NULL;
+}
 
-void wxWindowDC::SetPen( const wxPen &pen )
-{
-  if (!Ok()) return;
+wxClientDCImpl::wxClientDCImpl( wxDC *owner, wxWindow *pTheCanvas) :
+   wxWindowDCImpl( owner )
+{
+    SIZEL                           vSizl = { 0,0};
+    ERRORID                         vError;
+    wxString                        sError;
+
+    m_pCanvas = pTheCanvas;
+
+    //
+    // default under PM is that Window and Client DC's are the same
+    //
+
+    m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(pTheCanvas));
+    printf("Got WindowDC %X for window handle %X\n", m_hDC, pTheCanvas);
+
+    m_hPS = ::GpiCreatePS( wxGetInstance()
+                          ,m_hDC
+                          ,&vSizl
+                          ,PU_PELS | GPIF_LONG | GPIA_ASSOC
+                         );
+    ::GpiAssociate(m_hPS, NULLHANDLE);
+    ::GpiAssociate(m_hPS, m_hDC);
+
+    printf("Got m_hPS %X\n", m_hPS);
+    // Set the wxWidgets color table
+    if (!::GpiCreateLogColorTable( m_hPS
+                                  ,0L
+                                  ,LCOLF_CONSECRGB
+                                  ,0L
+                                  ,(LONG)wxTheColourDatabase->m_nSize
+                                  ,(PLONG)wxTheColourDatabase->m_palTable
+                                 ))
+    {
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError(wxT("Unable to set current color table (4). Error: %s\n"), sError.c_str());
+    }
+    ::GpiCreateLogColorTable( m_hPS
+                             ,0L
+                             ,LCOLF_RGB
+                             ,0L
+                             ,0L
+                             ,NULL
+                            );
+    //
+    // Set the DC/PS rectangle
+    //
+    ::WinQueryWindowRect( GetWinHwnd(m_pCanvas)
+                         ,&m_vRclPaint
+                        );
+    InitDC();
+} // end of wxClientDCImpl::wxClientDCImpl
+
+void wxClientDCImpl::InitDC()
+{
+    wxWindowDCImpl::InitDC();
+
+    // in wxUniv build we must manually do some DC adjustments usually
+    // performed by Windows for us
+#ifdef __WXUNIVERSAL__
+    wxPoint ptOrigin = m_pCanvas->GetClientAreaOrigin();
+    if ( ptOrigin.x || ptOrigin.y )
+    {
+        // no need to shift DC origin if shift is null
+        SetDeviceOrigin(ptOrigin.x, ptOrigin.y);
+    }
 
-  if (m_pen == pen) return;
-  
-  m_pen = pen;
-  
-  if (!m_pen.Ok()) return;
-};
+    // clip the DC to avoid overwriting the non client area
+    SetClippingRegion(wxPoint(0, 0), m_pCanvas->GetClientSize());
+#endif // __WXUNIVERSAL__
+} // end of wxClientDCImpl::InitDC
 
-void wxWindowDC::SetBrush( const wxBrush &brush )
+wxClientDCImpl::~wxClientDCImpl()
 {
-  if (!Ok()) return;
-  
-  if (m_brush == brush) return;
-  
-  m_brush = brush;
-  
-  if (!m_brush.Ok()) return;
-  
-};
-
-void wxWindowDC::SetBackground( const wxBrush &brush )
-{
-  if (!Ok()) return;
-  
-  if (m_backgroundBrush == brush) return;
-  
-  m_backgroundBrush = brush;
-  
-  if (!m_backgroundBrush.Ok()) return;
-  
-};
-
-void wxWindowDC::SetLogicalFunction( int function )
-{
-  if (m_logicalFunction == function) return;
-};
+} // end of wxClientDCImpl::~wxClientDCImpl
 
-void wxWindowDC::SetTextForeground( const wxColour &col )
-{
-  if (!Ok()) return;
-  
-  if (m_textForegroundColour == col) return;
-  
-  m_textForegroundColour = col;
-  if (!m_textForegroundColour.Ok()) return;
-};
-
-void wxWindowDC::SetTextBackground( const wxColour &col )
+void wxClientDCImpl::DoGetSize(
+  int*                              pnWidth
+, int*                              pnHeight
+) const
 {
-  if (!Ok()) return;
-  
-  if (m_textBackgroundColour == col) return;
-  
-  m_textBackgroundColour = col;
-  if (!m_textBackgroundColour.Ok()) return;
-};
-
-void wxWindowDC::SetBackgroundMode( int mode )
-{
-  m_backgroundMode = mode;
-
-  if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT)
-  {
-  }
-};
+    wxCHECK_RET( m_pCanvas, wxT("wxWindowDC without a window?") );
+    m_pCanvas->GetClientSize( pnWidth
+                             ,pnHeight
+                            );
+} // end of wxClientDCImpl::DoGetSize
 
-void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) )
-{
-};
+// ----------------------------------------------------------------------------
+// wxPaintDC
+// ----------------------------------------------------------------------------
 
-void wxWindowDC::SetClippingRegion( long x, long y, long width, long height )
-{
-  wxDC::SetClippingRegion( x, y, width, height );
+IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl)
 
-  // TODO
-  
-};
+wxArrayDCInfo wxPaintDCImpl::ms_cache;
 
-void wxWindowDC::SetClippingRegion( const wxRegion& region )
+wxPaintDCImpl::wxPaintDCImpl( wxDC *owner ) :
+   wxClientDCImpl( owner )
 {
-  wxRect box = region.GetBox();
-
-  wxDC::SetClippingRegion( box.x, box.y, box.width, box.height );
-
-  // TODO
+    m_pCanvas = NULL;
+    m_hDC = 0;
 }
 
-void wxWindowDC::DestroyClippingRegion(void)
+wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *pCanvas) :
+   wxClientDCImpl( owner )
 {
-  wxDC::DestroyClippingRegion();
-  
-};
-
-// ----------------------------------- spline code ----------------------------------------
-
-void wx_quadratic_spline(double a1, double b1, double a2, double b2,
-                         double a3, double b3, double a4, double b4);
-void wx_clear_stack(void);
-int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
-        double *y3, double *x4, double *y4);
-void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
-          double x4, double y4);
-static bool wx_spline_add_point(double x, double y);
-static void wx_spline_draw_point_array(wxDC *dc);
-
-wxList wx_spline_point_list;
-
-#define                half(z1, z2)    ((z1+z2)/2.0)
-#define                THRESHOLD       5
+    wxCHECK_RET(pCanvas, wxT("NULL canvas in wxPaintDC ctor"));
 
-/* iterative version */
-
-void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
-                 double b4)
-{
-    register double  xmid, ymid;
-    double           x1, y1, x2, y2, x3, y3, x4, y4;
-
-    wx_clear_stack();
-    wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
-
-    while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
-        xmid = (double)half(x2, x3);
-        ymid = (double)half(y2, y3);
-       if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
-           fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
-            wx_spline_add_point( x1, y1 );
-            wx_spline_add_point( xmid, ymid );
-       } else {
-            wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
-                 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
-            wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
-                 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
-       }
+#ifdef wxHAS_PAINT_DEBUG
+    if (g_isPainting <= 0)
+    {
+        wxFAIL_MSG( wxT("wxPaintDC may be created only in EVT_PAINT handler!") );
+        return;
     }
-}
+#endif // wxHAS_PAINT_DEBUG
 
-/* utilities used by spline drawing routines */
+    m_pCanvas = pCanvas;
 
-typedef struct wx_spline_stack_struct {
-    double           x1, y1, x2, y2, x3, y3, x4, y4;
-} Stack;
+    //
+    // Do we have a DC for this window in the cache?
+    //
+    wxPaintDCInfo*                  pInfo = FindInCache();
 
-#define         SPLINE_STACK_DEPTH             20
-static Stack    wx_spline_stack[SPLINE_STACK_DEPTH];
-static Stack   *wx_stack_top;
-static int      wx_stack_count;
+    if (pInfo)
+    {
+        m_hDC = pInfo->m_hDC;
+        pInfo->m_nCount++;
+    }
+    else // not in cache, create a new one
+    {
+        HPS                         hPS;
+
+        m_hDC = ::WinOpenWindowDC(GetWinHwnd(m_pCanvas));
+        hPS = ::WinBeginPaint( GetWinHwnd(m_pCanvas)
+                              ,NULLHANDLE
+                              ,&g_paintStruct
+                             );
+        if(hPS)
+        {
+            ::GpiAssociate(hPS, m_hDC);
+            m_hOldPS = m_hPS;
+            m_hPS = hPS;
+            ::GpiCreateLogColorTable( m_hPS
+                                     ,0L
+                                     ,LCOLF_CONSECRGB
+                                     ,0L
+                                     ,(LONG)wxTheColourDatabase->m_nSize
+                                     ,(PLONG)wxTheColourDatabase->m_palTable
+                                    );
+            ::GpiCreateLogColorTable( m_hPS
+                                     ,0L
+                                     ,LCOLF_RGB
+                                     ,0L
+                                     ,0L
+                                     ,NULL
+                                    );
+
+            ::WinFillRect(hPS, &g_paintStruct,  m_pCanvas->GetBackgroundColour().GetPixel());
+            ::WinQueryWindowRect( GetWinHwnd(m_pCanvas)
+                                 ,&m_vRclPaint
+                                );
+        }
+
+        m_bIsPaintTime   = true;
+        ms_cache.Add(new wxPaintDCInfo(m_pCanvas, this));
+    }
+    InitDC();
+} // end of wxPaintDCImpl::wxPaintDCImpl
 
-void wx_clear_stack(void)
+wxPaintDCImpl::~wxPaintDCImpl()
 {
-    wx_stack_top = wx_spline_stack;
-    wx_stack_count = 0;
-}
+    if ( m_hDC )
+    {
+        SelectOldObjects(m_hDC);
 
-void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
-{
-    wx_stack_top->x1 = x1;
-    wx_stack_top->y1 = y1;
-    wx_stack_top->x2 = x2;
-    wx_stack_top->y2 = y2;
-    wx_stack_top->x3 = x3;
-    wx_stack_top->y3 = y3;
-    wx_stack_top->x4 = x4;
-    wx_stack_top->y4 = y4;
-    wx_stack_top++;
-    wx_stack_count++;
-}
+        size_t                      nIndex;
+        wxPaintDCInfo*              pInfo = FindInCache(&nIndex);
 
-int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
-                  double *x3, double *y3, double *x4, double *y4)
-{
-    if (wx_stack_count == 0)
-       return (0);
-    wx_stack_top--;
-    wx_stack_count--;
-    *x1 = wx_stack_top->x1;
-    *y1 = wx_stack_top->y1;
-    *x2 = wx_stack_top->x2;
-    *y2 = wx_stack_top->y2;
-    *x3 = wx_stack_top->x3;
-    *y3 = wx_stack_top->y3;
-    *x4 = wx_stack_top->x4;
-    *y4 = wx_stack_top->y4;
-    return (1);
-}
+        wxCHECK_RET( pInfo, wxT("existing DC should have a cache entry") );
 
-static bool wx_spline_add_point(double x, double y)
-{
-  wxPoint *point = new wxPoint ;
-  point->x = (int) x;
-  point->y = (int) y;
-  wx_spline_point_list.Append((wxObject*)point);
-  return TRUE;
-}
+        if ( !--pInfo->m_nCount )
+        {
+            ::WinEndPaint(m_hPS);
+            m_hPS          = m_hOldPS;
+            m_bIsPaintTime = false;
+            ms_cache.RemoveAt(nIndex);
+        }
+        //else: cached DC entry is still in use
 
-static void wx_spline_draw_point_array(wxDC *dc)
-{
-  dc->DrawLines(&wx_spline_point_list, 0, 0 );
-  wxNode *node = wx_spline_point_list.First();
-  while (node)
-  {
-    wxPoint *point = (wxPoint *)node->Data();
-    delete point;
-    delete node;
-    node = wx_spline_point_list.First();
-  }
+        // prevent the base class dtor from ReleaseDC()ing it again
+        m_hDC = 0;
+    }
 }
 
-void wxWindowDC::DrawSpline( wxList *points )
+wxPaintDCInfo* wxPaintDCImpl::FindInCache(
+  size_t*                           pIndex
+) const
 {
-    wxPoint *p;
-    double           cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
-    double           x1, y1, x2, y2;
-
-    wxNode *node = points->First();
-    p = (wxPoint *)node->Data();
-
-    x1 = p->x;
-    y1 = p->y;
-
-    node = node->Next();
-    p = (wxPoint *)node->Data();
+    wxPaintDCInfo*                  pInfo = NULL;
+    size_t                          nCache = ms_cache.GetCount();
 
-    x2 = p->x;
-    y2 = p->y;
-    cx1 = (double)((x1 + x2) / 2);
-    cy1 = (double)((y1 + y2) / 2);
-    cx2 = (double)((cx1 + x2) / 2);
-    cy2 = (double)((cy1 + y2) / 2);
-
-    wx_spline_add_point(x1, y1);
-
-    while ((node = node->Next()) != NULL)
+    for (size_t n = 0; n < nCache; n++)
     {
-        p = (wxPoint *)node->Data();
-       x1 = x2;
-       y1 = y2;
-       x2 = p->x;
-       y2 = p->y;
-        cx4 = (double)(x1 + x2) / 2;
-        cy4 = (double)(y1 + y2) / 2;
-        cx3 = (double)(x1 + cx4) / 2;
-        cy3 = (double)(y1 + cy4) / 2;
-
-        wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
-
-       cx1 = cx4;
-       cy1 = cy4;
-        cx2 = (double)(cx1 + x2) / 2;
-        cy2 = (double)(cy1 + y2) / 2;
+        pInfo = &ms_cache[n];
+        if (pInfo->m_hWnd == m_pCanvas->GetHWND())
+        {
+            if (pIndex)
+                *pIndex = n;
+            break;
+        }
     }
+    return pInfo;
+} // end of wxPaintDCImpl::FindInCache
 
-    wx_spline_add_point( cx1, cy1 );
-    wx_spline_add_point( x2, y2 );
+// find the entry for this DC in the cache (keyed by the window)
+WXHDC wxPaintDCImpl::FindDCInCache(
+  wxWindow*                         pWin
+)
+{
+    wxPaintDCInfo*                  pInfo = NULL;
+    size_t                          nCache = ms_cache.GetCount();
 
-    wx_spline_draw_point_array( this );
-};
+    for (size_t n = 0; n < nCache; n++)
+    {
+        pInfo = &ms_cache[n];
+        if (pInfo->m_hWnd == pWin->GetHWND())
+        {
+            return pInfo->m_hDC;
+        }
+    }
+    return 0;
+} // end of wxPaintDCImpl::FindInCache