]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
Missing header.
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/mac/carbon/dcclient.cpp
e9576ca5 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
e4db172a 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/dcclient.h"
e4db172a
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
cdccdfab 18 #include "wx/window.h"
f38924e8 19 #include "wx/dcmemory.h"
9eddec69 20 #include "wx/settings.h"
e4db172a
WS
21#endif
22
e9576ca5 23#include "wx/region.h"
456c94e1 24#include "wx/toplevel.h"
463c4d71 25#include "wx/math.h"
76a5e5d2 26#include "wx/mac/private.h"
e9576ca5
SC
27
28//-----------------------------------------------------------------------------
29// constants
30//-----------------------------------------------------------------------------
31
32#define RAD2DEG 57.2957795131
33
34//-----------------------------------------------------------------------------
35// wxPaintDC
36//-----------------------------------------------------------------------------
37
e9576ca5
SC
38IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
e9576ca5
SC
41
42/*
43 * wxWindowDC
44 */
45
d497dca4 46#include "wx/mac/uma.h"
be346c26
SC
47#include "wx/notebook.h"
48#include "wx/tabctrl.h"
e4db172a 49
be346c26
SC
50
51static wxBrush MacGetBackgroundBrush( wxWindow* window )
52{
53 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
9b2eab52 54
be346c26
SC
55#if !TARGET_API_MAC_OSX
56 // transparency cannot be handled by the OS when not using composited windows
57 wxWindow* parent = window->GetParent() ;
9b2eab52 58
be346c26
SC
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
9b2eab52 63 while ( parent != NULL )
be346c26
SC
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 }
9b2eab52 71
be346c26
SC
72 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
73 {
74 bkdBrush = parent->MacGetBackgroundBrush() ;
75 break ;
76 }
9b2eab52 77
7301b2b8
WS
78 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) )
79#if wxUSE_TAB_DIALOG
80 || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )
9eddec69 81#endif // wxUSE_TAB_DIALOG
7301b2b8 82 )
be346c26
SC
83 {
84 Rect extent = { 0 , 0 , 0 , 0 } ;
85 int x , y ;
86 x = y = 0 ;
87 wxSize size = parent->GetSize() ;
88 parent->MacClientToRootWindow( &x , &y ) ;
89 extent.left = x ;
90 extent.top = y ;
91 extent.top-- ;
92 extent.right = x + size.x ;
93 extent.bottom = y + size.y ;
e4db172a 94 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
be346c26
SC
95 break ;
96 }
e4db172a
WS
97
98 parent = parent->GetParent() ;
be346c26
SC
99 }
100 }
9b2eab52 101
be346c26
SC
102 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
103 {
104 // if we did not find something, use a default
105 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
106 }
9b2eab52
DS
107#endif
108
be346c26 109 return bkdBrush ;
e4db172a 110}
be346c26 111
e4db172a 112wxWindowDC::wxWindowDC()
e9576ca5 113{
1be0560e 114 m_window = NULL ;
519cb848 115}
e9576ca5 116
e4db172a 117wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 118{
1be0560e 119 m_window = window ;
9f391ae1
SC
120 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
121 if (!rootwindow)
122 return;
9b2eab52 123
9f391ae1
SC
124 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
125 int x , y ;
126 x = y = 0 ;
127 wxSize size = window->GetSize() ;
128 window->MacWindowToRootWindow( &x , &y ) ;
129 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9
DS
130 m_ok = true ;
131
20b69855 132#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
133 m_macLocalOriginInPort.x = x ;
134 m_macLocalOriginInPort.y = y ;
135
20b69855
SC
136 if ( window->MacGetCGContextRef() )
137 {
138 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
139 m_graphicContext->SetPen( m_pen ) ;
140 m_graphicContext->SetBrush( m_brush ) ;
20b69855
SC
141 }
142 else
cb4b0966
SC
143 {
144 // as out of order redraw is not supported under CQ, we have to create a qd port for these
145 // situations
cb4b0966
SC
146 m_macLocalOrigin.x = x ;
147 m_macLocalOrigin.y = y ;
e4db172a 148
9f391ae1 149 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
cb4b0966
SC
150 m_graphicContext->SetPen( m_pen ) ;
151 m_graphicContext->SetBrush( m_brush ) ;
cb4b0966 152 }
20b69855
SC
153 // there is no out-of-order drawing on OSX
154#else
e40298d5
JS
155 m_macLocalOrigin.x = x ;
156 m_macLocalOrigin.y = y ;
cf9d0f93 157 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
158 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
159 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
20b69855 160#endif
489d2dd3 161 SetBackground(MacGetBackgroundBrush(window));
9b2eab52 162
20b69855 163 SetFont( window->GetFont() ) ;
519cb848 164}
e9576ca5 165
2f1ae414 166wxWindowDC::~wxWindowDC()
e9576ca5 167{
519cb848 168}
e9576ca5 169
1be0560e
SC
170void wxWindowDC::DoGetSize( int* width, int* height ) const
171{
172 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
173
174 m_window->GetSize(width, height);
175}
176
519cb848
SC
177/*
178 * wxClientDC
179 */
e9576ca5 180
2f1ae414 181wxClientDC::wxClientDC()
e9576ca5 182{
1be0560e 183 m_window = NULL ;
e9576ca5
SC
184}
185
519cb848 186wxClientDC::wxClientDC(wxWindow *window)
e9576ca5 187{
1be0560e 188 m_window = window ;
9f391ae1
SC
189 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
190 if (!rootwindow)
191 return;
9b2eab52 192
9f391ae1
SC
193 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
194 wxPoint origin = window->GetClientAreaOrigin() ;
195 wxSize size = window->GetClientSize() ;
196 int x , y ;
197 x = origin.x ;
198 y = origin.y ;
199 window->MacWindowToRootWindow( &x , &y ) ;
200 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9
DS
201 m_ok = true ;
202
20b69855 203#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
204 m_macLocalOriginInPort.x = x ;
205 m_macLocalOriginInPort.y = y ;
20b69855
SC
206 if ( window->MacGetCGContextRef() )
207 {
208 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
209 m_graphicContext->SetPen( m_pen ) ;
210 m_graphicContext->SetBrush( m_brush ) ;
e2f92883 211 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
20b69855
SC
212 }
213 else
214 {
eb1a7cf9
DS
215 // as out of order redraw is not supported under CQ,
216 // we have to create a QD port for these situations
20b69855
SC
217 m_macLocalOrigin.x = x ;
218 m_macLocalOrigin.y = y ;
9f391ae1 219 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
20b69855
SC
220 m_graphicContext->SetPen( m_pen ) ;
221 m_graphicContext->SetBrush( m_brush ) ;
cb4b0966 222 }
20b69855 223#else
e40298d5
JS
224 m_macLocalOrigin.x = x ;
225 m_macLocalOrigin.y = y ;
226 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
227 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
228 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
229 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
230 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
20b69855 231#endif
9b2eab52 232
be346c26 233 SetBackground(MacGetBackgroundBrush(window));
e40298d5 234 SetFont( window->GetFont() ) ;
e9576ca5
SC
235}
236
2f1ae414 237wxClientDC::~wxClientDC()
e9576ca5 238{
68654a82
SC
239#if wxMAC_USE_CORE_GRAPHICS
240/*
241 if ( m_window->MacGetCGContextRef() == 0)
242 {
bc8f7aee 243 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
68654a82
SC
244 CGContextFlush( cgContext ) ;
245 }
246*/
247#endif
e9576ca5
SC
248}
249
1be0560e
SC
250void wxClientDC::DoGetSize(int *width, int *height) const
251{
252 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
253
254 m_window->GetClientSize( width, height );
255}
256
519cb848
SC
257/*
258 * wxPaintDC
259 */
e9576ca5 260
2f1ae414 261wxPaintDC::wxPaintDC()
e9576ca5 262{
1be0560e 263 m_window = NULL ;
e9576ca5
SC
264}
265
519cb848 266wxPaintDC::wxPaintDC(wxWindow *window)
e9576ca5 267{
1be0560e 268 m_window = window ;
9f391ae1
SC
269 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
270 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
271 wxPoint origin = window->GetClientAreaOrigin() ;
272 wxSize size = window->GetClientSize() ;
273 int x , y ;
274 x = origin.x ;
275 y = origin.y ;
276 window->MacWindowToRootWindow( &x , &y ) ;
277 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9 278 m_ok = true ;
9b2eab52 279
20b69855 280#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
281 m_macLocalOriginInPort.x = x ;
282 m_macLocalOriginInPort.y = y ;
20b69855
SC
283 if ( window->MacGetCGContextRef() )
284 {
285 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
286 m_graphicContext->SetPen( m_pen ) ;
287 m_graphicContext->SetBrush( m_brush ) ;
9f391ae1
SC
288 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
289 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
290 }
291 else
292 {
293 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
294 m_graphicContext = NULL ;
20b69855
SC
295 }
296 // there is no out-of-order drawing on OSX
297#else
e40298d5
JS
298 m_macLocalOrigin.x = x ;
299 m_macLocalOrigin.y = y ;
300 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
301 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
302 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
303 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
304 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
305 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
be346c26 306 SetBackground(MacGetBackgroundBrush(window));
20b69855 307#endif
9b2eab52 308
e40298d5 309 SetFont( window->GetFont() ) ;
e9576ca5
SC
310}
311
519cb848 312wxPaintDC::~wxPaintDC()
e9576ca5 313{
519cb848 314}
1be0560e
SC
315
316void wxPaintDC::DoGetSize(int *width, int *height) const
317{
318 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
319
320 m_window->GetClientSize( width, height );
321}