]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
Include wx/window.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
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 #endif
20
21 #include "wx/dcmemory.h"
22 #include "wx/region.h"
23 #include "wx/toplevel.h"
24 #include "wx/settings.h"
25 #include "wx/math.h"
26 #include "wx/mac/private.h"
27
28 //-----------------------------------------------------------------------------
29 // constants
30 //-----------------------------------------------------------------------------
31
32 #define RAD2DEG 57.2957795131
33
34 //-----------------------------------------------------------------------------
35 // wxPaintDC
36 //-----------------------------------------------------------------------------
37
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
41
42 /*
43 * wxWindowDC
44 */
45
46 #include "wx/mac/uma.h"
47 #include "wx/notebook.h"
48 #include "wx/tabctrl.h"
49
50
51 static wxBrush MacGetBackgroundBrush( wxWindow* window )
52 {
53 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
54
55 #if !TARGET_API_MAC_OSX
56 // transparency cannot be handled by the OS when not using composited windows
57 wxWindow* parent = window->GetParent() ;
58
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
72 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
73 {
74 bkdBrush = parent->MacGetBackgroundBrush() ;
75 break ;
76 }
77
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 ;
90 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
91 break ;
92 }
93
94 parent = parent->GetParent() ;
95 }
96 }
97
98 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
99 {
100 // if we did not find something, use a default
101 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
102 }
103 #endif
104
105 return bkdBrush ;
106 }
107
108 wxWindowDC::wxWindowDC()
109 {
110 m_window = NULL ;
111 }
112
113 wxWindowDC::wxWindowDC(wxWindow *window)
114 {
115 m_window = window ;
116 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
117 if (!rootwindow)
118 return;
119
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 ) ;
126 m_ok = true ;
127
128 #if wxMAC_USE_CORE_GRAPHICS
129 m_macLocalOriginInPort.x = x ;
130 m_macLocalOriginInPort.y = y ;
131
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 ) ;
137 }
138 else
139 {
140 // as out of order redraw is not supported under CQ, we have to create a qd port for these
141 // situations
142 m_macLocalOrigin.x = x ;
143 m_macLocalOrigin.y = y ;
144
145 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
146 m_graphicContext->SetPen( m_pen ) ;
147 m_graphicContext->SetBrush( m_brush ) ;
148 }
149 // there is no out-of-order drawing on OSX
150 #else
151 m_macLocalOrigin.x = x ;
152 m_macLocalOrigin.y = y ;
153 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
154 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
155 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
156 #endif
157 SetBackground(MacGetBackgroundBrush(window));
158
159 SetFont( window->GetFont() ) ;
160 }
161
162 wxWindowDC::~wxWindowDC()
163 {
164 }
165
166 void 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
173 /*
174 * wxClientDC
175 */
176
177 wxClientDC::wxClientDC()
178 {
179 m_window = NULL ;
180 }
181
182 wxClientDC::wxClientDC(wxWindow *window)
183 {
184 m_window = window ;
185 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
186 if (!rootwindow)
187 return;
188
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 ) ;
197 m_ok = true ;
198
199 #if wxMAC_USE_CORE_GRAPHICS
200 m_macLocalOriginInPort.x = x ;
201 m_macLocalOriginInPort.y = y ;
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 ) ;
207 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
208 }
209 else
210 {
211 // as out of order redraw is not supported under CQ,
212 // we have to create a QD port for these situations
213 m_macLocalOrigin.x = x ;
214 m_macLocalOrigin.y = y ;
215 m_graphicContext = new wxMacCGContext( (CGrafPtr) m_macPort ) ;
216 m_graphicContext->SetPen( m_pen ) ;
217 m_graphicContext->SetBrush( m_brush ) ;
218 }
219 #else
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 ) ;
227 #endif
228
229 SetBackground(MacGetBackgroundBrush(window));
230 SetFont( window->GetFont() ) ;
231 }
232
233 wxClientDC::~wxClientDC()
234 {
235 #if wxMAC_USE_CORE_GRAPHICS
236 /*
237 if ( m_window->MacGetCGContextRef() == 0)
238 {
239 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
240 CGContextFlush( cgContext ) ;
241 }
242 */
243 #endif
244 }
245
246 void 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 /*
254 * wxPaintDC
255 */
256
257 wxPaintDC::wxPaintDC()
258 {
259 m_window = NULL ;
260 }
261
262 wxPaintDC::wxPaintDC(wxWindow *window)
263 {
264 m_window = window ;
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 ) ;
274 m_ok = true ;
275
276 #if wxMAC_USE_CORE_GRAPHICS
277 m_macLocalOriginInPort.x = x ;
278 m_macLocalOriginInPort.y = y ;
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 ) ;
284 SetClippingRegion( 0 , 0 , size.x , size.y ) ;
285 SetBackground(MacGetBackgroundBrush(window));
286 }
287 else
288 {
289 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
290 m_graphicContext = NULL ;
291 }
292 // there is no out-of-order drawing on OSX
293 #else
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 ) ;
302 SetBackground(MacGetBackgroundBrush(window));
303 #endif
304
305 SetFont( window->GetFont() ) ;
306 }
307
308 wxPaintDC::~wxPaintDC()
309 {
310 }
311
312 void 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 }