]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
replaced wxLogDebugs() with wxLogTrace()S
[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 {
122 // as out of order redraw is not supported under CQ, we have to create a qd port for these
123 // situations
124 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
125 if (!rootwindow)
126 return;
127 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
128 wxSize size = window->GetClientSize() ;
129 int x , y ;
130 x = y = 0 ;
131 window->MacWindowToRootWindow( &x , &y ) ;
132 m_macLocalOrigin.x = x ;
133 m_macLocalOrigin.y = y ;
134 CGrafPtr port = UMAGetWindowPort( windowref ) ;
135
136 m_graphicContext = new wxMacCGContext( port ) ;
137 m_graphicContext->SetPen( m_pen ) ;
138 m_graphicContext->SetBrush( m_brush ) ;
139 SetBackground(MacGetBackgroundBrush(window));
140 }
141 // there is no out-of-order drawing on OSX
142 #else
143 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
144 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
145 int x , y ;
146 x = y = 0 ;
147 window->MacWindowToRootWindow( &x , &y ) ;
148 m_macLocalOrigin.x = x ;
149 m_macLocalOrigin.y = y ;
150 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
151 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
152 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
153 m_macPort = UMAGetWindowPort( windowref ) ;
154 SetBackground(MacGetBackgroundBrush(window));
155 #endif
156 m_ok = TRUE ;
157 SetFont( window->GetFont() ) ;
158 }
159
160 wxWindowDC::~wxWindowDC()
161 {
162 }
163
164 void wxWindowDC::DoGetSize( int* width, int* height ) const
165 {
166 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
167
168 m_window->GetSize(width, height);
169 }
170
171 /*
172 * wxClientDC
173 */
174
175 wxClientDC::wxClientDC()
176 {
177 m_window = NULL ;
178 }
179
180 wxClientDC::wxClientDC(wxWindow *window)
181 {
182 m_window = window ;
183 #if wxMAC_USE_CORE_GRAPHICS
184 m_graphicContext = NULL ;
185 if ( window->MacGetCGContextRef() )
186 {
187 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
188 m_graphicContext->SetPen( m_pen ) ;
189 m_graphicContext->SetBrush( m_brush ) ;
190 SetBackground(MacGetBackgroundBrush(window));
191 }
192 else
193 {
194 // as out of order redraw is not supported under CQ, we have to create a qd port for these
195 // situations
196 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
197 if (!rootwindow)
198 return;
199 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
200 wxPoint origin = window->GetClientAreaOrigin() ;
201 wxSize size = window->GetClientSize() ;
202 int x , y ;
203 x = origin.x ;
204 y = origin.y ;
205 window->MacWindowToRootWindow( &x , &y ) ;
206 m_macLocalOrigin.x = x ;
207 m_macLocalOrigin.y = y ;
208 CGrafPtr port = UMAGetWindowPort( windowref ) ;
209
210 m_graphicContext = new wxMacCGContext( port ) ;
211 m_graphicContext->SetPen( m_pen ) ;
212 m_graphicContext->SetBrush( m_brush ) ;
213 SetBackground(MacGetBackgroundBrush(window));
214 }
215 m_ok = TRUE ;
216 #else
217 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
218 if (!rootwindow)
219 return;
220 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
221 wxPoint origin = window->GetClientAreaOrigin() ;
222 wxSize size = window->GetClientSize() ;
223 int x , y ;
224 x = origin.x ;
225 y = origin.y ;
226 window->MacWindowToRootWindow( &x , &y ) ;
227 m_macLocalOrigin.x = x ;
228 m_macLocalOrigin.y = y ;
229 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
230 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
231 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
232 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
233 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
234 m_macPort = UMAGetWindowPort( windowref ) ;
235 m_ok = TRUE ;
236 #endif
237 SetBackground(MacGetBackgroundBrush(window));
238 SetFont( window->GetFont() ) ;
239 }
240
241 wxClientDC::~wxClientDC()
242 {
243 }
244
245 void wxClientDC::DoGetSize(int *width, int *height) const
246 {
247 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
248
249 m_window->GetClientSize( width, height );
250 }
251
252
253 /*
254 * wxPaintDC
255 */
256
257 wxPaintDC::wxPaintDC()
258 {
259 m_window = NULL ;
260 }
261
262 wxPaintDC::wxPaintDC(wxWindow *window)
263 {
264 m_window = window ;
265 #if wxMAC_USE_CORE_GRAPHICS
266 if ( window->MacGetCGContextRef() )
267 {
268 m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
269 m_graphicContext->SetPen( m_pen ) ;
270 m_graphicContext->SetBrush( m_brush ) ;
271 SetBackground(MacGetBackgroundBrush(window));
272 m_ok = TRUE ;
273 }
274 else
275 {
276 wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
277 m_graphicContext = NULL ;
278 m_ok = TRUE ;
279 }
280 // there is no out-of-order drawing on OSX
281 #else
282 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
283 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
284 wxPoint origin = window->GetClientAreaOrigin() ;
285 wxSize size = window->GetClientSize() ;
286 int x , y ;
287 x = origin.x ;
288 y = origin.y ;
289 window->MacWindowToRootWindow( &x , &y ) ;
290 m_macLocalOrigin.x = x ;
291 m_macLocalOrigin.y = y ;
292 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
293 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
294 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
295 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
296 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
297 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
298 m_macPort = UMAGetWindowPort( windowref ) ;
299 SetBackground(MacGetBackgroundBrush(window));
300 m_ok = TRUE ;
301 #endif
302 SetFont( window->GetFont() ) ;
303 }
304
305 wxPaintDC::~wxPaintDC()
306 {
307 }
308
309 void wxPaintDC::DoGetSize(int *width, int *height) const
310 {
311 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
312
313 m_window->GetClientSize( width, height );
314 }
315
316