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