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"
18 #include "wx/window.h"
19 #include "wx/dcmemory.h"
20 #include "wx/settings.h"
23 #include "wx/region.h"
24 #include "wx/toplevel.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
) )
80 || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) )
81 #endif // wxUSE_TAB_DIALOG
84 Rect extent
= { 0 , 0 , 0 , 0 } ;
87 wxSize size
= parent
->GetSize() ;
88 parent
->MacClientToRootWindow( &x
, &y
) ;
92 extent
.right
= x
+ size
.x
;
93 extent
.bottom
= y
+ size
.y
;
94 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
98 parent
= parent
->GetParent() ;
102 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
104 // if we did not find something, use a default
105 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
112 wxWindowDC::wxWindowDC()
117 wxWindowDC::wxWindowDC(wxWindow
*window
)
120 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
124 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
127 wxSize size
= window
->GetSize() ;
128 window
->MacWindowToRootWindow( &x
, &y
) ;
129 m_macPort
= UMAGetWindowPort( windowref
) ;
132 #if wxMAC_USE_CORE_GRAPHICS
133 m_macLocalOriginInPort
.x
= x
;
134 m_macLocalOriginInPort
.y
= y
;
136 if ( window
->MacGetCGContextRef() )
138 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
139 m_graphicContext
->SetPen( m_pen
) ;
140 m_graphicContext
->SetBrush( m_brush
) ;
144 // as out of order redraw is not supported under CQ, we have to create a qd port for these
146 m_macLocalOrigin
.x
= x
;
147 m_macLocalOrigin
.y
= y
;
149 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
150 m_graphicContext
->SetPen( m_pen
) ;
151 m_graphicContext
->SetBrush( m_brush
) ;
153 // there is no out-of-order drawing on OSX
155 m_macLocalOrigin
.x
= x
;
156 m_macLocalOrigin
.y
= y
;
157 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
158 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
159 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
161 SetBackground(MacGetBackgroundBrush(window
));
163 SetFont( window
->GetFont() ) ;
166 wxWindowDC::~wxWindowDC()
170 void wxWindowDC::DoGetSize( int* width
, int* height
) const
172 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
174 m_window
->GetSize(width
, height
);
181 wxClientDC::wxClientDC()
186 wxClientDC::wxClientDC(wxWindow
*window
)
189 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
193 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
194 wxPoint origin
= window
->GetClientAreaOrigin() ;
195 wxSize size
= window
->GetClientSize() ;
199 window
->MacWindowToRootWindow( &x
, &y
) ;
200 m_macPort
= UMAGetWindowPort( windowref
) ;
203 #if wxMAC_USE_CORE_GRAPHICS
204 m_macLocalOriginInPort
.x
= x
;
205 m_macLocalOriginInPort
.y
= y
;
206 if ( window
->MacGetCGContextRef() )
208 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
209 m_graphicContext
->SetPen( m_pen
) ;
210 m_graphicContext
->SetBrush( m_brush
) ;
211 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
215 // as out of order redraw is not supported under CQ,
216 // we have to create a QD port for these situations
217 m_macLocalOrigin
.x
= x
;
218 m_macLocalOrigin
.y
= y
;
219 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
220 m_graphicContext
->SetPen( m_pen
) ;
221 m_graphicContext
->SetBrush( m_brush
) ;
224 m_macLocalOrigin
.x
= x
;
225 m_macLocalOrigin
.y
= y
;
226 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
227 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
228 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
229 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
230 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
233 SetBackground(MacGetBackgroundBrush(window
));
234 SetFont( window
->GetFont() ) ;
237 wxClientDC::~wxClientDC()
239 #if wxMAC_USE_CORE_GRAPHICS
241 if ( m_window->MacGetCGContextRef() == 0)
243 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
244 CGContextFlush( cgContext ) ;
250 void wxClientDC::DoGetSize(int *width
, int *height
) const
252 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
254 m_window
->GetClientSize( width
, height
);
261 wxPaintDC::wxPaintDC()
266 wxPaintDC::wxPaintDC(wxWindow
*window
)
269 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
270 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
271 wxPoint origin
= window
->GetClientAreaOrigin() ;
272 wxSize size
= window
->GetClientSize() ;
276 window
->MacWindowToRootWindow( &x
, &y
) ;
277 m_macPort
= UMAGetWindowPort( windowref
) ;
280 #if wxMAC_USE_CORE_GRAPHICS
281 m_macLocalOriginInPort
.x
= x
;
282 m_macLocalOriginInPort
.y
= y
;
283 if ( window
->MacGetCGContextRef() )
285 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
286 m_graphicContext
->SetPen( m_pen
) ;
287 m_graphicContext
->SetBrush( m_brush
) ;
288 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
289 SetBackground(MacGetBackgroundBrush(window
));
293 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
294 m_graphicContext
= NULL
;
296 // there is no out-of-order drawing on OSX
298 m_macLocalOrigin
.x
= x
;
299 m_macLocalOrigin
.y
= y
;
300 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
301 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
302 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
303 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
304 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
305 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
306 SetBackground(MacGetBackgroundBrush(window
));
309 SetFont( window
->GetFont() ) ;
312 wxPaintDC::~wxPaintDC()
316 void wxPaintDC::DoGetSize(int *width
, int *height
) const
318 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
320 m_window
->GetClientSize( width
, height
);