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
) ;
128 #if wxMAC_USE_CORE_GRAPHICS
129 m_window
->GetSize( &m_width
, &m_height
);
130 CGContextRef cg
= (CGContextRef
) window
->MacGetCGContextRef();
134 SetGraphicsContext( wxGraphicsContext::Create( window
) ) ;
135 SetDeviceOrigin( x
, y
);
139 CGContextSaveGState( cg
);
141 // make sure the context is having its origin at the wx-window coordinates of the
142 // view (read at the top of window.cpp about the differences)
143 if ( window
->MacGetLeftBorderSize() != 0 || window
->MacGetTopBorderSize() != 0 )
144 CGContextTranslateCTM( cg
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
146 SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg
) );
148 m_graphicContext
->SetPen( m_pen
) ;
149 m_graphicContext
->SetBrush( m_brush
) ;
150 SetClippingRegion( 0 , 0 , m_width
, m_height
) ;
152 m_macLocalOrigin
.x
= x
;
153 m_macLocalOrigin
.y
= y
;
154 m_macPort
= UMAGetWindowPort( windowref
) ;
156 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
157 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
158 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
160 SetBackground(MacGetBackgroundBrush(window
));
162 SetFont( window
->GetFont() ) ;
165 wxWindowDC::~wxWindowDC()
167 #if wxMAC_USE_CORE_GRAPHICS
168 if ( m_release
&& m_graphicContext
)
170 CGContextRef cg
= (CGContextRef
) m_window
->MacGetCGContextRef();
171 CGContextRestoreGState(cg
);
172 // CGContextRef cg = (CGContextRef) m_graphicContext->GetNativeContext() ;
177 void wxWindowDC::DoGetSize( int* width
, int* height
) const
179 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
181 #if wxMAC_USE_CORE_GRAPHICS
187 m_window
->GetSize(width
, height
);
195 wxClientDC::wxClientDC()
200 #if wxMAC_USE_CORE_GRAPHICS
201 wxClientDC::wxClientDC(wxWindow
*window
) :
204 wxPoint origin
= window
->GetClientAreaOrigin() ;
205 wxSize size
= window
->GetClientSize() ;
209 window
->MacWindowToRootWindow( &x
, &y
) ;
210 m_window
->GetClientSize( &m_width
, &m_height
);
211 SetDeviceOrigin( origin
.x
, origin
.y
);
212 SetClippingRegion( 0 , 0 , m_width
, m_height
) ;
215 wxClientDC::wxClientDC(wxWindow
*window
)
218 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
222 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
223 wxPoint origin
= window
->GetClientAreaOrigin() ;
224 wxSize size
= window
->GetClientSize() ;
228 window
->MacWindowToRootWindow( &x
, &y
) ;
229 m_macPort
= UMAGetWindowPort( windowref
) ;
232 m_macLocalOrigin
.x
= x
;
233 m_macLocalOrigin
.y
= y
;
234 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
235 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
236 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
237 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
238 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
240 SetBackground(MacGetBackgroundBrush(window
));
241 SetFont( window
->GetFont() ) ;
245 wxClientDC::~wxClientDC()
249 #if !wxMAC_USE_CORE_GRAPHICS
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
);
262 wxPaintDC::wxPaintDC()
267 #if wxMAC_USE_CORE_GRAPHICS
268 wxPaintDC::wxPaintDC(wxWindow
*window
) :
271 wxPoint origin
= window
->GetClientAreaOrigin() ;
272 wxSize size
= window
->GetClientSize() ;
276 window
->MacWindowToRootWindow( &x
, &y
) ;
277 m_window
->GetClientSize( &m_width
, &m_height
);
278 SetDeviceOrigin( origin
.x
, origin
.y
);
279 SetClippingRegion( 0 , 0 , m_width
, m_height
) ;
282 wxPaintDC::wxPaintDC(wxWindow
*window
)
285 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
286 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
287 wxPoint origin
= window
->GetClientAreaOrigin() ;
288 wxSize size
= window
->GetClientSize() ;
292 window
->MacWindowToRootWindow( &x
, &y
) ;
293 m_macPort
= UMAGetWindowPort( windowref
) ;
296 #if wxMAC_USE_CORE_GRAPHICS
297 if ( window
->MacGetCGContextRef() )
299 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
300 m_graphicContext
->SetPen( m_pen
) ;
301 m_graphicContext
->SetBrush( m_brush
) ;
302 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
303 SetBackground(MacGetBackgroundBrush(window
));
307 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
308 m_graphicContext
= NULL
;
310 // there is no out-of-order drawing on OSX
312 m_macLocalOrigin
.x
= x
;
313 m_macLocalOrigin
.y
= y
;
314 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
315 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
316 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
317 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
318 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
319 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
320 SetBackground(MacGetBackgroundBrush(window
));
323 SetFont( window
->GetFont() ) ;
327 wxPaintDC::~wxPaintDC()
331 #if !wxMAC_USE_CORE_GRAPHICS
332 void wxPaintDC::DoGetSize(int *width
, int *height
) const
334 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
336 m_window
->GetClientSize( width
, height
);