1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxClientDC class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcclient.h"
16 #include "wx/dcclient.h"
17 #include "wx/dcmemory.h"
18 #include "wx/region.h"
19 #include "wx/window.h"
20 #include "wx/toplevel.h"
22 #include "wx/mac/private.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 #define RAD2DEG 57.2957795131
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
36 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
37 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
44 #include "wx/mac/uma.h"
45 #include "wx/notebook.h"
46 #include "wx/tabctrl.h"
49 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
51 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
52 #if !TARGET_API_MAC_OSX
53 // transparency cannot be handled by the OS when not using composited windows
54 wxWindow
* parent
= window
->GetParent() ;
55 // if we have some 'pseudo' transparency
56 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
58 // walk up until we find something
59 while( parent
!= NULL
)
61 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
63 // if we have any other colours in the hierarchy
64 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
67 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
69 bkdBrush
= parent
->MacGetBackgroundBrush() ;
72 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
74 Rect extent
= { 0 , 0 , 0 , 0 } ;
77 wxSize size
= parent
->GetSize() ;
78 parent
->MacClientToRootWindow( &x
, &y
) ;
82 extent
.right
= x
+ size
.x
;
83 extent
.bottom
= y
+ size
.y
;
84 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
88 parent
= parent
->GetParent() ;
91 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
93 // if we did not find something, use a default
94 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
101 wxWindowDC::wxWindowDC()
106 wxWindowDC::wxWindowDC(wxWindow
*window
)
109 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
110 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
114 window
->MacWindowToRootWindow( &x
, &y
) ;
115 m_macLocalOrigin
.x
= x
;
116 m_macLocalOrigin
.y
= y
;
117 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
118 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
119 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
120 m_macPort
= UMAGetWindowPort( windowref
) ;
122 SetBackground(MacGetBackgroundBrush(window
));
125 wxWindowDC::~wxWindowDC()
129 void wxWindowDC::DoGetSize( int* width
, int* height
) const
131 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
133 m_window
->GetSize(width
, height
);
140 wxClientDC::wxClientDC()
145 wxClientDC::wxClientDC(wxWindow
*window
)
148 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
151 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
152 wxPoint origin
= window
->GetClientAreaOrigin() ;
153 wxSize size
= window
->GetClientSize() ;
157 window
->MacWindowToRootWindow( &x
, &y
) ;
158 m_macLocalOrigin
.x
= x
;
159 m_macLocalOrigin
.y
= y
;
160 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
161 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
162 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
163 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
164 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
165 m_macPort
= UMAGetWindowPort( windowref
) ;
168 SetBackground(MacGetBackgroundBrush(window
));
169 SetFont( window
->GetFont() ) ;
172 wxClientDC::~wxClientDC()
176 void wxClientDC::DoGetSize(int *width
, int *height
) const
178 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
180 m_window
->GetClientSize( width
, height
);
188 wxPaintDC::wxPaintDC()
193 wxPaintDC::wxPaintDC(wxWindow
*window
)
196 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
197 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
198 wxPoint origin
= window
->GetClientAreaOrigin() ;
199 wxSize size
= window
->GetClientSize() ;
203 window
->MacWindowToRootWindow( &x
, &y
) ;
204 m_macLocalOrigin
.x
= x
;
205 m_macLocalOrigin
.y
= y
;
206 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
207 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
208 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
209 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
210 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
211 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
212 m_macPort
= UMAGetWindowPort( windowref
) ;
215 SetBackground(MacGetBackgroundBrush(window
));
216 SetFont( window
->GetFont() ) ;
219 wxPaintDC::~wxPaintDC()
223 void wxPaintDC::DoGetSize(int *width
, int *height
) const
225 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
227 m_window
->GetClientSize( width
, height
);