]>
Commit | Line | Data |
---|---|---|
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" | |
83626bfa | 32 | #include "wx/log.h" |
2bda0e17 KB |
33 | |
34 | #include <windows.h> | |
35 | ||
36 | #if !USE_SHARED_LIBRARY | |
37 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxDC) | |
38 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) | |
39 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxDC) | |
40 | #endif | |
41 | ||
42 | wxClientDC::wxClientDC(void) | |
43 | { | |
44 | m_canvas = NULL; | |
45 | } | |
46 | ||
47 | wxClientDC::wxClientDC(wxWindow *the_canvas) | |
48 | { | |
49 | m_canvas = the_canvas; | |
50 | // BeginDrawing(); | |
51 | m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND()); | |
52 | } | |
53 | ||
54 | wxClientDC::~wxClientDC(void) | |
55 | { | |
56 | // EndDrawing(); | |
57 | ||
58 | if (m_canvas && (HDC) m_hDC) | |
59 | { | |
60 | SelectOldObjects(m_hDC); | |
61 | ||
62 | ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC); | |
63 | m_hDC = 0; | |
64 | } | |
65 | } | |
66 | ||
67 | wxWindowDC::wxWindowDC(void) | |
68 | { | |
69 | m_canvas = NULL; | |
70 | } | |
71 | ||
72 | wxWindowDC::wxWindowDC(wxWindow *the_canvas) | |
73 | { | |
74 | m_canvas = the_canvas; | |
75 | // m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW); | |
76 | m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() ); | |
77 | m_hDCCount ++; | |
78 | } | |
79 | ||
80 | wxWindowDC::~wxWindowDC(void) | |
81 | { | |
82 | if (m_canvas && m_hDC) | |
83 | { | |
84 | SelectOldObjects(m_hDC); | |
85 | ||
86 | ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC); | |
87 | m_hDC = 0; | |
88 | } | |
89 | m_hDCCount --; | |
90 | } | |
91 | ||
92 | wxPaintDC::wxPaintDC(void) | |
93 | { | |
94 | m_canvas = NULL; | |
95 | } | |
96 | ||
97 | static PAINTSTRUCT g_paintStruct; | |
98 | ||
99 | // Don't call Begin/EndPaint if it's already been called: | |
100 | // for example, if calling a base class OnPaint. | |
101 | ||
83626bfa | 102 | WXHDC wxPaintDC::ms_PaintHDC = 0; |
c86f1403 | 103 | size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage |
2bda0e17 | 104 | |
83626bfa | 105 | wxPaintDC::wxPaintDC(wxWindow *canvas) |
2bda0e17 | 106 | { |
83626bfa | 107 | wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" ); |
2bda0e17 | 108 | |
83626bfa VZ |
109 | m_canvas = canvas; |
110 | if ( ms_PaintCount > 0 ) { | |
111 | // it means that we've already called BeginPaint and so we must just | |
112 | // reuse the same HDC (BeginPaint shouldn't be called more than once) | |
113 | wxASSERT( ms_PaintHDC ); | |
114 | ||
115 | m_hDC = ms_PaintHDC; | |
116 | ms_PaintCount++; | |
117 | } | |
118 | else { | |
119 | ms_PaintHDC = | |
120 | m_hDC = (WXHDC)::BeginPaint((HWND)m_canvas->GetHWND(), &g_paintStruct); | |
121 | ms_PaintCount = 1; | |
122 | m_hDCCount++; | |
123 | } | |
2bda0e17 KB |
124 | } |
125 | ||
83626bfa | 126 | wxPaintDC::~wxPaintDC() |
2bda0e17 | 127 | { |
83626bfa VZ |
128 | if ( m_hDC ) { |
129 | if ( !--ms_PaintCount ) { | |
130 | ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct); | |
131 | m_hDCCount--; | |
132 | m_hDC = NULL; | |
133 | ms_PaintHDC = NULL; | |
1c089c47 | 134 | } |
83626bfa VZ |
135 | //else: ms_PaintHDC still in use |
136 | } | |
2bda0e17 | 137 | } |
81d66cf3 | 138 |