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"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 #define RAD2DEG 57.2957795131
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
40 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
41 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
48 #include "wx/mac/uma.h"
49 #include "wx/notebook.h"
50 #include "wx/tabctrl.h"
53 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
55 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
56 #if !TARGET_API_MAC_OSX
57 // transparency cannot be handled by the OS when not using composited windows
58 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() ) ;
71 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
73 bkdBrush
= parent
->MacGetBackgroundBrush() ;
76 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
78 Rect extent
= { 0 , 0 , 0 , 0 } ;
81 wxSize size
= parent
->GetSize() ;
82 parent
->MacClientToRootWindow( &x
, &y
) ;
86 extent
.right
= x
+ size
.x
;
87 extent
.bottom
= y
+ size
.y
;
88 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
92 parent
= parent
->GetParent() ;
95 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
97 // if we did not find something, use a default
98 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
105 wxWindowDC::wxWindowDC()
110 wxWindowDC::wxWindowDC(wxWindow
*window
)
113 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
116 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
119 wxSize size
= window
->GetSize() ;
120 window
->MacWindowToRootWindow( &x
, &y
) ;
121 m_macPort
= UMAGetWindowPort( windowref
) ;
123 #if wxMAC_USE_CORE_GRAPHICS
124 m_macLocalOriginInPort
.x
= x
;
125 m_macLocalOriginInPort
.y
= y
;
127 if ( window
->MacGetCGContextRef() )
129 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
130 m_graphicContext
->SetPen( m_pen
) ;
131 m_graphicContext
->SetBrush( m_brush
) ;
132 SetBackground(MacGetBackgroundBrush(window
));
136 // as out of order redraw is not supported under CQ, we have to create a qd port for these
138 m_macLocalOrigin
.x
= x
;
139 m_macLocalOrigin
.y
= y
;
141 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
142 m_graphicContext
->SetPen( m_pen
) ;
143 m_graphicContext
->SetBrush( m_brush
) ;
144 SetBackground(MacGetBackgroundBrush(window
));
146 // there is no out-of-order drawing on OSX
148 m_macLocalOrigin
.x
= x
;
149 m_macLocalOrigin
.y
= y
;
150 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
151 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
152 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
153 SetBackground(MacGetBackgroundBrush(window
));
156 SetFont( window
->GetFont() ) ;
159 wxWindowDC::~wxWindowDC()
163 void wxWindowDC::DoGetSize( int* width
, int* height
) const
165 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
167 m_window
->GetSize(width
, height
);
174 wxClientDC::wxClientDC()
179 wxClientDC::wxClientDC(wxWindow
*window
)
182 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
185 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
186 wxPoint origin
= window
->GetClientAreaOrigin() ;
187 wxSize size
= window
->GetClientSize() ;
191 window
->MacWindowToRootWindow( &x
, &y
) ;
192 m_macPort
= UMAGetWindowPort( windowref
) ;
194 #if wxMAC_USE_CORE_GRAPHICS
195 m_macLocalOriginInPort
.x
= x
;
196 m_macLocalOriginInPort
.y
= y
;
197 if ( window
->MacGetCGContextRef() )
199 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
200 m_graphicContext
->SetPen( m_pen
) ;
201 m_graphicContext
->SetBrush( m_brush
) ;
203 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
204 SetBackground(MacGetBackgroundBrush(window
));
208 // as out of order redraw is not supported under CQ, we have to create a qd port for these
210 m_macLocalOrigin
.x
= x
;
211 m_macLocalOrigin
.y
= y
;
212 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
213 m_graphicContext
->SetPen( m_pen
) ;
214 m_graphicContext
->SetBrush( m_brush
) ;
218 m_macLocalOrigin
.x
= x
;
219 m_macLocalOrigin
.y
= y
;
220 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
221 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
222 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
223 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
224 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
227 SetBackground(MacGetBackgroundBrush(window
));
228 SetFont( window
->GetFont() ) ;
231 wxClientDC::~wxClientDC()
233 #if wxMAC_USE_CORE_GRAPHICS
235 if ( m_window->MacGetCGContextRef() == 0)
237 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
238 CGContextFlush( cgContext ) ;
244 void wxClientDC::DoGetSize(int *width
, int *height
) const
246 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
248 m_window
->GetClientSize( width
, height
);
256 wxPaintDC::wxPaintDC()
261 wxPaintDC::wxPaintDC(wxWindow
*window
)
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_macPort
= UMAGetWindowPort( windowref
) ;
273 #if wxMAC_USE_CORE_GRAPHICS
274 m_macLocalOriginInPort
.x
= x
;
275 m_macLocalOriginInPort
.y
= y
;
276 if ( window
->MacGetCGContextRef() )
278 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
279 m_graphicContext
->SetPen( m_pen
) ;
280 m_graphicContext
->SetBrush( m_brush
) ;
282 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
283 SetBackground(MacGetBackgroundBrush(window
));
287 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
288 m_graphicContext
= NULL
;
291 // there is no out-of-order drawing on OSX
293 m_macLocalOrigin
.x
= x
;
294 m_macLocalOrigin
.y
= y
;
295 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
296 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
297 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
298 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
299 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
300 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
301 SetBackground(MacGetBackgroundBrush(window
));
304 SetFont( window
->GetFont() ) ;
307 wxPaintDC::~wxPaintDC()
311 void wxPaintDC::DoGetSize(int *width
, int *height
) const
313 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
315 m_window
->GetClientSize( width
, height
);