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