]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dcclient.cpp
wxProcess-related code now works
[wxWidgets.git] / src / msw / dcclient.cpp
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 // 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"
27 #include "wx/log.h"
28
29 #include <windows.h>
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
33 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
34 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
35 #endif
36
37 /*
38 * wxWindowDC
39 */
40
41 wxWindowDC::wxWindowDC(void)
42 {
43 m_canvas = NULL;
44 }
45
46 wxWindowDC::wxWindowDC(wxWindow *the_canvas)
47 {
48 m_canvas = the_canvas;
49 // m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW);
50 m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() );
51 m_hDCCount ++;
52 }
53
54 wxWindowDC::~wxWindowDC(void)
55 {
56 if (m_canvas && m_hDC)
57 {
58 SelectOldObjects(m_hDC);
59
60 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
61 m_hDC = 0;
62 }
63 m_hDCCount --;
64 }
65
66 /*
67 * wxClientDC
68 */
69
70 wxClientDC::wxClientDC(void)
71 {
72 m_canvas = NULL;
73 }
74
75 wxClientDC::wxClientDC(wxWindow *the_canvas)
76 {
77 m_canvas = the_canvas;
78 // BeginDrawing();
79 m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
80 }
81
82 wxClientDC::~wxClientDC(void)
83 {
84 // EndDrawing();
85
86 if (m_canvas && (HDC) m_hDC)
87 {
88 SelectOldObjects(m_hDC);
89
90 ::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC);
91 m_hDC = 0;
92 }
93 }
94
95 /*
96 * wxPaintDC
97 */
98
99 wxPaintDC::wxPaintDC(void)
100 {
101 m_canvas = NULL;
102 }
103
104 static 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
109 WXHDC wxPaintDC::ms_PaintHDC = 0;
110 size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
111
112 wxPaintDC::wxPaintDC(wxWindow *canvas)
113 {
114 wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" );
115
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 }
131 }
132
133 wxPaintDC::~wxPaintDC()
134 {
135 if ( m_hDC ) {
136 if ( !--ms_PaintCount ) {
137 ::EndPaint((HWND)m_canvas->GetHWND(), &g_paintStruct);
138 m_hDCCount--;
139 m_hDC = (WXHDC) NULL;
140 ms_PaintHDC = (WXHDC) NULL;
141 }
142 else { }//: ms_PaintHDC still in use
143 }
144 }
145