]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcclient.cpp | |
3 | // Purpose: wxClientDC class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "dcclient.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/dcclient.h" |
19 | #include "wx/dcmemory.h" | |
20 | #include "wx/region.h" | |
03e11df5 | 21 | #include "wx/window.h" |
456c94e1 | 22 | #include "wx/toplevel.h" |
5f5f809d | 23 | #include "wx/settings.h" |
463c4d71 | 24 | #include "wx/math.h" |
76a5e5d2 | 25 | #include "wx/mac/private.h" |
e928c28c | 26 | #include "wx/log.h" |
e9576ca5 SC |
27 | |
28 | //----------------------------------------------------------------------------- | |
29 | // constants | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | #define RAD2DEG 57.2957795131 | |
33 | ||
34 | //----------------------------------------------------------------------------- | |
35 | // wxPaintDC | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
2f1ae414 | 38 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
39 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
40 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
41 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
2f1ae414 | 42 | #endif |
e9576ca5 SC |
43 | |
44 | /* | |
45 | * wxWindowDC | |
46 | */ | |
47 | ||
d497dca4 | 48 | #include "wx/mac/uma.h" |
be346c26 SC |
49 | #include "wx/notebook.h" |
50 | #include "wx/tabctrl.h" | |
51 | ||
52 | ||
53 | static wxBrush MacGetBackgroundBrush( wxWindow* window ) | |
54 | { | |
55 | wxBrush bkdBrush = window->MacGetBackgroundBrush() ; | |
56 | #if !TARGET_API_MAC_OSX | |
57 | // transparency cannot be handled by the OS when not using composited windows | |
58 | wxWindow* parent = window->GetParent() ; | |
59 | // if we have some 'pseudo' transparency | |
60 | if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
61 | { | |
62 | // walk up until we find something | |
63 | while( parent != NULL ) | |
64 | { | |
65 | if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
66 | { | |
67 | // if we have any other colours in the hierarchy | |
68 | bkdBrush.SetColour( parent->GetBackgroundColour() ) ; | |
69 | break ; | |
70 | } | |
71 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) | |
72 | { | |
73 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
74 | break ; | |
75 | } | |
76 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) ) | |
77 | { | |
78 | Rect extent = { 0 , 0 , 0 , 0 } ; | |
79 | int x , y ; | |
80 | x = y = 0 ; | |
81 | wxSize size = parent->GetSize() ; | |
82 | parent->MacClientToRootWindow( &x , &y ) ; | |
83 | extent.left = x ; | |
84 | extent.top = y ; | |
85 | extent.top-- ; | |
86 | extent.right = x + size.x ; | |
87 | extent.bottom = y + size.y ; | |
88 | bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; | |
89 | break ; | |
90 | } | |
91 | ||
92 | parent = parent->GetParent() ; | |
93 | } | |
94 | } | |
95 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) | |
96 | { | |
97 | // if we did not find something, use a default | |
98 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
99 | } | |
100 | #endif | |
101 | return bkdBrush ; | |
102 | } | |
103 | ||
519cb848 | 104 | |
2f1ae414 | 105 | wxWindowDC::wxWindowDC() |
e9576ca5 | 106 | { |
1be0560e | 107 | m_window = NULL ; |
519cb848 | 108 | } |
e9576ca5 | 109 | |
1be0560e | 110 | wxWindowDC::wxWindowDC(wxWindow *window) |
519cb848 | 111 | { |
1be0560e | 112 | m_window = window ; |
9f391ae1 SC |
113 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
114 | if (!rootwindow) | |
115 | return; | |
116 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
117 | int x , y ; | |
118 | x = y = 0 ; | |
119 | wxSize size = window->GetSize() ; | |
120 | window->MacWindowToRootWindow( &x , &y ) ; | |
121 | m_macPort = UMAGetWindowPort( windowref ) ; | |
122 | ||
20b69855 | 123 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
124 | m_macLocalOriginInPort.x = x ; |
125 | m_macLocalOriginInPort.y = y ; | |
126 | ||
20b69855 SC |
127 | if ( window->MacGetCGContextRef() ) |
128 | { | |
129 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
130 | m_graphicContext->SetPen( m_pen ) ; | |
131 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 | 132 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
133 | } |
134 | else | |
cb4b0966 SC |
135 | { |
136 | // as out of order redraw is not supported under CQ, we have to create a qd port for these | |
137 | // situations | |
cb4b0966 SC |
138 | m_macLocalOrigin.x = x ; |
139 | m_macLocalOrigin.y = y ; | |
cb4b0966 | 140 | |
9f391ae1 | 141 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; |
cb4b0966 SC |
142 | m_graphicContext->SetPen( m_pen ) ; |
143 | m_graphicContext->SetBrush( m_brush ) ; | |
144 | SetBackground(MacGetBackgroundBrush(window)); | |
145 | } | |
20b69855 SC |
146 | // there is no out-of-order drawing on OSX |
147 | #else | |
e40298d5 JS |
148 | m_macLocalOrigin.x = x ; |
149 | m_macLocalOrigin.y = y ; | |
cf9d0f93 | 150 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; |
e40298d5 JS |
151 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; |
152 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 153 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
154 | #endif |
155 | m_ok = TRUE ; | |
156 | SetFont( window->GetFont() ) ; | |
519cb848 | 157 | } |
e9576ca5 | 158 | |
2f1ae414 | 159 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 160 | { |
519cb848 | 161 | } |
e9576ca5 | 162 | |
1be0560e SC |
163 | void wxWindowDC::DoGetSize( int* width, int* height ) const |
164 | { | |
165 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
166 | ||
167 | m_window->GetSize(width, height); | |
168 | } | |
169 | ||
519cb848 SC |
170 | /* |
171 | * wxClientDC | |
172 | */ | |
e9576ca5 | 173 | |
2f1ae414 | 174 | wxClientDC::wxClientDC() |
e9576ca5 | 175 | { |
1be0560e | 176 | m_window = NULL ; |
e9576ca5 SC |
177 | } |
178 | ||
519cb848 | 179 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 180 | { |
1be0560e | 181 | m_window = window ; |
9f391ae1 SC |
182 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
183 | if (!rootwindow) | |
184 | return; | |
185 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
186 | wxPoint origin = window->GetClientAreaOrigin() ; | |
187 | wxSize size = window->GetClientSize() ; | |
188 | int x , y ; | |
189 | x = origin.x ; | |
190 | y = origin.y ; | |
191 | window->MacWindowToRootWindow( &x , &y ) ; | |
192 | m_macPort = UMAGetWindowPort( windowref ) ; | |
193 | ||
20b69855 | 194 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
195 | m_macLocalOriginInPort.x = x ; |
196 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
197 | if ( window->MacGetCGContextRef() ) |
198 | { | |
199 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
200 | m_graphicContext->SetPen( m_pen ) ; | |
201 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 SC |
202 | m_ok = TRUE ; |
203 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; | |
20b69855 SC |
204 | SetBackground(MacGetBackgroundBrush(window)); |
205 | } | |
206 | else | |
207 | { | |
cb4b0966 SC |
208 | // as out of order redraw is not supported under CQ, we have to create a qd port for these |
209 | // situations | |
20b69855 SC |
210 | m_macLocalOrigin.x = x ; |
211 | m_macLocalOrigin.y = y ; | |
9f391ae1 | 212 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; |
20b69855 SC |
213 | m_graphicContext->SetPen( m_pen ) ; |
214 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 | 215 | m_ok = TRUE ; |
cb4b0966 | 216 | } |
20b69855 | 217 | #else |
e40298d5 JS |
218 | m_macLocalOrigin.x = x ; |
219 | m_macLocalOrigin.y = y ; | |
220 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
221 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
222 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
223 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
224 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
e40298d5 | 225 | m_ok = TRUE ; |
20b69855 | 226 | #endif |
be346c26 | 227 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 228 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
229 | } |
230 | ||
2f1ae414 | 231 | wxClientDC::~wxClientDC() |
e9576ca5 | 232 | { |
68654a82 SC |
233 | #if wxMAC_USE_CORE_GRAPHICS |
234 | /* | |
235 | if ( m_window->MacGetCGContextRef() == 0) | |
236 | { | |
237 | CGContextRef cgContext = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ; | |
238 | CGContextFlush( cgContext ) ; | |
239 | } | |
240 | */ | |
241 | #endif | |
e9576ca5 SC |
242 | } |
243 | ||
1be0560e SC |
244 | void wxClientDC::DoGetSize(int *width, int *height) const |
245 | { | |
246 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
247 | ||
248 | m_window->GetClientSize( width, height ); | |
249 | } | |
250 | ||
251 | ||
519cb848 SC |
252 | /* |
253 | * wxPaintDC | |
254 | */ | |
e9576ca5 | 255 | |
2f1ae414 | 256 | wxPaintDC::wxPaintDC() |
e9576ca5 | 257 | { |
1be0560e | 258 | m_window = NULL ; |
e9576ca5 SC |
259 | } |
260 | ||
519cb848 | 261 | wxPaintDC::wxPaintDC(wxWindow *window) |
e9576ca5 | 262 | { |
1be0560e | 263 | m_window = window ; |
9f391ae1 SC |
264 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
265 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
266 | wxPoint origin = window->GetClientAreaOrigin() ; | |
267 | wxSize size = window->GetClientSize() ; | |
268 | int x , y ; | |
269 | x = origin.x ; | |
270 | y = origin.y ; | |
271 | window->MacWindowToRootWindow( &x , &y ) ; | |
272 | m_macPort = UMAGetWindowPort( windowref ) ; | |
20b69855 | 273 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
274 | m_macLocalOriginInPort.x = x ; |
275 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
276 | if ( window->MacGetCGContextRef() ) |
277 | { | |
278 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
279 | m_graphicContext->SetPen( m_pen ) ; | |
280 | m_graphicContext->SetBrush( m_brush ) ; | |
20b69855 | 281 | m_ok = TRUE ; |
9f391ae1 SC |
282 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; |
283 | SetBackground(MacGetBackgroundBrush(window)); | |
20b69855 SC |
284 | } |
285 | else | |
286 | { | |
287 | wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ; | |
288 | m_graphicContext = NULL ; | |
289 | m_ok = TRUE ; | |
290 | } | |
291 | // there is no out-of-order drawing on OSX | |
292 | #else | |
e40298d5 JS |
293 | m_macLocalOrigin.x = x ; |
294 | m_macLocalOrigin.y = y ; | |
295 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
296 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
297 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
298 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
299 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
300 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 301 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
302 | m_ok = TRUE ; |
303 | #endif | |
e40298d5 | 304 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
305 | } |
306 | ||
519cb848 | 307 | wxPaintDC::~wxPaintDC() |
e9576ca5 | 308 | { |
519cb848 | 309 | } |
1be0560e SC |
310 | |
311 | void wxPaintDC::DoGetSize(int *width, int *height) const | |
312 | { | |
313 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
314 | ||
315 | m_window->GetClientSize( width, height ); | |
316 | } | |
317 | ||
318 |