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 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
113 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
117 window
->MacWindowToRootWindow( &x
, &y
) ;
118 m_macLocalOrigin
.x
= x
;
119 m_macLocalOrigin
.y
= y
;
120 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
121 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
122 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
123 m_macPort
= UMAGetWindowPort( windowref
) ;
125 MacSetupGraphicContext() ;
126 SetBackground(MacGetBackgroundBrush(window
));
129 wxWindowDC::~wxWindowDC()
133 void wxWindowDC::DoGetSize( int* width
, int* height
) const
135 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
137 m_window
->GetSize(width
, height
);
144 wxClientDC::wxClientDC()
149 wxClientDC::wxClientDC(wxWindow
*window
)
152 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
155 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
156 wxPoint origin
= window
->GetClientAreaOrigin() ;
157 wxSize size
= window
->GetClientSize() ;
161 window
->MacWindowToRootWindow( &x
, &y
) ;
162 m_macLocalOrigin
.x
= x
;
163 m_macLocalOrigin
.y
= y
;
164 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
165 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
166 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
167 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
168 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
169 m_macPort
= UMAGetWindowPort( windowref
) ;
172 MacSetupGraphicContext() ;
173 SetBackground(MacGetBackgroundBrush(window
));
174 SetFont( window
->GetFont() ) ;
177 wxClientDC::~wxClientDC()
181 void wxClientDC::DoGetSize(int *width
, int *height
) const
183 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
185 m_window
->GetClientSize( width
, height
);
193 wxPaintDC::wxPaintDC()
198 wxPaintDC::wxPaintDC(wxWindow
*window
)
201 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 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
215 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
216 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
217 m_macPort
= UMAGetWindowPort( windowref
) ;
220 MacSetupGraphicContext() ;
221 SetBackground(MacGetBackgroundBrush(window
));
222 SetFont( window
->GetFont() ) ;
225 wxPaintDC::~wxPaintDC()
229 void wxPaintDC::DoGetSize(int *width
, int *height
) const
231 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
233 m_window
->GetClientSize( width
, height
);