]>
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 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; |
123 | int x , y ; | |
124 | x = y = 0 ; | |
9f391ae1 | 125 | window->MacWindowToRootWindow( &x , &y ) ; |
eb1a7cf9 DS |
126 | m_ok = true ; |
127 | ||
20b69855 | 128 | #if wxMAC_USE_CORE_GRAPHICS |
4130e414 SC |
129 | m_window->GetSize( &m_width , &m_height); |
130 | CGContextRef cg = (CGContextRef) window->MacGetCGContextRef(); | |
131 | m_release = false; | |
132 | if ( cg == NULL ) | |
133 | SetGraphicsContext( wxGraphicsContext::Create( window ) ) ; | |
134 | else | |
135 | SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); | |
136 | m_graphicContext->SetPen( m_pen ) ; | |
137 | m_graphicContext->SetBrush( m_brush ) ; | |
138 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
20b69855 | 139 | #else |
4130e414 SC |
140 | m_macLocalOrigin.x = x ; |
141 | m_macLocalOrigin.y = y ; | |
142 | m_macPort = UMAGetWindowPort( windowref ) ; | |
143 | ||
cf9d0f93 | 144 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; |
e40298d5 JS |
145 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; |
146 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
20b69855 | 147 | #endif |
489d2dd3 | 148 | SetBackground(MacGetBackgroundBrush(window)); |
9b2eab52 | 149 | |
20b69855 | 150 | SetFont( window->GetFont() ) ; |
519cb848 | 151 | } |
e9576ca5 | 152 | |
2f1ae414 | 153 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 154 | { |
4130e414 SC |
155 | #if wxMAC_USE_CORE_GRAPHICS |
156 | if ( m_release && m_graphicContext ) | |
157 | { | |
158 | // CGContextRef cg = (CGContextRef) m_graphicContext->GetNativeContext() ; | |
159 | } | |
160 | #endif | |
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 | ||
4130e414 SC |
167 | #if wxMAC_USE_CORE_GRAPHICS |
168 | if ( width ) | |
169 | *width = m_width; | |
170 | if ( height ) | |
171 | *height = m_height; | |
172 | #else | |
1be0560e | 173 | m_window->GetSize(width, height); |
4130e414 | 174 | #endif |
1be0560e SC |
175 | } |
176 | ||
519cb848 SC |
177 | /* |
178 | * wxClientDC | |
179 | */ | |
e9576ca5 | 180 | |
2f1ae414 | 181 | wxClientDC::wxClientDC() |
e9576ca5 | 182 | { |
1be0560e | 183 | m_window = NULL ; |
e9576ca5 SC |
184 | } |
185 | ||
4130e414 SC |
186 | #if wxMAC_USE_CORE_GRAPHICS |
187 | wxClientDC::wxClientDC(wxWindow *window) : | |
188 | wxWindowDC( window ) | |
189 | { | |
190 | wxPoint origin = window->GetClientAreaOrigin() ; | |
191 | wxSize size = window->GetClientSize() ; | |
192 | int x , y ; | |
193 | x = origin.x ; | |
194 | y = origin.y ; | |
195 | window->MacWindowToRootWindow( &x , &y ) ; | |
196 | m_window->GetClientSize( &m_width , &m_height); | |
197 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
198 | } | |
199 | #else | |
519cb848 | 200 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 201 | { |
1be0560e | 202 | m_window = window ; |
9f391ae1 SC |
203 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
204 | if (!rootwindow) | |
205 | return; | |
9b2eab52 | 206 | |
9f391ae1 SC |
207 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; |
208 | wxPoint origin = window->GetClientAreaOrigin() ; | |
209 | wxSize size = window->GetClientSize() ; | |
210 | int x , y ; | |
211 | x = origin.x ; | |
212 | y = origin.y ; | |
213 | window->MacWindowToRootWindow( &x , &y ) ; | |
214 | m_macPort = UMAGetWindowPort( windowref ) ; | |
eb1a7cf9 DS |
215 | m_ok = true ; |
216 | ||
e40298d5 JS |
217 | m_macLocalOrigin.x = x ; |
218 | m_macLocalOrigin.y = y ; | |
219 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
220 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
221 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
222 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
223 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
9b2eab52 | 224 | |
be346c26 | 225 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 226 | SetFont( window->GetFont() ) ; |
e9576ca5 | 227 | } |
4130e414 | 228 | #endif |
e9576ca5 | 229 | |
2f1ae414 | 230 | wxClientDC::~wxClientDC() |
e9576ca5 | 231 | { |
e9576ca5 SC |
232 | } |
233 | ||
4130e414 | 234 | #if !wxMAC_USE_CORE_GRAPHICS |
1be0560e SC |
235 | void wxClientDC::DoGetSize(int *width, int *height) const |
236 | { | |
237 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
238 | ||
239 | m_window->GetClientSize( width, height ); | |
240 | } | |
4130e414 | 241 | #endif |
1be0560e | 242 | |
519cb848 SC |
243 | /* |
244 | * wxPaintDC | |
245 | */ | |
e9576ca5 | 246 | |
2f1ae414 | 247 | wxPaintDC::wxPaintDC() |
e9576ca5 | 248 | { |
1be0560e | 249 | m_window = NULL ; |
e9576ca5 SC |
250 | } |
251 | ||
4130e414 SC |
252 | #if wxMAC_USE_CORE_GRAPHICS |
253 | wxPaintDC::wxPaintDC(wxWindow *window) : | |
254 | wxWindowDC( window ) | |
255 | { | |
256 | wxPoint origin = window->GetClientAreaOrigin() ; | |
257 | wxSize size = window->GetClientSize() ; | |
258 | int x , y ; | |
259 | x = origin.x ; | |
260 | y = origin.y ; | |
261 | window->MacWindowToRootWindow( &x , &y ) ; | |
262 | m_window->GetClientSize( &m_width , &m_height); | |
263 | SetClippingRegion( 0 , 0 , m_width , m_height ) ; | |
264 | } | |
265 | #else | |
519cb848 | 266 | wxPaintDC::wxPaintDC(wxWindow *window) |
e9576ca5 | 267 | { |
1be0560e | 268 | m_window = window ; |
9f391ae1 SC |
269 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
270 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
271 | wxPoint origin = window->GetClientAreaOrigin() ; | |
272 | wxSize size = window->GetClientSize() ; | |
273 | int x , y ; | |
274 | x = origin.x ; | |
275 | y = origin.y ; | |
276 | window->MacWindowToRootWindow( &x , &y ) ; | |
277 | m_macPort = UMAGetWindowPort( windowref ) ; | |
eb1a7cf9 | 278 | m_ok = true ; |
9b2eab52 | 279 | |
20b69855 SC |
280 | #if wxMAC_USE_CORE_GRAPHICS |
281 | if ( window->MacGetCGContextRef() ) | |
282 | { | |
283 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
284 | m_graphicContext->SetPen( m_pen ) ; | |
285 | m_graphicContext->SetBrush( m_brush ) ; | |
9f391ae1 SC |
286 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; |
287 | SetBackground(MacGetBackgroundBrush(window)); | |
20b69855 SC |
288 | } |
289 | else | |
290 | { | |
291 | wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ; | |
292 | m_graphicContext = NULL ; | |
20b69855 SC |
293 | } |
294 | // there is no out-of-order drawing on OSX | |
295 | #else | |
e40298d5 JS |
296 | m_macLocalOrigin.x = x ; |
297 | m_macLocalOrigin.y = y ; | |
298 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
299 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
300 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
301 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
302 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
303 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 304 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 | 305 | #endif |
9b2eab52 | 306 | |
e40298d5 | 307 | SetFont( window->GetFont() ) ; |
e9576ca5 | 308 | } |
4130e414 | 309 | #endif |
e9576ca5 | 310 | |
519cb848 | 311 | wxPaintDC::~wxPaintDC() |
e9576ca5 | 312 | { |
519cb848 | 313 | } |
1be0560e | 314 | |
4130e414 | 315 | #if !wxMAC_USE_CORE_GRAPHICS |
1be0560e SC |
316 | void wxPaintDC::DoGetSize(int *width, int *height) const |
317 | { | |
318 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
319 | ||
320 | m_window->GetClientSize( width, height ); | |
321 | } | |
4130e414 | 322 | #endif |