]>
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 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 SC |
14 | #include "wx/dcclient.h" |
15 | #include "wx/dcmemory.h" | |
16 | #include "wx/region.h" | |
03e11df5 | 17 | #include "wx/window.h" |
456c94e1 | 18 | #include "wx/toplevel.h" |
5f5f809d | 19 | #include "wx/settings.h" |
463c4d71 | 20 | #include "wx/math.h" |
76a5e5d2 | 21 | #include "wx/mac/private.h" |
e928c28c | 22 | #include "wx/log.h" |
e9576ca5 SC |
23 | |
24 | //----------------------------------------------------------------------------- | |
25 | // constants | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | #define RAD2DEG 57.2957795131 | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // wxPaintDC | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
e9576ca5 SC |
34 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
35 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
36 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
e9576ca5 SC |
37 | |
38 | /* | |
39 | * wxWindowDC | |
40 | */ | |
41 | ||
d497dca4 | 42 | #include "wx/mac/uma.h" |
be346c26 SC |
43 | #include "wx/notebook.h" |
44 | #include "wx/tabctrl.h" | |
45 | ||
46 | ||
47 | static wxBrush MacGetBackgroundBrush( wxWindow* window ) | |
48 | { | |
49 | wxBrush bkdBrush = window->MacGetBackgroundBrush() ; | |
9b2eab52 | 50 | |
be346c26 SC |
51 | #if !TARGET_API_MAC_OSX |
52 | // transparency cannot be handled by the OS when not using composited windows | |
53 | wxWindow* parent = window->GetParent() ; | |
9b2eab52 | 54 | |
be346c26 SC |
55 | // if we have some 'pseudo' transparency |
56 | if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
57 | { | |
58 | // walk up until we find something | |
9b2eab52 | 59 | while ( parent != NULL ) |
be346c26 SC |
60 | { |
61 | if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
62 | { | |
63 | // if we have any other colours in the hierarchy | |
64 | bkdBrush.SetColour( parent->GetBackgroundColour() ) ; | |
65 | break ; | |
66 | } | |
9b2eab52 | 67 | |
be346c26 SC |
68 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) |
69 | { | |
70 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
71 | break ; | |
72 | } | |
9b2eab52 | 73 | |
be346c26 SC |
74 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) ) |
75 | { | |
76 | Rect extent = { 0 , 0 , 0 , 0 } ; | |
77 | int x , y ; | |
78 | x = y = 0 ; | |
79 | wxSize size = parent->GetSize() ; | |
80 | parent->MacClientToRootWindow( &x , &y ) ; | |
81 | extent.left = x ; | |
82 | extent.top = y ; | |
83 | extent.top-- ; | |
84 | extent.right = x + size.x ; | |
85 | extent.bottom = y + size.y ; | |
86 | bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; | |
87 | break ; | |
88 | } | |
89 | ||
90 | parent = parent->GetParent() ; | |
91 | } | |
92 | } | |
9b2eab52 | 93 | |
be346c26 SC |
94 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) |
95 | { | |
96 | // if we did not find something, use a default | |
97 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
98 | } | |
9b2eab52 DS |
99 | #endif |
100 | ||
be346c26 SC |
101 | return bkdBrush ; |
102 | } | |
103 | ||
2f1ae414 | 104 | wxWindowDC::wxWindowDC() |
e9576ca5 | 105 | { |
1be0560e | 106 | m_window = NULL ; |
519cb848 | 107 | } |
e9576ca5 | 108 | |
1be0560e | 109 | wxWindowDC::wxWindowDC(wxWindow *window) |
519cb848 | 110 | { |
1be0560e | 111 | m_window = window ; |
9f391ae1 SC |
112 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
113 | if (!rootwindow) | |
114 | return; | |
9b2eab52 | 115 | |
9f391ae1 SC |
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 | 154 | #endif |
9b2eab52 DS |
155 | |
156 | m_ok = true ; | |
20b69855 | 157 | SetFont( window->GetFont() ) ; |
519cb848 | 158 | } |
e9576ca5 | 159 | |
2f1ae414 | 160 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 161 | { |
519cb848 | 162 | } |
e9576ca5 | 163 | |
1be0560e SC |
164 | void wxWindowDC::DoGetSize( int* width, int* height ) const |
165 | { | |
166 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
167 | ||
168 | m_window->GetSize(width, height); | |
169 | } | |
170 | ||
519cb848 SC |
171 | /* |
172 | * wxClientDC | |
173 | */ | |
e9576ca5 | 174 | |
2f1ae414 | 175 | wxClientDC::wxClientDC() |
e9576ca5 | 176 | { |
1be0560e | 177 | m_window = NULL ; |
e9576ca5 SC |
178 | } |
179 | ||
519cb848 | 180 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 181 | { |
1be0560e | 182 | m_window = window ; |
9f391ae1 SC |
183 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
184 | if (!rootwindow) | |
185 | return; | |
9b2eab52 | 186 | |
9f391ae1 SC |
187 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; |
188 | wxPoint origin = window->GetClientAreaOrigin() ; | |
189 | wxSize size = window->GetClientSize() ; | |
190 | int x , y ; | |
191 | x = origin.x ; | |
192 | y = origin.y ; | |
193 | window->MacWindowToRootWindow( &x , &y ) ; | |
194 | m_macPort = UMAGetWindowPort( windowref ) ; | |
195 | ||
20b69855 | 196 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
197 | m_macLocalOriginInPort.x = x ; |
198 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
199 | if ( window->MacGetCGContextRef() ) |
200 | { | |
201 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
202 | m_graphicContext->SetPen( m_pen ) ; | |
203 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 | 204 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; |
20b69855 SC |
205 | SetBackground(MacGetBackgroundBrush(window)); |
206 | } | |
207 | else | |
208 | { | |
cb4b0966 SC |
209 | // as out of order redraw is not supported under CQ, we have to create a qd port for these |
210 | // situations | |
20b69855 SC |
211 | m_macLocalOrigin.x = x ; |
212 | m_macLocalOrigin.y = y ; | |
9f391ae1 | 213 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; |
20b69855 SC |
214 | m_graphicContext->SetPen( m_pen ) ; |
215 | m_graphicContext->SetBrush( m_brush ) ; | |
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 ) ; | |
20b69855 | 225 | #endif |
9b2eab52 DS |
226 | |
227 | m_ok = true ; | |
be346c26 | 228 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 229 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
230 | } |
231 | ||
2f1ae414 | 232 | wxClientDC::~wxClientDC() |
e9576ca5 | 233 | { |
68654a82 SC |
234 | #if wxMAC_USE_CORE_GRAPHICS |
235 | /* | |
236 | if ( m_window->MacGetCGContextRef() == 0) | |
237 | { | |
bc8f7aee | 238 | CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ; |
68654a82 SC |
239 | CGContextFlush( cgContext ) ; |
240 | } | |
241 | */ | |
242 | #endif | |
e9576ca5 SC |
243 | } |
244 | ||
1be0560e SC |
245 | void wxClientDC::DoGetSize(int *width, int *height) const |
246 | { | |
247 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
248 | ||
249 | m_window->GetClientSize( width, height ); | |
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 ) ; | |
9b2eab52 | 273 | |
20b69855 | 274 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
275 | m_macLocalOriginInPort.x = x ; |
276 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
277 | if ( window->MacGetCGContextRef() ) |
278 | { | |
279 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
280 | m_graphicContext->SetPen( m_pen ) ; | |
281 | m_graphicContext->SetBrush( m_brush ) ; | |
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 ; | |
20b69855 SC |
289 | } |
290 | // there is no out-of-order drawing on OSX | |
291 | #else | |
e40298d5 JS |
292 | m_macLocalOrigin.x = x ; |
293 | m_macLocalOrigin.y = y ; | |
294 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
295 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
296 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
297 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
298 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
299 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 300 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 | 301 | #endif |
9b2eab52 DS |
302 | |
303 | m_ok = true ; | |
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 | } |