]>
Commit | Line | Data |
---|---|---|
613a24f7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/mac/carbon/dccg.cpp |
613a24f7 SC |
3 | // Purpose: wxDC class |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
e4db172a | 9 | // Licence: wxWindows licence |
613a24f7 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
20b69855 SC |
12 | #include "wx/wxprec.h" |
13 | ||
613a24f7 | 14 | #include "wx/dc.h" |
20b69855 SC |
15 | |
16 | #if wxMAC_USE_CORE_GRAPHICS | |
17 | ||
e4db172a WS |
18 | #ifndef WX_PRECOMP |
19 | #include "wx/log.h" | |
f38924e8 | 20 | #include "wx/dcmemory.h" |
b3a44e05 | 21 | #include "wx/region.h" |
e4db172a WS |
22 | #endif |
23 | ||
613a24f7 | 24 | #include "wx/mac/uma.h" |
613a24f7 | 25 | |
138861bc VZ |
26 | #ifdef __MSL__ |
27 | #if __MSL__ >= 0x6000 | |
28 | #include "math.h" | |
d281db8b | 29 | // in case our functions were defined outside std, we make it known all the same |
0f4c3aa2 | 30 | namespace std { } |
138861bc VZ |
31 | using namespace std ; |
32 | #endif | |
613a24f7 SC |
33 | #endif |
34 | ||
35 | #include "wx/mac/private.h" | |
613a24f7 | 36 | |
613a24f7 | 37 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
613a24f7 | 38 | |
01b5ab33 SC |
39 | #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES |
40 | #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0 | |
41 | #endif | |
42 | ||
bc78039c SC |
43 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 |
44 | typedef float CGFloat ; | |
45 | #endif | |
46 | ||
613a24f7 SC |
47 | //----------------------------------------------------------------------------- |
48 | // constants | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
51 | #if !defined( __DARWIN__ ) || defined(__MWERKS__) | |
52 | #ifndef M_PI | |
53 | const double M_PI = 3.14159265358979 ; | |
54 | #endif | |
55 | #endif | |
b21d67a0 | 56 | |
83b96a06 | 57 | static const double RAD2DEG = 180.0 / M_PI; |
613a24f7 | 58 | |
4f74e0d1 | 59 | #ifndef __LP64__ |
613a24f7 | 60 | |
eb1a7cf9 | 61 | // TODO: update |
b21d67a0 DS |
62 | // The textctrl implementation still needs that (needs what?) for the non-HIView implementation |
63 | // | |
613a24f7 | 64 | wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) : |
0f4c3aa2 | 65 | wxMacPortSaver( (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ) |
613a24f7 | 66 | { |
0f4c3aa2 | 67 | m_newPort = (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ; |
613a24f7 SC |
68 | m_formerClip = NewRgn() ; |
69 | m_newClip = NewRgn() ; | |
70 | GetClip( m_formerClip ) ; | |
97071cdb | 71 | |
613a24f7 SC |
72 | if ( win ) |
73 | { | |
bcbbfab8 | 74 | // guard against half constructed objects, this just leads to a empty clip |
97071cdb | 75 | if ( win->GetPeer() ) |
bcbbfab8 SC |
76 | { |
77 | int x = 0 , y = 0; | |
eb1a7cf9 | 78 | win->MacWindowToRootWindow( &x, &y ) ; |
0f4c3aa2 | 79 | |
bcbbfab8 SC |
80 | // get area including focus rect |
81 | CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ; | |
82 | if ( !EmptyRgn( m_newClip ) ) | |
83 | OffsetRgn( m_newClip , x , y ) ; | |
84 | } | |
613a24f7 SC |
85 | |
86 | SetClip( m_newClip ) ; | |
87 | } | |
88 | } | |
89 | ||
0f4c3aa2 | 90 | wxMacWindowClipper::~wxMacWindowClipper() |
613a24f7 SC |
91 | { |
92 | SetPort( m_newPort ) ; | |
93 | SetClip( m_formerClip ) ; | |
94 | DisposeRgn( m_newClip ) ; | |
95 | DisposeRgn( m_formerClip ) ; | |
96 | } | |
97 | ||
98 | wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow* win ) : | |
99 | wxMacWindowClipper( win ) | |
100 | { | |
101 | // the port is already set at this point | |
0f4c3aa2 | 102 | m_newPort = (GrafPtr) GetWindowPort( (WindowRef) win->MacGetTopLevelWindowRef() ) ; |
613a24f7 SC |
103 | GetThemeDrawingState( &m_themeDrawingState ) ; |
104 | } | |
105 | ||
0f4c3aa2 | 106 | wxMacWindowStateSaver::~wxMacWindowStateSaver() |
613a24f7 SC |
107 | { |
108 | SetPort( m_newPort ) ; | |
109 | SetThemeDrawingState( m_themeDrawingState , true ) ; | |
110 | } | |
111 | ||
a8f234d2 SC |
112 | // minimal implementation only used for appearance drawing < 10.3 |
113 | ||
114 | wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : | |
115 | m_ph( (GrafPtr) dc->m_macPort ) | |
116 | { | |
117 | wxASSERT( dc->Ok() ) ; | |
118 | m_dc = dc ; | |
b21d67a0 | 119 | |
a8f234d2 SC |
120 | // dc->MacSetupPort(&m_ph) ; |
121 | } | |
97071cdb | 122 | |
a8f234d2 SC |
123 | wxMacPortSetter::~wxMacPortSetter() |
124 | { | |
125 | // m_dc->MacCleanupPort(&m_ph) ; | |
126 | } | |
4f74e0d1 | 127 | #endif |
a8f234d2 | 128 | |
613a24f7 SC |
129 | //----------------------------------------------------------------------------- |
130 | // Local functions | |
131 | //----------------------------------------------------------------------------- | |
20b69855 | 132 | |
613a24f7 SC |
133 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } |
134 | ||
135 | //----------------------------------------------------------------------------- | |
20b69855 SC |
136 | // device context implementation |
137 | // | |
138 | // more and more of the dc functionality should be implemented by calling | |
139 | // the appropricate wxMacCGContext, but we will have to do that step by step | |
140 | // also coordinate conversions should be moved to native matrix ops | |
613a24f7 | 141 | //----------------------------------------------------------------------------- |
613a24f7 | 142 | |
04732a7f SC |
143 | // we always stock two context states, one at entry, to be able to preserve the |
144 | // state we were called with, the other one after changing to HI Graphics orientation | |
145 | // (this one is used for getting back clippings etc) | |
146 | ||
ded83b1a SC |
147 | //----------------------------------------------------------------------------- |
148 | // wxGraphicPath implementation | |
149 | //----------------------------------------------------------------------------- | |
150 | ||
20b69855 | 151 | wxMacCGPath::wxMacCGPath() |
613a24f7 | 152 | { |
20b69855 | 153 | m_path = CGPathCreateMutable() ; |
613a24f7 SC |
154 | } |
155 | ||
20b69855 | 156 | wxMacCGPath::~wxMacCGPath() |
613a24f7 | 157 | { |
20b69855 SC |
158 | CGPathRelease( m_path ) ; |
159 | } | |
613a24f7 | 160 | |
b21d67a0 | 161 | // opens (starts) a new subpath |
20b69855 SC |
162 | void wxMacCGPath::MoveToPoint( wxCoord x1 , wxCoord y1 ) |
163 | { | |
164 | CGPathMoveToPoint( m_path , NULL , x1 , y1 ) ; | |
165 | } | |
613a24f7 | 166 | |
0f4c3aa2 | 167 | void wxMacCGPath::AddLineToPoint( wxCoord x1 , wxCoord y1 ) |
20b69855 SC |
168 | { |
169 | CGPathAddLineToPoint( m_path , NULL , x1 , y1 ) ; | |
170 | } | |
613a24f7 | 171 | |
e828c96a SC |
172 | void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) |
173 | { | |
174 | CGPathAddQuadCurveToPoint( m_path , NULL , cx1 , cy1 , x1 , y1 ); | |
175 | } | |
176 | ||
20b69855 | 177 | void wxMacCGPath::AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) |
613a24f7 | 178 | { |
20b69855 SC |
179 | CGRect cgRect = { { x , y } , { w , h } } ; |
180 | CGPathAddRect( m_path , NULL , cgRect ) ; | |
181 | } | |
613a24f7 | 182 | |
20b69855 SC |
183 | void wxMacCGPath::AddCircle( wxCoord x, wxCoord y , wxCoord r ) |
184 | { | |
185 | CGPathAddArc( m_path , NULL , x , y , r , 0.0 , 2 * M_PI , true ) ; | |
186 | } | |
613a24f7 | 187 | |
20b69855 SC |
188 | // closes the current subpath |
189 | void wxMacCGPath::CloseSubpath() | |
190 | { | |
191 | CGPathCloseSubpath( m_path ) ; | |
192 | } | |
613a24f7 | 193 | |
0f4c3aa2 | 194 | CGPathRef wxMacCGPath::GetPath() const |
613a24f7 | 195 | { |
20b69855 SC |
196 | return m_path ; |
197 | } | |
198 | ||
ded83b1a SC |
199 | void wxMacCGPath::AddArcToPoint( wxCoord x1, wxCoord y1 , wxCoord x2, wxCoord y2, wxCoord r ) |
200 | { | |
201 | CGPathAddArcToPoint( m_path, NULL , x1, y1, x2, y2, r); | |
202 | } | |
203 | ||
204 | void wxMacCGPath::AddArc( wxCoord x, wxCoord y, wxCoord r, double startAngle, double endAngle, bool clockwise ) | |
205 | { | |
206 | CGPathAddArc( m_path, NULL , x, y, r, startAngle, endAngle, clockwise); | |
207 | } | |
208 | ||
209 | //----------------------------------------------------------------------------- | |
210 | // wxGraphicContext implementation | |
211 | //----------------------------------------------------------------------------- | |
212 | ||
0f4c3aa2 | 213 | wxMacCGContext::wxMacCGContext( CGrafPtr port ) |
20b69855 SC |
214 | { |
215 | m_qdPort = port ; | |
cb4b0966 | 216 | m_cgContext = NULL ; |
ded83b1a SC |
217 | m_mode = kCGPathFill; |
218 | m_macATSUIStyle = NULL ; | |
20b69855 SC |
219 | } |
220 | ||
221 | wxMacCGContext::wxMacCGContext( CGContextRef cgcontext ) | |
222 | { | |
223 | m_qdPort = NULL ; | |
224 | m_cgContext = cgcontext ; | |
ded83b1a SC |
225 | m_mode = kCGPathFill; |
226 | m_macATSUIStyle = NULL ; | |
b014adcc SC |
227 | CGContextSaveGState( m_cgContext ) ; |
228 | CGContextSaveGState( m_cgContext ) ; | |
20b69855 SC |
229 | } |
230 | ||
231 | wxMacCGContext::wxMacCGContext() | |
232 | { | |
233 | m_qdPort = NULL ; | |
234 | m_cgContext = NULL ; | |
ded83b1a SC |
235 | m_mode = kCGPathFill; |
236 | m_macATSUIStyle = NULL ; | |
20b69855 | 237 | } |
613a24f7 | 238 | |
0f4c3aa2 | 239 | wxMacCGContext::~wxMacCGContext() |
20b69855 | 240 | { |
b014adcc SC |
241 | if ( m_cgContext ) |
242 | { | |
68654a82 | 243 | CGContextSynchronize( m_cgContext ) ; |
b014adcc SC |
244 | CGContextRestoreGState( m_cgContext ) ; |
245 | CGContextRestoreGState( m_cgContext ) ; | |
246 | } | |
4f74e0d1 | 247 | #ifndef __LP64__ |
20b69855 | 248 | if ( m_qdPort ) |
c0badae1 | 249 | QDEndCGContext( m_qdPort, &m_cgContext ) ; |
4f74e0d1 | 250 | #endif |
20b69855 SC |
251 | } |
252 | ||
253 | ||
254 | void wxMacCGContext::Clip( const wxRegion ®ion ) | |
255 | { | |
97071cdb | 256 | // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ; |
20b69855 SC |
257 | } |
258 | ||
0f4c3aa2 | 259 | void wxMacCGContext::StrokePath( const wxGraphicPath *p ) |
20b69855 SC |
260 | { |
261 | const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ; | |
ebbb5cb2 SC |
262 | |
263 | int width = m_pen.GetWidth(); | |
264 | if ( width == 0 ) | |
265 | width = 1 ; | |
266 | if ( m_pen.GetStyle() == wxTRANSPARENT ) | |
267 | width = 0 ; | |
268 | ||
269 | bool offset = ( width % 2 ) == 1 ; | |
270 | ||
271 | if ( offset ) | |
272 | CGContextTranslateCTM( m_cgContext, 0.5, 0.5 ); | |
273 | ||
20b69855 | 274 | CGContextAddPath( m_cgContext , path->GetPath() ) ; |
20b69855 | 275 | CGContextStrokePath( m_cgContext ) ; |
ebbb5cb2 SC |
276 | |
277 | if ( offset ) | |
278 | CGContextTranslateCTM( m_cgContext, -0.5, -0.5 ); | |
20b69855 SC |
279 | } |
280 | ||
0f4c3aa2 | 281 | void wxMacCGContext::DrawPath( const wxGraphicPath *p , int fillStyle ) |
20b69855 SC |
282 | { |
283 | const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ; | |
284 | CGPathDrawingMode mode = m_mode ; | |
97071cdb | 285 | |
20b69855 SC |
286 | if ( fillStyle == wxODDEVEN_RULE ) |
287 | { | |
288 | if ( mode == kCGPathFill ) | |
289 | mode = kCGPathEOFill ; | |
290 | else if ( mode == kCGPathFillStroke ) | |
291 | mode = kCGPathEOFillStroke ; | |
292 | } | |
97071cdb | 293 | |
ebbb5cb2 SC |
294 | int width = m_pen.GetWidth(); |
295 | if ( width == 0 ) | |
296 | width = 1 ; | |
297 | if ( m_pen.GetStyle() == wxTRANSPARENT ) | |
298 | width = 0 ; | |
299 | ||
300 | bool offset = ( width % 2 ) == 1 ; | |
301 | ||
302 | if ( offset ) | |
303 | CGContextTranslateCTM( m_cgContext, 0.5, 0.5 ); | |
304 | ||
20b69855 | 305 | CGContextAddPath( m_cgContext , path->GetPath() ) ; |
20b69855 | 306 | CGContextDrawPath( m_cgContext , mode ) ; |
ebbb5cb2 SC |
307 | |
308 | if ( offset ) | |
309 | CGContextTranslateCTM( m_cgContext, -0.5, -0.5 ); | |
613a24f7 SC |
310 | } |
311 | ||
0f4c3aa2 | 312 | void wxMacCGContext::FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle ) |
613a24f7 | 313 | { |
20b69855 SC |
314 | const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ; |
315 | CGContextSaveGState( m_cgContext ) ; | |
0f4c3aa2 | 316 | |
20b69855 SC |
317 | RGBColor col = MAC_WXCOLORREF( fillColor.GetPixel() ) ; |
318 | CGContextSetRGBFillColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; | |
319 | CGPathDrawingMode mode = kCGPathFill ; | |
320 | ||
321 | if ( fillStyle == wxODDEVEN_RULE ) | |
322 | mode = kCGPathEOFill ; | |
0f4c3aa2 | 323 | |
20b69855 SC |
324 | CGContextBeginPath( m_cgContext ) ; |
325 | CGContextAddPath( m_cgContext , path->GetPath() ) ; | |
326 | CGContextClosePath( m_cgContext ) ; | |
327 | CGContextDrawPath( m_cgContext , mode ) ; | |
0f4c3aa2 | 328 | |
20b69855 SC |
329 | CGContextRestoreGState( m_cgContext ) ; |
330 | } | |
0f4c3aa2 DS |
331 | |
332 | wxGraphicPath* wxMacCGContext::CreatePath() | |
333 | { | |
cb4b0966 SC |
334 | // make sure that we now have a real cgref, before doing |
335 | // anything with paths | |
a63b4755 SC |
336 | CGContextRef cg = GetNativeContext() ; |
337 | cg = NULL ; | |
75f0a06e | 338 | |
0f4c3aa2 | 339 | return new wxMacCGPath() ; |
cb4b0966 SC |
340 | } |
341 | ||
342 | // in case we only got a QDPort only create a cgref now | |
343 | ||
0f4c3aa2 DS |
344 | CGContextRef wxMacCGContext::GetNativeContext() |
345 | { | |
97071cdb | 346 | if ( m_cgContext == NULL ) |
cb4b0966 SC |
347 | { |
348 | Rect bounds ; | |
4f74e0d1 SC |
349 | OSStatus status = noErr; |
350 | #ifndef __LP64__ | |
cb4b0966 | 351 | GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ; |
4f74e0d1 SC |
352 | status = QDBeginCGContext((CGrafPtr) m_qdPort , &m_cgContext) ; |
353 | #endif | |
b014adcc | 354 | CGContextSaveGState( m_cgContext ) ; |
cb4b0966 SC |
355 | |
356 | wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ; | |
75f0a06e | 357 | |
cb4b0966 SC |
358 | CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ; |
359 | CGContextScaleCTM( m_cgContext , 1 , -1 ) ; | |
0f4c3aa2 | 360 | |
b014adcc | 361 | CGContextSaveGState( m_cgContext ) ; |
cb4b0966 SC |
362 | SetPen( m_pen ) ; |
363 | SetBrush( m_brush ) ; | |
364 | } | |
97071cdb | 365 | |
0f4c3aa2 | 366 | return m_cgContext ; |
cb4b0966 SC |
367 | } |
368 | ||
0f4c3aa2 DS |
369 | void wxMacCGContext::SetNativeContext( CGContextRef cg ) |
370 | { | |
0e71e845 SC |
371 | // we allow either setting or clearing but not replacing |
372 | wxASSERT( m_cgContext == NULL || cg == NULL ) ; | |
75f0a06e | 373 | |
0e71e845 SC |
374 | if ( cg ) |
375 | CGContextSaveGState( cg ) ; | |
0f4c3aa2 | 376 | m_cgContext = cg ; |
cb4b0966 | 377 | } |
20b69855 | 378 | |
ded83b1a SC |
379 | void wxMacCGContext::Translate( wxCoord dx , wxCoord dy ) |
380 | { | |
381 | CGContextTranslateCTM( m_cgContext, dx, dy ); | |
382 | } | |
383 | ||
384 | void wxMacCGContext::Scale( wxCoord xScale , wxCoord yScale ) | |
385 | { | |
386 | CGContextScaleCTM( m_cgContext , xScale , yScale ) ; | |
387 | } | |
388 | ||
389 | void wxMacCGContext::DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) | |
390 | { | |
391 | CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ) ; | |
4b1f9898 SC |
392 | HIRect r = CGRectMake( 0 , 0 , w , h ); |
393 | ||
394 | CGContextSaveGState( m_cgContext ); | |
395 | CGContextTranslateCTM( m_cgContext, x , y + h ); | |
396 | CGContextScaleCTM( m_cgContext, 1, -1 ); | |
397 | ||
398 | // in case image is a mask, set the foreground color | |
399 | CGContextSetRGBFillColor( m_cgContext , m_textForegroundColor.Red() / 255.0 , m_textForegroundColor.Green() / 255.0 , | |
400 | m_textForegroundColor.Blue() / 255.0 , m_textForegroundColor.Alpha() / 255.0 ) ; | |
401 | CGContextDrawImage( m_cgContext, r, image ); | |
402 | CGContextRestoreGState( m_cgContext ); | |
403 | ||
ded83b1a SC |
404 | CGImageRelease( image ) ; |
405 | } | |
406 | ||
407 | void wxMacCGContext::DrawIcon( const wxIcon &icon, wxCoord x, wxCoord y, wxCoord w, wxCoord h ) | |
408 | { | |
4b1f9898 | 409 | CGRect r = CGRectMake( 0 , 0 , w , h ) ; |
ded83b1a SC |
410 | CGContextSaveGState( m_cgContext ); |
411 | CGContextTranslateCTM( m_cgContext, x , y + h ); | |
412 | CGContextScaleCTM( m_cgContext, 1, -1 ); | |
413 | PlotIconRefInContext( m_cgContext , &r , kAlignNone , kTransformNone , | |
414 | NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ; | |
415 | CGContextRestoreGState( m_cgContext ) ; | |
416 | } | |
417 | ||
418 | void wxMacCGContext::PushState() | |
419 | { | |
420 | CGContextSaveGState( m_cgContext ); | |
421 | } | |
422 | ||
423 | void wxMacCGContext::PopState() | |
424 | { | |
425 | CGContextRestoreGState( m_cgContext ); | |
426 | } | |
427 | ||
428 | void wxMacCGContext::SetTextColor( const wxColour &col ) | |
429 | { | |
430 | m_textForegroundColor = col ; | |
431 | } | |
432 | ||
72ba915e | 433 | #pragma mark - |
b21d67a0 | 434 | #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes |
72ba915e | 435 | |
b21d67a0 | 436 | // CGPattern wrapper class: always allocate on heap, never call destructor |
72ba915e | 437 | |
24cd6f82 | 438 | class wxMacCGPattern |
72ba915e | 439 | { |
24cd6f82 | 440 | public : |
97071cdb DS |
441 | wxMacCGPattern() {} |
442 | ||
24cd6f82 | 443 | // is guaranteed to be called only with a non-Null CGContextRef |
75f0a06e | 444 | virtual void Render( CGContextRef ctxRef ) = 0 ; |
72ba915e | 445 | |
24cd6f82 | 446 | operator CGPatternRef() const { return m_patternRef ; } |
97071cdb | 447 | |
24cd6f82 SC |
448 | protected : |
449 | virtual ~wxMacCGPattern() | |
450 | { | |
b21d67a0 | 451 | // as this is called only when the m_patternRef is been released; |
97071cdb | 452 | // don't release it again |
24cd6f82 | 453 | } |
97071cdb | 454 | |
24cd6f82 SC |
455 | static void _Render( void *info, CGContextRef ctxRef ) |
456 | { | |
457 | wxMacCGPattern* self = (wxMacCGPattern*) info ; | |
458 | if ( self && ctxRef ) | |
459 | self->Render( ctxRef ) ; | |
460 | } | |
97071cdb | 461 | |
24cd6f82 SC |
462 | static void _Dispose( void *info ) |
463 | { | |
464 | wxMacCGPattern* self = (wxMacCGPattern*) info ; | |
465 | delete self ; | |
466 | } | |
97071cdb | 467 | |
24cd6f82 | 468 | CGPatternRef m_patternRef ; |
72ba915e | 469 | |
24cd6f82 SC |
470 | static const CGPatternCallbacks ms_Callbacks ; |
471 | } ; | |
72ba915e | 472 | |
24cd6f82 | 473 | const CGPatternCallbacks wxMacCGPattern::ms_Callbacks = { 0, &wxMacCGPattern::_Render, &wxMacCGPattern::_Dispose }; |
72ba915e | 474 | |
24cd6f82 | 475 | class ImagePattern : public wxMacCGPattern |
72ba915e | 476 | { |
24cd6f82 | 477 | public : |
83b96a06 | 478 | ImagePattern( const wxBitmap* bmp , const CGAffineTransform& transform ) |
24cd6f82 SC |
479 | { |
480 | wxASSERT( bmp && bmp->Ok() ) ; | |
75f0a06e | 481 | |
24cd6f82 SC |
482 | Init( (CGImageRef) bmp->CGImageCreate() , transform ) ; |
483 | } | |
0f4c3aa2 | 484 | |
24cd6f82 | 485 | // ImagePattern takes ownership of CGImageRef passed in |
83b96a06 | 486 | ImagePattern( CGImageRef image , const CGAffineTransform& transform ) |
24cd6f82 SC |
487 | { |
488 | if ( image ) | |
24cd6f82 | 489 | CFRetain( image ) ; |
97071cdb | 490 | |
24cd6f82 SC |
491 | Init( image , transform ) ; |
492 | } | |
0f4c3aa2 | 493 | |
75f0a06e | 494 | virtual void Render( CGContextRef ctxRef ) |
24cd6f82 SC |
495 | { |
496 | if (m_image != NULL) | |
497 | HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image ); | |
498 | } | |
72ba915e | 499 | |
24cd6f82 | 500 | protected : |
83b96a06 | 501 | void Init( CGImageRef image, const CGAffineTransform& transform ) |
24cd6f82 SC |
502 | { |
503 | m_image = image ; | |
504 | if ( m_image ) | |
505 | { | |
bc78039c | 506 | m_imageBounds = CGRectMake( 0.0, 0.0, (CGFloat)CGImageGetWidth( m_image ), (CGFloat)CGImageGetHeight( m_image ) ) ; |
0f4c3aa2 DS |
507 | m_patternRef = CGPatternCreate( |
508 | this , m_imageBounds, transform , | |
509 | m_imageBounds.size.width, m_imageBounds.size.height, | |
510 | kCGPatternTilingNoDistortion, true , &wxMacCGPattern::ms_Callbacks ) ; | |
24cd6f82 SC |
511 | } |
512 | } | |
97071cdb | 513 | |
d3c7fc99 | 514 | virtual ~ImagePattern() |
24cd6f82 SC |
515 | { |
516 | if ( m_image ) | |
517 | CGImageRelease( m_image ) ; | |
518 | } | |
97071cdb | 519 | |
0f4c3aa2 DS |
520 | CGImageRef m_image ; |
521 | CGRect m_imageBounds ; | |
24cd6f82 | 522 | } ; |
72ba915e | 523 | |
24cd6f82 | 524 | class HatchPattern : public wxMacCGPattern |
72ba915e | 525 | { |
24cd6f82 | 526 | public : |
83b96a06 | 527 | HatchPattern( int hatchstyle, const CGAffineTransform& transform ) |
24cd6f82 SC |
528 | { |
529 | m_hatch = hatchstyle ; | |
530 | m_imageBounds = CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ; | |
0f4c3aa2 DS |
531 | m_patternRef = CGPatternCreate( |
532 | this , m_imageBounds, transform , | |
533 | m_imageBounds.size.width, m_imageBounds.size.height, | |
534 | kCGPatternTilingNoDistortion, false , &wxMacCGPattern::ms_Callbacks ) ; | |
24cd6f82 | 535 | } |
0f4c3aa2 | 536 | |
24cd6f82 SC |
537 | void StrokeLineSegments( CGContextRef ctxRef , const CGPoint pts[] , size_t count ) |
538 | { | |
539 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 | |
540 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
541 | { | |
542 | CGContextStrokeLineSegments( ctxRef , pts , count ) ; | |
543 | } | |
544 | else | |
545 | #endif | |
546 | { | |
b21d67a0 | 547 | CGContextBeginPath( ctxRef ); |
75f0a06e DS |
548 | for (size_t i = 0; i < count; i += 2) |
549 | { | |
24cd6f82 SC |
550 | CGContextMoveToPoint(ctxRef, pts[i].x, pts[i].y); |
551 | CGContextAddLineToPoint(ctxRef, pts[i+1].x, pts[i+1].y); | |
552 | } | |
553 | CGContextStrokePath(ctxRef); | |
554 | } | |
555 | } | |
b21d67a0 | 556 | |
75f0a06e | 557 | virtual void Render( CGContextRef ctxRef ) |
24cd6f82 | 558 | { |
97071cdb | 559 | switch ( m_hatch ) |
24cd6f82 SC |
560 | { |
561 | case wxBDIAGONAL_HATCH : | |
562 | { | |
75f0a06e DS |
563 | CGPoint pts[] = |
564 | { | |
0f4c3aa2 | 565 | { 8.0 , 0.0 } , { 0.0 , 8.0 } |
24cd6f82 SC |
566 | }; |
567 | StrokeLineSegments( ctxRef , pts , 2 ) ; | |
568 | } | |
569 | break ; | |
97071cdb | 570 | |
24cd6f82 SC |
571 | case wxCROSSDIAG_HATCH : |
572 | { | |
75f0a06e DS |
573 | CGPoint pts[] = |
574 | { | |
0f4c3aa2 DS |
575 | { 0.0 , 0.0 } , { 8.0 , 8.0 } , |
576 | { 8.0 , 0.0 } , { 0.0 , 8.0 } | |
24cd6f82 SC |
577 | }; |
578 | StrokeLineSegments( ctxRef , pts , 4 ) ; | |
579 | } | |
580 | break ; | |
97071cdb | 581 | |
24cd6f82 SC |
582 | case wxFDIAGONAL_HATCH : |
583 | { | |
75f0a06e DS |
584 | CGPoint pts[] = |
585 | { | |
0f4c3aa2 | 586 | { 0.0 , 0.0 } , { 8.0 , 8.0 } |
24cd6f82 SC |
587 | }; |
588 | StrokeLineSegments( ctxRef , pts , 2 ) ; | |
589 | } | |
590 | break ; | |
97071cdb | 591 | |
24cd6f82 SC |
592 | case wxCROSS_HATCH : |
593 | { | |
75f0a06e DS |
594 | CGPoint pts[] = |
595 | { | |
0f4c3aa2 DS |
596 | { 0.0 , 4.0 } , { 8.0 , 4.0 } , |
597 | { 4.0 , 0.0 } , { 4.0 , 8.0 } , | |
24cd6f82 SC |
598 | }; |
599 | StrokeLineSegments( ctxRef , pts , 4 ) ; | |
600 | } | |
601 | break ; | |
97071cdb | 602 | |
24cd6f82 SC |
603 | case wxHORIZONTAL_HATCH : |
604 | { | |
75f0a06e DS |
605 | CGPoint pts[] = |
606 | { | |
0f4c3aa2 | 607 | { 0.0 , 4.0 } , { 8.0 , 4.0 } , |
24cd6f82 SC |
608 | }; |
609 | StrokeLineSegments( ctxRef , pts , 2 ) ; | |
610 | } | |
611 | break ; | |
97071cdb | 612 | |
24cd6f82 SC |
613 | case wxVERTICAL_HATCH : |
614 | { | |
75f0a06e DS |
615 | CGPoint pts[] = |
616 | { | |
0f4c3aa2 | 617 | { 4.0 , 0.0 } , { 4.0 , 8.0 } , |
24cd6f82 SC |
618 | }; |
619 | StrokeLineSegments( ctxRef , pts , 2 ) ; | |
620 | } | |
621 | break ; | |
75f0a06e DS |
622 | |
623 | default: | |
624 | break; | |
24cd6f82 SC |
625 | } |
626 | } | |
0f4c3aa2 | 627 | |
24cd6f82 | 628 | protected : |
d3c7fc99 | 629 | virtual ~HatchPattern() {} |
97071cdb | 630 | |
24cd6f82 | 631 | CGRect m_imageBounds ; |
b21d67a0 | 632 | int m_hatch ; |
0f4c3aa2 | 633 | }; |
72ba915e | 634 | |
b21d67a0 DS |
635 | #pragma mark - |
636 | ||
20b69855 SC |
637 | void wxMacCGContext::SetPen( const wxPen &pen ) |
638 | { | |
cb4b0966 SC |
639 | m_pen = pen ; |
640 | if ( m_cgContext == NULL ) | |
641 | return ; | |
75f0a06e | 642 | |
20b69855 SC |
643 | bool fill = m_brush.GetStyle() != wxTRANSPARENT ; |
644 | bool stroke = pen.GetStyle() != wxTRANSPARENT ; | |
0f4c3aa2 | 645 | |
20b69855 | 646 | #if 0 |
0f4c3aa2 | 647 | // we can benchmark performance; should go into a setting eventually |
20b69855 SC |
648 | CGContextSetShouldAntialias( m_cgContext , false ) ; |
649 | #endif | |
75f0a06e | 650 | |
83b96a06 | 651 | if ( fill || stroke ) |
613a24f7 | 652 | { |
75f0a06e | 653 | // set up brushes |
613a24f7 SC |
654 | m_mode = kCGPathFill ; // just a default |
655 | ||
613a24f7 SC |
656 | if ( stroke ) |
657 | { | |
83b445a6 SC |
658 | CGContextSetRGBStrokeColor( m_cgContext , pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 , |
659 | pen.GetColour().Blue() / 255.0 , pen.GetColour().Alpha() / 255.0 ) ; | |
24cd6f82 | 660 | |
0f4c3aa2 | 661 | // TODO: * m_dc->m_scaleX |
bc78039c | 662 | CGFloat penWidth = pen.GetWidth(); |
24cd6f82 SC |
663 | if (penWidth <= 0.0) |
664 | penWidth = 0.1; | |
665 | CGContextSetLineWidth( m_cgContext , penWidth ) ; | |
0f4c3aa2 | 666 | |
613a24f7 | 667 | CGLineCap cap ; |
97071cdb | 668 | switch ( pen.GetCap() ) |
613a24f7 SC |
669 | { |
670 | case wxCAP_ROUND : | |
671 | cap = kCGLineCapRound ; | |
672 | break ; | |
75f0a06e | 673 | |
613a24f7 SC |
674 | case wxCAP_PROJECTING : |
675 | cap = kCGLineCapSquare ; | |
676 | break ; | |
75f0a06e | 677 | |
613a24f7 SC |
678 | case wxCAP_BUTT : |
679 | cap = kCGLineCapButt ; | |
680 | break ; | |
75f0a06e | 681 | |
613a24f7 SC |
682 | default : |
683 | cap = kCGLineCapButt ; | |
684 | break ; | |
685 | } | |
613a24f7 SC |
686 | |
687 | CGLineJoin join ; | |
97071cdb | 688 | switch ( pen.GetJoin() ) |
613a24f7 SC |
689 | { |
690 | case wxJOIN_BEVEL : | |
691 | join = kCGLineJoinBevel ; | |
692 | break ; | |
75f0a06e | 693 | |
613a24f7 SC |
694 | case wxJOIN_MITER : |
695 | join = kCGLineJoinMiter ; | |
696 | break ; | |
75f0a06e | 697 | |
613a24f7 SC |
698 | case wxJOIN_ROUND : |
699 | join = kCGLineJoinRound ; | |
700 | break ; | |
75f0a06e | 701 | |
613a24f7 SC |
702 | default : |
703 | join = kCGLineJoinMiter ; | |
0f4c3aa2 | 704 | break; |
613a24f7 | 705 | } |
613a24f7 | 706 | |
613a24f7 SC |
707 | m_mode = kCGPathStroke ; |
708 | int count = 0 ; | |
0f4c3aa2 | 709 | |
bc78039c SC |
710 | const CGFloat *lengths = NULL ; |
711 | CGFloat *userLengths = NULL ; | |
72ba915e | 712 | |
bc78039c | 713 | const CGFloat dashUnit = penWidth < 1.0 ? 1.0 : penWidth; |
0f4c3aa2 | 714 | |
bc78039c SC |
715 | const CGFloat dotted[] = { dashUnit , dashUnit + 2.0 }; |
716 | const CGFloat short_dashed[] = { 9.0 , 6.0 }; | |
717 | const CGFloat dashed[] = { 19.0 , 9.0 }; | |
718 | const CGFloat dotted_dashed[] = { 9.0 , 6.0 , 3.0 , 3.0 }; | |
72ba915e | 719 | |
97071cdb | 720 | switch ( pen.GetStyle() ) |
613a24f7 SC |
721 | { |
722 | case wxSOLID : | |
723 | break ; | |
97071cdb | 724 | |
613a24f7 | 725 | case wxDOT : |
613a24f7 SC |
726 | lengths = dotted ; |
727 | count = WXSIZEOF(dotted); | |
728 | break ; | |
97071cdb | 729 | |
613a24f7 | 730 | case wxLONG_DASH : |
613a24f7 SC |
731 | lengths = dashed ; |
732 | count = WXSIZEOF(dashed) ; | |
733 | break ; | |
97071cdb | 734 | |
613a24f7 | 735 | case wxSHORT_DASH : |
613a24f7 SC |
736 | lengths = short_dashed ; |
737 | count = WXSIZEOF(short_dashed) ; | |
738 | break ; | |
97071cdb | 739 | |
613a24f7 | 740 | case wxDOT_DASH : |
613a24f7 SC |
741 | lengths = dotted_dashed ; |
742 | count = WXSIZEOF(dotted_dashed); | |
743 | break ; | |
97071cdb | 744 | |
613a24f7 SC |
745 | case wxUSER_DASH : |
746 | wxDash *dashes ; | |
20b69855 | 747 | count = pen.GetDashes( &dashes ) ; |
72ba915e | 748 | if ((dashes != NULL) && (count > 0)) |
613a24f7 | 749 | { |
bc78039c | 750 | userLengths = new CGFloat[count] ; |
ec4a2b5d | 751 | for ( int i = 0 ; i < count ; ++i ) |
72ba915e | 752 | { |
46bed958 | 753 | userLengths[i] = dashes[i] * dashUnit ; |
24cd6f82 SC |
754 | |
755 | if ( i % 2 == 1 && userLengths[i] < dashUnit + 2.0 ) | |
756 | userLengths[i] = dashUnit + 2.0 ; | |
757 | else if ( i % 2 == 0 && userLengths[i] < dashUnit ) | |
758 | userLengths[i] = dashUnit ; | |
72ba915e | 759 | } |
613a24f7 SC |
760 | } |
761 | lengths = userLengths ; | |
762 | break ; | |
97071cdb | 763 | |
24cd6f82 SC |
764 | case wxSTIPPLE : |
765 | { | |
bc78039c | 766 | CGFloat alphaArray[1] = { 1.0 } ; |
24cd6f82 | 767 | wxBitmap* bmp = pen.GetStipple() ; |
0f4c3aa2 | 768 | if ( bmp && bmp->Ok() ) |
24cd6f82 SC |
769 | { |
770 | wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( NULL ) ) ; | |
771 | CGContextSetStrokeColorSpace( m_cgContext , patternSpace ) ; | |
772 | wxMacCFRefHolder<CGPatternRef> pattern( *( new ImagePattern( bmp , CGContextGetCTM( m_cgContext ) ) ) ); | |
773 | CGContextSetStrokePattern( m_cgContext, pattern , alphaArray ) ; | |
774 | } | |
775 | } | |
776 | break ; | |
97071cdb | 777 | |
613a24f7 | 778 | default : |
24cd6f82 SC |
779 | { |
780 | wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ; | |
781 | CGContextSetStrokeColorSpace( m_cgContext , patternSpace ) ; | |
782 | wxMacCFRefHolder<CGPatternRef> pattern( *( new HatchPattern( pen.GetStyle() , CGContextGetCTM( m_cgContext ) ) ) ); | |
0f4c3aa2 | 783 | |
83b445a6 SC |
784 | CGFloat colorArray[4] = { pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 , |
785 | pen.GetColour().Blue() / 255.0 , pen.GetColour().Alpha() / 255.0 } ; | |
0f4c3aa2 | 786 | |
24cd6f82 SC |
787 | CGContextSetStrokePattern( m_cgContext, pattern , colorArray ) ; |
788 | } | |
0f4c3aa2 | 789 | break ; |
613a24f7 SC |
790 | } |
791 | ||
72ba915e SC |
792 | if ((lengths != NULL) && (count > 0)) |
793 | { | |
72ba915e | 794 | CGContextSetLineDash( m_cgContext , 0 , lengths , count ) ; |
24cd6f82 SC |
795 | // force the line cap, otherwise we get artifacts (overlaps) and just solid lines |
796 | cap = kCGLineCapButt ; | |
72ba915e | 797 | } |
0f4c3aa2 | 798 | else |
72ba915e SC |
799 | { |
800 | CGContextSetLineDash( m_cgContext , 0 , NULL , 0 ) ; | |
801 | } | |
97071cdb | 802 | |
24cd6f82 | 803 | CGContextSetLineCap( m_cgContext , cap ) ; |
75f0a06e | 804 | CGContextSetLineJoin( m_cgContext , join ) ; |
72ba915e SC |
805 | |
806 | delete[] userLengths ; | |
613a24f7 | 807 | } |
97071cdb | 808 | |
613a24f7 | 809 | if ( fill && stroke ) |
613a24f7 | 810 | m_mode = kCGPathFillStroke ; |
613a24f7 SC |
811 | } |
812 | } | |
72ba915e | 813 | |
20b69855 SC |
814 | void wxMacCGContext::SetBrush( const wxBrush &brush ) |
815 | { | |
cb4b0966 SC |
816 | m_brush = brush ; |
817 | if ( m_cgContext == NULL ) | |
818 | return ; | |
819 | ||
20b69855 SC |
820 | bool fill = brush.GetStyle() != wxTRANSPARENT ; |
821 | bool stroke = m_pen.GetStyle() != wxTRANSPARENT ; | |
613a24f7 | 822 | |
20b69855 SC |
823 | #if 0 |
824 | // we can benchmark performance, should go into a setting later | |
825 | CGContextSetShouldAntialias( m_cgContext , false ) ; | |
826 | #endif | |
72ba915e | 827 | |
83b96a06 | 828 | if ( fill || stroke ) |
20b69855 | 829 | { |
20b69855 SC |
830 | // setup brushes |
831 | m_mode = kCGPathFill ; // just a default | |
832 | ||
833 | if ( fill ) | |
834 | { | |
24cd6f82 | 835 | if ( brush.GetStyle() == wxSOLID ) |
72ba915e | 836 | { |
83b445a6 SC |
837 | CGContextSetRGBFillColor( m_cgContext , brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 , |
838 | brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 ) ; | |
24cd6f82 SC |
839 | } |
840 | else if ( brush.IsHatch() ) | |
841 | { | |
842 | wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ; | |
843 | CGContextSetFillColorSpace( m_cgContext , patternSpace ) ; | |
844 | wxMacCFRefHolder<CGPatternRef> pattern( *( new HatchPattern( brush.GetStyle() , CGContextGetCTM( m_cgContext ) ) ) ); | |
845 | ||
83b445a6 SC |
846 | CGFloat colorArray[4] = { brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 , |
847 | brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 } ; | |
0f4c3aa2 | 848 | |
24cd6f82 SC |
849 | CGContextSetFillPattern( m_cgContext, pattern , colorArray ) ; |
850 | } | |
851 | else | |
852 | { | |
853 | // now brush is a bitmap | |
bc78039c | 854 | CGFloat alphaArray[1] = { 1.0 } ; |
24cd6f82 | 855 | wxBitmap* bmp = brush.GetStipple() ; |
0f4c3aa2 | 856 | if ( bmp && bmp->Ok() ) |
72ba915e | 857 | { |
24cd6f82 SC |
858 | wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( NULL ) ) ; |
859 | CGContextSetFillColorSpace( m_cgContext , patternSpace ) ; | |
860 | wxMacCFRefHolder<CGPatternRef> pattern( *( new ImagePattern( bmp , CGContextGetCTM( m_cgContext ) ) ) ); | |
861 | CGContextSetFillPattern( m_cgContext, pattern , alphaArray ) ; | |
72ba915e SC |
862 | } |
863 | } | |
75f0a06e | 864 | |
20b69855 SC |
865 | m_mode = kCGPathFill ; |
866 | } | |
97071cdb | 867 | |
20b69855 | 868 | if ( fill && stroke ) |
20b69855 | 869 | m_mode = kCGPathFillStroke ; |
75f0a06e DS |
870 | else if ( stroke ) |
871 | m_mode = kCGPathStroke ; | |
20b69855 SC |
872 | } |
873 | } | |
874 | ||
ded83b1a | 875 | void wxMacCGContext::DrawText( const wxString &str, wxCoord x, wxCoord y, double angle ) |
613a24f7 | 876 | { |
ded83b1a SC |
877 | OSStatus status = noErr ; |
878 | ATSUTextLayout atsuLayout ; | |
879 | UniCharCount chars = str.length() ; | |
880 | UniChar* ubuf = NULL ; | |
613a24f7 | 881 | |
ded83b1a SC |
882 | #if SIZEOF_WCHAR_T == 4 |
883 | wxMBConvUTF16 converter ; | |
884 | #if wxUSE_UNICODE | |
885 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; | |
886 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
887 | converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ; | |
888 | #else | |
889 | const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
890 | size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; | |
891 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
892 | converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; | |
893 | #endif | |
894 | chars = unicharlen / 2 ; | |
895 | #else | |
896 | #if wxUSE_UNICODE | |
897 | ubuf = (UniChar*) str.wc_str() ; | |
898 | #else | |
899 | wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
900 | chars = wxWcslen( wchar.data() ) ; | |
901 | ubuf = (UniChar*) wchar.data() ; | |
902 | #endif | |
903 | #endif | |
904 | ||
905 | status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , | |
906 | &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; | |
907 | ||
908 | wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); | |
909 | ||
910 | status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ; | |
911 | wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") ); | |
912 | ||
913 | int iAngle = int( angle ); | |
914 | if ( abs(iAngle) > 0 ) | |
613a24f7 | 915 | { |
ded83b1a SC |
916 | Fixed atsuAngle = IntToFixed( iAngle ) ; |
917 | ATSUAttributeTag atsuTags[] = | |
918 | { | |
919 | kATSULineRotationTag , | |
920 | } ; | |
921 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
922 | { | |
923 | sizeof( Fixed ) , | |
924 | } ; | |
925 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
926 | { | |
927 | &atsuAngle , | |
928 | } ; | |
929 | status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), | |
930 | atsuTags, atsuSizes, atsuValues ) ; | |
613a24f7 | 931 | } |
97071cdb | 932 | |
ded83b1a SC |
933 | { |
934 | ATSUAttributeTag atsuTags[] = | |
935 | { | |
936 | kATSUCGContextTag , | |
937 | } ; | |
938 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
939 | { | |
940 | sizeof( CGContextRef ) , | |
941 | } ; | |
942 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
943 | { | |
944 | &m_cgContext , | |
945 | } ; | |
946 | status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), | |
947 | atsuTags, atsuSizes, atsuValues ) ; | |
948 | } | |
ec4a2b5d | 949 | |
ded83b1a SC |
950 | ATSUTextMeasurement textBefore, textAfter ; |
951 | ATSUTextMeasurement ascent, descent ; | |
ec4a2b5d | 952 | |
ded83b1a SC |
953 | status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, |
954 | &textBefore , &textAfter, &ascent , &descent ); | |
613a24f7 | 955 | |
ded83b1a | 956 | wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); |
eb1a7cf9 | 957 | |
ded83b1a SC |
958 | Rect rect ; |
959 | /* | |
960 | // TODO | |
961 | if ( m_backgroundMode == wxSOLID ) | |
962 | { | |
963 | wxGraphicPath* path = m_graphicContext->CreatePath() ; | |
964 | path->MoveToPoint( drawX , drawY ) ; | |
965 | path->AddLineToPoint( | |
966 | (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) , | |
967 | (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ; | |
968 | path->AddLineToPoint( | |
969 | (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) , | |
970 | (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ; | |
971 | path->AddLineToPoint( | |
972 | (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) , | |
973 | (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ; | |
24cd6f82 | 974 | |
ded83b1a SC |
975 | m_graphicContext->FillPath( path , m_textBackgroundColour ) ; |
976 | delete path ; | |
977 | } | |
978 | */ | |
979 | x += (int)(sin(angle / RAD2DEG) * FixedToInt(ascent)); | |
980 | y += (int)(cos(angle / RAD2DEG) * FixedToInt(ascent)); | |
20b69855 | 981 | |
ded83b1a SC |
982 | status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, |
983 | IntToFixed(x) , IntToFixed(y) , &rect ); | |
984 | wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); | |
20b69855 | 985 | |
ded83b1a SC |
986 | CGContextSaveGState(m_cgContext); |
987 | CGContextTranslateCTM(m_cgContext, x, y); | |
988 | CGContextScaleCTM(m_cgContext, 1, -1); | |
989 | status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, | |
990 | IntToFixed(0) , IntToFixed(0) ); | |
613a24f7 | 991 | |
ded83b1a | 992 | wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); |
613a24f7 | 993 | |
ded83b1a | 994 | CGContextRestoreGState(m_cgContext) ; |
20b69855 | 995 | |
ded83b1a | 996 | ::ATSUDisposeTextLayout(atsuLayout); |
613a24f7 | 997 | |
ded83b1a SC |
998 | #if SIZEOF_WCHAR_T == 4 |
999 | free( ubuf ) ; | |
1000 | #endif | |
1001 | } | |
1002 | ||
1003 | void wxMacCGContext::GetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, | |
1004 | wxCoord *descent, wxCoord *externalLeading ) const | |
613a24f7 | 1005 | { |
ded83b1a | 1006 | wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ; |
75f0a06e | 1007 | |
ded83b1a SC |
1008 | OSStatus status = noErr ; |
1009 | ||
1010 | ATSUTextLayout atsuLayout ; | |
1011 | UniCharCount chars = str.length() ; | |
1012 | UniChar* ubuf = NULL ; | |
20b69855 | 1013 | |
ded83b1a SC |
1014 | #if SIZEOF_WCHAR_T == 4 |
1015 | wxMBConvUTF16 converter ; | |
1016 | #if wxUSE_UNICODE | |
1017 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; | |
1018 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
1019 | converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ; | |
1020 | #else | |
1021 | const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
1022 | size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; | |
1023 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
1024 | converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; | |
1025 | #endif | |
1026 | chars = unicharlen / 2 ; | |
1027 | #else | |
1028 | #if wxUSE_UNICODE | |
1029 | ubuf = (UniChar*) str.wc_str() ; | |
1030 | #else | |
1031 | wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
1032 | chars = wxWcslen( wchar.data() ) ; | |
1033 | ubuf = (UniChar*) wchar.data() ; | |
1034 | #endif | |
1035 | #endif | |
613a24f7 | 1036 | |
ded83b1a SC |
1037 | status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , |
1038 | &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; | |
20b69855 | 1039 | |
ded83b1a | 1040 | wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") ); |
20b69855 | 1041 | |
ded83b1a SC |
1042 | ATSUTextMeasurement textBefore, textAfter ; |
1043 | ATSUTextMeasurement textAscent, textDescent ; | |
1044 | ||
1045 | status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, | |
1046 | &textBefore , &textAfter, &textAscent , &textDescent ); | |
1047 | ||
1048 | if ( height ) | |
1049 | *height = FixedToInt(textAscent + textDescent) ; | |
1050 | if ( descent ) | |
1051 | *descent = FixedToInt(textDescent) ; | |
1052 | if ( externalLeading ) | |
1053 | *externalLeading = 0 ; | |
1054 | if ( width ) | |
1055 | *width = FixedToInt(textAfter - textBefore) ; | |
1056 | ||
1057 | ::ATSUDisposeTextLayout(atsuLayout); | |
613a24f7 SC |
1058 | } |
1059 | ||
ded83b1a | 1060 | void wxMacCGContext::GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const |
613a24f7 | 1061 | { |
ded83b1a SC |
1062 | widths.Empty(); |
1063 | widths.Add(0, text.length()); | |
75f0a06e | 1064 | |
ded83b1a SC |
1065 | if (text.empty()) |
1066 | return ; | |
b014adcc | 1067 | |
ded83b1a SC |
1068 | ATSUTextLayout atsuLayout ; |
1069 | UniCharCount chars = text.length() ; | |
1070 | UniChar* ubuf = NULL ; | |
1071 | ||
1072 | #if SIZEOF_WCHAR_T == 4 | |
1073 | wxMBConvUTF16 converter ; | |
1074 | #if wxUSE_UNICODE | |
1075 | size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ) ; | |
1076 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
1077 | converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ) ; | |
1078 | #else | |
1079 | const wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ; | |
1080 | size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; | |
1081 | ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
1082 | converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; | |
1083 | #endif | |
1084 | chars = unicharlen / 2 ; | |
1085 | #else | |
1086 | #if wxUSE_UNICODE | |
1087 | ubuf = (UniChar*) text.wc_str() ; | |
1088 | #else | |
1089 | wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ; | |
1090 | chars = wxWcslen( wchar.data() ) ; | |
1091 | ubuf = (UniChar*) wchar.data() ; | |
1092 | #endif | |
1093 | #endif | |
1094 | ||
83b96a06 | 1095 | ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , |
ded83b1a SC |
1096 | &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; |
1097 | ||
1098 | for ( int pos = 0; pos < (int)chars; pos ++ ) | |
1099 | { | |
1100 | unsigned long actualNumberOfBounds = 0; | |
1101 | ATSTrapezoid glyphBounds; | |
1102 | ||
1103 | // We get a single bound, since the text should only require one. If it requires more, there is an issue | |
1104 | OSStatus result; | |
1105 | result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1, | |
1106 | kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds ); | |
1107 | if (result != noErr || actualNumberOfBounds != 1 ) | |
1108 | return ; | |
1109 | ||
1110 | widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ); | |
1111 | //unsigned char uch = s[i]; | |
1112 | } | |
1113 | ||
1114 | ::ATSUDisposeTextLayout(atsuLayout); | |
1115 | } | |
1116 | ||
1117 | void wxMacCGContext::SetFont( const wxFont &font ) | |
1118 | { | |
1119 | if ( m_macATSUIStyle ) | |
1120 | { | |
1121 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); | |
1122 | m_macATSUIStyle = NULL ; | |
1123 | } | |
1124 | ||
1125 | if ( font.Ok() ) | |
1126 | { | |
1127 | OSStatus status ; | |
1128 | ||
1129 | status = ATSUCreateAndCopyStyle( (ATSUStyle) font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ; | |
1130 | ||
1131 | wxASSERT_MSG( status == noErr, wxT("couldn't create ATSU style") ) ; | |
1132 | ||
1133 | // we need the scale here ... | |
1134 | ||
1135 | Fixed atsuSize = IntToFixed( int( /*m_scaleY*/ 1 * font.MacGetFontSize()) ) ; | |
1136 | RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColor.GetPixel() ) ; | |
1137 | ATSUAttributeTag atsuTags[] = | |
1138 | { | |
1139 | kATSUSizeTag , | |
1140 | kATSUColorTag , | |
1141 | } ; | |
1142 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
1143 | { | |
1144 | sizeof( Fixed ) , | |
1145 | sizeof( RGBColor ) , | |
1146 | } ; | |
1147 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
1148 | { | |
1149 | &atsuSize , | |
1150 | &atsuColor , | |
1151 | } ; | |
1152 | ||
1153 | status = ::ATSUSetAttributes( | |
1154 | (ATSUStyle)m_macATSUIStyle, sizeof(atsuTags) / sizeof(ATSUAttributeTag) , | |
1155 | atsuTags, atsuSizes, atsuValues); | |
1156 | ||
1157 | wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ) ; | |
1158 | } | |
1159 | } | |
1160 | ||
1161 | ||
1162 | #pragma mark - | |
1163 | ||
1164 | wxDC::wxDC() | |
1165 | { | |
1166 | m_ok = false ; | |
1167 | m_colour = true; | |
1168 | m_mm_to_pix_x = mm2pt; | |
1169 | m_mm_to_pix_y = mm2pt; | |
1170 | ||
1171 | m_externalDeviceOriginX = 0; | |
1172 | m_externalDeviceOriginY = 0; | |
1173 | m_logicalScaleX = 1.0; | |
1174 | m_logicalScaleY = 1.0; | |
1175 | m_userScaleX = 1.0; | |
1176 | m_userScaleY = 1.0; | |
1177 | m_scaleX = 1.0; | |
1178 | m_scaleY = 1.0; | |
1179 | m_needComputeScaleX = | |
1180 | m_needComputeScaleY = false; | |
1181 | ||
1182 | m_macPort = 0 ; | |
1183 | m_macLocalOrigin.x = | |
1184 | m_macLocalOrigin.y = 0 ; | |
1185 | ||
1186 | m_pen = *wxBLACK_PEN; | |
1187 | m_font = *wxNORMAL_FONT; | |
1188 | m_brush = *wxWHITE_BRUSH; | |
1189 | ||
1190 | m_macATSUIStyle = NULL ; | |
1191 | m_graphicContext = NULL ; | |
1192 | } | |
1193 | ||
1194 | wxDC::~wxDC() | |
1195 | { | |
1196 | if ( m_macATSUIStyle ) | |
1197 | { | |
1198 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); | |
1199 | m_macATSUIStyle = NULL ; | |
1200 | } | |
1201 | ||
1202 | delete m_graphicContext ; | |
1203 | } | |
1204 | ||
1205 | void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) | |
1206 | { | |
1207 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") ); | |
1208 | wxCHECK_RET( bmp.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") ); | |
1209 | ||
1210 | wxCoord xx = XLOG2DEVMAC(x); | |
1211 | wxCoord yy = YLOG2DEVMAC(y); | |
1212 | wxCoord w = bmp.GetWidth(); | |
1213 | wxCoord h = bmp.GetHeight(); | |
1214 | wxCoord ww = XLOG2DEVREL(w); | |
1215 | wxCoord hh = YLOG2DEVREL(h); | |
1216 | ||
4b1f9898 SC |
1217 | if ( bmp.GetDepth()==1 ) |
1218 | { | |
1219 | wxGraphicPath* path = m_graphicContext->CreatePath() ; | |
1220 | path->AddRectangle( xx , yy , ww , hh ) ; | |
1221 | m_graphicContext->FillPath( path , m_textBackgroundColour, wxODDEVEN_RULE) ; | |
1222 | delete path; | |
1223 | m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ; | |
1224 | } | |
1225 | else | |
1226 | { | |
1227 | m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ; | |
1228 | } | |
ded83b1a SC |
1229 | } |
1230 | ||
1231 | void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) | |
1232 | { | |
1233 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") ); | |
1234 | wxCHECK_RET( icon.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") ); | |
1235 | ||
1236 | wxCoord xx = XLOG2DEVMAC(x); | |
1237 | wxCoord yy = YLOG2DEVMAC(y); | |
1238 | wxCoord w = icon.GetWidth(); | |
1239 | wxCoord h = icon.GetHeight(); | |
1240 | wxCoord ww = XLOG2DEVREL(w); | |
1241 | wxCoord hh = YLOG2DEVREL(h); | |
1242 | ||
1243 | m_graphicContext->DrawIcon( icon , xx, yy, ww, hh ) ; | |
1244 | } | |
1245 | ||
1246 | void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) | |
1247 | { | |
1248 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") ); | |
1249 | ||
1250 | wxCoord xx, yy, ww, hh; | |
1251 | xx = XLOG2DEVMAC(x); | |
1252 | yy = YLOG2DEVMAC(y); | |
1253 | ww = XLOG2DEVREL(width); | |
1254 | hh = YLOG2DEVREL(height); | |
1255 | ||
1256 | CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; | |
b21d67a0 | 1257 | CGRect clipRect = CGRectMake( xx , yy , ww, hh ) ; |
b014adcc SC |
1258 | CGContextClipToRect( cgContext , clipRect ) ; |
1259 | ||
20b69855 SC |
1260 | // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ; |
1261 | // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
75f0a06e | 1262 | |
97071cdb | 1263 | if ( m_clipping ) |
613a24f7 | 1264 | { |
b21d67a0 DS |
1265 | m_clipX1 = wxMax( m_clipX1, xx ); |
1266 | m_clipY1 = wxMax( m_clipY1, yy ); | |
1267 | m_clipX2 = wxMin( m_clipX2, (xx + ww) ); | |
1268 | m_clipY2 = wxMin( m_clipY2, (yy + hh) ); | |
613a24f7 SC |
1269 | } |
1270 | else | |
1271 | { | |
97071cdb | 1272 | m_clipping = true; |
b21d67a0 | 1273 | |
613a24f7 SC |
1274 | m_clipX1 = xx; |
1275 | m_clipY1 = yy; | |
1276 | m_clipX2 = xx + ww; | |
1277 | m_clipY2 = yy + hh; | |
1278 | } | |
75f0a06e | 1279 | |
b21d67a0 | 1280 | // TODO: as soon as we don't reset the context for each operation anymore |
613a24f7 SC |
1281 | // we have to update the context as well |
1282 | } | |
1283 | ||
eb1a7cf9 | 1284 | void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
613a24f7 | 1285 | { |
b21d67a0 DS |
1286 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") ); |
1287 | ||
613a24f7 SC |
1288 | if (region.Empty()) |
1289 | { | |
1290 | DestroyClippingRegion(); | |
1291 | return; | |
1292 | } | |
97071cdb | 1293 | |
613a24f7 SC |
1294 | wxCoord x, y, w, h; |
1295 | region.GetBox( x, y, w, h ); | |
1296 | wxCoord xx, yy, ww, hh; | |
1297 | xx = XLOG2DEVMAC(x); | |
1298 | yy = YLOG2DEVMAC(y); | |
1299 | ww = XLOG2DEVREL(w); | |
1300 | hh = YLOG2DEVREL(h); | |
75f0a06e | 1301 | |
613a24f7 SC |
1302 | // if we have a scaling that we cannot map onto native regions |
1303 | // we must use the box | |
1304 | if ( ww != w || hh != h ) | |
1305 | { | |
1306 | wxDC::DoSetClippingRegion( x, y, w, h ); | |
1307 | } | |
1308 | else | |
1309 | { | |
75f0a06e | 1310 | #if 0 |
613a24f7 SC |
1311 | CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ; |
1312 | if ( xx != x || yy != y ) | |
613a24f7 | 1313 | OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ; |
b21d67a0 | 1314 | SectRgn( (RgnHandle)m_macCurrentClipRgn , (RgnHandle)m_macBoundaryClipRgn , (RgnHandle)m_macCurrentClipRgn ) ; |
75f0a06e DS |
1315 | #endif |
1316 | ||
97071cdb | 1317 | if ( m_clipping ) |
613a24f7 | 1318 | { |
b21d67a0 DS |
1319 | m_clipX1 = wxMax( m_clipX1, xx ); |
1320 | m_clipY1 = wxMax( m_clipY1, yy ); | |
1321 | m_clipX2 = wxMin( m_clipX2, (xx + ww) ); | |
1322 | m_clipY2 = wxMin( m_clipY2, (yy + hh) ); | |
613a24f7 SC |
1323 | } |
1324 | else | |
1325 | { | |
97071cdb | 1326 | m_clipping = true; |
b21d67a0 | 1327 | |
613a24f7 SC |
1328 | m_clipX1 = xx; |
1329 | m_clipY1 = yy; | |
1330 | m_clipX2 = xx + ww; | |
1331 | m_clipY2 = yy + hh; | |
1332 | } | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | void wxDC::DestroyClippingRegion() | |
1337 | { | |
20b69855 | 1338 | // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; |
b21d67a0 | 1339 | |
b60f5ca5 | 1340 | CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; |
0f4c3aa2 | 1341 | CGContextRestoreGState( cgContext ); |
b21d67a0 DS |
1342 | CGContextSaveGState( cgContext ); |
1343 | ||
0e71e845 SC |
1344 | m_graphicContext->SetPen( m_pen ) ; |
1345 | m_graphicContext->SetBrush( m_brush ) ; | |
b21d67a0 | 1346 | |
97071cdb | 1347 | m_clipping = false; |
613a24f7 SC |
1348 | } |
1349 | ||
1350 | void wxDC::DoGetSizeMM( int* width, int* height ) const | |
1351 | { | |
75f0a06e DS |
1352 | int w = 0, h = 0; |
1353 | ||
613a24f7 | 1354 | GetSize( &w, &h ); |
75f0a06e DS |
1355 | if (width) |
1356 | *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) ); | |
1357 | if (height) | |
1358 | *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) ); | |
613a24f7 SC |
1359 | } |
1360 | ||
1361 | void wxDC::SetTextForeground( const wxColour &col ) | |
1362 | { | |
b21d67a0 | 1363 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") ); |
75f0a06e | 1364 | |
20b69855 SC |
1365 | if ( col != m_textForegroundColour ) |
1366 | { | |
1367 | m_textForegroundColour = col; | |
a51cb1e6 SC |
1368 | m_graphicContext->SetTextColor( col ); |
1369 | // in the current implementation the font contains the text color | |
1370 | m_graphicContext->SetFont(m_font); | |
20b69855 | 1371 | } |
613a24f7 SC |
1372 | } |
1373 | ||
1374 | void wxDC::SetTextBackground( const wxColour &col ) | |
1375 | { | |
b21d67a0 | 1376 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") ); |
75f0a06e | 1377 | |
613a24f7 | 1378 | m_textBackgroundColour = col; |
613a24f7 SC |
1379 | } |
1380 | ||
1381 | void wxDC::SetMapMode( int mode ) | |
1382 | { | |
1383 | switch (mode) | |
1384 | { | |
1385 | case wxMM_TWIPS: | |
75f0a06e | 1386 | SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y ); |
613a24f7 | 1387 | break; |
97071cdb | 1388 | |
613a24f7 | 1389 | case wxMM_POINTS: |
75f0a06e | 1390 | SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y ); |
613a24f7 | 1391 | break; |
97071cdb | 1392 | |
613a24f7 SC |
1393 | case wxMM_METRIC: |
1394 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
1395 | break; | |
97071cdb | 1396 | |
613a24f7 | 1397 | case wxMM_LOMETRIC: |
75f0a06e | 1398 | SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 ); |
613a24f7 | 1399 | break; |
97071cdb | 1400 | |
613a24f7 | 1401 | case wxMM_TEXT: |
97071cdb | 1402 | default: |
613a24f7 SC |
1403 | SetLogicalScale( 1.0, 1.0 ); |
1404 | break; | |
1405 | } | |
97071cdb | 1406 | |
613a24f7 SC |
1407 | if (mode != wxMM_TEXT) |
1408 | { | |
97071cdb DS |
1409 | m_needComputeScaleX = |
1410 | m_needComputeScaleY = true; | |
613a24f7 SC |
1411 | } |
1412 | } | |
1413 | ||
1414 | void wxDC::SetUserScale( double x, double y ) | |
1415 | { | |
1416 | // allow negative ? -> no | |
1417 | m_userScaleX = x; | |
1418 | m_userScaleY = y; | |
1419 | ComputeScaleAndOrigin(); | |
1420 | } | |
1421 | ||
1422 | void wxDC::SetLogicalScale( double x, double y ) | |
1423 | { | |
1424 | // allow negative ? | |
1425 | m_logicalScaleX = x; | |
1426 | m_logicalScaleY = y; | |
1427 | ComputeScaleAndOrigin(); | |
1428 | } | |
1429 | ||
1430 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
1431 | { | |
1432 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
1433 | m_logicalOriginY = y * m_signY; | |
1434 | ComputeScaleAndOrigin(); | |
1435 | } | |
1436 | ||
1437 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1438 | { | |
1439 | m_externalDeviceOriginX = x; | |
1440 | m_externalDeviceOriginY = y; | |
1441 | ComputeScaleAndOrigin(); | |
1442 | } | |
1443 | ||
1444 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1445 | { | |
1446 | m_signX = (xLeftRight ? 1 : -1); | |
b21d67a0 | 1447 | m_signY = (yBottomUp ? -1 : 1); |
613a24f7 SC |
1448 | ComputeScaleAndOrigin(); |
1449 | } | |
1450 | ||
1451 | wxSize wxDC::GetPPI() const | |
1452 | { | |
1453 | return wxSize(72, 72); | |
1454 | } | |
1455 | ||
1456 | int wxDC::GetDepth() const | |
1457 | { | |
0f4c3aa2 | 1458 | return 32; |
613a24f7 SC |
1459 | } |
1460 | ||
1461 | void wxDC::ComputeScaleAndOrigin() | |
1462 | { | |
1463 | // CMB: copy scale to see if it changes | |
1464 | double origScaleX = m_scaleX; | |
1465 | double origScaleY = m_scaleY; | |
1466 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
1467 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
24cd6f82 SC |
1468 | m_deviceOriginX = m_externalDeviceOriginX; |
1469 | m_deviceOriginY = m_externalDeviceOriginY; | |
97071cdb | 1470 | |
613a24f7 SC |
1471 | // CMB: if scale has changed call SetPen to recalulate the line width |
1472 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) | |
1473 | { | |
1474 | // this is a bit artificial, but we need to force wxDC to think | |
1475 | // the pen has changed | |
75f0a06e | 1476 | wxPen pen( GetPen() ); |
97071cdb | 1477 | |
613a24f7 | 1478 | m_pen = wxNullPen; |
0f4c3aa2 | 1479 | SetPen( pen ); |
613a24f7 SC |
1480 | } |
1481 | } | |
1482 | ||
b21d67a0 | 1483 | void wxDC::SetPalette( const wxPalette& palette ) |
613a24f7 SC |
1484 | { |
1485 | } | |
1486 | ||
b21d67a0 | 1487 | void wxDC::SetBackgroundMode( int mode ) |
613a24f7 SC |
1488 | { |
1489 | m_backgroundMode = mode ; | |
1490 | } | |
1491 | ||
b21d67a0 | 1492 | void wxDC::SetFont( const wxFont &font ) |
613a24f7 SC |
1493 | { |
1494 | m_font = font; | |
ded83b1a SC |
1495 | if ( m_graphicContext ) |
1496 | m_graphicContext->SetFont( font ) ; | |
613a24f7 SC |
1497 | } |
1498 | ||
b21d67a0 | 1499 | void wxDC::SetPen( const wxPen &pen ) |
613a24f7 SC |
1500 | { |
1501 | if ( m_pen == pen ) | |
1502 | return ; | |
ebbb5cb2 | 1503 | |
613a24f7 | 1504 | m_pen = pen; |
20b69855 SC |
1505 | if ( m_graphicContext ) |
1506 | { | |
24cd6f82 SC |
1507 | if ( m_pen.GetStyle() == wxSOLID || m_pen.GetStyle() == wxTRANSPARENT ) |
1508 | { | |
1509 | m_graphicContext->SetPen( m_pen ) ; | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | // we have to compensate for moved device origins etc. otherwise patterned pens are standing still | |
1514 | // eg when using a wxScrollWindow and scrolling around | |
0f4c3aa2 DS |
1515 | int origX = XLOG2DEVMAC( 0 ) ; |
1516 | int origY = YLOG2DEVMAC( 0 ) ; | |
ded83b1a | 1517 | m_graphicContext->Translate( origX , origY ) ; |
24cd6f82 | 1518 | m_graphicContext->SetPen( m_pen ) ; |
ded83b1a | 1519 | m_graphicContext->Translate( -origX , -origY ) ; |
24cd6f82 | 1520 | } |
20b69855 | 1521 | } |
613a24f7 SC |
1522 | } |
1523 | ||
b21d67a0 | 1524 | void wxDC::SetBrush( const wxBrush &brush ) |
613a24f7 SC |
1525 | { |
1526 | if (m_brush == brush) | |
1527 | return; | |
97071cdb | 1528 | |
613a24f7 | 1529 | m_brush = brush; |
20b69855 SC |
1530 | if ( m_graphicContext ) |
1531 | { | |
24cd6f82 SC |
1532 | if ( brush.GetStyle() == wxSOLID || brush.GetStyle() == wxTRANSPARENT ) |
1533 | { | |
1534 | m_graphicContext->SetBrush( m_brush ) ; | |
1535 | } | |
1536 | else | |
1537 | { | |
1538 | // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still | |
1539 | // eg when using a wxScrollWindow and scrolling around | |
24cd6f82 SC |
1540 | int origX = XLOG2DEVMAC(0) ; |
1541 | int origY = YLOG2DEVMAC(0) ; | |
ded83b1a | 1542 | m_graphicContext->Translate( origX , origY ) ; |
24cd6f82 | 1543 | m_graphicContext->SetBrush( m_brush ) ; |
ded83b1a | 1544 | m_graphicContext->Translate( -origX , -origY ) ; |
24cd6f82 | 1545 | } |
20b69855 | 1546 | } |
613a24f7 SC |
1547 | } |
1548 | ||
b21d67a0 | 1549 | void wxDC::SetBackground( const wxBrush &brush ) |
613a24f7 SC |
1550 | { |
1551 | if (m_backgroundBrush == brush) | |
1552 | return; | |
0f4c3aa2 | 1553 | |
613a24f7 SC |
1554 | m_backgroundBrush = brush; |
1555 | if (!m_backgroundBrush.Ok()) | |
1556 | return; | |
613a24f7 SC |
1557 | } |
1558 | ||
b21d67a0 | 1559 | void wxDC::SetLogicalFunction( int function ) |
613a24f7 SC |
1560 | { |
1561 | if (m_logicalFunction == function) | |
1562 | return; | |
97071cdb | 1563 | |
613a24f7 | 1564 | m_logicalFunction = function ; |
01b5ab33 SC |
1565 | #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES |
1566 | CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; | |
1567 | if ( m_logicalFunction == wxCOPY ) | |
1568 | CGContextSetBlendMode( cgContext, kCGBlendModeNormal ) ; | |
1569 | else if ( m_logicalFunction == wxINVERT ) | |
1570 | CGContextSetBlendMode( cgContext, kCGBlendModeExclusion ) ; | |
1571 | else | |
1572 | CGContextSetBlendMode( cgContext, kCGBlendModeNormal ) ; | |
1573 | #endif | |
613a24f7 SC |
1574 | } |
1575 | ||
1576 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
1577 | const wxColour & col, int style); | |
1578 | ||
1579 | bool wxDC::DoFloodFill(wxCoord x, wxCoord y, | |
1580 | const wxColour& col, int style) | |
1581 | { | |
1582 | return wxDoFloodFill(this, x, y, col, style); | |
1583 | } | |
1584 | ||
b21d67a0 | 1585 | bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const |
613a24f7 | 1586 | { |
b21d67a0 | 1587 | wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") ); |
75f0a06e | 1588 | |
880f5369 | 1589 | RGBColor colour; |
4f74e0d1 SC |
1590 | #ifndef __LP64__ |
1591 | wxMacPortSaver helper((CGrafPtr)m_macPort) ; | |
75f0a06e | 1592 | // NB: GetCPixel is a deprecated QD call, and a slow one at that |
0f4c3aa2 DS |
1593 | GetCPixel( |
1594 | XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x, | |
880f5369 | 1595 | YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour ); |
4f74e0d1 | 1596 | #endif |
75f0a06e DS |
1597 | // convert from Mac colour to wx |
1598 | col->Set( colour.red >> 8, colour.green >> 8, colour.blue >> 8 ); | |
97071cdb | 1599 | |
880f5369 | 1600 | return true ; |
613a24f7 SC |
1601 | } |
1602 | ||
b21d67a0 | 1603 | void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
613a24f7 | 1604 | { |
b21d67a0 DS |
1605 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") ); |
1606 | ||
01b5ab33 | 1607 | #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES |
08c8555e SC |
1608 | if ( m_logicalFunction != wxCOPY ) |
1609 | return ; | |
0f4c3aa2 | 1610 | #endif |
b21d67a0 | 1611 | |
613a24f7 SC |
1612 | wxCoord xx1 = XLOG2DEVMAC(x1) ; |
1613 | wxCoord yy1 = YLOG2DEVMAC(y1) ; | |
1614 | wxCoord xx2 = XLOG2DEVMAC(x2) ; | |
1615 | wxCoord yy2 = YLOG2DEVMAC(y2) ; | |
1616 | ||
20b69855 | 1617 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
b21d67a0 | 1618 | path->MoveToPoint( xx1, yy1 ) ; |
20b69855 SC |
1619 | path->AddLineToPoint( xx2 , yy2 ) ; |
1620 | path->CloseSubpath() ; | |
1621 | m_graphicContext->StrokePath( path ) ; | |
1622 | delete path ; | |
613a24f7 SC |
1623 | |
1624 | CalcBoundingBox(x1, y1); | |
1625 | CalcBoundingBox(x2, y2); | |
1626 | } | |
1627 | ||
b21d67a0 | 1628 | void wxDC::DoCrossHair( wxCoord x, wxCoord y ) |
613a24f7 | 1629 | { |
b21d67a0 | 1630 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") ); |
613a24f7 | 1631 | |
08c8555e SC |
1632 | if ( m_logicalFunction != wxCOPY ) |
1633 | return ; | |
0f4c3aa2 | 1634 | |
b21d67a0 DS |
1635 | int w = 0, h = 0; |
1636 | ||
613a24f7 SC |
1637 | GetSize( &w, &h ); |
1638 | wxCoord xx = XLOG2DEVMAC(x); | |
1639 | wxCoord yy = YLOG2DEVMAC(y); | |
1640 | ||
20b69855 | 1641 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
b21d67a0 | 1642 | path->MoveToPoint( XLOG2DEVMAC(0), yy ) ; |
20b69855 SC |
1643 | path->AddLineToPoint( XLOG2DEVMAC(w), yy ) ; |
1644 | path->CloseSubpath() ; | |
1645 | path->MoveToPoint( xx, YLOG2DEVMAC(0) ) ; | |
1646 | path->AddLineToPoint( xx, YLOG2DEVMAC(h) ) ; | |
1647 | path->CloseSubpath() ; | |
1648 | m_graphicContext->StrokePath( path ) ; | |
1649 | delete path ; | |
613a24f7 SC |
1650 | |
1651 | CalcBoundingBox(x, y); | |
b21d67a0 | 1652 | CalcBoundingBox(x + w, y + h); |
613a24f7 SC |
1653 | } |
1654 | ||
b21d67a0 | 1655 | void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, |
613a24f7 SC |
1656 | wxCoord x2, wxCoord y2, |
1657 | wxCoord xc, wxCoord yc ) | |
1658 | { | |
b21d67a0 | 1659 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") ); |
08c8555e SC |
1660 | |
1661 | if ( m_logicalFunction != wxCOPY ) | |
1662 | return ; | |
1663 | ||
613a24f7 SC |
1664 | wxCoord xx1 = XLOG2DEVMAC(x1); |
1665 | wxCoord yy1 = YLOG2DEVMAC(y1); | |
1666 | wxCoord xx2 = XLOG2DEVMAC(x2); | |
1667 | wxCoord yy2 = YLOG2DEVMAC(y2); | |
1668 | wxCoord xxc = XLOG2DEVMAC(xc); | |
1669 | wxCoord yyc = YLOG2DEVMAC(yc); | |
75f0a06e | 1670 | |
613a24f7 SC |
1671 | double dx = xx1 - xxc; |
1672 | double dy = yy1 - yyc; | |
b21d67a0 | 1673 | double radius = sqrt((double)(dx * dx + dy * dy)); |
75f0a06e | 1674 | wxCoord rad = (wxCoord)radius; |
72ba915e | 1675 | double sa, ea; |
613a24f7 SC |
1676 | if (xx1 == xx2 && yy1 == yy2) |
1677 | { | |
72ba915e SC |
1678 | sa = 0.0; |
1679 | ea = 360.0; | |
613a24f7 SC |
1680 | } |
1681 | else if (radius == 0.0) | |
1682 | { | |
72ba915e | 1683 | sa = ea = 0.0; |
613a24f7 SC |
1684 | } |
1685 | else | |
1686 | { | |
72ba915e | 1687 | sa = (xx1 - xxc == 0) ? |
613a24f7 | 1688 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
b21d67a0 | 1689 | -atan2(double(yy1 - yyc), double(xx1 - xxc)) * RAD2DEG; |
72ba915e | 1690 | ea = (xx2 - xxc == 0) ? |
613a24f7 | 1691 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
b21d67a0 | 1692 | -atan2(double(yy2 - yyc), double(xx2 - xxc)) * RAD2DEG; |
613a24f7 | 1693 | } |
72ba915e SC |
1694 | |
1695 | bool fill = m_brush.GetStyle() != wxTRANSPARENT ; | |
ded83b1a SC |
1696 | |
1697 | wxGraphicPath* path = m_graphicContext->CreatePath() ; | |
1698 | m_graphicContext->PushState() ; | |
1699 | m_graphicContext->Translate( xxc, yyc ) ; | |
1700 | m_graphicContext->Scale( 1, -1 ) ; | |
72ba915e | 1701 | if ( fill ) |
ded83b1a SC |
1702 | path->MoveToPoint( 0, 0 ) ; |
1703 | path->AddArc( 0, 0, rad , DegToRad(sa) , DegToRad(ea), false ) ; | |
72ba915e | 1704 | if ( fill ) |
ded83b1a SC |
1705 | path->AddLineToPoint( 0, 0 ) ; |
1706 | m_graphicContext->DrawPath( path ) ; | |
1707 | m_graphicContext->PopState() ; | |
1708 | delete path ; | |
613a24f7 SC |
1709 | } |
1710 | ||
b21d67a0 | 1711 | void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
613a24f7 SC |
1712 | double sa, double ea ) |
1713 | { | |
b21d67a0 | 1714 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") ); |
20b69855 | 1715 | |
08c8555e SC |
1716 | if ( m_logicalFunction != wxCOPY ) |
1717 | return ; | |
1718 | ||
613a24f7 SC |
1719 | wxCoord xx = XLOG2DEVMAC(x); |
1720 | wxCoord yy = YLOG2DEVMAC(y); | |
1721 | wxCoord ww = m_signX * XLOG2DEVREL(w); | |
1722 | wxCoord hh = m_signY * YLOG2DEVREL(h); | |
75f0a06e | 1723 | |
613a24f7 | 1724 | // handle -ve width and/or height |
75f0a06e DS |
1725 | if (ww < 0) |
1726 | { | |
1727 | ww = -ww; | |
1728 | xx = xx - ww; | |
1729 | } | |
1730 | if (hh < 0) | |
1731 | { | |
1732 | hh = -hh; | |
1733 | yy = yy - hh; | |
1734 | } | |
72ba915e SC |
1735 | |
1736 | bool fill = m_brush.GetStyle() != wxTRANSPARENT ; | |
1737 | ||
ded83b1a SC |
1738 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
1739 | m_graphicContext->PushState() ; | |
1740 | m_graphicContext->Translate( xx + ww / 2, yy + hh / 2 ) ; | |
1741 | m_graphicContext->Scale( 1 * ww / 2 , -1 * hh / 2 ) ; | |
72ba915e | 1742 | if ( fill ) |
ded83b1a SC |
1743 | path->MoveToPoint( 0, 0 ) ; |
1744 | path->AddArc( 0, 0, 1 , DegToRad(sa) , DegToRad(ea), false ) ; | |
72ba915e | 1745 | if ( fill ) |
ded83b1a SC |
1746 | path->AddLineToPoint( 0, 0 ) ; |
1747 | m_graphicContext->DrawPath( path ) ; | |
1748 | m_graphicContext->PopState() ; | |
1749 | delete path ; | |
613a24f7 SC |
1750 | } |
1751 | ||
b21d67a0 | 1752 | void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) |
613a24f7 | 1753 | { |
b21d67a0 | 1754 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") ); |
75f0a06e | 1755 | |
613a24f7 SC |
1756 | DoDrawLine( x , y , x + 1 , y + 1 ) ; |
1757 | } | |
1758 | ||
b21d67a0 | 1759 | void wxDC::DoDrawLines(int n, wxPoint points[], |
613a24f7 SC |
1760 | wxCoord xoffset, wxCoord yoffset) |
1761 | { | |
b21d67a0 | 1762 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") ); |
75f0a06e | 1763 | |
01b5ab33 | 1764 | #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES |
08c8555e SC |
1765 | if ( m_logicalFunction != wxCOPY ) |
1766 | return ; | |
0f4c3aa2 | 1767 | #endif |
08c8555e | 1768 | |
613a24f7 SC |
1769 | wxCoord x1, x2 , y1 , y2 ; |
1770 | x1 = XLOG2DEVMAC(points[0].x + xoffset); | |
1771 | y1 = YLOG2DEVMAC(points[0].y + yoffset); | |
20b69855 SC |
1772 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
1773 | path->MoveToPoint( x1 , y1 ) ; | |
613a24f7 SC |
1774 | for (int i = 1; i < n; i++) |
1775 | { | |
1776 | x2 = XLOG2DEVMAC(points[i].x + xoffset); | |
1777 | y2 = YLOG2DEVMAC(points[i].y + yoffset); | |
1778 | ||
20b69855 | 1779 | path->AddLineToPoint( x2 , y2 ) ; |
613a24f7 | 1780 | } |
97071cdb | 1781 | |
20b69855 SC |
1782 | m_graphicContext->StrokePath( path ) ; |
1783 | delete path ; | |
613a24f7 SC |
1784 | } |
1785 | ||
e828c96a SC |
1786 | #if wxUSE_SPLINES |
1787 | void wxDC::DoDrawSpline(wxList *points) | |
1788 | { | |
b21d67a0 DS |
1789 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") ); |
1790 | ||
e828c96a SC |
1791 | if ( m_logicalFunction != wxCOPY ) |
1792 | return ; | |
0f4c3aa2 | 1793 | |
e828c96a | 1794 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
0f4c3aa2 | 1795 | |
e828c96a SC |
1796 | wxList::compatibility_iterator node = points->GetFirst(); |
1797 | if (node == wxList::compatibility_iterator()) | |
1798 | // empty list | |
1799 | return; | |
0f4c3aa2 | 1800 | |
e828c96a | 1801 | wxPoint *p = (wxPoint *)node->GetData(); |
0f4c3aa2 | 1802 | |
e828c96a SC |
1803 | wxCoord x1 = p->x; |
1804 | wxCoord y1 = p->y; | |
0f4c3aa2 | 1805 | |
e828c96a SC |
1806 | node = node->GetNext(); |
1807 | p = (wxPoint *)node->GetData(); | |
0f4c3aa2 | 1808 | |
e828c96a SC |
1809 | wxCoord x2 = p->x; |
1810 | wxCoord y2 = p->y; | |
1811 | wxCoord cx1 = ( x1 + x2 ) / 2; | |
1812 | wxCoord cy1 = ( y1 + y2 ) / 2; | |
0f4c3aa2 | 1813 | |
de8e2d31 SC |
1814 | path->MoveToPoint( XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) ) ; |
1815 | path->AddLineToPoint( XLOG2DEVMAC( cx1 ) , YLOG2DEVMAC( cy1 ) ) ; | |
0f4c3aa2 | 1816 | |
e828c96a SC |
1817 | #if !wxUSE_STL |
1818 | while ((node = node->GetNext()) != NULL) | |
1819 | #else | |
1820 | while ((node = node->GetNext())) | |
1821 | #endif // !wxUSE_STL | |
1822 | { | |
1823 | p = (wxPoint *)node->GetData(); | |
1824 | x1 = x2; | |
1825 | y1 = y2; | |
1826 | x2 = p->x; | |
1827 | y2 = p->y; | |
1828 | wxCoord cx4 = (x1 + x2) / 2; | |
1829 | wxCoord cy4 = (y1 + y2) / 2; | |
b21d67a0 | 1830 | |
0f4c3aa2 | 1831 | path->AddQuadCurveToPoint( |
de8e2d31 SC |
1832 | XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) , |
1833 | XLOG2DEVMAC( cx4 ) , YLOG2DEVMAC( cy4 ) ) ; | |
b21d67a0 | 1834 | |
e828c96a SC |
1835 | cx1 = cx4; |
1836 | cy1 = cy4; | |
1837 | } | |
0f4c3aa2 | 1838 | |
de8e2d31 | 1839 | path->AddLineToPoint( XLOG2DEVMAC( x2 ) , YLOG2DEVMAC( y2 ) ) ; |
0f4c3aa2 | 1840 | |
e828c96a SC |
1841 | m_graphicContext->StrokePath( path ) ; |
1842 | delete path ; | |
1843 | } | |
1844 | #endif | |
1845 | ||
b21d67a0 | 1846 | void wxDC::DoDrawPolygon( int n, wxPoint points[], |
613a24f7 SC |
1847 | wxCoord xoffset, wxCoord yoffset, |
1848 | int fillStyle ) | |
1849 | { | |
b21d67a0 | 1850 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") ); |
75f0a06e DS |
1851 | |
1852 | if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) | |
613a24f7 | 1853 | return ; |
08c8555e SC |
1854 | if ( m_logicalFunction != wxCOPY ) |
1855 | return ; | |
1856 | ||
75f0a06e | 1857 | wxCoord x1, x2 , y1 , y2 ; |
613a24f7 SC |
1858 | x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset); |
1859 | y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset); | |
0f4c3aa2 | 1860 | |
20b69855 SC |
1861 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
1862 | path->MoveToPoint( x1 , y1 ) ; | |
613a24f7 SC |
1863 | for (int i = 1; i < n; i++) |
1864 | { | |
1865 | x2 = XLOG2DEVMAC(points[i].x + xoffset); | |
1866 | y2 = YLOG2DEVMAC(points[i].y + yoffset); | |
1867 | ||
20b69855 | 1868 | path->AddLineToPoint( x2 , y2 ) ; |
613a24f7 | 1869 | } |
97071cdb | 1870 | |
613a24f7 | 1871 | if ( x1 != x2 || y1 != y2 ) |
b21d67a0 | 1872 | path->AddLineToPoint( x1, y1 ) ; |
97071cdb | 1873 | |
20b69855 SC |
1874 | path->CloseSubpath() ; |
1875 | m_graphicContext->DrawPath( path , fillStyle ) ; | |
75f0a06e | 1876 | |
20b69855 | 1877 | delete path ; |
613a24f7 SC |
1878 | } |
1879 | ||
1880 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
1881 | { | |
b21d67a0 | 1882 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") ); |
08c8555e SC |
1883 | |
1884 | if ( m_logicalFunction != wxCOPY ) | |
1885 | return ; | |
1886 | ||
613a24f7 SC |
1887 | wxCoord xx = XLOG2DEVMAC(x); |
1888 | wxCoord yy = YLOG2DEVMAC(y); | |
1889 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
1890 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
75f0a06e | 1891 | |
613a24f7 SC |
1892 | // CMB: draw nothing if transformed w or h is 0 |
1893 | if (ww == 0 || hh == 0) | |
1894 | return; | |
97071cdb | 1895 | |
613a24f7 SC |
1896 | // CMB: handle -ve width and/or height |
1897 | if (ww < 0) | |
1898 | { | |
1899 | ww = -ww; | |
1900 | xx = xx - ww; | |
1901 | } | |
1902 | if (hh < 0) | |
1903 | { | |
1904 | hh = -hh; | |
1905 | yy = yy - hh; | |
1906 | } | |
97071cdb | 1907 | |
4bc28209 SC |
1908 | int penwidth = m_pen.GetWidth(); |
1909 | if ( penwidth == 0 ) | |
1910 | penwidth = 1 ; | |
1911 | if ( m_pen.GetStyle() == wxTRANSPARENT ) | |
1912 | penwidth = 0 ; | |
1913 | ||
1914 | bool offset = ( penwidth % 2 ) == 1 ; | |
1915 | ||
20b69855 | 1916 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
4bc28209 SC |
1917 | // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1 |
1918 | if ( offset ) | |
1919 | path->AddRectangle( xx , yy , ww-1 , hh-1 ) ; | |
1920 | else | |
1921 | path->AddRectangle( xx , yy , ww , hh ) ; | |
1922 | ||
20b69855 SC |
1923 | m_graphicContext->DrawPath( path ) ; |
1924 | delete path ; | |
613a24f7 SC |
1925 | } |
1926 | ||
b21d67a0 | 1927 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
613a24f7 SC |
1928 | wxCoord width, wxCoord height, |
1929 | double radius) | |
1930 | { | |
b21d67a0 | 1931 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") ); |
08c8555e SC |
1932 | |
1933 | if ( m_logicalFunction != wxCOPY ) | |
1934 | return ; | |
1935 | ||
613a24f7 SC |
1936 | if (radius < 0.0) |
1937 | radius = - radius * ((width < height) ? width : height); | |
1938 | wxCoord xx = XLOG2DEVMAC(x); | |
1939 | wxCoord yy = YLOG2DEVMAC(y); | |
1940 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
1941 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
75f0a06e | 1942 | |
613a24f7 SC |
1943 | // CMB: draw nothing if transformed w or h is 0 |
1944 | if (ww == 0 || hh == 0) | |
1945 | return; | |
97071cdb | 1946 | |
613a24f7 SC |
1947 | // CMB: handle -ve width and/or height |
1948 | if (ww < 0) | |
1949 | { | |
1950 | ww = -ww; | |
1951 | xx = xx - ww; | |
1952 | } | |
1953 | if (hh < 0) | |
1954 | { | |
1955 | hh = -hh; | |
1956 | yy = yy - hh; | |
1957 | } | |
97071cdb | 1958 | |
ded83b1a SC |
1959 | wxGraphicPath* path = m_graphicContext->CreatePath() ; |
1960 | if ( radius == 0) | |
1961 | { | |
1962 | path->AddRectangle( xx , yy , ww , hh ) ; | |
1963 | m_graphicContext->DrawPath( path ) ; | |
1964 | } | |
1965 | else | |
1966 | { | |
4bc28209 SC |
1967 | path->MoveToPoint( xx + ww, yy + hh / 2); |
1968 | path->AddArcToPoint(xx + ww, yy + hh, xx + ww / 2,yy + hh, radius); | |
1969 | path->AddArcToPoint(xx , yy + hh, xx , yy + hh / 2, radius); | |
1970 | path->AddArcToPoint(xx , yy , xx + ww / 2, yy , radius); | |
1971 | path->AddArcToPoint(xx + ww, yy , xx + ww, yy + hh / 2, radius); | |
ded83b1a SC |
1972 | path->CloseSubpath(); |
1973 | m_graphicContext->DrawPath( path ) ; | |
ded83b1a SC |
1974 | } |
1975 | delete path ; | |
613a24f7 SC |
1976 | } |
1977 | ||
b21d67a0 | 1978 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
613a24f7 | 1979 | { |
b21d67a0 | 1980 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") ); |
08c8555e SC |
1981 | |
1982 | if ( m_logicalFunction != wxCOPY ) | |
1983 | return ; | |
1984 | ||
613a24f7 SC |
1985 | wxCoord xx = XLOG2DEVMAC(x); |
1986 | wxCoord yy = YLOG2DEVMAC(y); | |
1987 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
1988 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
0f4c3aa2 | 1989 | |
613a24f7 SC |
1990 | // CMB: draw nothing if transformed w or h is 0 |
1991 | if (ww == 0 || hh == 0) | |
1992 | return; | |
97071cdb | 1993 | |
613a24f7 SC |
1994 | // CMB: handle -ve width and/or height |
1995 | if (ww < 0) | |
1996 | { | |
1997 | ww = -ww; | |
1998 | xx = xx - ww; | |
1999 | } | |
2000 | if (hh < 0) | |
2001 | { | |
2002 | hh = -hh; | |
2003 | yy = yy - hh; | |
2004 | } | |
ded83b1a SC |
2005 | |
2006 | wxGraphicPath* path = m_graphicContext->CreatePath() ; | |
2007 | m_graphicContext->PushState() ; | |
2008 | m_graphicContext->Translate(xx + ww / 2, yy + hh / 2); | |
2009 | m_graphicContext->Scale(ww / 2 , hh / 2); | |
2010 | path->AddArc( 0, 0, 1, 0 , 2 * M_PI , false ) ; | |
2011 | m_graphicContext->DrawPath( path ) ; | |
2012 | m_graphicContext->PopState() ; | |
2013 | delete path ; | |
613a24f7 SC |
2014 | } |
2015 | ||
0f4c3aa2 | 2016 | bool wxDC::CanDrawBitmap() const |
613a24f7 SC |
2017 | { |
2018 | return true ; | |
2019 | } | |
2020 | ||
0f4c3aa2 DS |
2021 | bool wxDC::DoBlit( |
2022 | wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
2023 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask, | |
2024 | wxCoord xsrcMask, wxCoord ysrcMask ) | |
613a24f7 | 2025 | { |
b21d67a0 DS |
2026 | wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") ); |
2027 | wxCHECK_MSG( source->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") ); | |
75f0a06e | 2028 | |
613a24f7 | 2029 | if ( logical_func == wxNO_OP ) |
97071cdb DS |
2030 | return true ; |
2031 | ||
613a24f7 SC |
2032 | if (xsrcMask == -1 && ysrcMask == -1) |
2033 | { | |
97071cdb DS |
2034 | xsrcMask = xsrc; |
2035 | ysrcMask = ysrc; | |
613a24f7 | 2036 | } |
20b69855 | 2037 | |
68654a82 | 2038 | wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ; |
ec4a2b5d DS |
2039 | wxCoord xxsrc = source->XLOG2DEVMAC(xsrc) ; |
2040 | wxCoord wwsrc = source->XLOG2DEVREL(width) ; | |
68654a82 | 2041 | wxCoord hhsrc = source->YLOG2DEVREL(height) ; |
0f4c3aa2 | 2042 | |
68654a82 SC |
2043 | wxCoord yydest = YLOG2DEVMAC(ydest) ; |
2044 | wxCoord xxdest = XLOG2DEVMAC(xdest) ; | |
ec4a2b5d | 2045 | wxCoord wwdest = XLOG2DEVREL(width) ; |
68654a82 | 2046 | wxCoord hhdest = YLOG2DEVREL(height) ; |
0f4c3aa2 | 2047 | |
20b69855 | 2048 | wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source) ; |
a8f234d2 | 2049 | if ( memdc && logical_func == wxCOPY ) |
613a24f7 | 2050 | { |
20b69855 | 2051 | wxBitmap blit = memdc->GetSelectedObject() ; |
b21d67a0 | 2052 | |
20b69855 SC |
2053 | wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ; |
2054 | ||
20b69855 SC |
2055 | wxCoord bmpwidth = blit.GetWidth(); |
2056 | wxCoord bmpheight = blit.GetHeight(); | |
0f4c3aa2 | 2057 | |
68654a82 SC |
2058 | if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc ) |
2059 | { | |
2060 | wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ; | |
2061 | hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ; | |
2062 | if ( wwsrc > 0 && hhsrc > 0 ) | |
2063 | { | |
2064 | if ( xxsrc >= 0 && yysrc >= 0 ) | |
2065 | { | |
2066 | wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ; | |
ded83b1a | 2067 | // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons |
68654a82 SC |
2068 | blit = blit.GetSubBitmap( subrect ) ; |
2069 | } | |
2070 | else | |
2071 | { | |
2072 | // in this case we'd probably have to adjust the different coordinates, but | |
2073 | // we have to find out proper contract first | |
2074 | blit = wxNullBitmap ; | |
2075 | } | |
2076 | } | |
2077 | else | |
2078 | { | |
2079 | blit = wxNullBitmap ; | |
2080 | } | |
2081 | } | |
97071cdb | 2082 | |
68654a82 | 2083 | if ( blit.Ok() ) |
613a24f7 | 2084 | { |
ded83b1a | 2085 | m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest ) ; |
613a24f7 | 2086 | } |
20b69855 SC |
2087 | } |
2088 | else | |
2089 | { | |
7f345078 | 2090 | wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ; |
ded83b1a | 2091 | return false ; |
613a24f7 | 2092 | } |
97071cdb DS |
2093 | |
2094 | return true; | |
613a24f7 SC |
2095 | } |
2096 | ||
b21d67a0 | 2097 | void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, |
613a24f7 SC |
2098 | double angle) |
2099 | { | |
b21d67a0 | 2100 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") ); |
ded83b1a | 2101 | // wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") ); |
613a24f7 | 2102 | |
e4db172a | 2103 | if ( str.length() == 0 ) |
613a24f7 | 2104 | return ; |
08c8555e SC |
2105 | if ( m_logicalFunction != wxCOPY ) |
2106 | return ; | |
2107 | ||
613a24f7 SC |
2108 | int drawX = XLOG2DEVMAC(x) ; |
2109 | int drawY = YLOG2DEVMAC(y) ; | |
2110 | ||
ded83b1a | 2111 | m_graphicContext->DrawText( str, drawX ,drawY , angle ) ; |
613a24f7 SC |
2112 | } |
2113 | ||
b21d67a0 | 2114 | void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) |
613a24f7 | 2115 | { |
b21d67a0 | 2116 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") ); |
75f0a06e | 2117 | |
613a24f7 SC |
2118 | DoDrawRotatedText( strtext , x , y , 0.0 ) ; |
2119 | } | |
2120 | ||
b21d67a0 | 2121 | bool wxDC::CanGetTextExtent() const |
613a24f7 | 2122 | { |
b21d67a0 | 2123 | wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") ); |
75f0a06e | 2124 | |
613a24f7 SC |
2125 | return true ; |
2126 | } | |
2127 | ||
b21d67a0 | 2128 | void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height, |
613a24f7 SC |
2129 | wxCoord *descent, wxCoord *externalLeading , |
2130 | wxFont *theFont ) const | |
2131 | { | |
b21d67a0 | 2132 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") ); |
75f0a06e | 2133 | |
613a24f7 SC |
2134 | if ( theFont ) |
2135 | { | |
ded83b1a | 2136 | m_graphicContext->SetFont( *theFont ) ; |
613a24f7 SC |
2137 | } |
2138 | ||
ded83b1a SC |
2139 | wxCoord h , d , e , w ; |
2140 | ||
2141 | m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ) ; | |
0f4c3aa2 | 2142 | |
613a24f7 | 2143 | if ( height ) |
ded83b1a | 2144 | *height = YDEV2LOGREL( h ) ; |
613a24f7 | 2145 | if ( descent ) |
ded83b1a | 2146 | *descent =YDEV2LOGREL( d); |
613a24f7 | 2147 | if ( externalLeading ) |
ded83b1a | 2148 | *externalLeading = YDEV2LOGREL( e); |
613a24f7 | 2149 | if ( width ) |
ded83b1a | 2150 | *width = XDEV2LOGREL( w ) ; |
b21d67a0 | 2151 | |
613a24f7 SC |
2152 | if ( theFont ) |
2153 | { | |
ded83b1a | 2154 | m_graphicContext->SetFont( m_font ) ; |
613a24f7 SC |
2155 | } |
2156 | } | |
2157 | ||
613a24f7 SC |
2158 | bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const |
2159 | { | |
b21d67a0 | 2160 | wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") ); |
613a24f7 | 2161 | |
ded83b1a SC |
2162 | m_graphicContext->GetPartialTextExtents( text, widths ) ; |
2163 | for ( size_t i = 0 ; i < widths.GetCount() ; ++i ) | |
2164 | widths[i] = XDEV2LOGREL( widths[i] ); | |
764e6694 | 2165 | |
764e6694 | 2166 | return true; |
613a24f7 SC |
2167 | } |
2168 | ||
b21d67a0 | 2169 | wxCoord wxDC::GetCharWidth(void) const |
613a24f7 SC |
2170 | { |
2171 | wxCoord width ; | |
b21d67a0 | 2172 | DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ) ; |
75f0a06e | 2173 | |
613a24f7 SC |
2174 | return width ; |
2175 | } | |
2176 | ||
b21d67a0 | 2177 | wxCoord wxDC::GetCharHeight(void) const |
613a24f7 SC |
2178 | { |
2179 | wxCoord height ; | |
b21d67a0 | 2180 | DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ) ; |
75f0a06e | 2181 | |
613a24f7 SC |
2182 | return height ; |
2183 | } | |
2184 | ||
b21d67a0 | 2185 | void wxDC::Clear(void) |
613a24f7 | 2186 | { |
b21d67a0 | 2187 | wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") ); |
613a24f7 | 2188 | |
75f0a06e | 2189 | if (m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) |
ec4a2b5d | 2190 | { |
b014adcc | 2191 | HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ; |
b60f5ca5 | 2192 | CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; |
b21d67a0 | 2193 | switch ( m_backgroundBrush.MacGetBrushKind() ) |
613a24f7 SC |
2194 | { |
2195 | case kwxMacBrushTheme : | |
2196 | { | |
a63b4755 SC |
2197 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
2198 | if ( HIThemeSetFill != 0 ) | |
2199 | { | |
72ba915e | 2200 | HIThemeSetFill( m_backgroundBrush.MacGetTheme(), NULL, cg, kHIThemeOrientationNormal ); |
a63b4755 SC |
2201 | CGContextFillRect(cg, rect); |
2202 | ||
2203 | } | |
2204 | else | |
2205 | #endif | |
2206 | { | |
75f0a06e | 2207 | RGBColor color; |
72ba915e | 2208 | GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color ); |
bc78039c SC |
2209 | CGContextSetRGBFillColor( cg, (CGFloat) color.red / 65536, |
2210 | (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 ); | |
97071cdb | 2211 | CGContextFillRect( cg, rect ); |
a63b4755 | 2212 | } |
72ba915e | 2213 | |
a63b4755 SC |
2214 | // reset to normal value |
2215 | RGBColor col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ; | |
72ba915e | 2216 | CGContextSetRGBFillColor( cg, col.red / 65536.0, col.green / 65536.0, col.blue / 65536.0, 1.0 ); |
613a24f7 | 2217 | } |
97071cdb DS |
2218 | break ; |
2219 | ||
613a24f7 SC |
2220 | case kwxMacBrushThemeBackground : |
2221 | { | |
a63b4755 | 2222 | wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ; |
75f0a06e | 2223 | |
b014adcc | 2224 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
1688bb38 | 2225 | if ( UMAGetSystemVersion() >= 0x1030 ) |
b014adcc SC |
2226 | { |
2227 | HIThemeBackgroundDrawInfo drawInfo ; | |
2228 | drawInfo.version = 0 ; | |
2229 | drawInfo.state = kThemeStateActive ; | |
ec4a2b5d | 2230 | drawInfo.kind = m_backgroundBrush.MacGetThemeBackground( NULL ) ; |
b014adcc | 2231 | if ( drawInfo.kind == kThemeBackgroundMetal ) |
ec4a2b5d DS |
2232 | { |
2233 | HIThemeDrawBackground( &rect, &drawInfo, cg, kHIThemeOrientationNormal ) ; | |
2234 | HIThemeApplyBackground( &rect, &drawInfo, cg, kHIThemeOrientationNormal ) ; | |
2235 | } | |
b014adcc SC |
2236 | } |
2237 | #endif | |
613a24f7 | 2238 | } |
97071cdb DS |
2239 | break ; |
2240 | ||
613a24f7 | 2241 | case kwxMacBrushColour : |
97071cdb | 2242 | { |
ec4a2b5d DS |
2243 | // FIXME: doesn't correctly render stippled brushes !! |
2244 | // FIXME: should this be replaced by ::SetBrush() ?? | |
2245 | ||
97071cdb DS |
2246 | RGBColor col = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ; |
2247 | CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; | |
2248 | CGContextFillRect(cg, rect); | |
613a24f7 | 2249 | |
97071cdb DS |
2250 | // reset to normal value |
2251 | col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ; | |
2252 | CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; | |
2253 | } | |
2254 | break ; | |
2255 | ||
75f0a06e DS |
2256 | default : |
2257 | wxFAIL_MSG( wxT("unknown brush kind") ) ; | |
97071cdb | 2258 | break ; |
613a24f7 SC |
2259 | } |
2260 | } | |
2261 | } | |
2262 | ||
eb1a7cf9 DS |
2263 | #pragma mark - |
2264 | ||
613a24f7 SC |
2265 | // --------------------------------------------------------------------------- |
2266 | // coordinates transformations | |
2267 | // --------------------------------------------------------------------------- | |
2268 | ||
2269 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
2270 | { | |
2271 | return ((wxDC *)this)->XDEV2LOG(x); | |
2272 | } | |
2273 | ||
2274 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
2275 | { | |
2276 | return ((wxDC *)this)->YDEV2LOG(y); | |
2277 | } | |
2278 | ||
2279 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
2280 | { | |
2281 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
2282 | } | |
2283 | ||
2284 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
2285 | { | |
2286 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
2287 | } | |
2288 | ||
2289 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
2290 | { | |
2291 | return ((wxDC *)this)->XLOG2DEV(x); | |
2292 | } | |
2293 | ||
2294 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
2295 | { | |
2296 | return ((wxDC *)this)->YLOG2DEV(y); | |
2297 | } | |
2298 | ||
2299 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
2300 | { | |
2301 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
2302 | } | |
2303 | ||
2304 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
2305 | { | |
2306 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
2307 | } | |
20b69855 SC |
2308 | |
2309 | #endif // wxMAC_USE_CORE_GRAPHICS |