1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #if wxMAC_USE_CORE_GRAPHICS
19 #include "wx/mac/uma.h"
20 #include "wx/dcmemory.h"
21 #include "wx/dcprint.h"
22 #include "wx/region.h"
30 // in case our functions were defined outside std, we make it known all the same
36 #include "wx/mac/private.h"
38 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
40 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
41 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
50 const double M_PI
= 3.14159265358979 ;
54 const double RAD2DEG
= 180.0 / M_PI
;
55 const short kEmulatedMode
= -1 ;
56 const short kUnsupportedMode
= -2 ;
58 extern TECObjectRef s_TECNativeCToUnicode
;
62 // The textctrl implementation still needs that (needs what?) for the non-HIView implementation
64 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
65 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
67 m_newPort
= (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
68 m_formerClip
= NewRgn() ;
69 m_newClip
= NewRgn() ;
70 GetClip( m_formerClip
) ;
74 // guard against half constructed objects, this just leads to a empty clip
78 win
->MacWindowToRootWindow( &x
, &y
) ;
79 // get area including focus rect
80 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
81 if ( !EmptyRgn( m_newClip
) )
82 OffsetRgn( m_newClip
, x
, y
) ;
85 SetClip( m_newClip
) ;
89 wxMacWindowClipper::~wxMacWindowClipper()
91 SetPort( m_newPort
) ;
92 SetClip( m_formerClip
) ;
93 DisposeRgn( m_newClip
) ;
94 DisposeRgn( m_formerClip
) ;
97 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
98 wxMacWindowClipper( win
)
100 // the port is already set at this point
101 m_newPort
= (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
102 GetThemeDrawingState( &m_themeDrawingState
) ;
105 wxMacWindowStateSaver::~wxMacWindowStateSaver()
107 SetPort( m_newPort
) ;
108 SetThemeDrawingState( m_themeDrawingState
, true ) ;
111 // minimal implementation only used for appearance drawing < 10.3
113 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
114 m_ph( (GrafPtr
) dc
->m_macPort
)
116 wxASSERT( dc
->Ok() ) ;
119 // dc->MacSetupPort(&m_ph) ;
122 wxMacPortSetter::~wxMacPortSetter()
124 // m_dc->MacCleanupPort(&m_ph) ;
127 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
131 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
132 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
133 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
135 //-----------------------------------------------------------------------------
136 // device context implementation
138 // more and more of the dc functionality should be implemented by calling
139 // the appropricate wxMacCGContext, but we will have to do that step by step
140 // also coordinate conversions should be moved to native matrix ops
141 //-----------------------------------------------------------------------------
143 // we always stock two context states, one at entry, to be able to preserve the
144 // state we were called with, the other one after changing to HI Graphics orientation
145 // (this one is used for getting back clippings etc)
147 wxMacCGPath::wxMacCGPath()
149 m_path
= CGPathCreateMutable() ;
152 wxMacCGPath::~wxMacCGPath()
154 CGPathRelease( m_path
) ;
157 // opens (starts) a new subpath
158 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
160 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
163 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
165 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
168 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
170 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
173 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
175 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
176 CGPathAddRect( m_path
, NULL
, cgRect
) ;
179 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
181 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
184 // closes the current subpath
185 void wxMacCGPath::CloseSubpath()
187 CGPathCloseSubpath( m_path
) ;
190 CGPathRef
wxMacCGPath::GetPath() const
195 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
201 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
204 m_cgContext
= cgcontext
;
205 CGContextSaveGState( m_cgContext
) ;
206 CGContextSaveGState( m_cgContext
) ;
209 wxMacCGContext::wxMacCGContext()
215 wxMacCGContext::~wxMacCGContext()
219 CGContextSynchronize( m_cgContext
) ;
220 CGContextRestoreGState( m_cgContext
) ;
221 CGContextRestoreGState( m_cgContext
) ;
225 CGContextRelease( m_cgContext
) ;
229 void wxMacCGContext::Clip( const wxRegion
®ion
)
231 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
234 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
236 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
237 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
238 CGContextStrokePath( m_cgContext
) ;
241 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
243 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
244 CGPathDrawingMode mode
= m_mode
;
246 if ( fillStyle
== wxODDEVEN_RULE
)
248 if ( mode
== kCGPathFill
)
249 mode
= kCGPathEOFill
;
250 else if ( mode
== kCGPathFillStroke
)
251 mode
= kCGPathEOFillStroke
;
254 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
255 CGContextDrawPath( m_cgContext
, mode
) ;
258 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
260 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
261 CGContextSaveGState( m_cgContext
) ;
263 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
264 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
265 CGPathDrawingMode mode
= kCGPathFill
;
267 if ( fillStyle
== wxODDEVEN_RULE
)
268 mode
= kCGPathEOFill
;
270 CGContextBeginPath( m_cgContext
) ;
271 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
272 CGContextClosePath( m_cgContext
) ;
273 CGContextDrawPath( m_cgContext
, mode
) ;
275 CGContextRestoreGState( m_cgContext
) ;
278 wxGraphicPath
* wxMacCGContext::CreatePath()
280 // make sure that we now have a real cgref, before doing
281 // anything with paths
282 CGContextRef cg
= GetNativeContext() ;
285 return new wxMacCGPath() ;
288 // in case we only got a QDPort only create a cgref now
290 CGContextRef
wxMacCGContext::GetNativeContext()
292 if ( m_cgContext
== NULL
)
295 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
296 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
297 CGContextSaveGState( m_cgContext
) ;
299 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
301 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
302 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
304 CGContextSaveGState( m_cgContext
) ;
306 SetBrush( m_brush
) ;
312 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
314 // we allow either setting or clearing but not replacing
315 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
318 CGContextSaveGState( cg
) ;
323 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
325 // CGPattern wrapper class: always allocate on heap, never call destructor
332 // is guaranteed to be called only with a non-Null CGContextRef
333 virtual void Render( CGContextRef ctxRef
) = 0 ;
335 operator CGPatternRef() const { return m_patternRef
; }
338 virtual ~wxMacCGPattern()
340 // as this is called only when the m_patternRef is been released;
341 // don't release it again
344 static void _Render( void *info
, CGContextRef ctxRef
)
346 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
347 if ( self
&& ctxRef
)
348 self
->Render( ctxRef
) ;
351 static void _Dispose( void *info
)
353 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
357 CGPatternRef m_patternRef
;
359 static const CGPatternCallbacks ms_Callbacks
;
362 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
364 class ImagePattern
: public wxMacCGPattern
367 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
369 wxASSERT( bmp
&& bmp
->Ok() ) ;
371 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
374 // ImagePattern takes ownership of CGImageRef passed in
375 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
380 Init( image
, transform
) ;
383 virtual void Render( CGContextRef ctxRef
)
386 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
390 void Init( CGImageRef image
, CGAffineTransform transform
)
395 m_imageBounds
= CGRectMake( 0.0, 0.0, (float)CGImageGetWidth( m_image
), (float)CGImageGetHeight( m_image
) ) ;
396 m_patternRef
= CGPatternCreate( this , m_imageBounds
, transform
,
397 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
398 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
405 CGImageRelease( m_image
) ;
409 CGRect m_imageBounds
;
412 class HatchPattern
: public wxMacCGPattern
415 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
417 m_hatch
= hatchstyle
;
418 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
419 m_patternRef
= CGPatternCreate( this , m_imageBounds
, transform
,
420 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
421 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
424 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
426 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
427 if ( UMAGetSystemVersion() >= 0x1040 )
429 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
434 CGContextBeginPath( ctxRef
);
435 for (size_t i
= 0; i
< count
; i
+= 2)
437 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
438 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
440 CGContextStrokePath(ctxRef
);
444 virtual void Render( CGContextRef ctxRef
)
448 case wxBDIAGONAL_HATCH
:
452 { 8.0 , 0.0 } , { 0.0 , 8.0 }
454 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
458 case wxCROSSDIAG_HATCH
:
462 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
463 { 8.0 , 0.0 } , { 0.0 , 8.0 }
465 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
469 case wxFDIAGONAL_HATCH
:
473 { 0.0 , 0.0 } , { 8.0 , 8.0 }
475 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
483 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
484 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
486 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
490 case wxHORIZONTAL_HATCH
:
494 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
496 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
500 case wxVERTICAL_HATCH
:
504 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
506 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
518 CGRect m_imageBounds
;
524 void wxMacCGContext::SetPen( const wxPen
&pen
)
527 if ( m_cgContext
== NULL
)
530 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
531 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
534 // we can benchmark performance, should go into a setting later
535 CGContextSetShouldAntialias( m_cgContext
, false ) ;
541 m_mode
= kCGPathFill
; // just a default
545 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
546 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
548 // TODO * m_dc->m_scaleX
549 float penWidth
= pen
.GetWidth();
552 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
555 switch ( pen
.GetCap() )
558 cap
= kCGLineCapRound
;
561 case wxCAP_PROJECTING
:
562 cap
= kCGLineCapSquare
;
566 cap
= kCGLineCapButt
;
570 cap
= kCGLineCapButt
;
575 switch ( pen
.GetJoin() )
578 join
= kCGLineJoinBevel
;
582 join
= kCGLineJoinMiter
;
586 join
= kCGLineJoinRound
;
590 join
= kCGLineJoinMiter
;
594 m_mode
= kCGPathStroke
;
597 const float *lengths
= NULL
;
598 float *userLengths
= NULL
;
600 const float dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
602 const float dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
603 const float short_dashed
[] = { 9.0 , 6.0 };
604 const float dashed
[] = { 19.0 , 9.0 };
605 const float dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
607 switch ( pen
.GetStyle() )
614 count
= WXSIZEOF(dotted
);
619 count
= WXSIZEOF(dashed
) ;
623 lengths
= short_dashed
;
624 count
= WXSIZEOF(short_dashed
) ;
628 lengths
= dotted_dashed
;
629 count
= WXSIZEOF(dotted_dashed
);
634 count
= pen
.GetDashes( &dashes
) ;
635 if ((dashes
!= NULL
) && (count
> 0))
637 userLengths
= new float[count
] ;
638 for ( int i
= 0 ; i
< count
; ++i
)
640 userLengths
[i
] = dashes
[i
] * dashUnit
;
642 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
643 userLengths
[i
] = dashUnit
+ 2.0 ;
644 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
645 userLengths
[i
] = dashUnit
;
648 lengths
= userLengths
;
653 float alphaArray
[1] = { 1.0 } ;
654 wxBitmap
* bmp
= pen
.GetStipple() ;
655 if ( bmp
&& bmp
->Ok() )
657 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
658 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
659 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
660 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
667 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
668 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
669 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
671 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
672 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
674 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
679 if ((lengths
!= NULL
) && (count
> 0))
681 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
682 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
683 cap
= kCGLineCapButt
;
687 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
690 CGContextSetLineCap( m_cgContext
, cap
) ;
691 CGContextSetLineJoin( m_cgContext
, join
) ;
693 delete[] userLengths
;
696 if ( fill
&& stroke
)
697 m_mode
= kCGPathFillStroke
;
701 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
704 if ( m_cgContext
== NULL
)
707 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
708 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
711 // we can benchmark performance, should go into a setting later
712 CGContextSetShouldAntialias( m_cgContext
, false ) ;
718 m_mode
= kCGPathFill
; // just a default
722 if ( brush
.GetStyle() == wxSOLID
)
724 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
725 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
727 else if ( brush
.IsHatch() )
729 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
730 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
731 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
733 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
734 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
736 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
740 // now brush is a bitmap
741 float alphaArray
[1] = { 1.0 } ;
742 wxBitmap
* bmp
= brush
.GetStipple() ;
743 if ( bmp
&& bmp
->Ok() )
745 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
746 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
747 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
748 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
752 m_mode
= kCGPathFill
;
755 if ( fill
&& stroke
)
756 m_mode
= kCGPathFillStroke
;
758 m_mode
= kCGPathStroke
;
762 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
764 CGContextSaveGState(c
);
765 CGContextTranslateCTM(c
, center
.x
, center
.y
);
766 CGContextScaleCTM(c
, a
, b
);
767 CGContextMoveToPoint(c
, 1, 0);
768 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
769 CGContextClosePath(c
);
770 CGContextRestoreGState(c
);
773 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
777 if (ovalWidth
== 0 || ovalHeight
== 0)
779 CGContextAddRect(c
, rect
);
783 CGContextSaveGState(c
);
784 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
785 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
787 fw
= CGRectGetWidth(rect
) / ovalWidth
;
788 fh
= CGRectGetHeight(rect
) / ovalHeight
;
790 CGContextMoveToPoint(c
, fw
, fh
/ 2);
791 CGContextAddArcToPoint(c
, fw
, fh
, fw
/ 2, fh
, 1);
792 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/ 2, 1);
793 CGContextAddArcToPoint(c
, 0, 0, fw
/ 2, 0, 1);
794 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/ 2, 1);
795 CGContextClosePath(c
);
796 CGContextRestoreGState(c
);
805 m_mm_to_pix_x
= mm2pt
;
806 m_mm_to_pix_y
= mm2pt
;
808 m_externalDeviceOriginX
= 0;
809 m_externalDeviceOriginY
= 0;
810 m_logicalScaleX
= 1.0;
811 m_logicalScaleY
= 1.0;
816 m_needComputeScaleX
=
817 m_needComputeScaleY
= false;
821 m_macLocalOrigin
.y
= 0 ;
823 m_pen
= *wxBLACK_PEN
;
824 m_font
= *wxNORMAL_FONT
;
825 m_brush
= *wxWHITE_BRUSH
;
827 m_macATSUIStyle
= NULL
;
828 m_graphicContext
= NULL
;
833 if ( m_macATSUIStyle
)
835 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
836 m_macATSUIStyle
= NULL
;
839 delete m_graphicContext
;
842 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
844 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
845 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
847 wxCoord xx
= XLOG2DEVMAC(x
);
848 wxCoord yy
= YLOG2DEVMAC(y
);
849 wxCoord w
= bmp
.GetWidth();
850 wxCoord h
= bmp
.GetHeight();
851 wxCoord ww
= XLOG2DEVREL(w
);
852 wxCoord hh
= YLOG2DEVREL(h
);
854 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
855 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
856 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
857 HIViewDrawCGImage( cg
, &r
, image
) ;
858 CGImageRelease( image
) ;
861 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
863 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
864 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
866 wxCoord xx
= XLOG2DEVMAC(x
);
867 wxCoord yy
= YLOG2DEVMAC(y
);
868 wxCoord w
= icon
.GetWidth();
869 wxCoord h
= icon
.GetHeight();
870 wxCoord ww
= XLOG2DEVREL(w
);
871 wxCoord hh
= YLOG2DEVREL(h
);
873 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
874 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
875 CGContextSaveGState( cg
);
876 CGContextTranslateCTM( cg
, xx
, yy
+ hh
);
877 CGContextScaleCTM( cg
, 1, -1 );
878 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
879 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
880 CGContextRestoreGState( cg
) ;
883 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
885 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
887 wxCoord xx
, yy
, ww
, hh
;
890 ww
= XLOG2DEVREL(width
);
891 hh
= YLOG2DEVREL(height
);
893 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
894 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
895 CGContextClipToRect( cgContext
, clipRect
) ;
897 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
898 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
902 m_clipX1
= wxMax( m_clipX1
, xx
);
903 m_clipY1
= wxMax( m_clipY1
, yy
);
904 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
905 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
917 // TODO: as soon as we don't reset the context for each operation anymore
918 // we have to update the context as well
921 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
923 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
927 DestroyClippingRegion();
932 region
.GetBox( x
, y
, w
, h
);
933 wxCoord xx
, yy
, ww
, hh
;
939 // if we have a scaling that we cannot map onto native regions
940 // we must use the box
941 if ( ww
!= w
|| hh
!= h
)
943 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
948 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
949 if ( xx
!= x
|| yy
!= y
)
950 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
951 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
956 m_clipX1
= wxMax( m_clipX1
, xx
);
957 m_clipY1
= wxMax( m_clipY1
, yy
);
958 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
959 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
973 void wxDC::DestroyClippingRegion()
975 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
977 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
978 CGContextRestoreGState( cgContext
);
979 CGContextSaveGState( cgContext
);
981 m_graphicContext
->SetPen( m_pen
) ;
982 m_graphicContext
->SetBrush( m_brush
) ;
987 void wxDC::DoGetSizeMM( int* width
, int* height
) const
993 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
995 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
998 void wxDC::SetTextForeground( const wxColour
&col
)
1000 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1002 if ( col
!= m_textForegroundColour
)
1004 m_textForegroundColour
= col
;
1009 void wxDC::SetTextBackground( const wxColour
&col
)
1011 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1013 m_textBackgroundColour
= col
;
1016 void wxDC::SetMapMode( int mode
)
1021 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1025 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1029 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1033 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1038 SetLogicalScale( 1.0, 1.0 );
1042 if (mode
!= wxMM_TEXT
)
1044 m_needComputeScaleX
=
1045 m_needComputeScaleY
= true;
1049 void wxDC::SetUserScale( double x
, double y
)
1051 // allow negative ? -> no
1054 ComputeScaleAndOrigin();
1057 void wxDC::SetLogicalScale( double x
, double y
)
1060 m_logicalScaleX
= x
;
1061 m_logicalScaleY
= y
;
1062 ComputeScaleAndOrigin();
1065 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1067 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1068 m_logicalOriginY
= y
* m_signY
;
1069 ComputeScaleAndOrigin();
1072 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1074 m_externalDeviceOriginX
= x
;
1075 m_externalDeviceOriginY
= y
;
1076 ComputeScaleAndOrigin();
1079 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1081 m_signX
= (xLeftRight
? 1 : -1);
1082 m_signY
= (yBottomUp
? -1 : 1);
1083 ComputeScaleAndOrigin();
1086 wxSize
wxDC::GetPPI() const
1088 return wxSize(72, 72);
1091 int wxDC::GetDepth() const
1096 void wxDC::ComputeScaleAndOrigin()
1098 // CMB: copy scale to see if it changes
1099 double origScaleX
= m_scaleX
;
1100 double origScaleY
= m_scaleY
;
1101 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1102 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1103 m_deviceOriginX
= m_externalDeviceOriginX
;
1104 m_deviceOriginY
= m_externalDeviceOriginY
;
1106 // CMB: if scale has changed call SetPen to recalulate the line width
1107 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1109 // this is a bit artificial, but we need to force wxDC to think
1110 // the pen has changed
1111 wxPen
pen( GetPen() );
1118 void wxDC::SetPalette( const wxPalette
& palette
)
1122 void wxDC::SetBackgroundMode( int mode
)
1124 m_backgroundMode
= mode
;
1127 void wxDC::SetFont( const wxFont
&font
)
1133 void wxDC::SetPen( const wxPen
&pen
)
1139 if ( m_graphicContext
)
1141 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1143 m_graphicContext
->SetPen( m_pen
) ;
1147 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1148 // eg when using a wxScrollWindow and scrolling around
1149 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1150 int origX
= XLOG2DEVMAC(0) ;
1151 int origY
= YLOG2DEVMAC(0) ;
1152 CGContextTranslateCTM( cgContext
, origX
, origY
);
1153 m_graphicContext
->SetPen( m_pen
) ;
1154 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1159 void wxDC::SetBrush( const wxBrush
&brush
)
1161 if (m_brush
== brush
)
1165 if ( m_graphicContext
)
1167 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1169 m_graphicContext
->SetBrush( m_brush
) ;
1173 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1174 // eg when using a wxScrollWindow and scrolling around
1175 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1176 int origX
= XLOG2DEVMAC(0) ;
1177 int origY
= YLOG2DEVMAC(0) ;
1178 CGContextTranslateCTM( cgContext
, origX
, origY
);
1179 m_graphicContext
->SetBrush( m_brush
) ;
1180 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1185 void wxDC::SetBackground( const wxBrush
&brush
)
1187 if (m_backgroundBrush
== brush
)
1190 m_backgroundBrush
= brush
;
1191 if (!m_backgroundBrush
.Ok())
1195 void wxDC::SetLogicalFunction( int function
)
1197 if (m_logicalFunction
== function
)
1200 m_logicalFunction
= function
;
1201 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1202 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1203 if ( m_logicalFunction
== wxCOPY
)
1204 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1205 else if ( m_logicalFunction
== wxINVERT
)
1206 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1208 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1212 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1213 const wxColour
& col
, int style
);
1215 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1216 const wxColour
& col
, int style
)
1218 return wxDoFloodFill(this, x
, y
, col
, style
);
1221 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1223 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1225 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1228 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1230 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1231 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1233 // convert from Mac colour to wx
1234 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1239 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1241 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1243 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1244 if ( m_logicalFunction
!= wxCOPY
)
1248 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1249 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1250 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1251 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1253 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1254 path
->MoveToPoint( xx1
, yy1
) ;
1255 path
->AddLineToPoint( xx2
, yy2
) ;
1256 path
->CloseSubpath() ;
1257 m_graphicContext
->StrokePath( path
) ;
1260 CalcBoundingBox(x1
, y1
);
1261 CalcBoundingBox(x2
, y2
);
1264 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1266 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1268 if ( m_logicalFunction
!= wxCOPY
)
1274 wxCoord xx
= XLOG2DEVMAC(x
);
1275 wxCoord yy
= YLOG2DEVMAC(y
);
1277 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1278 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1279 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1280 path
->CloseSubpath() ;
1281 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1282 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1283 path
->CloseSubpath() ;
1284 m_graphicContext
->StrokePath( path
) ;
1287 CalcBoundingBox(x
, y
);
1288 CalcBoundingBox(x
+ w
, y
+ h
);
1291 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1292 wxCoord x2
, wxCoord y2
,
1293 wxCoord xc
, wxCoord yc
)
1295 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1297 if ( m_logicalFunction
!= wxCOPY
)
1300 wxCoord xx1
= XLOG2DEVMAC(x1
);
1301 wxCoord yy1
= YLOG2DEVMAC(y1
);
1302 wxCoord xx2
= XLOG2DEVMAC(x2
);
1303 wxCoord yy2
= YLOG2DEVMAC(y2
);
1304 wxCoord xxc
= XLOG2DEVMAC(xc
);
1305 wxCoord yyc
= YLOG2DEVMAC(yc
);
1307 double dx
= xx1
- xxc
;
1308 double dy
= yy1
- yyc
;
1309 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1310 wxCoord rad
= (wxCoord
)radius
;
1312 if (xx1
== xx2
&& yy1
== yy2
)
1317 else if (radius
== 0.0)
1323 sa
= (xx1
- xxc
== 0) ?
1324 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1325 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1326 ea
= (xx2
- xxc
== 0) ?
1327 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1328 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1331 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1332 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1333 CGContextRef ctx
= mctx
->GetNativeContext() ;
1334 CGContextSaveGState( ctx
) ;
1335 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1336 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1338 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1339 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0 );
1341 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1342 CGContextRestoreGState( ctx
) ;
1343 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1346 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1347 double sa
, double ea
)
1349 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1351 if ( m_logicalFunction
!= wxCOPY
)
1354 wxCoord xx
= XLOG2DEVMAC(x
);
1355 wxCoord yy
= YLOG2DEVMAC(y
);
1356 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1357 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1359 // handle -ve width and/or height
1371 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1373 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1374 CGContextRef ctx
= mctx
->GetNativeContext() ;
1376 CGContextSaveGState( ctx
) ;
1377 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1378 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1380 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1381 CGContextAddArc( ctx
, 0, 0, 1, DegToRad(sa
), DegToRad(ea
), 0 );
1383 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1384 CGContextRestoreGState( ctx
) ;
1385 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1388 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1390 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1392 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1395 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1396 wxCoord xoffset
, wxCoord yoffset
)
1398 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1400 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1401 if ( m_logicalFunction
!= wxCOPY
)
1405 wxCoord x1
, x2
, y1
, y2
;
1406 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1407 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1408 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1409 path
->MoveToPoint( x1
, y1
) ;
1410 for (int i
= 1; i
< n
; i
++)
1412 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1413 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1415 path
->AddLineToPoint( x2
, y2
) ;
1418 m_graphicContext
->StrokePath( path
) ;
1423 void wxDC::DoDrawSpline(wxList
*points
)
1425 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1427 if ( m_logicalFunction
!= wxCOPY
)
1430 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1432 wxList::compatibility_iterator node
= points
->GetFirst();
1433 if (node
== wxList::compatibility_iterator())
1437 wxPoint
*p
= (wxPoint
*)node
->GetData();
1442 node
= node
->GetNext();
1443 p
= (wxPoint
*)node
->GetData();
1447 wxCoord cx1
= ( x1
+ x2
) / 2;
1448 wxCoord cy1
= ( y1
+ y2
) / 2;
1450 path
->MoveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ) ;
1451 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , XLOG2DEVMAC( cy1
) ) ;
1454 while ((node
= node
->GetNext()) != NULL
)
1456 while ((node
= node
->GetNext()))
1457 #endif // !wxUSE_STL
1459 p
= (wxPoint
*)node
->GetData();
1464 wxCoord cx4
= (x1
+ x2
) / 2;
1465 wxCoord cy4
= (y1
+ y2
) / 2;
1467 path
->AddQuadCurveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ,
1468 XLOG2DEVMAC( cx4
) , XLOG2DEVMAC( cy4
) ) ;
1474 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , XLOG2DEVMAC( y2
) ) ;
1476 m_graphicContext
->StrokePath( path
) ;
1481 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1482 wxCoord xoffset
, wxCoord yoffset
,
1485 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1487 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1489 if ( m_logicalFunction
!= wxCOPY
)
1492 wxCoord x1
, x2
, y1
, y2
;
1493 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1494 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1496 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1497 path
->MoveToPoint( x1
, y1
) ;
1498 for (int i
= 1; i
< n
; i
++)
1500 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1501 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1503 path
->AddLineToPoint( x2
, y2
) ;
1506 if ( x1
!= x2
|| y1
!= y2
)
1507 path
->AddLineToPoint( x1
, y1
) ;
1509 path
->CloseSubpath() ;
1510 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1515 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1517 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1519 if ( m_logicalFunction
!= wxCOPY
)
1522 wxCoord xx
= XLOG2DEVMAC(x
);
1523 wxCoord yy
= YLOG2DEVMAC(y
);
1524 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1525 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1527 // CMB: draw nothing if transformed w or h is 0
1528 if (ww
== 0 || hh
== 0)
1531 // CMB: handle -ve width and/or height
1543 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1544 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1545 m_graphicContext
->DrawPath( path
) ;
1549 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1550 wxCoord width
, wxCoord height
,
1553 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1555 if ( m_logicalFunction
!= wxCOPY
)
1559 radius
= - radius
* ((width
< height
) ? width
: height
);
1560 wxCoord xx
= XLOG2DEVMAC(x
);
1561 wxCoord yy
= YLOG2DEVMAC(y
);
1562 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1563 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1565 // CMB: draw nothing if transformed w or h is 0
1566 if (ww
== 0 || hh
== 0)
1569 // CMB: handle -ve width and/or height
1581 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1582 CGContextRef ctx
= mctx
->GetNativeContext() ;
1583 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , 16 ,16 ) ;
1584 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1587 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1589 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1591 if ( m_logicalFunction
!= wxCOPY
)
1594 wxCoord xx
= XLOG2DEVMAC(x
);
1595 wxCoord yy
= YLOG2DEVMAC(y
);
1596 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1597 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1598 // CMB: draw nothing if transformed w or h is 0
1599 if (ww
== 0 || hh
== 0)
1602 // CMB: handle -ve width and/or height
1614 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1615 CGContextRef ctx
= mctx
->GetNativeContext() ;
1616 CGContextSaveGState( ctx
) ;
1617 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1618 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1619 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2 * M_PI
, 0 );
1620 CGContextRestoreGState( ctx
) ;
1621 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1624 bool wxDC::CanDrawBitmap(void) const
1629 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1630 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1631 wxCoord xsrcMask
, wxCoord ysrcMask
)
1633 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
1634 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
1636 if ( logical_func
== wxNO_OP
)
1639 if (xsrcMask
== -1 && ysrcMask
== -1)
1645 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1646 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1647 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1648 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1650 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1651 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1652 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1653 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1655 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1656 if ( memdc
&& logical_func
== wxCOPY
)
1658 wxBitmap blit
= memdc
->GetSelectedObject() ;
1660 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1662 wxCoord bmpwidth
= blit
.GetWidth();
1663 wxCoord bmpheight
= blit
.GetHeight();
1665 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1667 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1668 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1669 if ( wwsrc
> 0 && hhsrc
> 0 )
1671 if ( xxsrc
>= 0 && yysrc
>= 0 )
1673 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1674 blit
= blit
.GetSubBitmap( subrect
) ;
1678 // in this case we'd probably have to adjust the different coordinates, but
1679 // we have to find out proper contract first
1680 blit
= wxNullBitmap
;
1685 blit
= wxNullBitmap
;
1691 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1692 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1693 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1694 HIViewDrawCGImage( cg
, &r
, image
) ;
1695 CGImageRelease( image
) ;
1701 CGContextRef cg
= (wxMacCGContext
*)(source
->GetGraphicContext())->GetNativeContext() ;
1702 void *data
= CGBitmapContextGetData( cg
) ;
1705 return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1711 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1714 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
1715 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
1717 if ( str
.Length() == 0 )
1719 if ( m_logicalFunction
!= wxCOPY
)
1722 OSStatus status
= noErr
;
1723 ATSUTextLayout atsuLayout
;
1724 UniCharCount chars
= str
.Length() ;
1725 UniChar
* ubuf
= NULL
;
1727 #if SIZEOF_WCHAR_T == 4
1728 wxMBConvUTF16 converter
;
1730 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1731 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1732 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1734 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1735 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1736 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1737 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1739 chars
= unicharlen
/ 2 ;
1742 ubuf
= (UniChar
*) str
.wc_str() ;
1744 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1745 chars
= wxWcslen( wchar
.data() ) ;
1746 ubuf
= (UniChar
*) wchar
.data() ;
1750 int drawX
= XLOG2DEVMAC(x
) ;
1751 int drawY
= YLOG2DEVMAC(y
) ;
1753 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1754 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1756 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1758 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1759 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1761 int iAngle
= int( angle
);
1762 if ( abs(iAngle
) > 0 )
1764 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1765 ATSUAttributeTag atsuTags
[] =
1767 kATSULineRotationTag
,
1769 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1773 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1777 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1778 atsuTags
, atsuSizes
, atsuValues
) ;
1782 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1783 ATSUAttributeTag atsuTags
[] =
1787 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1789 sizeof( CGContextRef
) ,
1791 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1795 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1796 atsuTags
, atsuSizes
, atsuValues
) ;
1799 ATSUTextMeasurement textBefore
, textAfter
;
1800 ATSUTextMeasurement ascent
, descent
;
1802 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1803 &textBefore
, &textAfter
, &ascent
, &descent
);
1805 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1809 if ( m_backgroundMode
== wxSOLID
)
1811 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1815 path
->AddLineToPoint(
1816 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1817 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1818 path
->AddLineToPoint(
1819 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1820 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1821 path
->AddLineToPoint(
1822 (int) (drawX
+ cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1823 (int) (drawY
- sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1825 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1829 drawX
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1830 drawY
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1832 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1833 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1834 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1836 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1837 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1838 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1839 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1840 IntToFixed(0) , IntToFixed(0) );
1842 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1844 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1846 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1847 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1849 ::ATSUDisposeTextLayout(atsuLayout
);
1851 #if SIZEOF_WCHAR_T == 4
1856 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1858 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
1860 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1863 bool wxDC::CanGetTextExtent() const
1865 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
1870 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1871 wxCoord
*descent
, wxCoord
*externalLeading
,
1872 wxFont
*theFont
) const
1874 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
1876 wxFont formerFont
= m_font
;
1879 // work around the const-ness
1880 *((wxFont
*)(&m_font
)) = *theFont
;
1884 if ( str
.Length() == 0 )
1887 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1889 OSStatus status
= noErr
;
1890 ATSUTextLayout atsuLayout
;
1891 UniCharCount chars
= str
.Length() ;
1892 UniChar
* ubuf
= NULL
;
1894 #if SIZEOF_WCHAR_T == 4
1895 wxMBConvUTF16 converter
;
1897 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1898 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1899 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1901 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1902 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1903 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1904 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1906 chars
= unicharlen
/ 2 ;
1909 ubuf
= (UniChar
*) str
.wc_str() ;
1911 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1912 chars
= wxWcslen( wchar
.data() ) ;
1913 ubuf
= (UniChar
*) wchar
.data() ;
1917 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1918 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1920 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1922 ATSUTextMeasurement textBefore
, textAfter
;
1923 ATSUTextMeasurement textAscent
, textDescent
;
1925 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1926 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1929 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1931 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1932 if ( externalLeading
)
1933 *externalLeading
= 0 ;
1935 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1937 ::ATSUDisposeTextLayout(atsuLayout
);
1939 #if SIZEOF_WCHAR_T == 4
1945 // work around the constness
1946 *((wxFont
*)(&m_font
)) = formerFont
;
1951 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1953 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
1956 widths
.Add(0, text
.Length());
1958 if (text
.Length() == 0)
1961 ATSUTextLayout atsuLayout
;
1962 UniCharCount chars
= text
.Length() ;
1963 UniChar
* ubuf
= NULL
;
1965 #if SIZEOF_WCHAR_T == 4
1966 wxMBConvUTF16 converter
;
1968 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1969 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1970 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1972 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1973 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1974 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1975 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1977 chars
= unicharlen
/ 2 ;
1980 ubuf
= (UniChar
*) text
.wc_str() ;
1982 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1983 chars
= wxWcslen( wchar
.data() ) ;
1984 ubuf
= (UniChar
*) wchar
.data() ;
1989 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1990 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1992 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1994 unsigned long actualNumberOfBounds
= 0;
1995 ATSTrapezoid glyphBounds
;
1997 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1999 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2000 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2001 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2004 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
2005 //unsigned char uch = s[i];
2008 ::ATSUDisposeTextLayout(atsuLayout
);
2012 wxCoord
wxDC::GetCharWidth(void) const
2015 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2020 wxCoord
wxDC::GetCharHeight(void) const
2023 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2028 void wxDC::Clear(void)
2030 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2032 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2034 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2035 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2036 switch ( m_backgroundBrush
.MacGetBrushKind() )
2038 case kwxMacBrushTheme
:
2040 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2041 if ( HIThemeSetFill
!= 0 )
2043 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2044 CGContextFillRect(cg
, rect
);
2051 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2052 CGContextSetRGBFillColor( cg
, (float) color
.red
/ 65536,
2053 (float) color
.green
/ 65536, (float) color
.blue
/ 65536, 1 );
2054 CGContextFillRect( cg
, rect
);
2057 // reset to normal value
2058 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2059 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2063 case kwxMacBrushThemeBackground
:
2065 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2067 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2068 if ( UMAGetSystemVersion() >= 0x1030 )
2070 HIThemeBackgroundDrawInfo drawInfo
;
2071 drawInfo
.version
= 0 ;
2072 drawInfo
.state
= kThemeStateActive
;
2073 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2074 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2076 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2077 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2084 case kwxMacBrushColour
:
2086 // FIXME: doesn't correctly render stippled brushes !!
2087 // FIXME: should this be replaced by ::SetBrush() ??
2089 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2090 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2091 CGContextFillRect(cg
, rect
);
2093 // reset to normal value
2094 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2095 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2100 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2106 void wxDC::MacInstallFont() const
2108 wxCHECK_RET( Ok(), wxT("wxDC(cg)::MacInstallFont - invalid DC") );
2110 if ( m_macATSUIStyle
)
2112 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2113 m_macATSUIStyle
= NULL
;
2120 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2122 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
2124 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2125 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2126 ATSUAttributeTag atsuTags
[] =
2131 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2134 sizeof( RGBColor
) ,
2136 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2142 status
= ::ATSUSetAttributes(
2143 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
2144 atsuTags
, atsuSizes
, atsuValues
);
2146 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
2152 // ---------------------------------------------------------------------------
2153 // coordinates transformations
2154 // ---------------------------------------------------------------------------
2156 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2158 return ((wxDC
*)this)->XDEV2LOG(x
);
2161 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2163 return ((wxDC
*)this)->YDEV2LOG(y
);
2166 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2168 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2171 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2173 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2176 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2178 return ((wxDC
*)this)->XLOG2DEV(x
);
2181 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2183 return ((wxDC
*)this)->YLOG2DEV(y
);
2186 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2188 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2191 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2193 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2196 #endif // wxMAC_USE_CORE_GRAPHICS