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 #if wxMAC_USE_CORE_GRAPHICS
114 if ( window
->MacGetCGContextRef() )
116 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
117 m_graphicContext
->SetPen( m_pen
) ;
118 m_graphicContext
->SetBrush( m_brush
) ;
119 SetBackground(MacGetBackgroundBrush(window
));
123 // as out of order redraw is not supported under CQ, we have to create a qd port for these
125 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
128 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
131 window
->MacWindowToRootWindow( &x
, &y
) ;
132 m_macLocalOrigin
.x
= x
;
133 m_macLocalOrigin
.y
= y
;
134 CGrafPtr port
= UMAGetWindowPort( windowref
) ;
136 m_graphicContext
= new wxMacCGContext( port
) ;
137 m_graphicContext
->SetPen( m_pen
) ;
138 m_graphicContext
->SetBrush( m_brush
) ;
139 SetBackground(MacGetBackgroundBrush(window
));
141 // there is no out-of-order drawing on OSX
143 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
144 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
147 window
->MacWindowToRootWindow( &x
, &y
) ;
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 m_macPort
= UMAGetWindowPort( windowref
) ;
154 SetBackground(MacGetBackgroundBrush(window
));
157 SetFont( window
->GetFont() ) ;
160 wxWindowDC::~wxWindowDC()
164 void wxWindowDC::DoGetSize( int* width
, int* height
) const
166 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
168 m_window
->GetSize(width
, height
);
175 wxClientDC::wxClientDC()
180 wxClientDC::wxClientDC(wxWindow
*window
)
183 #if wxMAC_USE_CORE_GRAPHICS
184 m_graphicContext
= NULL
;
185 if ( window
->MacGetCGContextRef() )
187 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
188 m_graphicContext
->SetPen( m_pen
) ;
189 m_graphicContext
->SetBrush( m_brush
) ;
190 SetBackground(MacGetBackgroundBrush(window
));
194 // as out of order redraw is not supported under CQ, we have to create a qd port for these
196 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
199 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
200 wxPoint origin
= window
->GetClientAreaOrigin() ;
204 window
->MacWindowToRootWindow( &x
, &y
) ;
205 m_macLocalOrigin
.x
= x
;
206 m_macLocalOrigin
.y
= y
;
207 CGrafPtr port
= UMAGetWindowPort( windowref
) ;
209 m_graphicContext
= new wxMacCGContext( port
) ;
210 m_graphicContext
->SetPen( m_pen
) ;
211 m_graphicContext
->SetBrush( m_brush
) ;
212 SetBackground(MacGetBackgroundBrush(window
));
216 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
219 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
220 wxPoint origin
= window
->GetClientAreaOrigin() ;
221 wxSize size
= window
->GetClientSize() ;
225 window
->MacWindowToRootWindow( &x
, &y
) ;
226 m_macLocalOrigin
.x
= x
;
227 m_macLocalOrigin
.y
= y
;
228 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
229 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
230 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
231 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
232 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
233 m_macPort
= UMAGetWindowPort( windowref
) ;
236 SetBackground(MacGetBackgroundBrush(window
));
237 SetFont( window
->GetFont() ) ;
240 wxClientDC::~wxClientDC()
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 #if wxMAC_USE_CORE_GRAPHICS
265 if ( window
->MacGetCGContextRef() )
267 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
268 m_graphicContext
->SetPen( m_pen
) ;
269 m_graphicContext
->SetBrush( m_brush
) ;
270 SetBackground(MacGetBackgroundBrush(window
));
275 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
276 m_graphicContext
= NULL
;
279 // there is no out-of-order drawing on OSX
281 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
282 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
283 wxPoint origin
= window
->GetClientAreaOrigin() ;
284 wxSize size
= window
->GetClientSize() ;
288 window
->MacWindowToRootWindow( &x
, &y
) ;
289 m_macLocalOrigin
.x
= x
;
290 m_macLocalOrigin
.y
= y
;
291 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
292 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
293 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
294 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
295 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
296 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
297 m_macPort
= UMAGetWindowPort( windowref
) ;
298 SetBackground(MacGetBackgroundBrush(window
));
301 SetFont( window
->GetFont() ) ;
304 wxPaintDC::~wxPaintDC()
308 void wxPaintDC::DoGetSize(int *width
, int *height
) const
310 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
312 m_window
->GetClientSize( width
, height
);