]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
optimizing gauge cpu usage
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcclient.cpp
3 // Purpose: wxClientDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dcclient.h"
14 #endif
15
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"
22 #include "wx/math.h"
23 #include "wx/mac/private.h"
24
25 //-----------------------------------------------------------------------------
26 // constants
27 //-----------------------------------------------------------------------------
28
29 #define RAD2DEG 57.2957795131
30
31 //-----------------------------------------------------------------------------
32 // wxPaintDC
33 //-----------------------------------------------------------------------------
34
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
37 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
38 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
39 #endif
40
41 /*
42 * wxWindowDC
43 */
44
45 #include "wx/mac/uma.h"
46 #include "wx/notebook.h"
47 #include "wx/tabctrl.h"
48
49
50 static wxBrush MacGetBackgroundBrush( wxWindow* window )
51 {
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 ) )
58 {
59 // walk up until we find something
60 while( parent != NULL )
61 {
62 if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
63 {
64 // if we have any other colours in the hierarchy
65 bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
66 break ;
67 }
68 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
69 {
70 bkdBrush = parent->MacGetBackgroundBrush() ;
71 break ;
72 }
73 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
74 {
75 Rect extent = { 0 , 0 , 0 , 0 } ;
76 int x , y ;
77 x = y = 0 ;
78 wxSize size = parent->GetSize() ;
79 parent->MacClientToRootWindow( &x , &y ) ;
80 extent.left = x ;
81 extent.top = y ;
82 extent.top-- ;
83 extent.right = x + size.x ;
84 extent.bottom = y + size.y ;
85 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
86 break ;
87 }
88
89 parent = parent->GetParent() ;
90 }
91 }
92 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
93 {
94 // if we did not find something, use a default
95 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
96 }
97 #endif
98 return bkdBrush ;
99 }
100
101
102 wxWindowDC::wxWindowDC()
103 {
104 m_window = NULL ;
105 }
106
107 wxWindowDC::wxWindowDC(wxWindow *window)
108 {
109 m_window = window ;
110 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
111 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
112
113 int x , y ;
114 x = y = 0 ;
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 ) ;
122 m_ok = TRUE ;
123 SetBackground(MacGetBackgroundBrush(window));
124 }
125
126 wxWindowDC::~wxWindowDC()
127 {
128 }
129
130 void wxWindowDC::DoGetSize( int* width, int* height ) const
131 {
132 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
133
134 m_window->GetSize(width, height);
135 }
136
137 /*
138 * wxClientDC
139 */
140
141 wxClientDC::wxClientDC()
142 {
143 m_window = NULL ;
144 }
145
146 wxClientDC::wxClientDC(wxWindow *window)
147 {
148 m_window = window ;
149 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
150 if (!rootwindow)
151 return;
152 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
153 wxPoint origin = window->GetClientAreaOrigin() ;
154 wxSize size = window->GetClientSize() ;
155 int x , y ;
156 x = origin.x ;
157 y = origin.y ;
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 ) ;
167
168 m_ok = TRUE ;
169 SetBackground(MacGetBackgroundBrush(window));
170 SetFont( window->GetFont() ) ;
171 }
172
173 wxClientDC::~wxClientDC()
174 {
175 }
176
177 void wxClientDC::DoGetSize(int *width, int *height) const
178 {
179 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
180
181 m_window->GetClientSize( width, height );
182 }
183
184
185 /*
186 * wxPaintDC
187 */
188
189 wxPaintDC::wxPaintDC()
190 {
191 m_window = NULL ;
192 }
193
194 wxPaintDC::wxPaintDC(wxWindow *window)
195 {
196 m_window = window ;
197 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
198 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
199 wxPoint origin = window->GetClientAreaOrigin() ;
200 wxSize size = window->GetClientSize() ;
201 int x , y ;
202 x = origin.x ;
203 y = origin.y ;
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 ) ;
214
215 m_ok = TRUE ;
216 SetBackground(MacGetBackgroundBrush(window));
217 SetFont( window->GetFont() ) ;
218 }
219
220 wxPaintDC::~wxPaintDC()
221 {
222 }
223
224 void wxPaintDC::DoGetSize(int *width, int *height) const
225 {
226 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
227
228 m_window->GetClientSize( width, height );
229 }
230
231