]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
ac107c5cdfbcbb7a013de47f86b3e4f39cb398f3
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dcclient.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
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"
24 #include "wx/math.h"
25 #include "wx/mac/private.h"
26
27 //-----------------------------------------------------------------------------
28 // constants
29 //-----------------------------------------------------------------------------
30
31 #define RAD2DEG 57.2957795131
32
33 //-----------------------------------------------------------------------------
34 // wxPaintDC
35 //-----------------------------------------------------------------------------
36
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
41 #endif
42
43 /*
44 * wxWindowDC
45 */
46
47 #include "wx/mac/uma.h"
48 #include "wx/notebook.h"
49 #include "wx/tabctrl.h"
50
51
52 static wxBrush MacGetBackgroundBrush( wxWindow* window )
53 {
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 ) )
60 {
61 // walk up until we find something
62 while( parent != NULL )
63 {
64 if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
65 {
66 // if we have any other colours in the hierarchy
67 bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
68 break ;
69 }
70 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
71 {
72 bkdBrush = parent->MacGetBackgroundBrush() ;
73 break ;
74 }
75 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
76 {
77 Rect extent = { 0 , 0 , 0 , 0 } ;
78 int x , y ;
79 x = y = 0 ;
80 wxSize size = parent->GetSize() ;
81 parent->MacClientToRootWindow( &x , &y ) ;
82 extent.left = x ;
83 extent.top = y ;
84 extent.top-- ;
85 extent.right = x + size.x ;
86 extent.bottom = y + size.y ;
87 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
88 break ;
89 }
90
91 parent = parent->GetParent() ;
92 }
93 }
94 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
95 {
96 // if we did not find something, use a default
97 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
98 }
99 #endif
100 return bkdBrush ;
101 }
102
103
104 wxWindowDC::wxWindowDC()
105 {
106 m_window = NULL ;
107 }
108
109 wxWindowDC::wxWindowDC(wxWindow *window)
110 {
111 m_window = window ;
112 #if wxMAC_USE_CORE_GRAPHICS
113 if ( window->MacGetCGContextRef() )
114 {
115 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
116 m_graphicContext->SetPen( m_pen ) ;
117 m_graphicContext->SetBrush( m_brush ) ;
118 SetBackground(MacGetBackgroundBrush(window));
119 }
120 else
121 m_graphicContext = NULL ;
122 // there is no out-of-order drawing on OSX
123 #else
124 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
125 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
126 int x , y ;
127 x = y = 0 ;
128 window->MacWindowToRootWindow( &x , &y ) ;
129 m_macLocalOrigin.x = x ;
130 m_macLocalOrigin.y = y ;
131 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
132 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
133 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
134 m_macPort = UMAGetWindowPort( windowref ) ;
135 SetBackground(MacGetBackgroundBrush(window));
136 #endif
137 m_ok = TRUE ;
138 SetFont( window->GetFont() ) ;
139 }
140
141 wxWindowDC::~wxWindowDC()
142 {
143 }
144
145 void wxWindowDC::DoGetSize( int* width, int* height ) const
146 {
147 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
148
149 m_window->GetSize(width, height);
150 }
151
152 /*
153 * wxClientDC
154 */
155
156 wxClientDC::wxClientDC()
157 {
158 m_window = NULL ;
159 }
160
161 wxClientDC::wxClientDC(wxWindow *window)
162 {
163 m_window = window ;
164 #if wxMAC_USE_CORE_GRAPHICS
165 m_graphicContext = NULL ;
166 if ( window->MacGetCGContextRef() )
167 {
168 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
169 m_graphicContext->SetPen( m_pen ) ;
170 m_graphicContext->SetBrush( m_brush ) ;
171 SetBackground(MacGetBackgroundBrush(window));
172 }
173 else
174 {
175 /*
176 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
177 if (!rootwindow)
178 return;
179 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
180 wxPoint origin = window->GetClientAreaOrigin() ;
181 wxSize size = window->GetClientSize() ;
182 int x , y ;
183 x = origin.x ;
184 y = origin.y ;
185 window->MacWindowToRootWindow( &x , &y ) ;
186 m_macLocalOrigin.x = x ;
187 m_macLocalOrigin.y = y ;
188 CGrafPtr port = UMAGetWindowPort( windowref ) ;
189
190 m_graphicContext = new wxMacCGContext( port ) ;
191 m_graphicContext->SetPen( m_pen ) ;
192 m_graphicContext->SetBrush( m_brush ) ;
193 SetBackground(MacGetBackgroundBrush(window));
194 m_ok = TRUE ;
195 */
196 }
197 m_ok = TRUE ;
198 #else
199 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
200 if (!rootwindow)
201 return;
202 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
203 wxPoint origin = window->GetClientAreaOrigin() ;
204 wxSize size = window->GetClientSize() ;
205 int x , y ;
206 x = origin.x ;
207 y = origin.y ;
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 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
215 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
216 m_macPort = UMAGetWindowPort( windowref ) ;
217 m_ok = TRUE ;
218 #endif
219 SetBackground(MacGetBackgroundBrush(window));
220 SetFont( window->GetFont() ) ;
221 }
222
223 wxClientDC::~wxClientDC()
224 {
225 }
226
227 void wxClientDC::DoGetSize(int *width, int *height) const
228 {
229 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
230
231 m_window->GetClientSize( width, height );
232 }
233
234
235 /*
236 * wxPaintDC
237 */
238
239 wxPaintDC::wxPaintDC()
240 {
241 m_window = NULL ;
242 }
243
244 wxPaintDC::wxPaintDC(wxWindow *window)
245 {
246 m_window = window ;
247 #if wxMAC_USE_CORE_GRAPHICS
248 if ( window->MacGetCGContextRef() )
249 {
250 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
251 m_graphicContext->SetPen( m_pen ) ;
252 m_graphicContext->SetBrush( m_brush ) ;
253 SetBackground(MacGetBackgroundBrush(window));
254 m_ok = TRUE ;
255 }
256 else
257 {
258 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
259 m_graphicContext = NULL ;
260 m_ok = TRUE ;
261 }
262 // there is no out-of-order drawing on OSX
263 #else
264 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
265 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
266 wxPoint origin = window->GetClientAreaOrigin() ;
267 wxSize size = window->GetClientSize() ;
268 int x , y ;
269 x = origin.x ;
270 y = origin.y ;
271 window->MacWindowToRootWindow( &x , &y ) ;
272 m_macLocalOrigin.x = x ;
273 m_macLocalOrigin.y = y ;
274 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
275 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
276 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
277 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
278 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
279 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
280 m_macPort = UMAGetWindowPort( windowref ) ;
281 SetBackground(MacGetBackgroundBrush(window));
282 m_ok = TRUE ;
283 #endif
284 SetFont( window->GetFont() ) ;
285 }
286
287 wxPaintDC::~wxPaintDC()
288 {
289 }
290
291 void wxPaintDC::DoGetSize(int *width, int *height) const
292 {
293 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
294
295 m_window->GetClientSize( width, height );
296 }
297
298