]>
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 | ||
e9576ca5 SC |
38 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
39 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
40 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
e9576ca5 SC |
41 | |
42 | /* | |
43 | * wxWindowDC | |
44 | */ | |
45 | ||
d497dca4 | 46 | #include "wx/mac/uma.h" |
be346c26 SC |
47 | #include "wx/notebook.h" |
48 | #include "wx/tabctrl.h" | |
49 | ||
50 | ||
51 | static wxBrush MacGetBackgroundBrush( wxWindow* window ) | |
52 | { | |
53 | wxBrush bkdBrush = window->MacGetBackgroundBrush() ; | |
54 | #if !TARGET_API_MAC_OSX | |
55 | // transparency cannot be handled by the OS when not using composited windows | |
56 | wxWindow* parent = window->GetParent() ; | |
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 | |
61 | while( parent != NULL ) | |
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 | } | |
69 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) | |
70 | { | |
71 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
72 | break ; | |
73 | } | |
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 | } | |
93 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) | |
94 | { | |
95 | // if we did not find something, use a default | |
96 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
97 | } | |
98 | #endif | |
99 | return bkdBrush ; | |
100 | } | |
101 | ||
519cb848 | 102 | |
2f1ae414 | 103 | wxWindowDC::wxWindowDC() |
e9576ca5 | 104 | { |
1be0560e | 105 | m_window = NULL ; |
519cb848 | 106 | } |
e9576ca5 | 107 | |
1be0560e | 108 | wxWindowDC::wxWindowDC(wxWindow *window) |
519cb848 | 109 | { |
1be0560e | 110 | m_window = window ; |
9f391ae1 SC |
111 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
112 | if (!rootwindow) | |
113 | return; | |
114 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
115 | int x , y ; | |
116 | x = y = 0 ; | |
117 | wxSize size = window->GetSize() ; | |
118 | window->MacWindowToRootWindow( &x , &y ) ; | |
119 | m_macPort = UMAGetWindowPort( windowref ) ; | |
120 | ||
20b69855 | 121 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
122 | m_macLocalOriginInPort.x = x ; |
123 | m_macLocalOriginInPort.y = y ; | |
124 | ||
20b69855 SC |
125 | if ( window->MacGetCGContextRef() ) |
126 | { | |
127 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
128 | m_graphicContext->SetPen( m_pen ) ; | |
129 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 | 130 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
131 | } |
132 | else | |
cb4b0966 SC |
133 | { |
134 | // as out of order redraw is not supported under CQ, we have to create a qd port for these | |
135 | // situations | |
cb4b0966 SC |
136 | m_macLocalOrigin.x = x ; |
137 | m_macLocalOrigin.y = y ; | |
cb4b0966 | 138 | |
9f391ae1 | 139 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; |
cb4b0966 SC |
140 | m_graphicContext->SetPen( m_pen ) ; |
141 | m_graphicContext->SetBrush( m_brush ) ; | |
142 | SetBackground(MacGetBackgroundBrush(window)); | |
143 | } | |
20b69855 SC |
144 | // there is no out-of-order drawing on OSX |
145 | #else | |
e40298d5 JS |
146 | m_macLocalOrigin.x = x ; |
147 | m_macLocalOrigin.y = y ; | |
cf9d0f93 | 148 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; |
e40298d5 JS |
149 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; |
150 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 151 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
152 | #endif |
153 | m_ok = TRUE ; | |
154 | SetFont( window->GetFont() ) ; | |
519cb848 | 155 | } |
e9576ca5 | 156 | |
2f1ae414 | 157 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 158 | { |
519cb848 | 159 | } |
e9576ca5 | 160 | |
1be0560e SC |
161 | void wxWindowDC::DoGetSize( int* width, int* height ) const |
162 | { | |
163 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
164 | ||
165 | m_window->GetSize(width, height); | |
166 | } | |
167 | ||
519cb848 SC |
168 | /* |
169 | * wxClientDC | |
170 | */ | |
e9576ca5 | 171 | |
2f1ae414 | 172 | wxClientDC::wxClientDC() |
e9576ca5 | 173 | { |
1be0560e | 174 | m_window = NULL ; |
e9576ca5 SC |
175 | } |
176 | ||
519cb848 | 177 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 178 | { |
1be0560e | 179 | m_window = window ; |
9f391ae1 SC |
180 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
181 | if (!rootwindow) | |
182 | return; | |
183 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
184 | wxPoint origin = window->GetClientAreaOrigin() ; | |
185 | wxSize size = window->GetClientSize() ; | |
186 | int x , y ; | |
187 | x = origin.x ; | |
188 | y = origin.y ; | |
189 | window->MacWindowToRootWindow( &x , &y ) ; | |
190 | m_macPort = UMAGetWindowPort( windowref ) ; | |
191 | ||
20b69855 | 192 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
193 | m_macLocalOriginInPort.x = x ; |
194 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
195 | if ( window->MacGetCGContextRef() ) |
196 | { | |
197 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
198 | m_graphicContext->SetPen( m_pen ) ; | |
199 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 SC |
200 | m_ok = TRUE ; |
201 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; | |
20b69855 SC |
202 | SetBackground(MacGetBackgroundBrush(window)); |
203 | } | |
204 | else | |
205 | { | |
cb4b0966 SC |
206 | // as out of order redraw is not supported under CQ, we have to create a qd port for these |
207 | // situations | |
20b69855 SC |
208 | m_macLocalOrigin.x = x ; |
209 | m_macLocalOrigin.y = y ; | |
9f391ae1 | 210 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; |
20b69855 SC |
211 | m_graphicContext->SetPen( m_pen ) ; |
212 | m_graphicContext->SetBrush( m_brush ) ; | |
e2f92883 | 213 | m_ok = TRUE ; |
cb4b0966 | 214 | } |
20b69855 | 215 | #else |
e40298d5 JS |
216 | m_macLocalOrigin.x = x ; |
217 | m_macLocalOrigin.y = y ; | |
218 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
219 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
220 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
221 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
222 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
e40298d5 | 223 | m_ok = TRUE ; |
20b69855 | 224 | #endif |
be346c26 | 225 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 226 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
227 | } |
228 | ||
2f1ae414 | 229 | wxClientDC::~wxClientDC() |
e9576ca5 | 230 | { |
68654a82 SC |
231 | #if wxMAC_USE_CORE_GRAPHICS |
232 | /* | |
233 | if ( m_window->MacGetCGContextRef() == 0) | |
234 | { | |
bc8f7aee | 235 | CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ; |
68654a82 SC |
236 | CGContextFlush( cgContext ) ; |
237 | } | |
238 | */ | |
239 | #endif | |
e9576ca5 SC |
240 | } |
241 | ||
1be0560e SC |
242 | void wxClientDC::DoGetSize(int *width, int *height) const |
243 | { | |
244 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
245 | ||
246 | m_window->GetClientSize( width, height ); | |
247 | } | |
248 | ||
249 | ||
519cb848 SC |
250 | /* |
251 | * wxPaintDC | |
252 | */ | |
e9576ca5 | 253 | |
2f1ae414 | 254 | wxPaintDC::wxPaintDC() |
e9576ca5 | 255 | { |
1be0560e | 256 | m_window = NULL ; |
e9576ca5 SC |
257 | } |
258 | ||
519cb848 | 259 | wxPaintDC::wxPaintDC(wxWindow *window) |
e9576ca5 | 260 | { |
1be0560e | 261 | m_window = window ; |
9f391ae1 SC |
262 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
263 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
264 | wxPoint origin = window->GetClientAreaOrigin() ; | |
265 | wxSize size = window->GetClientSize() ; | |
266 | int x , y ; | |
267 | x = origin.x ; | |
268 | y = origin.y ; | |
269 | window->MacWindowToRootWindow( &x , &y ) ; | |
270 | m_macPort = UMAGetWindowPort( windowref ) ; | |
20b69855 | 271 | #if wxMAC_USE_CORE_GRAPHICS |
9f391ae1 SC |
272 | m_macLocalOriginInPort.x = x ; |
273 | m_macLocalOriginInPort.y = y ; | |
20b69855 SC |
274 | if ( window->MacGetCGContextRef() ) |
275 | { | |
276 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
277 | m_graphicContext->SetPen( m_pen ) ; | |
278 | m_graphicContext->SetBrush( m_brush ) ; | |
20b69855 | 279 | m_ok = TRUE ; |
9f391ae1 SC |
280 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; |
281 | SetBackground(MacGetBackgroundBrush(window)); | |
20b69855 SC |
282 | } |
283 | else | |
284 | { | |
285 | wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ; | |
286 | m_graphicContext = NULL ; | |
287 | m_ok = TRUE ; | |
288 | } | |
289 | // there is no out-of-order drawing on OSX | |
290 | #else | |
e40298d5 JS |
291 | m_macLocalOrigin.x = x ; |
292 | m_macLocalOrigin.y = y ; | |
293 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
294 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
295 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
296 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
297 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
298 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
be346c26 | 299 | SetBackground(MacGetBackgroundBrush(window)); |
20b69855 SC |
300 | m_ok = TRUE ; |
301 | #endif | |
e40298d5 | 302 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
303 | } |
304 | ||
519cb848 | 305 | wxPaintDC::~wxPaintDC() |
e9576ca5 | 306 | { |
519cb848 | 307 | } |
1be0560e SC |
308 | |
309 | void wxPaintDC::DoGetSize(int *width, int *height) const | |
310 | { | |
311 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
312 | ||
313 | m_window->GetClientSize( width, height ); | |
314 | } | |
315 | ||
316 |