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