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"
21 #include "wx/toplevel.h"
23 #include "wx/region.h"
26 #include "wx/mac/private.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
37 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
38 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
44 #include "wx/mac/uma.h"
45 #include "wx/notebook.h"
46 #include "wx/tabctrl.h"
49 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
51 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
53 #if !TARGET_API_MAC_OSX
54 // transparency cannot be handled by the OS when not using composited windows
55 wxWindow
* parent
= window
->GetParent() ;
57 // if we have some 'pseudo' transparency
58 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
60 // walk up until we find something
61 while ( parent
!= NULL
)
63 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
65 // if we have any other colours in the hierarchy
66 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
70 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
72 bkdBrush
= parent
->MacGetBackgroundBrush() ;
76 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) )
78 || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) )
79 #endif // wxUSE_TAB_DIALOG
82 Rect extent
= { 0 , 0 , 0 , 0 } ;
85 wxSize size
= parent
->GetSize() ;
86 parent
->MacClientToRootWindow( &x
, &y
) ;
90 extent
.right
= x
+ size
.x
;
91 extent
.bottom
= y
+ size
.y
;
92 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
96 parent
= parent
->GetParent() ;
100 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
102 // if we did not find something, use a default
103 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
110 wxWindowDC::wxWindowDC()
115 wxWindowDC::wxWindowDC(wxWindow
*window
)
118 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
122 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
125 window
->MacWindowToRootWindow( &x
, &y
) ;
126 m_macPort
= UMAGetWindowPort( windowref
) ;
129 #if wxMAC_USE_CORE_GRAPHICS
130 m_macLocalOriginInPort
.x
= x
;
131 m_macLocalOriginInPort
.y
= y
;
133 if ( window
->MacGetCGContextRef() )
135 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
136 m_graphicContext
->SetPen( m_pen
) ;
137 m_graphicContext
->SetBrush( m_brush
) ;
141 // as out of order redraw is not supported under CQ, we have to create a qd port for these
143 m_macLocalOrigin
.x
= x
;
144 m_macLocalOrigin
.y
= y
;
146 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
147 m_graphicContext
->SetPen( m_pen
) ;
148 m_graphicContext
->SetBrush( m_brush
) ;
150 // there is no out-of-order drawing on OSX
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
) ;
158 SetBackground(MacGetBackgroundBrush(window
));
160 SetFont( window
->GetFont() ) ;
163 wxWindowDC::~wxWindowDC()
167 void wxWindowDC::DoGetSize( int* width
, int* height
) const
169 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
171 m_window
->GetSize(width
, height
);
178 wxClientDC::wxClientDC()
183 wxClientDC::wxClientDC(wxWindow
*window
)
186 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
190 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
191 wxPoint origin
= window
->GetClientAreaOrigin() ;
192 wxSize size
= window
->GetClientSize() ;
196 window
->MacWindowToRootWindow( &x
, &y
) ;
197 m_macPort
= UMAGetWindowPort( windowref
) ;
200 #if wxMAC_USE_CORE_GRAPHICS
201 m_macLocalOriginInPort
.x
= x
;
202 m_macLocalOriginInPort
.y
= y
;
203 if ( window
->MacGetCGContextRef() )
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
) ;
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
) ;
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
) ;
230 SetBackground(MacGetBackgroundBrush(window
));
231 SetFont( window
->GetFont() ) ;
234 wxClientDC::~wxClientDC()
236 #if wxMAC_USE_CORE_GRAPHICS
238 if ( m_window->MacGetCGContextRef() == 0)
240 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
241 CGContextFlush( cgContext ) ;
247 void wxClientDC::DoGetSize(int *width
, int *height
) const
249 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
251 m_window
->GetClientSize( width
, height
);
258 wxPaintDC::wxPaintDC()
263 wxPaintDC::wxPaintDC(wxWindow
*window
)
266 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
267 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
268 wxPoint origin
= window
->GetClientAreaOrigin() ;
269 wxSize size
= window
->GetClientSize() ;
273 window
->MacWindowToRootWindow( &x
, &y
) ;
274 m_macPort
= UMAGetWindowPort( windowref
) ;
277 #if wxMAC_USE_CORE_GRAPHICS
278 m_macLocalOriginInPort
.x
= x
;
279 m_macLocalOriginInPort
.y
= y
;
280 if ( window
->MacGetCGContextRef() )
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
));
290 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
291 m_graphicContext
= NULL
;
293 // there is no out-of-order drawing on OSX
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
));
306 SetFont( window
->GetFont() ) ;
309 wxPaintDC::~wxPaintDC()
313 void wxPaintDC::DoGetSize(int *width
, int *height
) const
315 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
317 m_window
->GetClientSize( width
, height
);