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 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
46 #include "wx/mac/uma.h"
47 #include "wx/notebook.h"
48 #include "wx/tabctrl.h"
51 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
53 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
54 #if !TARGET_API_MAC_OSX
55 // transparency cannot be handled by the OS when not using composited windows
56 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() ) ;
69 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
71 bkdBrush
= parent
->MacGetBackgroundBrush() ;
74 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
76 Rect extent
= { 0 , 0 , 0 , 0 } ;
79 wxSize size
= parent
->GetSize() ;
80 parent
->MacClientToRootWindow( &x
, &y
) ;
84 extent
.right
= x
+ size
.x
;
85 extent
.bottom
= y
+ size
.y
;
86 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
90 parent
= parent
->GetParent() ;
93 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
95 // if we did not find something, use a default
96 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
103 wxWindowDC::wxWindowDC()
108 wxWindowDC::wxWindowDC(wxWindow
*window
)
111 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
114 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
117 wxSize size
= window
->GetSize() ;
118 window
->MacWindowToRootWindow( &x
, &y
) ;
119 m_macPort
= UMAGetWindowPort( windowref
) ;
121 #if wxMAC_USE_CORE_GRAPHICS
122 m_macLocalOriginInPort
.x
= x
;
123 m_macLocalOriginInPort
.y
= y
;
125 if ( window
->MacGetCGContextRef() )
127 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
128 m_graphicContext
->SetPen( m_pen
) ;
129 m_graphicContext
->SetBrush( m_brush
) ;
130 SetBackground(MacGetBackgroundBrush(window
));
134 // as out of order redraw is not supported under CQ, we have to create a qd port for these
136 m_macLocalOrigin
.x
= x
;
137 m_macLocalOrigin
.y
= y
;
139 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
140 m_graphicContext
->SetPen( m_pen
) ;
141 m_graphicContext
->SetBrush( m_brush
) ;
142 SetBackground(MacGetBackgroundBrush(window
));
144 // there is no out-of-order drawing on OSX
146 m_macLocalOrigin
.x
= x
;
147 m_macLocalOrigin
.y
= y
;
148 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
149 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
150 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
151 SetBackground(MacGetBackgroundBrush(window
));
154 SetFont( window
->GetFont() ) ;
157 wxWindowDC::~wxWindowDC()
161 void wxWindowDC::DoGetSize( int* width
, int* height
) const
163 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
165 m_window
->GetSize(width
, height
);
172 wxClientDC::wxClientDC()
177 wxClientDC::wxClientDC(wxWindow
*window
)
180 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
183 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
184 wxPoint origin
= window
->GetClientAreaOrigin() ;
185 wxSize size
= window
->GetClientSize() ;
189 window
->MacWindowToRootWindow( &x
, &y
) ;
190 m_macPort
= UMAGetWindowPort( windowref
) ;
192 #if wxMAC_USE_CORE_GRAPHICS
193 m_macLocalOriginInPort
.x
= x
;
194 m_macLocalOriginInPort
.y
= y
;
195 if ( window
->MacGetCGContextRef() )
197 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
198 m_graphicContext
->SetPen( m_pen
) ;
199 m_graphicContext
->SetBrush( m_brush
) ;
201 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
202 SetBackground(MacGetBackgroundBrush(window
));
206 // as out of order redraw is not supported under CQ, we have to create a qd port for these
208 m_macLocalOrigin
.x
= x
;
209 m_macLocalOrigin
.y
= y
;
210 m_graphicContext
= new wxMacCGContext( (CGrafPtr
) m_macPort
) ;
211 m_graphicContext
->SetPen( m_pen
) ;
212 m_graphicContext
->SetBrush( m_brush
) ;
216 m_macLocalOrigin
.x
= x
;
217 m_macLocalOrigin
.y
= y
;
218 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
219 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
220 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
221 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
222 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
225 SetBackground(MacGetBackgroundBrush(window
));
226 SetFont( window
->GetFont() ) ;
229 wxClientDC::~wxClientDC()
231 #if wxMAC_USE_CORE_GRAPHICS
233 if ( m_window->MacGetCGContextRef() == 0)
235 CGContextRef cgContext = (wxMacCGContext*)(m_graphicContext)->GetNativeContext() ;
236 CGContextFlush( cgContext ) ;
242 void wxClientDC::DoGetSize(int *width
, int *height
) const
244 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
246 m_window
->GetClientSize( width
, height
);
254 wxPaintDC::wxPaintDC()
259 wxPaintDC::wxPaintDC(wxWindow
*window
)
262 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
263 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
264 wxPoint origin
= window
->GetClientAreaOrigin() ;
265 wxSize size
= window
->GetClientSize() ;
269 window
->MacWindowToRootWindow( &x
, &y
) ;
270 m_macPort
= UMAGetWindowPort( windowref
) ;
271 #if wxMAC_USE_CORE_GRAPHICS
272 m_macLocalOriginInPort
.x
= x
;
273 m_macLocalOriginInPort
.y
= y
;
274 if ( window
->MacGetCGContextRef() )
276 m_graphicContext
= new wxMacCGContext( (CGContextRef
) window
->MacGetCGContextRef() ) ;
277 m_graphicContext
->SetPen( m_pen
) ;
278 m_graphicContext
->SetBrush( m_brush
) ;
280 SetClippingRegion( 0 , 0 , size
.x
, size
.y
) ;
281 SetBackground(MacGetBackgroundBrush(window
));
285 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
286 m_graphicContext
= NULL
;
289 // there is no out-of-order drawing on OSX
291 m_macLocalOrigin
.x
= x
;
292 m_macLocalOrigin
.y
= y
;
293 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
294 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
295 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
296 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
297 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
298 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
299 SetBackground(MacGetBackgroundBrush(window
));
302 SetFont( window
->GetFont() ) ;
305 wxPaintDC::~wxPaintDC()
309 void wxPaintDC::DoGetSize(int *width
, int *height
) const
311 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
313 m_window
->GetClientSize( width
, height
);