]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dcclient.cpp
fixed incorrect GetTextExtent for wxTELETYPE font
[wxWidgets.git] / src / os2 / dcclient.cpp
index 9fa35aa9d7530f126f210b7475e23c13918e7701..af77090fd1610087023c5fa8f7bcf3b95f79efaf 100644 (file)
@@ -82,14 +82,14 @@ static RECT        g_paintStruct;
 
 wxWindowDC::wxWindowDC()
 {
-  m_canvas = NULL;
+  m_pCanvas = NULL;
 }
 
 wxWindowDC::wxWindowDC(wxWindow *the_canvas)
 {
-  m_canvas = the_canvas;
+  m_pCanvas = the_canvas;
   m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(the_canvas) );
-  m_hDCCount++;
+  m_nDCCount++;
   //
   // default under PM is that Window and Client DC's are the same
   // so we offer a separate Presentation Space to use for the
@@ -103,12 +103,12 @@ wxWindowDC::wxWindowDC(wxWindow *the_canvas)
                       );
   ::GpiAssociate(m_hPS, NULLHANDLE);
   ::GpiAssociate(m_hPS, m_hDC);
-  SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
+  SetBackground(wxBrush(m_pCanvas->GetBackgroundColour(), wxSOLID));
 }
 
 wxWindowDC::~wxWindowDC()
 {
-  if (m_canvas && m_hDC)
+  if (m_pCanvas && m_hDC)
   {
     SelectOldObjects(m_hDC);
 
@@ -117,13 +117,16 @@ wxWindowDC::~wxWindowDC()
     // They automatically close with the window, unless explicitly detached
     // but we need to destroy our PS
     //
-    ::GpiAssociate(m_hPS, NULLHANDLE);
-    ::GpiDestroyPS(m_hPS);
+    if(m_hPS)
+    {
+        ::GpiAssociate(m_hPS, NULLHANDLE);
+        ::GpiDestroyPS(m_hPS);
+    }
     m_hPS = NULLHANDLE;
     m_hDC = NULLHANDLE;
   }
 
-  m_hDCCount--;
+  m_nDCCount--;
 }
 
 // ----------------------------------------------------------------------------
@@ -132,27 +135,37 @@ wxWindowDC::~wxWindowDC()
 
 wxClientDC::wxClientDC()
 {
-  m_canvas = NULL;
+  m_pCanvas = NULL;
 }
 
 wxClientDC::wxClientDC(wxWindow *the_canvas)
 {
-  m_canvas = the_canvas;
+    SIZEL                           vSizl = { 0,0};
 
-  //
-  // default under PM is that Window and Client DC's are the same
-  //
-  m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(the_canvas));
+    m_pCanvas = the_canvas;
 
-  //
-  // Default mode is BM_LEAVEALONE so we make no call Set the mix
-  //
-  SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
+    //
+    // default under PM is that Window and Client DC's are the same
+    //
+    m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(the_canvas));
+    m_hPS = ::GpiCreatePS( wxGetInstance()
+                          ,m_hDC
+                          ,&vSizl
+                          ,PU_PELS | GPIF_LONG | GPIA_ASSOC
+                         );
+
+    //
+    // Default mode is BM_LEAVEALONE so we make no call Set the mix
+    //
+    SetBackground(wxBrush( m_pCanvas->GetBackgroundColour()
+                          ,wxSOLID
+                         )
+                 );
 }
 
 wxClientDC::~wxClientDC()
 {
-  if ( m_canvas && GetHdc() )
+  if ( m_pCanvas && GetHdc() )
   {
     SelectOldObjects(m_hDC);
 
@@ -187,38 +200,55 @@ wxArrayDCInfo wxPaintDC::ms_cache;
 
 wxPaintDC::wxPaintDC()
 {
-    m_canvas = NULL;
+    m_pCanvas = NULL;
     m_hDC = 0;
 }
 
-wxPaintDC::wxPaintDC(wxWindow *canvas)
+wxPaintDC::wxPaintDC(
+  wxWindow*                         pCanvas
+)
 {
-    wxCHECK_RET( canvas, wxT("NULL canvas in wxPaintDC ctor") );
+    wxCHECK_RET(pCanvas, wxT("NULL canvas in wxPaintDC ctor"));
 
 #ifdef __WXDEBUG__
-    if ( g_isPainting <= 0 )
+    if (g_isPainting <= 0)
     {
         wxFAIL_MSG( wxT("wxPaintDC may be created only in EVT_PAINT handler!") );
-
         return;
     }
 #endif // __WXDEBUG__
 
-    m_canvas = canvas;
+    m_pCanvas = pCanvas;
+
+    //
+    // Do we have a DC for this window in the cache?
+    //
+    wxPaintDCInfo*                  pInfo = FindInCache();
 
-    // do we have a DC for this window in the cache?
-    wxPaintDCInfo *info = FindInCache();
-    if ( info )
+    if (pInfo)
     {
-        m_hDC = info->hdc;
-        info->count++;
+        m_hDC = pInfo->hdc;
+        pInfo->count++;
     }
     else // not in cache, create a new one
     {
-        m_hDC = (WXHDC)::WinBeginPaint(GetWinHwnd(m_canvas), NULLHANDLE, &g_paintStruct);
-        ms_cache.Add(new wxPaintDCInfo(m_canvas, this));
+        HPS                         hPS;
+
+        hPS = ::WinBeginPaint( GetWinHwnd(m_pCanvas)
+                              ,NULLHANDLE
+                              ,&g_paintStruct
+                             );
+        if(hPS)
+        {
+            m_hOldPS = m_hPS;
+            m_hPS = hPS;
+        }
+        m_bIsPaintTime   = TRUE;
+        m_hDC = (WXHDC) -1; // to satisfy those anonizmous efforts
+        m_vRclPaint = g_paintStruct;
+        ms_cache.Add(new wxPaintDCInfo(m_pCanvas, this));
     }
-    SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
+    SetBackground(wxBrush(m_pCanvas->GetBackgroundColour(), wxSOLID));
 }
 
 wxPaintDC::~wxPaintDC()
@@ -235,7 +265,8 @@ wxPaintDC::~wxPaintDC()
         if ( !--info->count )
         {
             ::WinEndPaint(m_hPS);
-
+            m_hPS          = m_hOldPS;
+            m_bIsPaintTime = FALSE;
             ms_cache.Remove(index);
         }
         //else: cached DC entry is still in use
@@ -252,7 +283,7 @@ wxPaintDCInfo *wxPaintDC::FindInCache(size_t *index) const
     for ( size_t n = 0; n < nCache; n++ )
     {
         info = &ms_cache[n];
-        if ( info->hwnd == m_canvas->GetHWND() )
+        if ( info->hwnd == m_pCanvas->GetHWND() )
         {
             if ( index )
                 *index = n;