1 /////////////////////////////////////////////////////////////////////////////
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"
15 #include "wx/dcmemory.h"
16 #include "wx/region.h"
17 #include "wx/window.h"
18 #include "wx/toplevel.h"
19 #include "wx/settings.h"
21 #include "wx/mac/private.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 #define RAD2DEG 57.2957795131
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
35 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
36 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
42 #include "wx/mac/uma.h"
43 #include "wx/notebook.h"
44 #include "wx/tabctrl.h"
47 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
49 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
50 #if !TARGET_API_MAC_OSX
51 // transparency cannot be handled by the OS when not using composited windows
52 wxWindow
* parent
= window
->GetParent() ;
53 // if we have some 'pseudo' transparency
54 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
56 // walk up until we find something
57 while( parent
!= NULL
)
59 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
61 // if we have any other colours in the hierarchy
62 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
65 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
67 bkdBrush
= parent
->MacGetBackgroundBrush() ;
70 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
72 Rect extent
= { 0 , 0 , 0 , 0 } ;
75 wxSize size
= parent
->GetSize() ;
76 parent
->MacClientToRootWindow( &x
, &y
) ;
80 extent
.right
= x
+ size
.x
;
81 extent
.bottom
= y
+ size
.y
;
82 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
86 parent
= parent
->GetParent() ;
89 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
91 // if we did not find something, use a default
92 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
99 wxWindowDC::wxWindowDC()
104 wxWindowDC::wxWindowDC(wxWindow
*window
)
107 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
110 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
113 wxSize size
= window
->GetSize() ;
114 window
->MacWindowToRootWindow( &x
, &y
) ;
115 m_macPort
= UMAGetWindowPort( windowref
) ;
117 #if wxMAC_USE_CORE_GRAPHICS
118 m_macLocalOriginInPort
.x
= x
;
119 m_macLocalOriginInPort
.y
= y
;
121 if ( window
->MacGetCGContextRef() )
123 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
124 m_graphicContext
->SetPen( m_pen
) ;
125 m_graphicContext
->SetBrush( m_brush
) ;
126 SetBackground(MacGetBackgroundBrush(window
));
130 // as out of order redraw is not supported under CQ, we have to create a qd port for these
132 m_macLocalOrigin
.x
= x
;
133 m_macLocalOrigin
.y
= y
;
135 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
136 m_graphicContext
->SetPen( m_pen
) ;
137 m_graphicContext
->SetBrush( m_brush
) ;
138 SetBackground(MacGetBackgroundBrush(window
));
140 // there is no out-of-order drawing on OSX
142 m_macLocalOrigin
.x
= x
;
143 m_macLocalOrigin
.y
= y
;
144 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
145 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
146 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
147 SetBackground(MacGetBackgroundBrush(window
));
150 SetFont( window
->GetFont() ) ;
153 wxWindowDC::~wxWindowDC()
157 void wxWindowDC::DoGetSize( int* width
, int* height
) const
159 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
161 m_window
->GetSize(width
, height
);
168 wxClientDC::wxClientDC()
173 wxClientDC::wxClientDC(wxWindow
*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_macPort
= UMAGetWindowPort( windowref
) ;
188 #if wxMAC_USE_CORE_GRAPHICS
189 m_macLocalOriginInPort
.x
= x
;
190 m_macLocalOriginInPort
.y
= y
;
191 if ( window
->MacGetCGContextRef() )
193 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
194 m_graphicContext
->SetPen( m_pen
) ;
195 m_graphicContext
->SetBrush( m_brush
) ;
197 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
198 SetBackground(MacGetBackgroundBrush(window
));
202 // as out of order redraw is not supported under CQ, we have to create a qd port for these
204 m_macLocalOrigin
.x
= x
;
205 m_macLocalOrigin
.y
= y
;
206 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
207 m_graphicContext
->SetPen( m_pen
) ;
208 m_graphicContext
->SetBrush( m_brush
) ;
212 m_macLocalOrigin
.x
= x
;
213 m_macLocalOrigin
.y
= y
;
214 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
215 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
216 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
217 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
218 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
221 SetBackground(MacGetBackgroundBrush(window
));
222 SetFont( window
->GetFont() ) ;
225 wxClientDC::~wxClientDC()
227 #if wxMAC_USE_CORE_GRAPHICS
229 if ( m_window->MacGetCGContextRef() == 0)
231 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
232 CGContextFlush( cgContext ) ;
238 void wxClientDC::DoGetSize(int *width
, int *height
) const
240 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
242 m_window
->GetClientSize( width
, height
);
250 wxPaintDC::wxPaintDC()
255 wxPaintDC::wxPaintDC(wxWindow
*window
)
258 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
259 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
260 wxPoint origin
= window
->GetClientAreaOrigin() ;
261 wxSize size
= window
->GetClientSize() ;
265 window
->MacWindowToRootWindow( &x
, &y
) ;
266 m_macPort
= UMAGetWindowPort( windowref
) ;
267 #if wxMAC_USE_CORE_GRAPHICS
268 m_macLocalOriginInPort
.x
= x
;
269 m_macLocalOriginInPort
.y
= y
;
270 if ( window
->MacGetCGContextRef() )
272 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
273 m_graphicContext
->SetPen( m_pen
) ;
274 m_graphicContext
->SetBrush( m_brush
) ;
276 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
277 SetBackground(MacGetBackgroundBrush(window
));
281 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
282 m_graphicContext
= NULL
;
285 // there is no out-of-order drawing on OSX
287 m_macLocalOrigin
.x
= x
;
288 m_macLocalOrigin
.y
= y
;
289 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
290 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
291 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
292 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
293 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
294 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
295 SetBackground(MacGetBackgroundBrush(window
));
298 SetFont( window
->GetFont() ) ;
301 wxPaintDC::~wxPaintDC()
305 void wxPaintDC::DoGetSize(int *width
, int *height
) const
307 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
309 m_window
->GetClientSize( width
, height
);