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"
21 #include "wx/settings.h"
23 #include "wx/mac/private.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 #define RAD2DEG 57.2957795131
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
37 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
38 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
45 #include "wx/mac/uma.h"
46 #include "wx/notebook.h"
47 #include "wx/tabctrl.h"
50 static wxBrush
MacGetBackgroundBrush( wxWindow
* window
)
52 wxBrush bkdBrush
= window
->MacGetBackgroundBrush() ;
53 #if !TARGET_API_MAC_OSX
54 // transparency cannot be handled by the OS when not using composited windows
55 wxWindow
* parent
= window
->GetParent() ;
56 // if we have some 'pseudo' transparency
57 if ( ! bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
|| window
->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
59 // walk up until we find something
60 while( parent
!= NULL
)
62 if ( parent
->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
64 // if we have any other colours in the hierarchy
65 bkdBrush
.SetColour( parent
->GetBackgroundColour() ) ;
68 if ( parent
->IsKindOf( CLASSINFO(wxTopLevelWindow
) ) )
70 bkdBrush
= parent
->MacGetBackgroundBrush() ;
73 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
75 Rect extent
= { 0 , 0 , 0 , 0 } ;
78 wxSize size
= parent
->GetSize() ;
79 parent
->MacClientToRootWindow( &x
, &y
) ;
83 extent
.right
= x
+ size
.x
;
84 extent
.bottom
= y
+ size
.y
;
85 bkdBrush
.MacSetThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ;
89 parent
= parent
->GetParent() ;
92 if ( !bkdBrush
.Ok() || bkdBrush
.GetStyle() == wxTRANSPARENT
)
94 // if we did not find something, use a default
95 bkdBrush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
102 wxWindowDC::wxWindowDC()
107 wxWindowDC::wxWindowDC(wxWindow
*window
)
110 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
111 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
115 window
->MacWindowToRootWindow( &x
, &y
) ;
116 m_macLocalOrigin
.x
= x
;
117 m_macLocalOrigin
.y
= y
;
118 CopyRgn( (RgnHandle
) window
->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
119 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
120 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
121 m_macPort
= UMAGetWindowPort( windowref
) ;
123 SetBackground(MacGetBackgroundBrush(window
));
126 wxWindowDC::~wxWindowDC()
130 void wxWindowDC::DoGetSize( int* width
, int* height
) const
132 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
134 m_window
->GetSize(width
, height
);
141 wxClientDC::wxClientDC()
146 wxClientDC::wxClientDC(wxWindow
*window
)
149 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
152 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
153 wxPoint origin
= window
->GetClientAreaOrigin() ;
154 wxSize size
= window
->GetClientSize() ;
158 window
->MacWindowToRootWindow( &x
, &y
) ;
159 m_macLocalOrigin
.x
= x
;
160 m_macLocalOrigin
.y
= y
;
161 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
162 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
163 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
164 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
165 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
,(RgnHandle
) m_macCurrentClipRgn
) ;
166 m_macPort
= UMAGetWindowPort( windowref
) ;
169 SetBackground(MacGetBackgroundBrush(window
));
170 SetFont( window
->GetFont() ) ;
173 wxClientDC::~wxClientDC()
177 void wxClientDC::DoGetSize(int *width
, int *height
) const
179 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
181 m_window
->GetClientSize( width
, height
);
189 wxPaintDC::wxPaintDC()
194 wxPaintDC::wxPaintDC(wxWindow
*window
)
197 wxTopLevelWindowMac
* rootwindow
= window
->MacGetTopLevelWindow() ;
198 WindowRef windowref
= (WindowRef
) rootwindow
->MacGetWindowRef() ;
199 wxPoint origin
= window
->GetClientAreaOrigin() ;
200 wxSize size
= window
->GetClientSize() ;
204 window
->MacWindowToRootWindow( &x
, &y
) ;
205 m_macLocalOrigin
.x
= x
;
206 m_macLocalOrigin
.y
= y
;
207 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, origin
.x
, origin
.y
, origin
.x
+ size
.x
, origin
.y
+ size
.y
) ;
208 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
209 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, -origin
.x
, -origin
.y
) ;
210 SectRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) window
->GetUpdateRegion().GetWXHRGN() , (RgnHandle
) m_macBoundaryClipRgn
) ;
211 OffsetRgn( (RgnHandle
) m_macBoundaryClipRgn
, m_macLocalOrigin
.x
, m_macLocalOrigin
.y
) ;
212 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
213 m_macPort
= UMAGetWindowPort( windowref
) ;
216 SetBackground(MacGetBackgroundBrush(window
));
217 SetFont( window
->GetFont() ) ;
220 wxPaintDC::~wxPaintDC()
224 void wxPaintDC::DoGetSize(int *width
, int *height
) const
226 wxCHECK_RET( m_window
, _T("GetSize() doesn't work without window") );
228 m_window
->GetClientSize( width
, height
);