]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
cleanup - reformat
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
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 SetBackground(MacGetBackgroundBrush(window));
134 }
135 else
136 {
137 // as out of order redraw is not supported under CQ, we have to create a qd port for these
138 // situations
139 m_macLocalOrigin.x = x ;
140 m_macLocalOrigin.y = y ;
141
142 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
143 m_graphicContext->SetPen( m_pen ) ;
144 m_graphicContext->SetBrush( m_brush ) ;
145 SetBackground(MacGetBackgroundBrush(window));
146 }
147 // there is no out-of-order drawing on OSX
148 #else
149 m_macLocalOrigin.x = x ;
150 m_macLocalOrigin.y = y ;
151 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
152 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
153 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
154 SetBackground(MacGetBackgroundBrush(window));
155 #endif
156
157 SetFont( window->GetFont() ) ;
158 }
159
160 wxWindowDC::~wxWindowDC()
161 {
162 }
163
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
171 /*
172 * wxClientDC
173 */
174
175 wxClientDC::wxClientDC()
176 {
177 m_window = NULL ;
178 }
179
180 wxClientDC::wxClientDC(wxWindow *window)
181 {
182 m_window = window ;
183 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
184 if (!rootwindow)
185 return;
186
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 m_ok = true ;
196
197 #if wxMAC_USE_CORE_GRAPHICS
198 m_macLocalOriginInPort.x = x ;
199 m_macLocalOriginInPort.y = y ;
200 if ( window->MacGetCGContextRef() )
201 {
202 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
203 m_graphicContext->SetPen( m_pen ) ;
204 m_graphicContext->SetBrush( m_brush ) ;
205 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
206 SetBackground(MacGetBackgroundBrush(window));
207 }
208 else
209 {
210 // as out of order redraw is not supported under CQ,
211 // we have to create a QD port for these situations
212 m_macLocalOrigin.x = x ;
213 m_macLocalOrigin.y = y ;
214 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
215 m_graphicContext->SetPen( m_pen ) ;
216 m_graphicContext->SetBrush( m_brush ) ;
217 }
218 #else
219 m_macLocalOrigin.x = x ;
220 m_macLocalOrigin.y = y ;
221 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
222 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
223 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
224 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
225 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
226 #endif
227
228 SetBackground(MacGetBackgroundBrush(window));
229 SetFont( window->GetFont() ) ;
230 }
231
232 wxClientDC::~wxClientDC()
233 {
234 #if wxMAC_USE_CORE_GRAPHICS
235 /*
236 if ( m_window->MacGetCGContextRef() == 0)
237 {
238 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
239 CGContextFlush( cgContext ) ;
240 }
241 */
242 #endif
243 }
244
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
252 /*
253 * wxPaintDC
254 */
255
256 wxPaintDC::wxPaintDC()
257 {
258 m_window = NULL ;
259 }
260
261 wxPaintDC::wxPaintDC(wxWindow *window)
262 {
263 m_window = window ;
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 ) ;
273 m_ok = true ;
274
275 #if wxMAC_USE_CORE_GRAPHICS
276 m_macLocalOriginInPort.x = x ;
277 m_macLocalOriginInPort.y = y ;
278 if ( window->MacGetCGContextRef() )
279 {
280 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
281 m_graphicContext->SetPen( m_pen ) ;
282 m_graphicContext->SetBrush( m_brush ) ;
283 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
284 SetBackground(MacGetBackgroundBrush(window));
285 }
286 else
287 {
288 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
289 m_graphicContext = NULL ;
290 }
291 // there is no out-of-order drawing on OSX
292 #else
293 m_macLocalOrigin.x = x ;
294 m_macLocalOrigin.y = y ;
295 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
296 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
297 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
298 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
299 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
300 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
301 SetBackground(MacGetBackgroundBrush(window));
302 #endif
303
304 SetFont( window->GetFont() ) ;
305 }
306
307 wxPaintDC::~wxPaintDC()
308 {
309 }
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 }