1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxClientDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dcclient.h"
16 #include "wx/wxprec.h"
18 #include "wx/dcclient.h"
19 #include "wx/dcmemory.h"
20 #include "wx/region.h"
21 #include "wx/window.h"
22 #include "wx/toplevel.h"
23 #include "wx/settings.h"
25 #include "wx/mac/private.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 #define RAD2DEG 57.2957795131
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
47 #include "wx/mac/uma.h"
48 #include "wx/notebook.h"
49 #include "wx/tabctrl.h"
52 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
54 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() ;
58 // if we have some 'pseudo' transparency
59 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
61 // walk up until we find something
62 while( parent
!= NULL
)
64 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
66 // if we have any other colours in the hierarchy
67 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
70 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
72 bkdBrush
= parent
->MacGetBackgroundBrush() ;
75 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
77 Rect extent
= { 0 , 0 , 0 , 0 } ;
80 wxSize size
= parent
->GetSize() ;
81 parent
->MacClientToRootWindow( &x
, &y
) ;
85 extent
.right
= x
+ size
.x
;
86 extent
.bottom
= y
+ size
.y
;
87 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
91 parent
= parent
->GetParent() ;
94 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
96 // if we did not find something, use a default
97 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
104 wxWindowDC::wxWindowDC()
109 wxWindowDC::wxWindowDC(wxWindow
*window
)
112 #if wxMAC_USE_CORE_GRAPHICS
113 if ( window
->MacGetCGContextRef() )
115 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
116 m_graphicContext
->SetPen( m_pen
) ;
117 m_graphicContext
->SetBrush( m_brush
) ;
118 SetBackground(MacGetBackgroundBrush(window
));
121 m_graphicContext
= NULL
;
122 // there is no out-of-order drawing on OSX
124 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
125 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
128 window
->MacWindowToRootWindow( &x
, &y
) ;
129 m_macLocalOrigin
.x
= x
;
130 m_macLocalOrigin
.y
= y
;
131 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
132 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
133 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
134 m_macPort
= UMAGetWindowPort( windowref
) ;
135 SetBackground(MacGetBackgroundBrush(window
));
138 SetFont( window
->GetFont() ) ;
141 wxWindowDC::~wxWindowDC()
145 void wxWindowDC::DoGetSize( int* width
, int* height
) const
147 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
149 m_window
->GetSize(width
, height
);
156 wxClientDC::wxClientDC()
161 wxClientDC::wxClientDC(wxWindow
*window
)
164 #if wxMAC_USE_CORE_GRAPHICS
165 m_graphicContext
= NULL
;
166 if ( window
->MacGetCGContextRef() )
168 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
169 m_graphicContext
->SetPen( m_pen
) ;
170 m_graphicContext
->SetBrush( m_brush
) ;
171 SetBackground(MacGetBackgroundBrush(window
));
176 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
179 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
180 wxPoint origin = window->GetClientAreaOrigin() ;
181 wxSize size = window->GetClientSize() ;
185 window->MacWindowToRootWindow( &x , &y ) ;
186 m_macLocalOrigin.x = x ;
187 m_macLocalOrigin.y = y ;
188 CGrafPtr port = UMAGetWindowPort( windowref ) ;
190 m_graphicContext = new wxMacCGContext( port ) ;
191 m_graphicContext->SetPen( m_pen ) ;
192 m_graphicContext->SetBrush( m_brush ) ;
193 SetBackground(MacGetBackgroundBrush(window));
199 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
202 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
203 wxPoint origin
= window
->GetClientAreaOrigin() ;
204 wxSize size
= window
->GetClientSize() ;
208 window
->MacWindowToRootWindow( &x
, &y
) ;
209 m_macLocalOrigin
.x
= x
;
210 m_macLocalOrigin
.y
= y
;
211 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
212 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
213 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
214 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
215 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
216 m_macPort
= UMAGetWindowPort( windowref
) ;
219 SetBackground(MacGetBackgroundBrush(window
));
220 SetFont( window
->GetFont() ) ;
223 wxClientDC::~wxClientDC()
227 void wxClientDC::DoGetSize(int *width
, int *height
) const
229 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
231 m_window
->GetClientSize( width
, height
);
239 wxPaintDC::wxPaintDC()
244 wxPaintDC::wxPaintDC(wxWindow
*window
)
247 #if wxMAC_USE_CORE_GRAPHICS
248 if ( window
->MacGetCGContextRef() )
250 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
251 m_graphicContext
->SetPen( m_pen
) ;
252 m_graphicContext
->SetBrush( m_brush
) ;
253 SetBackground(MacGetBackgroundBrush(window
));
258 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
259 m_graphicContext
= NULL
;
262 // there is no out-of-order drawing on OSX
264 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
265 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
266 wxPoint origin
= window
->GetClientAreaOrigin() ;
267 wxSize size
= window
->GetClientSize() ;
271 window
->MacWindowToRootWindow( &x
, &y
) ;
272 m_macLocalOrigin
.x
= x
;
273 m_macLocalOrigin
.y
= y
;
274 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
275 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
276 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
277 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
278 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
279 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
280 m_macPort
= UMAGetWindowPort( windowref
) ;
281 SetBackground(MacGetBackgroundBrush(window
));
284 SetFont( window
->GetFont() ) ;
287 wxPaintDC::~wxPaintDC()
291 void wxPaintDC::DoGetSize(int *width
, int *height
) const
293 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
295 m_window
->GetClientSize( width
, height
);