]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
default button on older systems was not shown with OK, but empty, resulting in wxID_C...
[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"
18#endif
19
e9576ca5
SC
20#include "wx/dcmemory.h"
21#include "wx/region.h"
03e11df5 22#include "wx/window.h"
456c94e1 23#include "wx/toplevel.h"
5f5f809d 24#include "wx/settings.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
be346c26
SC
78 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
79 {
80 Rect extent = { 0 , 0 , 0 , 0 } ;
81 int x , y ;
82 x = y = 0 ;
83 wxSize size = parent->GetSize() ;
84 parent->MacClientToRootWindow( &x , &y ) ;
85 extent.left = x ;
86 extent.top = y ;
87 extent.top-- ;
88 extent.right = x + size.x ;
89 extent.bottom = y + size.y ;
e4db172a 90 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
be346c26
SC
91 break ;
92 }
e4db172a
WS
93
94 parent = parent->GetParent() ;
be346c26
SC
95 }
96 }
9b2eab52 97
be346c26
SC
98 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
99 {
100 // if we did not find something, use a default
101 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
102 }
9b2eab52
DS
103#endif
104
be346c26 105 return bkdBrush ;
e4db172a 106}
be346c26 107
e4db172a 108wxWindowDC::wxWindowDC()
e9576ca5 109{
1be0560e 110 m_window = NULL ;
519cb848 111}
e9576ca5 112
e4db172a 113wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 114{
1be0560e 115 m_window = window ;
9f391ae1
SC
116 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
117 if (!rootwindow)
118 return;
9b2eab52 119
9f391ae1
SC
120 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
121 int x , y ;
122 x = y = 0 ;
123 wxSize size = window->GetSize() ;
124 window->MacWindowToRootWindow( &x , &y ) ;
125 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9
DS
126 m_ok = true ;
127
20b69855 128#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
129 m_macLocalOriginInPort.x = x ;
130 m_macLocalOriginInPort.y = y ;
131
20b69855
SC
132 if ( window->MacGetCGContextRef() )
133 {
134 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
135 m_graphicContext->SetPen( m_pen ) ;
136 m_graphicContext->SetBrush( m_brush ) ;
20b69855
SC
137 }
138 else
cb4b0966
SC
139 {
140 // as out of order redraw is not supported under CQ, we have to create a qd port for these
141 // situations
cb4b0966
SC
142 m_macLocalOrigin.x = x ;
143 m_macLocalOrigin.y = y ;
e4db172a 144
9f391ae1 145 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
cb4b0966
SC
146 m_graphicContext->SetPen( m_pen ) ;
147 m_graphicContext->SetBrush( m_brush ) ;
cb4b0966 148 }
20b69855
SC
149 // there is no out-of-order drawing on OSX
150#else
e40298d5
JS
151 m_macLocalOrigin.x = x ;
152 m_macLocalOrigin.y = y ;
cf9d0f93 153 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
154 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
155 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
20b69855 156#endif
489d2dd3 157 SetBackground(MacGetBackgroundBrush(window));
9b2eab52 158
20b69855 159 SetFont( window->GetFont() ) ;
519cb848 160}
e9576ca5 161
2f1ae414 162wxWindowDC::~wxWindowDC()
e9576ca5 163{
519cb848 164}
e9576ca5 165
1be0560e
SC
166void wxWindowDC::DoGetSize( int* width, int* height ) const
167{
168 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
169
170 m_window->GetSize(width, height);
171}
172
519cb848
SC
173/*
174 * wxClientDC
175 */
e9576ca5 176
2f1ae414 177wxClientDC::wxClientDC()
e9576ca5 178{
1be0560e 179 m_window = NULL ;
e9576ca5
SC
180}
181
519cb848 182wxClientDC::wxClientDC(wxWindow *window)
e9576ca5 183{
1be0560e 184 m_window = window ;
9f391ae1
SC
185 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
186 if (!rootwindow)
187 return;
9b2eab52 188
9f391ae1
SC
189 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
190 wxPoint origin = window->GetClientAreaOrigin() ;
191 wxSize size = window->GetClientSize() ;
192 int x , y ;
193 x = origin.x ;
194 y = origin.y ;
195 window->MacWindowToRootWindow( &x , &y ) ;
196 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9
DS
197 m_ok = true ;
198
20b69855 199#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
200 m_macLocalOriginInPort.x = x ;
201 m_macLocalOriginInPort.y = y ;
20b69855
SC
202 if ( window->MacGetCGContextRef() )
203 {
204 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
205 m_graphicContext->SetPen( m_pen ) ;
206 m_graphicContext->SetBrush( m_brush ) ;
e2f92883 207 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
20b69855
SC
208 }
209 else
210 {
eb1a7cf9
DS
211 // as out of order redraw is not supported under CQ,
212 // we have to create a QD port for these situations
20b69855
SC
213 m_macLocalOrigin.x = x ;
214 m_macLocalOrigin.y = y ;
9f391ae1 215 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
20b69855
SC
216 m_graphicContext->SetPen( m_pen ) ;
217 m_graphicContext->SetBrush( m_brush ) ;
cb4b0966 218 }
20b69855 219#else
e40298d5
JS
220 m_macLocalOrigin.x = x ;
221 m_macLocalOrigin.y = y ;
222 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
223 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
224 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
225 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
226 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
20b69855 227#endif
9b2eab52 228
be346c26 229 SetBackground(MacGetBackgroundBrush(window));
e40298d5 230 SetFont( window->GetFont() ) ;
e9576ca5
SC
231}
232
2f1ae414 233wxClientDC::~wxClientDC()
e9576ca5 234{
68654a82
SC
235#if wxMAC_USE_CORE_GRAPHICS
236/*
237 if ( m_window->MacGetCGContextRef() == 0)
238 {
bc8f7aee 239 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
68654a82
SC
240 CGContextFlush( cgContext ) ;
241 }
242*/
243#endif
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
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 ;
9f391ae1
SC
265 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
266 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
267 wxPoint origin = window->GetClientAreaOrigin() ;
268 wxSize size = window->GetClientSize() ;
269 int x , y ;
270 x = origin.x ;
271 y = origin.y ;
272 window->MacWindowToRootWindow( &x , &y ) ;
273 m_macPort = UMAGetWindowPort( windowref ) ;
eb1a7cf9 274 m_ok = true ;
9b2eab52 275
20b69855 276#if wxMAC_USE_CORE_GRAPHICS
9f391ae1
SC
277 m_macLocalOriginInPort.x = x ;
278 m_macLocalOriginInPort.y = y ;
20b69855
SC
279 if ( window->MacGetCGContextRef() )
280 {
281 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
282 m_graphicContext->SetPen( m_pen ) ;
283 m_graphicContext->SetBrush( m_brush ) ;
9f391ae1
SC
284 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
285 SetBackground(MacGetBackgroundBrush(window));
20b69855
SC
286 }
287 else
288 {
289 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
290 m_graphicContext = NULL ;
20b69855
SC
291 }
292 // there is no out-of-order drawing on OSX
293#else
e40298d5
JS
294 m_macLocalOrigin.x = x ;
295 m_macLocalOrigin.y = y ;
296 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
297 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
298 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
299 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
300 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
301 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
be346c26 302 SetBackground(MacGetBackgroundBrush(window));
20b69855 303#endif
9b2eab52 304
e40298d5 305 SetFont( window->GetFont() ) ;
e9576ca5
SC
306}
307
519cb848 308wxPaintDC::~wxPaintDC()
e9576ca5 309{
519cb848 310}
1be0560e
SC
311
312void wxPaintDC::DoGetSize(int *width, int *height) const
313{
314 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
315
316 m_window->GetClientSize( width, height );
317}