]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
reintroducing direct access, cleanup
[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"
e928c28c 26#include "wx/log.h"
e9576ca5
SC
27
28//-----------------------------------------------------------------------------
29// constants
30//-----------------------------------------------------------------------------
31
32#define RAD2DEG 57.2957795131
33
34//-----------------------------------------------------------------------------
35// wxPaintDC
36//-----------------------------------------------------------------------------
37
2f1ae414 38#if !USE_SHARED_LIBRARY
e9576ca5
SC
39IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
40IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
41IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
2f1ae414 42#endif
e9576ca5
SC
43
44/*
45 * wxWindowDC
46 */
47
d497dca4 48#include "wx/mac/uma.h"
be346c26
SC
49#include "wx/notebook.h"
50#include "wx/tabctrl.h"
51
52
53static wxBrush MacGetBackgroundBrush( wxWindow* window )
54{
55 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
56#if !TARGET_API_MAC_OSX
57 // transparency cannot be handled by the OS when not using composited windows
58 wxWindow* parent = window->GetParent() ;
59 // if we have some 'pseudo' transparency
60 if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
61 {
62 // walk up until we find something
63 while( parent != NULL )
64 {
65 if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
66 {
67 // if we have any other colours in the hierarchy
68 bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
69 break ;
70 }
71 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
72 {
73 bkdBrush = parent->MacGetBackgroundBrush() ;
74 break ;
75 }
76 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
77 {
78 Rect extent = { 0 , 0 , 0 , 0 } ;
79 int x , y ;
80 x = y = 0 ;
81 wxSize size = parent->GetSize() ;
82 parent->MacClientToRootWindow( &x , &y ) ;
83 extent.left = x ;
84 extent.top = y ;
85 extent.top-- ;
86 extent.right = x + size.x ;
87 extent.bottom = y + size.y ;
88 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
89 break ;
90 }
91
92 parent = parent->GetParent() ;
93 }
94 }
95 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
96 {
97 // if we did not find something, use a default
98 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
99 }
100#endif
101 return bkdBrush ;
102}
103
519cb848 104
2f1ae414 105wxWindowDC::wxWindowDC()
e9576ca5 106{
1be0560e 107 m_window = NULL ;
519cb848 108}
e9576ca5 109
1be0560e 110wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 111{
1be0560e 112 m_window = window ;
20b69855
SC
113#if wxMAC_USE_CORE_GRAPHICS
114 if ( window->MacGetCGContextRef() )
115 {
116 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
117 m_graphicContext->SetPen( m_pen ) ;
118 m_graphicContext->SetBrush( m_brush ) ;
e2f92883 119 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
120 }
121 else
cb4b0966
SC
122 {
123 // as out of order redraw is not supported under CQ, we have to create a qd port for these
124 // situations
125 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
126 if (!rootwindow)
127 return;
128 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
cb4b0966
SC
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 ) ;
e2f92883
SC
190 wxSize size = window->GetClientSize() ;
191 m_ok = TRUE ;
192 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
20b69855
SC
193 SetBackground(MacGetBackgroundBrush(window));
194 }
195 else
196 {
cb4b0966
SC
197 // as out of order redraw is not supported under CQ, we have to create a qd port for these
198 // situations
20b69855
SC
199 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
200 if (!rootwindow)
201 return;
202 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
203 wxPoint origin = window->GetClientAreaOrigin() ;
20b69855
SC
204 int x , y ;
205 x = origin.x ;
206 y = origin.y ;
207 window->MacWindowToRootWindow( &x , &y ) ;
208 m_macLocalOrigin.x = x ;
209 m_macLocalOrigin.y = y ;
210 CGrafPtr port = UMAGetWindowPort( windowref ) ;
211
212 m_graphicContext = new wxMacCGContext( port ) ;
213 m_graphicContext->SetPen( m_pen ) ;
214 m_graphicContext->SetBrush( m_brush ) ;
e2f92883 215 m_ok = TRUE ;
cb4b0966 216 }
20b69855 217#else
e40298d5
JS
218 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
219 if (!rootwindow)
220 return;
221 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
222 wxPoint origin = window->GetClientAreaOrigin() ;
223 wxSize size = window->GetClientSize() ;
224 int x , y ;
225 x = origin.x ;
226 y = origin.y ;
227 window->MacWindowToRootWindow( &x , &y ) ;
228 m_macLocalOrigin.x = x ;
229 m_macLocalOrigin.y = y ;
230 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
231 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
232 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
233 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
234 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
235 m_macPort = UMAGetWindowPort( windowref ) ;
e40298d5 236 m_ok = TRUE ;
20b69855 237#endif
be346c26 238 SetBackground(MacGetBackgroundBrush(window));
e40298d5 239 SetFont( window->GetFont() ) ;
e9576ca5
SC
240}
241
2f1ae414 242wxClientDC::~wxClientDC()
e9576ca5 243{
e9576ca5
SC
244}
245
1be0560e
SC
246void wxClientDC::DoGetSize(int *width, int *height) const
247{
248 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
249
250 m_window->GetClientSize( width, height );
251}
252
253
519cb848
SC
254/*
255 * wxPaintDC
256 */
e9576ca5 257
2f1ae414 258wxPaintDC::wxPaintDC()
e9576ca5 259{
1be0560e 260 m_window = NULL ;
e9576ca5
SC
261}
262
519cb848 263wxPaintDC::wxPaintDC(wxWindow *window)
e9576ca5 264{
1be0560e 265 m_window = window ;
20b69855
SC
266#if wxMAC_USE_CORE_GRAPHICS
267 if ( window->MacGetCGContextRef() )
268 {
269 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
270 m_graphicContext->SetPen( m_pen ) ;
271 m_graphicContext->SetBrush( m_brush ) ;
272 SetBackground(MacGetBackgroundBrush(window));
273 m_ok = TRUE ;
274 }
275 else
276 {
277 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
278 m_graphicContext = NULL ;
279 m_ok = TRUE ;
280 }
281 // there is no out-of-order drawing on OSX
282#else
e40298d5
JS
283 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
284 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
285 wxPoint origin = window->GetClientAreaOrigin() ;
286 wxSize size = window->GetClientSize() ;
287 int x , y ;
288 x = origin.x ;
289 y = origin.y ;
290 window->MacWindowToRootWindow( &x , &y ) ;
291 m_macLocalOrigin.x = x ;
292 m_macLocalOrigin.y = y ;
293 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
294 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
295 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
296 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
297 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
298 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
299 m_macPort = UMAGetWindowPort( windowref ) ;
be346c26 300 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
301 m_ok = TRUE ;
302#endif
e40298d5 303 SetFont( window->GetFont() ) ;
e9576ca5
SC
304}
305
519cb848 306wxPaintDC::~wxPaintDC()
e9576ca5 307{
519cb848 308}
1be0560e
SC
309
310void wxPaintDC::DoGetSize(int *width, int *height) const
311{
312 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
313
314 m_window->GetClientSize( width, height );
315}
316
317