]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
10.2 fix for CG
[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 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"
e9576ca5
SC
26
27//-----------------------------------------------------------------------------
28// constants
29//-----------------------------------------------------------------------------
30
31#define RAD2DEG 57.2957795131
32
33//-----------------------------------------------------------------------------
34// wxPaintDC
35//-----------------------------------------------------------------------------
36
2f1ae414 37#if !USE_SHARED_LIBRARY
e9576ca5
SC
38IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
2f1ae414 41#endif
e9576ca5
SC
42
43/*
44 * wxWindowDC
45 */
46
d497dca4 47#include "wx/mac/uma.h"
be346c26
SC
48#include "wx/notebook.h"
49#include "wx/tabctrl.h"
50
51
52static wxBrush MacGetBackgroundBrush( wxWindow* window )
53{
54 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
55#if !TARGET_API_MAC_OSX
56 // transparency cannot be handled by the OS when not using composited windows
57 wxWindow* parent = window->GetParent() ;
58 // if we have some 'pseudo' transparency
59 if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
60 {
61 // walk up until we find something
62 while( parent != NULL )
63 {
64 if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
65 {
66 // if we have any other colours in the hierarchy
67 bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
68 break ;
69 }
70 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
71 {
72 bkdBrush = parent->MacGetBackgroundBrush() ;
73 break ;
74 }
75 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
76 {
77 Rect extent = { 0 , 0 , 0 , 0 } ;
78 int x , y ;
79 x = y = 0 ;
80 wxSize size = parent->GetSize() ;
81 parent->MacClientToRootWindow( &x , &y ) ;
82 extent.left = x ;
83 extent.top = y ;
84 extent.top-- ;
85 extent.right = x + size.x ;
86 extent.bottom = y + size.y ;
87 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
88 break ;
89 }
90
91 parent = parent->GetParent() ;
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 return bkdBrush ;
101}
102
519cb848 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 ;
20b69855
SC
112#if wxMAC_USE_CORE_GRAPHICS
113 if ( window->MacGetCGContextRef() )
114 {
115 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
116 m_graphicContext->SetPen( m_pen ) ;
117 m_graphicContext->SetBrush( m_brush ) ;
118 SetBackground(MacGetBackgroundBrush(window));
119 }
120 else
cb4b0966
SC
121 {
122 // as out of order redraw is not supported under CQ, we have to create a qd port for these
123 // situations
124 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
125 if (!rootwindow)
126 return;
127 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
128 wxSize size = window->GetClientSize() ;
129 int x , y ;
130 x = y = 0 ;
131 window->MacWindowToRootWindow( &x , &y ) ;
132 m_macLocalOrigin.x = x ;
133 m_macLocalOrigin.y = y ;
134 CGrafPtr port = UMAGetWindowPort( windowref ) ;
135
136 m_graphicContext = new wxMacCGContext( port ) ;
137 m_graphicContext->SetPen( m_pen ) ;
138 m_graphicContext->SetBrush( m_brush ) ;
139 SetBackground(MacGetBackgroundBrush(window));
140 }
20b69855
SC
141 // there is no out-of-order drawing on OSX
142#else
1be0560e 143 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
e40298d5 144 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
e40298d5
JS
145 int x , y ;
146 x = y = 0 ;
1be0560e 147 window->MacWindowToRootWindow( &x , &y ) ;
e40298d5
JS
148 m_macLocalOrigin.x = x ;
149 m_macLocalOrigin.y = y ;
cf9d0f93 150 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
151 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
152 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
153 m_macPort = UMAGetWindowPort( windowref ) ;
be346c26 154 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
155#endif
156 m_ok = TRUE ;
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 ;
20b69855
SC
183#if wxMAC_USE_CORE_GRAPHICS
184 m_graphicContext = NULL ;
185 if ( window->MacGetCGContextRef() )
186 {
187 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
188 m_graphicContext->SetPen( m_pen ) ;
189 m_graphicContext->SetBrush( m_brush ) ;
190 SetBackground(MacGetBackgroundBrush(window));
191 }
192 else
193 {
cb4b0966
SC
194 // as out of order redraw is not supported under CQ, we have to create a qd port for these
195 // situations
20b69855
SC
196 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
197 if (!rootwindow)
198 return;
199 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
200 wxPoint origin = window->GetClientAreaOrigin() ;
201 wxSize size = window->GetClientSize() ;
202 int x , y ;
203 x = origin.x ;
204 y = origin.y ;
205 window->MacWindowToRootWindow( &x , &y ) ;
206 m_macLocalOrigin.x = x ;
207 m_macLocalOrigin.y = y ;
208 CGrafPtr port = UMAGetWindowPort( windowref ) ;
209
210 m_graphicContext = new wxMacCGContext( port ) ;
211 m_graphicContext->SetPen( m_pen ) ;
212 m_graphicContext->SetBrush( m_brush ) ;
213 SetBackground(MacGetBackgroundBrush(window));
cb4b0966 214 }
20b69855
SC
215 m_ok = TRUE ;
216#else
e40298d5
JS
217 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
218 if (!rootwindow)
219 return;
220 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
221 wxPoint origin = window->GetClientAreaOrigin() ;
222 wxSize size = window->GetClientSize() ;
223 int x , y ;
224 x = origin.x ;
225 y = origin.y ;
226 window->MacWindowToRootWindow( &x , &y ) ;
227 m_macLocalOrigin.x = x ;
228 m_macLocalOrigin.y = y ;
229 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
230 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
231 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
232 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
233 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
234 m_macPort = UMAGetWindowPort( windowref ) ;
e40298d5 235 m_ok = TRUE ;
20b69855 236#endif
be346c26 237 SetBackground(MacGetBackgroundBrush(window));
e40298d5 238 SetFont( window->GetFont() ) ;
e9576ca5
SC
239}
240
2f1ae414 241wxClientDC::~wxClientDC()
e9576ca5 242{
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
252
519cb848
SC
253/*
254 * wxPaintDC
255 */
e9576ca5 256
2f1ae414 257wxPaintDC::wxPaintDC()
e9576ca5 258{
1be0560e 259 m_window = NULL ;
e9576ca5
SC
260}
261
519cb848 262wxPaintDC::wxPaintDC(wxWindow *window)
e9576ca5 263{
1be0560e 264 m_window = window ;
20b69855
SC
265#if wxMAC_USE_CORE_GRAPHICS
266 if ( window->MacGetCGContextRef() )
267 {
268 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
269 m_graphicContext->SetPen( m_pen ) ;
270 m_graphicContext->SetBrush( m_brush ) ;
271 SetBackground(MacGetBackgroundBrush(window));
272 m_ok = TRUE ;
273 }
274 else
275 {
276 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
277 m_graphicContext = NULL ;
278 m_ok = TRUE ;
279 }
280 // there is no out-of-order drawing on OSX
281#else
e40298d5
JS
282 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
283 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
284 wxPoint origin = window->GetClientAreaOrigin() ;
285 wxSize size = window->GetClientSize() ;
286 int x , y ;
287 x = origin.x ;
288 y = origin.y ;
289 window->MacWindowToRootWindow( &x , &y ) ;
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 m_macPort = UMAGetWindowPort( windowref ) ;
be346c26 299 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
300 m_ok = TRUE ;
301#endif
e40298d5 302 SetFont( window->GetFont() ) ;
e9576ca5
SC
303}
304
519cb848 305wxPaintDC::~wxPaintDC()
e9576ca5 306{
519cb848 307}
1be0560e
SC
308
309void 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