]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/dcclient.cpp
define bookctrl (and -derived) classes flags in their headers instead of defs.h;...
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/dcclient.cpp
3// Purpose: wxClientDC class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/dcclient.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #include "wx/window.h"
19 #include "wx/dcmemory.h"
20 #include "wx/settings.h"
21 #include "wx/toplevel.h"
22 #include "wx/math.h"
23 #include "wx/region.h"
24#endif
25
26#include "wx/mac/private.h"
27
28//-----------------------------------------------------------------------------
29// constants
30//-----------------------------------------------------------------------------
31
32//-----------------------------------------------------------------------------
33// wxPaintDC
34//-----------------------------------------------------------------------------
35
36IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
37IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
38IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
39
40/*
41 * wxWindowDC
42 */
43
44#include "wx/mac/uma.h"
45#include "wx/notebook.h"
46#include "wx/tabctrl.h"
47
48
49static wxBrush MacGetBackgroundBrush( wxWindow* window )
50{
51 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
52
53#if !TARGET_API_MAC_OSX
54 // transparency cannot be handled by the OS when not using composited windows
55 wxWindow* parent = window->GetParent() ;
56
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
61 while ( parent != NULL )
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 }
69
70 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
71 {
72 bkdBrush = parent->MacGetBackgroundBrush() ;
73 break ;
74 }
75
76 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) )
77#if wxUSE_TAB_DIALOG
78 || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )
79#endif // wxUSE_TAB_DIALOG
80 )
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 ;
92 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
93 break ;
94 }
95
96 parent = parent->GetParent() ;
97 }
98 }
99
100 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
101 {
102 // if we did not find something, use a default
103 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
104 }
105#endif
106
107 return bkdBrush ;
108}
109
110wxWindowDC::wxWindowDC()
111{
112 m_window = NULL ;
113}
114
115wxWindowDC::wxWindowDC(wxWindow *window)
116{
117 m_window = window ;
118 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
119 if (!rootwindow)
120 return;
121
122 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
123 int x , y ;
124 x = y = 0 ;
125 window->MacWindowToRootWindow( &x , &y ) ;
126 m_macPort = UMAGetWindowPort( windowref ) ;
127 m_ok = true ;
128
129#if wxMAC_USE_CORE_GRAPHICS
130 m_macLocalOriginInPort.x = x ;
131 m_macLocalOriginInPort.y = y ;
132
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 ) ;
138 }
139 else
140 {
141 // as out of order redraw is not supported under CQ, we have to create a qd port for these
142 // situations
143 m_macLocalOrigin.x = x ;
144 m_macLocalOrigin.y = y ;
145
146 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
147 m_graphicContext->SetPen( m_pen ) ;
148 m_graphicContext->SetBrush( m_brush ) ;
149 }
150 // there is no out-of-order drawing on OSX
151#else
152 m_macLocalOrigin.x = x ;
153 m_macLocalOrigin.y = y ;
154 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
155 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
156 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
157#endif
158 SetBackground(MacGetBackgroundBrush(window));
159
160 SetFont( window->GetFont() ) ;
161}
162
163wxWindowDC::~wxWindowDC()
164{
165}
166
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
174/*
175 * wxClientDC
176 */
177
178wxClientDC::wxClientDC()
179{
180 m_window = NULL ;
181}
182
183wxClientDC::wxClientDC(wxWindow *window)
184{
185 m_window = window ;
186 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
187 if (!rootwindow)
188 return;
189
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 ) ;
198 m_ok = true ;
199
200#if wxMAC_USE_CORE_GRAPHICS
201 m_macLocalOriginInPort.x = x ;
202 m_macLocalOriginInPort.y = y ;
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 ) ;
208 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
209 }
210 else
211 {
212 // as out of order redraw is not supported under CQ,
213 // we have to create a QD port for these situations
214 m_macLocalOrigin.x = x ;
215 m_macLocalOrigin.y = y ;
216 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
217 m_graphicContext->SetPen( m_pen ) ;
218 m_graphicContext->SetBrush( m_brush ) ;
219 }
220#else
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 ) ;
228#endif
229
230 SetBackground(MacGetBackgroundBrush(window));
231 SetFont( window->GetFont() ) ;
232}
233
234wxClientDC::~wxClientDC()
235{
236#if wxMAC_USE_CORE_GRAPHICS
237/*
238 if ( m_window->MacGetCGContextRef() == 0)
239 {
240 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
241 CGContextFlush( cgContext ) ;
242 }
243*/
244#endif
245}
246
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
254/*
255 * wxPaintDC
256 */
257
258wxPaintDC::wxPaintDC()
259{
260 m_window = NULL ;
261}
262
263wxPaintDC::wxPaintDC(wxWindow *window)
264{
265 m_window = window ;
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 ) ;
275 m_ok = true ;
276
277#if wxMAC_USE_CORE_GRAPHICS
278 m_macLocalOriginInPort.x = x ;
279 m_macLocalOriginInPort.y = y ;
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 ) ;
285 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
286 SetBackground(MacGetBackgroundBrush(window));
287 }
288 else
289 {
290 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
291 m_graphicContext = NULL ;
292 }
293 // there is no out-of-order drawing on OSX
294#else
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 ) ;
303 SetBackground(MacGetBackgroundBrush(window));
304#endif
305
306 SetFont( window->GetFont() ) ;
307}
308
309wxPaintDC::~wxPaintDC()
310{
311}
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}