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