]>
Commit | Line | Data |
---|---|---|
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 | |
36 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxDC) | |
37 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) | |
38 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxDC) | |
39 | #endif | |
40 | ||
41 | wxClientDC::wxClientDC(void) | |
42 | { | |
43 | m_canvas = NULL; | |
44 | } | |
45 | ||
46 | wxClientDC::wxClientDC(wxWindow *the_canvas) | |
47 | { | |
48 | m_canvas = the_canvas; | |
49 | // BeginDrawing(); | |
50 | m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND()); | |
51 | } | |
52 | ||
53 | wxClientDC::~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 | ||
66 | wxWindowDC::wxWindowDC(void) | |
67 | { | |
68 | m_canvas = NULL; | |
69 | } | |
70 | ||
71 | wxWindowDC::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 | ||
79 | wxWindowDC::~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 | ||
91 | wxPaintDC::wxPaintDC(void) | |
92 | { | |
93 | m_canvas = NULL; | |
94 | } | |
95 | ||
96 | static 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 | ||
101 | WXHDC wxPaintDC::m_staticPaintHDC = 0; | |
102 | int wxPaintDC::m_staticPaintCount = 0; | |
103 | ||
104 | wxPaintDC::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 | |
114 | { | |
115 | wxDebugMsg("wxPaintDC: Using existing HDC\n"); | |
116 | m_hDC = m_staticPaintHDC ; | |
117 | } | |
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 | ||
128 | wxPaintDC::~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 | } | |
142 | else | |
143 | wxDebugMsg("~wxPaintDC: Did not release HDC\n"); | |
144 | ||
145 | m_staticPaintHDC = 0 ; | |
146 | } | |
147 | else | |
148 | { | |
149 | wxDebugMsg("~wxPaintDC: Did not release HDC\n"); | |
150 | } | |
151 | } |