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