]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: dcclient.cpp | |
3 | // Purpose: wxClientDC class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/dcclient.h" | |
15 | #include "wx/dcmemory.h" | |
16 | #include "wx/region.h" | |
17 | #include "wx/window.h" | |
18 | #include "wx/toplevel.h" | |
19 | #include "wx/settings.h" | |
20 | #include "wx/math.h" | |
21 | #include "wx/mac/private.h" | |
22 | #include "wx/log.h" | |
23 | ||
24 | //----------------------------------------------------------------------------- | |
25 | // constants | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | #define RAD2DEG 57.2957795131 | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // wxPaintDC | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) | |
35 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
36 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
37 | ||
38 | /* | |
39 | * wxWindowDC | |
40 | */ | |
41 | ||
42 | #include "wx/mac/uma.h" | |
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 | ||
51 | #if !TARGET_API_MAC_OSX | |
52 | // transparency cannot be handled by the OS when not using composited windows | |
53 | wxWindow* parent = window->GetParent() ; | |
54 | ||
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 | |
59 | while ( parent != NULL ) | |
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 | } | |
67 | ||
68 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) | |
69 | { | |
70 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
71 | break ; | |
72 | } | |
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 | ||
94 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) | |
95 | { | |
96 | // if we did not find something, use a default | |
97 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
98 | } | |
99 | #endif | |
100 | ||
101 | return bkdBrush ; | |
102 | } | |
103 | ||
104 | wxWindowDC::wxWindowDC() | |
105 | { | |
106 | m_window = NULL ; | |
107 | } | |
108 | ||
109 | wxWindowDC::wxWindowDC(wxWindow *window) | |
110 | { | |
111 | m_window = window ; | |
112 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; | |
113 | if (!rootwindow) | |
114 | return; | |
115 | ||
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 | m_ok = true ; | |
123 | ||
124 | #if wxMAC_USE_CORE_GRAPHICS | |
125 | m_macLocalOriginInPort.x = x ; | |
126 | m_macLocalOriginInPort.y = y ; | |
127 | ||
128 | if ( window->MacGetCGContextRef() ) | |
129 | { | |
130 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
131 | m_graphicContext->SetPen( m_pen ) ; | |
132 | m_graphicContext->SetBrush( m_brush ) ; | |
133 | } | |
134 | else | |
135 | { | |
136 | // as out of order redraw is not supported under CQ, we have to create a qd port for these | |
137 | // situations | |
138 | m_macLocalOrigin.x = x ; | |
139 | m_macLocalOrigin.y = y ; | |
140 | ||
141 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; | |
142 | m_graphicContext->SetPen( m_pen ) ; | |
143 | m_graphicContext->SetBrush( m_brush ) ; | |
144 | } | |
145 | // there is no out-of-order drawing on OSX | |
146 | #else | |
147 | m_macLocalOrigin.x = x ; | |
148 | m_macLocalOrigin.y = y ; | |
149 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
150 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
151 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
152 | #endif | |
153 | SetBackground(MacGetBackgroundBrush(window)); | |
154 | ||
155 | SetFont( window->GetFont() ) ; | |
156 | } | |
157 | ||
158 | wxWindowDC::~wxWindowDC() | |
159 | { | |
160 | } | |
161 | ||
162 | void wxWindowDC::DoGetSize( int* width, int* height ) const | |
163 | { | |
164 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
165 | ||
166 | m_window->GetSize(width, height); | |
167 | } | |
168 | ||
169 | /* | |
170 | * wxClientDC | |
171 | */ | |
172 | ||
173 | wxClientDC::wxClientDC() | |
174 | { | |
175 | m_window = NULL ; | |
176 | } | |
177 | ||
178 | wxClientDC::wxClientDC(wxWindow *window) | |
179 | { | |
180 | m_window = window ; | |
181 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; | |
182 | if (!rootwindow) | |
183 | return; | |
184 | ||
185 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
186 | wxPoint origin = window->GetClientAreaOrigin() ; | |
187 | wxSize size = window->GetClientSize() ; | |
188 | int x , y ; | |
189 | x = origin.x ; | |
190 | y = origin.y ; | |
191 | window->MacWindowToRootWindow( &x , &y ) ; | |
192 | m_macPort = UMAGetWindowPort( windowref ) ; | |
193 | m_ok = true ; | |
194 | ||
195 | #if wxMAC_USE_CORE_GRAPHICS | |
196 | m_macLocalOriginInPort.x = x ; | |
197 | m_macLocalOriginInPort.y = y ; | |
198 | if ( window->MacGetCGContextRef() ) | |
199 | { | |
200 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
201 | m_graphicContext->SetPen( m_pen ) ; | |
202 | m_graphicContext->SetBrush( m_brush ) ; | |
203 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; | |
204 | } | |
205 | else | |
206 | { | |
207 | // as out of order redraw is not supported under CQ, | |
208 | // we have to create a QD port for these situations | |
209 | m_macLocalOrigin.x = x ; | |
210 | m_macLocalOrigin.y = y ; | |
211 | m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ; | |
212 | m_graphicContext->SetPen( m_pen ) ; | |
213 | m_graphicContext->SetBrush( m_brush ) ; | |
214 | } | |
215 | #else | |
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 ) ; | |
223 | #endif | |
224 | ||
225 | SetBackground(MacGetBackgroundBrush(window)); | |
226 | SetFont( window->GetFont() ) ; | |
227 | } | |
228 | ||
229 | wxClientDC::~wxClientDC() | |
230 | { | |
231 | #if wxMAC_USE_CORE_GRAPHICS | |
232 | /* | |
233 | if ( m_window->MacGetCGContextRef() == 0) | |
234 | { | |
235 | CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ; | |
236 | CGContextFlush( cgContext ) ; | |
237 | } | |
238 | */ | |
239 | #endif | |
240 | } | |
241 | ||
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 | /* | |
250 | * wxPaintDC | |
251 | */ | |
252 | ||
253 | wxPaintDC::wxPaintDC() | |
254 | { | |
255 | m_window = NULL ; | |
256 | } | |
257 | ||
258 | wxPaintDC::wxPaintDC(wxWindow *window) | |
259 | { | |
260 | m_window = window ; | |
261 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; | |
262 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
263 | wxPoint origin = window->GetClientAreaOrigin() ; | |
264 | wxSize size = window->GetClientSize() ; | |
265 | int x , y ; | |
266 | x = origin.x ; | |
267 | y = origin.y ; | |
268 | window->MacWindowToRootWindow( &x , &y ) ; | |
269 | m_macPort = UMAGetWindowPort( windowref ) ; | |
270 | m_ok = true ; | |
271 | ||
272 | #if wxMAC_USE_CORE_GRAPHICS | |
273 | m_macLocalOriginInPort.x = x ; | |
274 | m_macLocalOriginInPort.y = y ; | |
275 | if ( window->MacGetCGContextRef() ) | |
276 | { | |
277 | m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ; | |
278 | m_graphicContext->SetPen( m_pen ) ; | |
279 | m_graphicContext->SetBrush( m_brush ) ; | |
280 | SetClippingRegion( 0 , 0 , size.x , size.y ) ; | |
281 | SetBackground(MacGetBackgroundBrush(window)); | |
282 | } | |
283 | else | |
284 | { | |
285 | wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ; | |
286 | m_graphicContext = NULL ; | |
287 | } | |
288 | // there is no out-of-order drawing on OSX | |
289 | #else | |
290 | m_macLocalOrigin.x = x ; | |
291 | m_macLocalOrigin.y = y ; | |
292 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
293 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
294 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
295 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
296 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
297 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
298 | SetBackground(MacGetBackgroundBrush(window)); | |
299 | #endif | |
300 | ||
301 | SetFont( window->GetFont() ) ; | |
302 | } | |
303 | ||
304 | wxPaintDC::~wxPaintDC() | |
305 | { | |
306 | } | |
307 | ||
308 | void wxPaintDC::DoGetSize(int *width, int *height) const | |
309 | { | |
310 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
311 | ||
312 | m_window->GetClientSize( width, height ); | |
313 | } |