]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dcclient.cpp
Removed floor() references
[wxWidgets.git] / src / msw / dcclient.cpp
index 4c6b19b03b73057983c401d5d7f39543051d5727..763e70bb579677cd1737db2a7564bda1efbe3dda 100644 (file)
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "dcclient.h"
-#endif
+// ===========================================================================
+// declarations
+// ===========================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
 
 #ifdef __GNUG__
-#pragma implementation
-#pragma implementation "dcclient.h"
+    #pragma implementation "dcclient.h"
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-#endif
+#include "wx/string.h"
+#include "wx/log.h"
+#include "wx/window.h"
+
+#include "wx/msw/private.h"
 
 #include "wx/dcclient.h"
-#include "wx/log.h"
 
-#include <windows.h>
+// ----------------------------------------------------------------------------
+// macros
+// ----------------------------------------------------------------------------
 
 #if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxDC)
-IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
-IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxDC)
+    IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
+    IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
+    IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
 #endif
 
-wxClientDC::wxClientDC(void)
+// ----------------------------------------------------------------------------
+// global variables
+// ----------------------------------------------------------------------------
+
+static PAINTSTRUCT g_paintStruct;
+
+#ifdef __WXDEBUG__
+    // 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 wxWindows programmers and might lead to
+    // very subtle and difficult to debug refresh/repaint bugs.
+    extern bool g_isPainting = FALSE;
+#endif // __WXDEBUG__
+
+// ===========================================================================
+// implementation
+// ===========================================================================
+
+// ----------------------------------------------------------------------------
+// wxWindowDC
+// ----------------------------------------------------------------------------
+
+wxWindowDC::wxWindowDC()
 {
   m_canvas = NULL;
 }
 
-wxClientDC::wxClientDC(wxWindow *the_canvas)
+wxWindowDC::wxWindowDC(wxWindow *the_canvas)
 {
   m_canvas = the_canvas;
-//  BeginDrawing();
-  m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
+  m_hDC = (WXHDC) ::GetWindowDC(GetWinHwnd(the_canvas) );
+  m_hDCCount++;
+
+  SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
 }
 
-wxClientDC::~wxClientDC(void)
+wxWindowDC::~wxWindowDC()
 {
-//  EndDrawing();
-
-  if (m_canvas && (HDC) m_hDC)
+  if (m_canvas && m_hDC)
   {
     SelectOldObjects(m_hDC);
 
-    ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
-       m_hDC = 0;
+    ::ReleaseDC(GetWinHwnd(m_canvas), GetHdc());
+    m_hDC = 0;
   }
+
+  m_hDCCount--;
 }
 
-wxWindowDC::wxWindowDC(void)
+// ----------------------------------------------------------------------------
+// wxClientDC
+// ----------------------------------------------------------------------------
+
+wxClientDC::wxClientDC()
 {
   m_canvas = NULL;
 }
 
-wxWindowDC::wxWindowDC(wxWindow *the_canvas)
+wxClientDC::wxClientDC(wxWindow *the_canvas)
 {
   m_canvas = the_canvas;
-//  m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW);
-  m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() );
-  m_hDCCount ++;
+  m_hDC = (WXHDC) ::GetDC(GetWinHwnd(the_canvas));
+
+  SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
 }
 
-wxWindowDC::~wxWindowDC(void)
+wxClientDC::~wxClientDC()
 {
-  if (m_canvas && m_hDC)
+  if ( m_canvas && GetHdc() )
   {
     SelectOldObjects(m_hDC);
 
-    ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
-       m_hDC = 0;
+    ::ReleaseDC(GetWinHwnd(m_canvas), GetHdc());
+    m_hDC = 0;
   }
-  m_hDCCount --;
 }
 
-wxPaintDC::wxPaintDC(void)
-{
-  m_canvas = NULL;
-}
+// ----------------------------------------------------------------------------
+// wxPaintDC
+// ----------------------------------------------------------------------------
 
-static PAINTSTRUCT g_paintStruct;
+// TODO (VZ) I have still some doubts about this hack and I still think that we
+//           should store pairs of (hwnd, hdc) and not just the DC - what if
+//           BeginPaint() was called on other window? It seems to work like
+//           this, but to be sure about it we'd need to store hwnd too...
 
-// Don't call Begin/EndPaint if it's already been called:
-// for example, if calling a base class OnPaint.
+WXHDC  wxPaintDC::ms_PaintHDC = 0;
+size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
 
-WXHDC wxPaintDC::ms_PaintHDC = 0;
-uint  wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
+wxPaintDC::wxPaintDC()
+{
+  m_canvas = NULL;
+}
 
 wxPaintDC::wxPaintDC(wxWindow *canvas)
 {
   wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" );
+  wxCHECK_RET( g_isPainting,
+               _T("wxPaintDC may be created only in EVT_PAINT handler!") );
 
   m_canvas = canvas;
+
+  // Don't call Begin/EndPaint if it's already been called: for example, if
+  // calling a base class OnPaint.
   if ( ms_PaintCount > 0 ) {
     // it means that we've already called BeginPaint and so we must just
     // reuse the same HDC (BeginPaint shouldn't be called more than once)
@@ -121,6 +164,8 @@ wxPaintDC::wxPaintDC(wxWindow *canvas)
     ms_PaintCount = 1;
     m_hDCCount++;
   }
+
+  SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
 }
 
 wxPaintDC::~wxPaintDC()
@@ -129,8 +174,8 @@ wxPaintDC::~wxPaintDC()
     if ( !--ms_PaintCount ) {
       ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
       m_hDCCount--;
-      m_hDC = NULL;
-      ms_PaintHDC = NULL;
+      m_hDC = (WXHDC) NULL;
+      ms_PaintHDC = (WXHDC) NULL;
     }
     //else: ms_PaintHDC still in use
   }