]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/mac/carbon/dcclient.cpp |
e9576ca5 | 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 |
e4db172a | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/dcclient.h" |
e4db172a WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/log.h" | |
cdccdfab | 18 | #include "wx/window.h" |
f38924e8 | 19 | #include "wx/dcmemory.h" |
9eddec69 | 20 | #include "wx/settings.h" |
1832043f | 21 | #include "wx/toplevel.h" |
18680f86 | 22 | #include "wx/math.h" |
b3a44e05 | 23 | #include "wx/region.h" |
e4db172a WS |
24 | #endif |
25 | ||
76a5e5d2 | 26 | #include "wx/mac/private.h" |
e9576ca5 SC |
27 | |
28 | //----------------------------------------------------------------------------- | |
29 | // constants | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
e9576ca5 SC |
32 | //----------------------------------------------------------------------------- |
33 | // wxPaintDC | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
e9576ca5 SC |
36 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
37 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
38 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
e9576ca5 SC |
39 | |
40 | /* | |
41 | * wxWindowDC | |
42 | */ | |
43 | ||
d497dca4 | 44 | #include "wx/mac/uma.h" |
be346c26 SC |
45 | #include "wx/notebook.h" |
46 | #include "wx/tabctrl.h" | |
e4db172a | 47 | |
be346c26 SC |
48 | |
49 | static wxBrush MacGetBackgroundBrush( wxWindow* window ) | |
50 | { | |
51 | wxBrush bkdBrush = window->MacGetBackgroundBrush() ; | |
9b2eab52 | 52 | |
be346c26 SC |
53 | #if !TARGET_API_MAC_OSX |
54 | // transparency cannot be handled by the OS when not using composited windows | |
55 | wxWindow* parent = window->GetParent() ; | |
9b2eab52 | 56 | |
be346c26 SC |
57 | // if we have some 'pseudo' transparency |
58 | if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
59 | { | |
60 | // walk up until we find something | |
9b2eab52 | 61 | while ( parent != NULL ) |
be346c26 SC |
62 | { |
63 | if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
64 | { | |
65 | // if we have any other colours in the hierarchy | |
66 | bkdBrush.SetColour( parent->GetBackgroundColour() ) ; | |
67 | break ; | |
68 | } | |
9b2eab52 | 69 | |
be346c26 SC |
70 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) |
71 | { | |
72 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
73 | break ; | |
74 | } | |
9b2eab52 | 75 | |
7301b2b8 WS |
76 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) |
77 | #if wxUSE_TAB_DIALOG | |
78 | || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) | |
9eddec69 | 79 | #endif // wxUSE_TAB_DIALOG |
7301b2b8 | 80 | ) |
be346c26 SC |
81 | { |
82 | Rect extent = { 0 , 0 , 0 , 0 } ; | |
83 | int x , y ; | |
84 | x = y = 0 ; | |
85 | wxSize size = parent->GetSize() ; | |
86 | parent->MacClientToRootWindow( &x , &y ) ; | |
87 | extent.left = x ; | |
88 | extent.top = y ; | |
89 | extent.top-- ; | |
90 | extent.right = x + size.x ; | |
91 | extent.bottom = y + size.y ; | |
e4db172a | 92 | bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; |
be346c26 SC |
93 | break ; |
94 | } | |
e4db172a WS |
95 | |
96 | parent = parent->GetParent() ; | |
be346c26 SC |
97 | } |
98 | } | |
9b2eab52 | 99 | |
be346c26 SC |
100 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) |
101 | { | |
102 | // if we did not find something, use a default | |
103 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
104 | } | |
9b2eab52 DS |
105 | #endif |
106 | ||
be346c26 | 107 | return bkdBrush ; |
e4db172a | 108 | } |
be346c26 | 109 | |
e4db172a | 110 | wxWindowDC::wxWindowDC() |
e9576ca5 | 111 | { |
1be0560e | 112 | m_window = NULL ; |
519cb848 | 113 | } |
e9576ca5 | 114 | |
e4db172a | 115 | wxWindowDC::wxWindowDC(wxWindow *window) |
519cb848 | 116 | { |
1be0560e | 117 | m_window = window ; |
9f391ae1 SC |
118 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
119 | if (!rootwindow) | |
120 | return; | |
9b2eab52 | 121 | |
9f391ae1 SC |
122 | int x , y ; |
123 | x = y = 0 ; | |
9f391ae1 | 124 | window->MacWindowToRootWindow( &x , &y ) ; |
eb1a7cf9 DS |
125 | m_ok = true ; |
126 | ||
20b69855 | 127 | #if wxMAC_USE_CORE_GRAPHICS |
4130e414 | 128 | m_window->GetSize( &m_width , &m_height); |
a2d6d210 VZ |
129 | CGContextRef cg = (CGContextRef) window->MacGetCGContextRef(); |
130 | m_release = false; | |
4130e414 | 131 | if ( cg == NULL ) |
a2d6d210 VZ |
132 | { |
133 | SetGraphicsContext( wxGraphicsContext::Create( window ) ) ; | |
134 | SetDeviceOrigin( x, y ); | |
135 | } | |
136 | else | |
137 | { | |
138 | CGContextSaveGState( cg ); | |
139 | m_release = true ; | |
140 | // make sure the context is having its origin at the wx-window coordinates of the | |
141 | // view (read at the top of window.cpp about the differences) | |
142 | if ( window->MacGetLeftBorderSize() != 0 || window->MacGetTopBorderSize() != 0 ) | |
143 | CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); | |
144 | ||
145 | SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); | |
146 | } | |
147 | m_graphicContext->SetPen( m_pen ) ; | |
148 | m_graphicContext->SetBrush( m_brush ) ; | |
149 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
20b69855 | 150 | #else |
a2d6d210 VZ |
151 | m_macLocalOrigin.x = x ; |
152 | m_macLocalOrigin.y = y ; | |
153 | m_macPort = UMAGetWindowPort( (WindowRef) rootwindow->MacGetWindowRef() ) ; | |
4130e414 | 154 | |
cf9d0f93 | 155 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; |
e40298d5 JS |
156 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; |
157 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
20b69855 | 158 | #endif |
489d2dd3 | 159 | SetBackground(MacGetBackgroundBrush(window)); |
9b2eab52 | 160 | |
20b69855 | 161 | SetFont( window->GetFont() ) ; |
519cb848 | 162 | } |
e9576ca5 | 163 | |
2f1ae414 | 164 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 165 | { |
4130e414 | 166 | #if wxMAC_USE_CORE_GRAPHICS |
a2d6d210 VZ |
167 | if ( m_release && m_graphicContext ) |
168 | { | |
169 | CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef(); | |
170 | CGContextRestoreGState(cg); | |
171 | //CGContextRef cg = (CGContextRef) m_graphicContext->GetNativeContext() ; | |
172 | } | |
4130e414 | 173 | #endif |
519cb848 | 174 | } |
e9576ca5 | 175 | |
1be0560e SC |
176 | void wxWindowDC::DoGetSize( int* width, int* height ) const |
177 | { | |
4130e414 | 178 | #if wxMAC_USE_CORE_GRAPHICS |
a2d6d210 VZ |
179 | if ( width ) |
180 | *width = m_width; | |
181 | if ( height ) | |
182 | *height = m_height; | |
4130e414 | 183 | #else |
513b47e9 | 184 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); |
1be0560e | 185 | m_window->GetSize(width, height); |
4130e414 | 186 | #endif |
1be0560e SC |
187 | } |
188 | ||
519cb848 SC |
189 | /* |
190 | * wxClientDC | |
191 | */ | |
e9576ca5 | 192 | |
2f1ae414 | 193 | wxClientDC::wxClientDC() |
e9576ca5 | 194 | { |
1be0560e | 195 | m_window = NULL ; |
e9576ca5 SC |
196 | } |
197 | ||
4130e414 SC |
198 | #if wxMAC_USE_CORE_GRAPHICS |
199 | wxClientDC::wxClientDC(wxWindow *window) : | |
a2d6d210 | 200 | wxWindowDC( window ) |
4130e414 SC |
201 | { |
202 | wxPoint origin = window->GetClientAreaOrigin() ; | |
203 | wxSize size = window->GetClientSize() ; | |
204 | int x , y ; | |
205 | x = origin.x ; | |
206 | y = origin.y ; | |
207 | window->MacWindowToRootWindow( &x , &y ) ; | |
208 | m_window->GetClientSize( &m_width , &m_height); | |
a2d6d210 VZ |
209 | SetDeviceOrigin( origin.x, origin.y ); |
210 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
4130e414 SC |
211 | } |
212 | #else | |
519cb848 | 213 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 214 | { |
1be0560e | 215 | m_window = window ; |
9f391ae1 SC |
216 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
217 | if (!rootwindow) | |
218 | return; | |
9b2eab52 | 219 | |
9f391ae1 SC |
220 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; |
221 | wxPoint origin = window->GetClientAreaOrigin() ; | |
222 | wxSize size = window->GetClientSize() ; | |
223 | int x , y ; | |
224 | x = origin.x ; | |
225 | y = origin.y ; | |
226 | window->MacWindowToRootWindow( &x , &y ) ; | |
227 | m_macPort = UMAGetWindowPort( windowref ) ; | |
eb1a7cf9 DS |
228 | m_ok = true ; |
229 | ||
e40298d5 JS |
230 | m_macLocalOrigin.x = x ; |
231 | m_macLocalOrigin.y = y ; | |
232 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
233 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
234 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
235 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
236 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
9b2eab52 | 237 | |
be346c26 | 238 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 239 | SetFont( window->GetFont() ) ; |
e9576ca5 | 240 | } |
4130e414 | 241 | #endif |
e9576ca5 | 242 | |
2f1ae414 | 243 | wxClientDC::~wxClientDC() |
e9576ca5 | 244 | { |
e9576ca5 SC |
245 | } |
246 | ||
4130e414 | 247 | #if !wxMAC_USE_CORE_GRAPHICS |
1be0560e SC |
248 | void wxClientDC::DoGetSize(int *width, int *height) const |
249 | { | |
250 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
251 | ||
252 | m_window->GetClientSize( width, height ); | |
253 | } | |
4130e414 | 254 | #endif |
1be0560e | 255 | |
519cb848 SC |
256 | /* |
257 | * wxPaintDC | |
258 | */ | |
e9576ca5 | 259 | |
2f1ae414 | 260 | wxPaintDC::wxPaintDC() |
e9576ca5 | 261 | { |
1be0560e | 262 | m_window = NULL ; |
e9576ca5 SC |
263 | } |
264 | ||
4130e414 SC |
265 | #if wxMAC_USE_CORE_GRAPHICS |
266 | wxPaintDC::wxPaintDC(wxWindow *window) : | |
a2d6d210 | 267 | wxWindowDC( window ) |
4130e414 SC |
268 | { |
269 | wxPoint origin = window->GetClientAreaOrigin() ; | |
270 | wxSize size = window->GetClientSize() ; | |
271 | int x , y ; | |
272 | x = origin.x ; | |
273 | y = origin.y ; | |
274 | window->MacWindowToRootWindow( &x , &y ) ; | |
275 | m_window->GetClientSize( &m_width , &m_height); | |
a2d6d210 VZ |
276 | SetDeviceOrigin( origin.x, origin.y ); |
277 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
4130e414 SC |
278 | } |
279 | #else | |
519cb848 | 280 | wxPaintDC::wxPaintDC(wxWindow *window) |
e9576ca5 | 281 | { |
1be0560e | 282 | m_window = window ; |
9f391ae1 SC |
283 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
284 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
285 | wxPoint origin = window->GetClientAreaOrigin() ; | |
286 | wxSize size = window->GetClientSize() ; | |
287 | int x , y ; | |
288 | x = origin.x ; | |
289 | y = origin.y ; | |
290 | window->MacWindowToRootWindow( &x , &y ) ; | |
291 | m_macPort = UMAGetWindowPort( windowref ) ; | |
eb1a7cf9 | 292 | m_ok = true ; |
9b2eab52 | 293 | |
20b69855 SC |
294 | #if wxMAC_USE_CORE_GRAPHICS |
295 | if ( window->MacGetCGContextRef() ) | |
296 | { | |
297 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
298 | m_graphicContext->SetPen( m_pen ) ; | |
299 | m_graphicContext->SetBrush( m_brush ) ; | |
9f391ae1 SC |
300 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; |
301 | SetBackground(MacGetBackgroundBrush(window)); | |
20b69855 SC |
302 | } |
303 | else | |
304 | { | |
305 | wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ; | |
306 | m_graphicContext = NULL ; | |
20b69855 SC |
307 | } |
308 | // there is no out-of-order drawing on OSX | |
309 | #else | |
e40298d5 JS |
310 | m_macLocalOrigin.x = x ; |
311 | m_macLocalOrigin.y = y ; | |
312 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
313 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
314 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
315 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
316 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
317 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 318 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 | 319 | #endif |
9b2eab52 | 320 | |
e40298d5 | 321 | SetFont( window->GetFont() ) ; |
e9576ca5 | 322 | } |
4130e414 | 323 | #endif |
e9576ca5 | 324 | |
519cb848 | 325 | wxPaintDC::~wxPaintDC() |
e9576ca5 | 326 | { |
519cb848 | 327 | } |
1be0560e | 328 | |
4130e414 | 329 | #if !wxMAC_USE_CORE_GRAPHICS |
1be0560e SC |
330 | void wxPaintDC::DoGetSize(int *width, int *height) const |
331 | { | |
332 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
333 | ||
334 | m_window->GetClientSize( width, height ); | |
335 | } | |
4130e414 | 336 | #endif |