]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
cleanup - reformat
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
CommitLineData
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
34IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
35IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
36IMPLEMENT_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
47static 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 104wxWindowDC::wxWindowDC()
e9576ca5 105{
1be0560e 106 m_window = NULL ;
519cb848 107}
e9576ca5 108
1be0560e 109wxWindowDC::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 ) ;
eb1a7cf9
DS
122 m_ok = true ;
123
20b69855 124#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
125 m_macLocalOriginInPort.x = x ;
126 m_macLocalOriginInPort.y = y ;
127
20b69855
SC
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 ) ;
e2f92883 133 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
134 }
135 else
cb4b0966
SC
136 {
137 // as out of order redraw is not supported under CQ, we have to create a qd port for these
138 // situations
cb4b0966
SC
139 m_macLocalOrigin.x = x ;
140 m_macLocalOrigin.y = y ;
cb4b0966 141
9f391ae1 142 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
cb4b0966
SC
143 m_graphicContext->SetPen( m_pen ) ;
144 m_graphicContext->SetBrush( m_brush ) ;
145 SetBackground(MacGetBackgroundBrush(window));
146 }
20b69855
SC
147 // there is no out-of-order drawing on OSX
148#else
e40298d5
JS
149 m_macLocalOrigin.x = x ;
150 m_macLocalOrigin.y = y ;
cf9d0f93 151 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
152 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
153 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
be346c26 154 SetBackground(MacGetBackgroundBrush(window));
20b69855 155#endif
9b2eab52 156
20b69855 157 SetFont( window->GetFont() ) ;
519cb848 158}
e9576ca5 159
2f1ae414 160wxWindowDC::~wxWindowDC()
e9576ca5 161{
519cb848 162}
e9576ca5 163
1be0560e
SC
164void 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 175wxClientDC::wxClientDC()
e9576ca5 176{
1be0560e 177 m_window = NULL ;
e9576ca5
SC
178}
179
519cb848 180wxClientDC::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 ) ;
eb1a7cf9
DS
195 m_ok = true ;
196
20b69855 197#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
198 m_macLocalOriginInPort.x = x ;
199 m_macLocalOriginInPort.y = y ;
20b69855
SC
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 ) ;
e2f92883 205 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
20b69855
SC
206 SetBackground(MacGetBackgroundBrush(window));
207 }
208 else
209 {
eb1a7cf9
DS
210 // as out of order redraw is not supported under CQ,
211 // we have to create a QD port for these situations
20b69855
SC
212 m_macLocalOrigin.x = x ;
213 m_macLocalOrigin.y = y ;
9f391ae1 214 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
20b69855
SC
215 m_graphicContext->SetPen( m_pen ) ;
216 m_graphicContext->SetBrush( m_brush ) ;
cb4b0966 217 }
20b69855 218#else
e40298d5
JS
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 ) ;
20b69855 226#endif
9b2eab52 227
be346c26 228 SetBackground(MacGetBackgroundBrush(window));
e40298d5 229 SetFont( window->GetFont() ) ;
e9576ca5
SC
230}
231
2f1ae414 232wxClientDC::~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
245void 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 256wxPaintDC::wxPaintDC()
e9576ca5 257{
1be0560e 258 m_window = NULL ;
e9576ca5
SC
259}
260
519cb848 261wxPaintDC::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 ) ;
eb1a7cf9 273 m_ok = true ;
9b2eab52 274
20b69855 275#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
276 m_macLocalOriginInPort.x = x ;
277 m_macLocalOriginInPort.y = y ;
20b69855
SC
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 ) ;
9f391ae1
SC
283 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
284 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
285 }
286 else
287 {
288 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
289 m_graphicContext = NULL ;
20b69855
SC
290 }
291 // there is no out-of-order drawing on OSX
292#else
e40298d5
JS
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 ) ;
be346c26 301 SetBackground(MacGetBackgroundBrush(window));
20b69855 302#endif
9b2eab52 303
e40298d5 304 SetFont( window->GetFont() ) ;
e9576ca5
SC
305}
306
519cb848 307wxPaintDC::~wxPaintDC()
e9576ca5 308{
519cb848 309}
1be0560e
SC
310
311void 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}