1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dcclient.cpp
3 // Purpose: wxClientDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dcclient.h"
20 #include "wx/dcmemory.h"
21 #include "wx/region.h"
22 #include "wx/window.h"
23 #include "wx/toplevel.h"
24 #include "wx/settings.h"
26 #include "wx/mac/private.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 #define RAD2DEG 57.2957795131
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
46 #include "wx/mac/uma.h"
47 #include "wx/notebook.h"
48 #include "wx/tabctrl.h"
51 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
53 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
55 #if !TARGET_API_MAC_OSX
56 // transparency cannot be handled by the OS when not using composited windows
57 wxWindow
* parent
= window
->GetParent() ;
59 // if we have some 'pseudo' transparency
60 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
62 // walk up until we find something
63 while ( parent
!= NULL
)
65 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
67 // if we have any other colours in the hierarchy
68 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
72 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
74 bkdBrush
= parent
->MacGetBackgroundBrush() ;
78 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
80 Rect extent
= { 0 , 0 , 0 , 0 } ;
83 wxSize size
= parent
->GetSize() ;
84 parent
->MacClientToRootWindow( &x
, &y
) ;
88 extent
.right
= x
+ size
.x
;
89 extent
.bottom
= y
+ size
.y
;
90 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
94 parent
= parent
->GetParent() ;
98 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
100 // if we did not find something, use a default
101 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
108 wxWindowDC::wxWindowDC()
113 wxWindowDC::wxWindowDC(wxWindow
*window
)
116 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
120 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
123 wxSize size
= window
->GetSize() ;
124 window
->MacWindowToRootWindow( &x
, &y
) ;
125 m_macPort
= UMAGetWindowPort( windowref
) ;
128 #if wxMAC_USE_CORE_GRAPHICS
129 m_macLocalOriginInPort
.x
= x
;
130 m_macLocalOriginInPort
.y
= y
;
132 if ( window
->MacGetCGContextRef() )
134 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
135 m_graphicContext
->SetPen( m_pen
) ;
136 m_graphicContext
->SetBrush( m_brush
) ;
140 // as out of order redraw is not supported under CQ, we have to create a qd port for these
142 m_macLocalOrigin
.x
= x
;
143 m_macLocalOrigin
.y
= y
;
145 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
146 m_graphicContext
->SetPen( m_pen
) ;
147 m_graphicContext
->SetBrush( m_brush
) ;
149 // there is no out-of-order drawing on OSX
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
) ;
157 SetBackground(MacGetBackgroundBrush(window
));
159 SetFont( window
->GetFont() ) ;
162 wxWindowDC::~wxWindowDC()
166 void wxWindowDC::DoGetSize( int* width
, int* height
) const
168 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
170 m_window
->GetSize(width
, height
);
177 wxClientDC::wxClientDC()
182 wxClientDC::wxClientDC(wxWindow
*window
)
185 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
189 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
190 wxPoint origin
= window
->GetClientAreaOrigin() ;
191 wxSize size
= window
->GetClientSize() ;
195 window
->MacWindowToRootWindow( &x
, &y
) ;
196 m_macPort
= UMAGetWindowPort( windowref
) ;
199 #if wxMAC_USE_CORE_GRAPHICS
200 m_macLocalOriginInPort
.x
= x
;
201 m_macLocalOriginInPort
.y
= y
;
202 if ( window
->MacGetCGContextRef() )
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
) ;
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
) ;
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
) ;
229 SetBackground(MacGetBackgroundBrush(window
));
230 SetFont( window
->GetFont() ) ;
233 wxClientDC::~wxClientDC()
235 #if wxMAC_USE_CORE_GRAPHICS
237 if ( m_window->MacGetCGContextRef() == 0)
239 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
240 CGContextFlush( cgContext ) ;
246 void wxClientDC::DoGetSize(int *width
, int *height
) const
248 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
250 m_window
->GetClientSize( width
, height
);
257 wxPaintDC::wxPaintDC()
262 wxPaintDC::wxPaintDC(wxWindow
*window
)
265 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
266 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
267 wxPoint origin
= window
->GetClientAreaOrigin() ;
268 wxSize size
= window
->GetClientSize() ;
272 window
->MacWindowToRootWindow( &x
, &y
) ;
273 m_macPort
= UMAGetWindowPort( windowref
) ;
276 #if wxMAC_USE_CORE_GRAPHICS
277 m_macLocalOriginInPort
.x
= x
;
278 m_macLocalOriginInPort
.y
= y
;
279 if ( window
->MacGetCGContextRef() )
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
));
289 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
290 m_graphicContext
= NULL
;
292 // there is no out-of-order drawing on OSX
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
));
305 SetFont( window
->GetFont() ) ;
308 wxPaintDC::~wxPaintDC()
312 void wxPaintDC::DoGetSize(int *width
, int *height
) const
314 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
316 m_window
->GetClientSize( width
, height
);