]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcclient.cpp
added FreeBSD
[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 ++;
2bda0e17
KB
52}
53
e6460682 54wxWindowDC::~wxWindowDC(void)
2bda0e17 55{
e6460682 56 if (m_canvas && m_hDC)
2bda0e17
KB
57 {
58 SelectOldObjects(m_hDC);
59
60 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
61 m_hDC = 0;
62 }
e6460682 63 m_hDCCount --;
2bda0e17
KB
64}
65
e6460682
JS
66/*
67 * wxClientDC
68 */
69
70wxClientDC::wxClientDC(void)
2bda0e17
KB
71{
72 m_canvas = NULL;
73}
74
e6460682 75wxClientDC::wxClientDC(wxWindow *the_canvas)
2bda0e17
KB
76{
77 m_canvas = the_canvas;
e6460682
JS
78// BeginDrawing();
79 m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
2bda0e17
KB
80}
81
e6460682 82wxClientDC::~wxClientDC(void)
2bda0e17 83{
e6460682
JS
84// EndDrawing();
85
86 if (m_canvas && (HDC) m_hDC)
2bda0e17
KB
87 {
88 SelectOldObjects(m_hDC);
89
90 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
91 m_hDC = 0;
92 }
2bda0e17
KB
93}
94
e6460682
JS
95/*
96 * wxPaintDC
97 */
98
2bda0e17
KB
99wxPaintDC::wxPaintDC(void)
100{
101 m_canvas = NULL;
102}
103
104static PAINTSTRUCT g_paintStruct;
105
106// Don't call Begin/EndPaint if it's already been called:
107// for example, if calling a base class OnPaint.
108
c085e333
VZ
109WXHDC wxPaintDC::ms_PaintHDC = 0;
110size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
2bda0e17 111
83626bfa 112wxPaintDC::wxPaintDC(wxWindow *canvas)
2bda0e17 113{
83626bfa 114 wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" );
2bda0e17 115
83626bfa
VZ
116 m_canvas = canvas;
117 if ( ms_PaintCount > 0 ) {
118 // it means that we've already called BeginPaint and so we must just
119 // reuse the same HDC (BeginPaint shouldn't be called more than once)
120 wxASSERT( ms_PaintHDC );
121
122 m_hDC = ms_PaintHDC;
123 ms_PaintCount++;
124 }
125 else {
126 ms_PaintHDC =
127 m_hDC = (WXHDC)::BeginPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
128 ms_PaintCount = 1;
129 m_hDCCount++;
130 }
2bda0e17
KB
131}
132
83626bfa 133wxPaintDC::~wxPaintDC()
2bda0e17 134{
83626bfa
VZ
135 if ( m_hDC ) {
136 if ( !--ms_PaintCount ) {
137 ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
138 m_hDCCount--;
a0a302dc
JS
139 m_hDC = (WXHDC) NULL;
140 ms_PaintHDC = (WXHDC) NULL;
1c089c47 141 }
c085e333 142 else { }//: ms_PaintHDC still in use
83626bfa 143 }
2bda0e17 144}
81d66cf3 145