]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcclient.cpp
memdc and bitmap fixes
[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
16#ifdef __GNUG__
17#pragma implementation
18#pragma implementation "dcclient.h"
19#endif
20
21// For compilers that support precompilation, includes "wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
25#pragma hdrstop
26#endif
27
28#ifndef WX_PRECOMP
29#endif
30
31#include "wx/dcclient.h"
32
33#include <windows.h>
34
35#if !USE_SHARED_LIBRARY
36IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxDC)
37IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
38IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxDC)
39#endif
40
41wxClientDC::wxClientDC(void)
42{
43 m_canvas = NULL;
44}
45
46wxClientDC::wxClientDC(wxWindow *the_canvas)
47{
48 m_canvas = the_canvas;
49// BeginDrawing();
50 m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
51}
52
53wxClientDC::~wxClientDC(void)
54{
55// EndDrawing();
56
57 if (m_canvas && (HDC) m_hDC)
58 {
59 SelectOldObjects(m_hDC);
60
61 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
62 m_hDC = 0;
63 }
64}
65
66wxWindowDC::wxWindowDC(void)
67{
68 m_canvas = NULL;
69}
70
71wxWindowDC::wxWindowDC(wxWindow *the_canvas)
72{
73 m_canvas = the_canvas;
74// m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW);
75 m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() );
76 m_hDCCount ++;
77}
78
79wxWindowDC::~wxWindowDC(void)
80{
81 if (m_canvas && m_hDC)
82 {
83 SelectOldObjects(m_hDC);
84
85 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
86 m_hDC = 0;
87 }
88 m_hDCCount --;
89}
90
91wxPaintDC::wxPaintDC(void)
92{
93 m_canvas = NULL;
94}
95
96static PAINTSTRUCT g_paintStruct;
97
98// Don't call Begin/EndPaint if it's already been called:
99// for example, if calling a base class OnPaint.
100
101WXHDC wxPaintDC::m_staticPaintHDC = 0;
102int wxPaintDC::m_staticPaintCount = 0;
103
104wxPaintDC::wxPaintDC(wxWindow *the_canvas)
105{
106 if ( the_canvas && (m_staticPaintCount == 0))
107 {
108 m_hDC = (WXHDC) ::BeginPaint((HWND) the_canvas->GetHWND(), &g_paintStruct);
109 m_hDCCount ++;
110 m_staticPaintCount ++ ;
111 m_staticPaintHDC = m_hDC ;
112 }
113 else
1c089c47
JS
114 {
115 wxDebugMsg("wxPaintDC: Using existing HDC\n");
2bda0e17 116 m_hDC = m_staticPaintHDC ;
1c089c47 117 }
2bda0e17
KB
118
119 m_canvas = the_canvas;
120 RECT updateRect1 = g_paintStruct.rcPaint;
121 m_canvas->m_updateRect.x = updateRect1.left;
122 m_canvas->m_updateRect.y = updateRect1.top;
123 m_canvas->m_updateRect.width = updateRect1.right - updateRect1.left;
124 m_canvas->m_updateRect.height = updateRect1.bottom - updateRect1.top;
125// m_canvas->m_paintHDC = m_staticPaintHDC ;
126}
127
128wxPaintDC::~wxPaintDC(void)
129{
130 m_staticPaintCount -- ;
131
132 if (m_staticPaintCount == 0)
133 {
134// m_canvas->m_paintHDC = 0;
135
136 if ( m_hDC && m_canvas)
137 {
138 ::EndPaint((HWND) m_canvas->GetHWND(), &g_paintStruct);
139 m_hDCCount --;
140 m_hDC = 0;
141 }
1c089c47
JS
142 else
143 wxDebugMsg("~wxPaintDC: Did not release HDC\n");
144
2bda0e17
KB
145 m_staticPaintHDC = 0 ;
146 }
1c089c47
JS
147 else
148 {
149 wxDebugMsg("~wxPaintDC: Did not release HDC\n");
150 }
2bda0e17 151}