]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcclient.cpp
First attempt at clean-up
[wxWidgets.git] / src / msw / dcclient.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcclient.cpp
3// Purpose: wxClientDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dcclient.h"
14#endif
15
2bda0e17
KB
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#endif
25
26#include "wx/dcclient.h"
83626bfa 27#include "wx/log.h"
2bda0e17
KB
28
29#include <windows.h>
30
31#if !USE_SHARED_LIBRARY
2bda0e17 32IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
e6460682
JS
33IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
34IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
2bda0e17
KB
35#endif
36
e6460682
JS
37/*
38 * wxWindowDC
39 */
40
41wxWindowDC::wxWindowDC(void)
2bda0e17
KB
42{
43 m_canvas = NULL;
44}
45
e6460682 46wxWindowDC::wxWindowDC(wxWindow *the_canvas)
2bda0e17
KB
47{
48 m_canvas = the_canvas;
e6460682
JS
49// m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW);
50 m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() );
51 m_hDCCount ++;
a91b47e8
JS
52
53 SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
2bda0e17
KB
54}
55
e6460682 56wxWindowDC::~wxWindowDC(void)
2bda0e17 57{
e6460682 58 if (m_canvas && m_hDC)
2bda0e17
KB
59 {
60 SelectOldObjects(m_hDC);
61
62 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
63 m_hDC = 0;
64 }
e6460682 65 m_hDCCount --;
2bda0e17
KB
66}
67
e6460682
JS
68/*
69 * wxClientDC
70 */
71
72wxClientDC::wxClientDC(void)
2bda0e17
KB
73{
74 m_canvas = NULL;
75}
76
e6460682 77wxClientDC::wxClientDC(wxWindow *the_canvas)
2bda0e17
KB
78{
79 m_canvas = the_canvas;
e6460682
JS
80// BeginDrawing();
81 m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
a91b47e8
JS
82
83 SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
2bda0e17
KB
84}
85
e6460682 86wxClientDC::~wxClientDC(void)
2bda0e17 87{
e6460682
JS
88// EndDrawing();
89
90 if (m_canvas && (HDC) m_hDC)
2bda0e17
KB
91 {
92 SelectOldObjects(m_hDC);
93
94 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
95 m_hDC = 0;
96 }
2bda0e17
KB
97}
98
e6460682
JS
99/*
100 * wxPaintDC
101 */
102
2bda0e17
KB
103wxPaintDC::wxPaintDC(void)
104{
105 m_canvas = NULL;
106}
107
108static PAINTSTRUCT g_paintStruct;
109
110// Don't call Begin/EndPaint if it's already been called:
111// for example, if calling a base class OnPaint.
112
c085e333
VZ
113WXHDC wxPaintDC::ms_PaintHDC = 0;
114size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
2bda0e17 115
83626bfa 116wxPaintDC::wxPaintDC(wxWindow *canvas)
2bda0e17 117{
83626bfa 118 wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" );
2bda0e17 119
83626bfa
VZ
120 m_canvas = canvas;
121 if ( ms_PaintCount > 0 ) {
122 // it means that we've already called BeginPaint and so we must just
123 // reuse the same HDC (BeginPaint shouldn't be called more than once)
124 wxASSERT( ms_PaintHDC );
125
126 m_hDC = ms_PaintHDC;
127 ms_PaintCount++;
128 }
129 else {
130 ms_PaintHDC =
131 m_hDC = (WXHDC)::BeginPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
132 ms_PaintCount = 1;
133 m_hDCCount++;
134 }
a91b47e8
JS
135
136 SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
2bda0e17
KB
137}
138
83626bfa 139wxPaintDC::~wxPaintDC()
2bda0e17 140{
83626bfa
VZ
141 if ( m_hDC ) {
142 if ( !--ms_PaintCount ) {
143 ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
144 m_hDCCount--;
a0a302dc
JS
145 m_hDC = (WXHDC) NULL;
146 ms_PaintHDC = (WXHDC) NULL;
1c089c47 147 }
c085e333 148 else { }//: ms_PaintHDC still in use
83626bfa 149 }
2bda0e17 150}
81d66cf3 151