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
) ;
80 // get area including focus rect
81 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
82 if ( !EmptyRgn( m_newClip
) )
83 OffsetRgn( m_newClip
, x
, y
) ;
86 SetClip( m_newClip
) ;
90 wxMacWindowClipper::~wxMacWindowClipper()
92 SetPort( m_newPort
) ;
93 SetClip( m_formerClip
) ;
94 DisposeRgn( m_newClip
) ;
95 DisposeRgn( m_formerClip
) ;
98 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
99 wxMacWindowClipper( win
)
101 // the port is already set at this point
102 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
103 GetThemeDrawingState( &m_themeDrawingState
) ;
106 wxMacWindowStateSaver::~wxMacWindowStateSaver()
108 SetPort( m_newPort
) ;
109 SetThemeDrawingState( m_themeDrawingState
, true ) ;
112 // minimal implementation only used for appearance drawing < 10.3
114 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
115 m_ph( (GrafPtr
) dc
->m_macPort
)
117 wxASSERT( dc
->Ok() ) ;
120 // dc->MacSetupPort(&m_ph) ;
123 wxMacPortSetter::~wxMacPortSetter()
125 // m_dc->MacCleanupPort(&m_ph) ;
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
132 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
133 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
134 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
136 //-----------------------------------------------------------------------------
137 // device context implementation
139 // more and more of the dc functionality should be implemented by calling
140 // the appropricate wxMacCGContext, but we will have to do that step by step
141 // also coordinate conversions should be moved to native matrix ops
142 //-----------------------------------------------------------------------------
144 // we always stock two context states, one at entry, to be able to preserve the
145 // state we were called with, the other one after changing to HI Graphics orientation
146 // (this one is used for getting back clippings etc)
148 wxMacCGPath::wxMacCGPath()
150 m_path
= CGPathCreateMutable() ;
153 wxMacCGPath::~wxMacCGPath()
155 CGPathRelease( m_path
) ;
158 // opens (starts) a new subpath
159 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
161 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
164 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
166 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
169 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
171 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
174 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
176 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
177 CGPathAddRect( m_path
, NULL
, cgRect
) ;
180 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
182 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
185 // closes the current subpath
186 void wxMacCGPath::CloseSubpath()
188 CGPathCloseSubpath( m_path
) ;
191 CGPathRef
wxMacCGPath::GetPath() const
196 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
202 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
205 m_cgContext
= cgcontext
;
206 CGContextSaveGState( m_cgContext
) ;
207 CGContextSaveGState( m_cgContext
) ;
210 wxMacCGContext::wxMacCGContext()
216 wxMacCGContext::~wxMacCGContext()
220 CGContextSynchronize( m_cgContext
) ;
221 CGContextRestoreGState( m_cgContext
) ;
222 CGContextRestoreGState( m_cgContext
) ;
226 CGContextRelease( m_cgContext
) ;
230 void wxMacCGContext::Clip( const wxRegion
®ion
)
232 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
235 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
237 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
238 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
239 CGContextStrokePath( m_cgContext
) ;
242 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
244 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
245 CGPathDrawingMode mode
= m_mode
;
247 if ( fillStyle
== wxODDEVEN_RULE
)
249 if ( mode
== kCGPathFill
)
250 mode
= kCGPathEOFill
;
251 else if ( mode
== kCGPathFillStroke
)
252 mode
= kCGPathEOFillStroke
;
255 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
256 CGContextDrawPath( m_cgContext
, mode
) ;
259 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
261 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
262 CGContextSaveGState( m_cgContext
) ;
264 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
265 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
266 CGPathDrawingMode mode
= kCGPathFill
;
268 if ( fillStyle
== wxODDEVEN_RULE
)
269 mode
= kCGPathEOFill
;
271 CGContextBeginPath( m_cgContext
) ;
272 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
273 CGContextClosePath( m_cgContext
) ;
274 CGContextDrawPath( m_cgContext
, mode
) ;
276 CGContextRestoreGState( m_cgContext
) ;
279 wxGraphicPath
* wxMacCGContext::CreatePath()
281 // make sure that we now have a real cgref, before doing
282 // anything with paths
283 CGContextRef cg
= GetNativeContext() ;
286 return new wxMacCGPath() ;
289 // in case we only got a QDPort only create a cgref now
291 CGContextRef
wxMacCGContext::GetNativeContext()
293 if ( m_cgContext
== NULL
)
296 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
297 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
298 CGContextSaveGState( m_cgContext
) ;
300 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
302 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
303 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
305 CGContextSaveGState( m_cgContext
) ;
307 SetBrush( m_brush
) ;
313 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
315 // we allow either setting or clearing but not replacing
316 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
319 CGContextSaveGState( cg
) ;
324 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
326 // CGPattern wrapper class: always allocate on heap, never call destructor
333 // is guaranteed to be called only with a non-Null CGContextRef
334 virtual void Render( CGContextRef ctxRef
) = 0 ;
336 operator CGPatternRef() const { return m_patternRef
; }
339 virtual ~wxMacCGPattern()
341 // as this is called only when the m_patternRef is been released;
342 // don't release it again
345 static void _Render( void *info
, CGContextRef ctxRef
)
347 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
348 if ( self
&& ctxRef
)
349 self
->Render( ctxRef
) ;
352 static void _Dispose( void *info
)
354 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
358 CGPatternRef m_patternRef
;
360 static const CGPatternCallbacks ms_Callbacks
;
363 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
365 class ImagePattern
: public wxMacCGPattern
368 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
370 wxASSERT( bmp
&& bmp
->Ok() ) ;
372 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
375 // ImagePattern takes ownership of CGImageRef passed in
376 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
381 Init( image
, transform
) ;
384 virtual void Render( CGContextRef ctxRef
)
387 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
391 void Init( CGImageRef image
, CGAffineTransform transform
)
396 m_imageBounds
= CGRectMake( 0.0, 0.0, (float)CGImageGetWidth( m_image
), (float)CGImageGetHeight( m_image
) ) ;
397 m_patternRef
= CGPatternCreate(
398 this , m_imageBounds
, transform
,
399 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
400 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
407 CGImageRelease( m_image
) ;
411 CGRect m_imageBounds
;
414 class HatchPattern
: public wxMacCGPattern
417 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
419 m_hatch
= hatchstyle
;
420 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
421 m_patternRef
= CGPatternCreate(
422 this , m_imageBounds
, transform
,
423 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
424 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
427 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
429 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
430 if ( UMAGetSystemVersion() >= 0x1040 )
432 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
437 CGContextBeginPath( ctxRef
);
438 for (size_t i
= 0; i
< count
; i
+= 2)
440 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
441 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
443 CGContextStrokePath(ctxRef
);
447 virtual void Render( CGContextRef ctxRef
)
451 case wxBDIAGONAL_HATCH
:
455 { 8.0 , 0.0 } , { 0.0 , 8.0 }
457 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
461 case wxCROSSDIAG_HATCH
:
465 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
466 { 8.0 , 0.0 } , { 0.0 , 8.0 }
468 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
472 case wxFDIAGONAL_HATCH
:
476 { 0.0 , 0.0 } , { 8.0 , 8.0 }
478 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
486 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
487 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
489 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
493 case wxHORIZONTAL_HATCH
:
497 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
499 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
503 case wxVERTICAL_HATCH
:
507 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
509 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
521 CGRect m_imageBounds
;
527 void wxMacCGContext::SetPen( const wxPen
&pen
)
530 if ( m_cgContext
== NULL
)
533 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
534 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
537 // we can benchmark performance; should go into a setting eventually
538 CGContextSetShouldAntialias( m_cgContext
, false ) ;
544 m_mode
= kCGPathFill
; // just a default
548 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
549 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
551 // TODO: * m_dc->m_scaleX
552 float penWidth
= pen
.GetWidth();
555 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
558 switch ( pen
.GetCap() )
561 cap
= kCGLineCapRound
;
564 case wxCAP_PROJECTING
:
565 cap
= kCGLineCapSquare
;
569 cap
= kCGLineCapButt
;
573 cap
= kCGLineCapButt
;
578 switch ( pen
.GetJoin() )
581 join
= kCGLineJoinBevel
;
585 join
= kCGLineJoinMiter
;
589 join
= kCGLineJoinRound
;
593 join
= kCGLineJoinMiter
;
597 m_mode
= kCGPathStroke
;
600 const float *lengths
= NULL
;
601 float *userLengths
= NULL
;
603 const float dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
605 const float dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
606 const float short_dashed
[] = { 9.0 , 6.0 };
607 const float dashed
[] = { 19.0 , 9.0 };
608 const float dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
610 switch ( pen
.GetStyle() )
617 count
= WXSIZEOF(dotted
);
622 count
= WXSIZEOF(dashed
) ;
626 lengths
= short_dashed
;
627 count
= WXSIZEOF(short_dashed
) ;
631 lengths
= dotted_dashed
;
632 count
= WXSIZEOF(dotted_dashed
);
637 count
= pen
.GetDashes( &dashes
) ;
638 if ((dashes
!= NULL
) && (count
> 0))
640 userLengths
= new float[count
] ;
641 for ( int i
= 0 ; i
< count
; ++i
)
643 userLengths
[i
] = dashes
[i
] * dashUnit
;
645 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
646 userLengths
[i
] = dashUnit
+ 2.0 ;
647 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
648 userLengths
[i
] = dashUnit
;
651 lengths
= userLengths
;
656 float alphaArray
[1] = { 1.0 } ;
657 wxBitmap
* bmp
= pen
.GetStipple() ;
658 if ( bmp
&& bmp
->Ok() )
660 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
661 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
662 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
663 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
670 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
671 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
672 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
674 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
675 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
677 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
682 if ((lengths
!= NULL
) && (count
> 0))
684 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
685 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
686 cap
= kCGLineCapButt
;
690 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
693 CGContextSetLineCap( m_cgContext
, cap
) ;
694 CGContextSetLineJoin( m_cgContext
, join
) ;
696 delete[] userLengths
;
699 if ( fill
&& stroke
)
700 m_mode
= kCGPathFillStroke
;
704 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
707 if ( m_cgContext
== NULL
)
710 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
711 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
714 // we can benchmark performance, should go into a setting later
715 CGContextSetShouldAntialias( m_cgContext
, false ) ;
721 m_mode
= kCGPathFill
; // just a default
725 if ( brush
.GetStyle() == wxSOLID
)
727 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
728 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
730 else if ( brush
.IsHatch() )
732 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
733 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
734 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
736 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
737 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
739 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
743 // now brush is a bitmap
744 float alphaArray
[1] = { 1.0 } ;
745 wxBitmap
* bmp
= brush
.GetStipple() ;
746 if ( bmp
&& bmp
->Ok() )
748 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
749 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
750 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
751 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
755 m_mode
= kCGPathFill
;
758 if ( fill
&& stroke
)
759 m_mode
= kCGPathFillStroke
;
761 m_mode
= kCGPathStroke
;
765 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
767 CGContextSaveGState(c
);
768 CGContextTranslateCTM(c
, center
.x
, center
.y
);
769 CGContextScaleCTM(c
, a
, b
);
770 CGContextMoveToPoint(c
, 1, 0);
771 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
772 CGContextClosePath(c
);
773 CGContextRestoreGState(c
);
776 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
780 if (ovalWidth
== 0 || ovalHeight
== 0)
782 CGContextAddRect(c
, rect
);
786 CGContextSaveGState(c
);
787 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
788 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
790 fw
= CGRectGetWidth(rect
) / ovalWidth
;
791 fh
= CGRectGetHeight(rect
) / ovalHeight
;
793 CGContextMoveToPoint(c
, fw
, fh
/ 2);
794 CGContextAddArcToPoint(c
, fw
, fh
, fw
/ 2, fh
, 1);
795 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/ 2, 1);
796 CGContextAddArcToPoint(c
, 0, 0, fw
/ 2, 0, 1);
797 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/ 2, 1);
798 CGContextClosePath(c
);
799 CGContextRestoreGState(c
);
808 m_mm_to_pix_x
= mm2pt
;
809 m_mm_to_pix_y
= mm2pt
;
811 m_externalDeviceOriginX
= 0;
812 m_externalDeviceOriginY
= 0;
813 m_logicalScaleX
= 1.0;
814 m_logicalScaleY
= 1.0;
819 m_needComputeScaleX
=
820 m_needComputeScaleY
= false;
824 m_macLocalOrigin
.y
= 0 ;
826 m_pen
= *wxBLACK_PEN
;
827 m_font
= *wxNORMAL_FONT
;
828 m_brush
= *wxWHITE_BRUSH
;
830 m_macATSUIStyle
= NULL
;
831 m_graphicContext
= NULL
;
836 if ( m_macATSUIStyle
)
838 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
839 m_macATSUIStyle
= NULL
;
842 delete m_graphicContext
;
845 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
847 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
848 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
850 wxCoord xx
= XLOG2DEVMAC(x
);
851 wxCoord yy
= YLOG2DEVMAC(y
);
852 wxCoord w
= bmp
.GetWidth();
853 wxCoord h
= bmp
.GetHeight();
854 wxCoord ww
= XLOG2DEVREL(w
);
855 wxCoord hh
= YLOG2DEVREL(h
);
857 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
858 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
859 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
860 HIViewDrawCGImage( cg
, &r
, image
) ;
861 CGImageRelease( image
) ;
864 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
866 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
867 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
869 wxCoord xx
= XLOG2DEVMAC(x
);
870 wxCoord yy
= YLOG2DEVMAC(y
);
871 wxCoord w
= icon
.GetWidth();
872 wxCoord h
= icon
.GetHeight();
873 wxCoord ww
= XLOG2DEVREL(w
);
874 wxCoord hh
= YLOG2DEVREL(h
);
876 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
877 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
878 CGContextSaveGState( cg
);
879 CGContextTranslateCTM( cg
, xx
, yy
+ hh
);
880 CGContextScaleCTM( cg
, 1, -1 );
881 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
882 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
883 CGContextRestoreGState( cg
) ;
886 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
888 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
890 wxCoord xx
, yy
, ww
, hh
;
893 ww
= XLOG2DEVREL(width
);
894 hh
= YLOG2DEVREL(height
);
896 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
897 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
898 CGContextClipToRect( cgContext
, clipRect
) ;
900 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
901 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
905 m_clipX1
= wxMax( m_clipX1
, xx
);
906 m_clipY1
= wxMax( m_clipY1
, yy
);
907 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
908 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
920 // TODO: as soon as we don't reset the context for each operation anymore
921 // we have to update the context as well
924 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
926 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
930 DestroyClippingRegion();
935 region
.GetBox( x
, y
, w
, h
);
936 wxCoord xx
, yy
, ww
, hh
;
942 // if we have a scaling that we cannot map onto native regions
943 // we must use the box
944 if ( ww
!= w
|| hh
!= h
)
946 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
951 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
952 if ( xx
!= x
|| yy
!= y
)
953 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
954 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
959 m_clipX1
= wxMax( m_clipX1
, xx
);
960 m_clipY1
= wxMax( m_clipY1
, yy
);
961 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
962 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
976 void wxDC::DestroyClippingRegion()
978 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
980 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
981 CGContextRestoreGState( cgContext
);
982 CGContextSaveGState( cgContext
);
984 m_graphicContext
->SetPen( m_pen
) ;
985 m_graphicContext
->SetBrush( m_brush
) ;
990 void wxDC::DoGetSizeMM( int* width
, int* height
) const
996 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
998 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1001 void wxDC::SetTextForeground( const wxColour
&col
)
1003 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1005 if ( col
!= m_textForegroundColour
)
1007 m_textForegroundColour
= col
;
1012 void wxDC::SetTextBackground( const wxColour
&col
)
1014 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1016 m_textBackgroundColour
= col
;
1019 void wxDC::SetMapMode( int mode
)
1024 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1028 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1032 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1036 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1041 SetLogicalScale( 1.0, 1.0 );
1045 if (mode
!= wxMM_TEXT
)
1047 m_needComputeScaleX
=
1048 m_needComputeScaleY
= true;
1052 void wxDC::SetUserScale( double x
, double y
)
1054 // allow negative ? -> no
1057 ComputeScaleAndOrigin();
1060 void wxDC::SetLogicalScale( double x
, double y
)
1063 m_logicalScaleX
= x
;
1064 m_logicalScaleY
= y
;
1065 ComputeScaleAndOrigin();
1068 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1070 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1071 m_logicalOriginY
= y
* m_signY
;
1072 ComputeScaleAndOrigin();
1075 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1077 m_externalDeviceOriginX
= x
;
1078 m_externalDeviceOriginY
= y
;
1079 ComputeScaleAndOrigin();
1082 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1084 m_signX
= (xLeftRight
? 1 : -1);
1085 m_signY
= (yBottomUp
? -1 : 1);
1086 ComputeScaleAndOrigin();
1089 wxSize
wxDC::GetPPI() const
1091 return wxSize(72, 72);
1094 int wxDC::GetDepth() const
1099 void wxDC::ComputeScaleAndOrigin()
1101 // CMB: copy scale to see if it changes
1102 double origScaleX
= m_scaleX
;
1103 double origScaleY
= m_scaleY
;
1104 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1105 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1106 m_deviceOriginX
= m_externalDeviceOriginX
;
1107 m_deviceOriginY
= m_externalDeviceOriginY
;
1109 // CMB: if scale has changed call SetPen to recalulate the line width
1110 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1112 // this is a bit artificial, but we need to force wxDC to think
1113 // the pen has changed
1114 wxPen
pen( GetPen() );
1121 void wxDC::SetPalette( const wxPalette
& palette
)
1125 void wxDC::SetBackgroundMode( int mode
)
1127 m_backgroundMode
= mode
;
1130 void wxDC::SetFont( const wxFont
&font
)
1136 void wxDC::SetPen( const wxPen
&pen
)
1142 if ( m_graphicContext
)
1144 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1146 m_graphicContext
->SetPen( m_pen
) ;
1150 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1151 // eg when using a wxScrollWindow and scrolling around
1152 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1153 int origX
= XLOG2DEVMAC( 0 ) ;
1154 int origY
= YLOG2DEVMAC( 0 ) ;
1155 CGContextTranslateCTM( cgContext
, origX
, origY
);
1156 m_graphicContext
->SetPen( m_pen
) ;
1157 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1162 void wxDC::SetBrush( const wxBrush
&brush
)
1164 if (m_brush
== brush
)
1168 if ( m_graphicContext
)
1170 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1172 m_graphicContext
->SetBrush( m_brush
) ;
1176 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1177 // eg when using a wxScrollWindow and scrolling around
1178 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1179 int origX
= XLOG2DEVMAC(0) ;
1180 int origY
= YLOG2DEVMAC(0) ;
1181 CGContextTranslateCTM( cgContext
, origX
, origY
);
1182 m_graphicContext
->SetBrush( m_brush
) ;
1183 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1188 void wxDC::SetBackground( const wxBrush
&brush
)
1190 if (m_backgroundBrush
== brush
)
1193 m_backgroundBrush
= brush
;
1194 if (!m_backgroundBrush
.Ok())
1198 void wxDC::SetLogicalFunction( int function
)
1200 if (m_logicalFunction
== function
)
1203 m_logicalFunction
= function
;
1204 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1205 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1206 if ( m_logicalFunction
== wxCOPY
)
1207 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1208 else if ( m_logicalFunction
== wxINVERT
)
1209 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1211 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1215 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1216 const wxColour
& col
, int style
);
1218 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1219 const wxColour
& col
, int style
)
1221 return wxDoFloodFill(this, x
, y
, col
, style
);
1224 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1226 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1228 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1231 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1233 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1234 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1236 // convert from Mac colour to wx
1237 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1242 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1244 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1246 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1247 if ( m_logicalFunction
!= wxCOPY
)
1251 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1252 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1253 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1254 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1256 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1257 path
->MoveToPoint( xx1
, yy1
) ;
1258 path
->AddLineToPoint( xx2
, yy2
) ;
1259 path
->CloseSubpath() ;
1260 m_graphicContext
->StrokePath( path
) ;
1263 CalcBoundingBox(x1
, y1
);
1264 CalcBoundingBox(x2
, y2
);
1267 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1269 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1271 if ( m_logicalFunction
!= wxCOPY
)
1277 wxCoord xx
= XLOG2DEVMAC(x
);
1278 wxCoord yy
= YLOG2DEVMAC(y
);
1280 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1281 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1282 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1283 path
->CloseSubpath() ;
1284 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1285 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1286 path
->CloseSubpath() ;
1287 m_graphicContext
->StrokePath( path
) ;
1290 CalcBoundingBox(x
, y
);
1291 CalcBoundingBox(x
+ w
, y
+ h
);
1294 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1295 wxCoord x2
, wxCoord y2
,
1296 wxCoord xc
, wxCoord yc
)
1298 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1300 if ( m_logicalFunction
!= wxCOPY
)
1303 wxCoord xx1
= XLOG2DEVMAC(x1
);
1304 wxCoord yy1
= YLOG2DEVMAC(y1
);
1305 wxCoord xx2
= XLOG2DEVMAC(x2
);
1306 wxCoord yy2
= YLOG2DEVMAC(y2
);
1307 wxCoord xxc
= XLOG2DEVMAC(xc
);
1308 wxCoord yyc
= YLOG2DEVMAC(yc
);
1310 double dx
= xx1
- xxc
;
1311 double dy
= yy1
- yyc
;
1312 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1313 wxCoord rad
= (wxCoord
)radius
;
1315 if (xx1
== xx2
&& yy1
== yy2
)
1320 else if (radius
== 0.0)
1326 sa
= (xx1
- xxc
== 0) ?
1327 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1328 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1329 ea
= (xx2
- xxc
== 0) ?
1330 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1331 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1334 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1335 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1336 CGContextRef ctx
= mctx
->GetNativeContext() ;
1337 CGContextSaveGState( ctx
) ;
1338 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1339 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1341 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1342 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0 );
1344 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1345 CGContextRestoreGState( ctx
) ;
1346 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1349 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1350 double sa
, double ea
)
1352 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1354 if ( m_logicalFunction
!= wxCOPY
)
1357 wxCoord xx
= XLOG2DEVMAC(x
);
1358 wxCoord yy
= YLOG2DEVMAC(y
);
1359 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1360 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1362 // handle -ve width and/or height
1374 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1376 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1377 CGContextRef ctx
= mctx
->GetNativeContext() ;
1379 CGContextSaveGState( ctx
) ;
1380 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1381 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1383 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1384 CGContextAddArc( ctx
, 0, 0, 1, DegToRad( sa
), DegToRad( ea
), 0 );
1386 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1387 CGContextRestoreGState( ctx
) ;
1388 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1391 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1393 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1395 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1398 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1399 wxCoord xoffset
, wxCoord yoffset
)
1401 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1403 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1404 if ( m_logicalFunction
!= wxCOPY
)
1408 wxCoord x1
, x2
, y1
, y2
;
1409 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1410 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1411 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1412 path
->MoveToPoint( x1
, y1
) ;
1413 for (int i
= 1; i
< n
; i
++)
1415 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1416 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1418 path
->AddLineToPoint( x2
, y2
) ;
1421 m_graphicContext
->StrokePath( path
) ;
1426 void wxDC::DoDrawSpline(wxList
*points
)
1428 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1430 if ( m_logicalFunction
!= wxCOPY
)
1433 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1435 wxList::compatibility_iterator node
= points
->GetFirst();
1436 if (node
== wxList::compatibility_iterator())
1440 wxPoint
*p
= (wxPoint
*)node
->GetData();
1445 node
= node
->GetNext();
1446 p
= (wxPoint
*)node
->GetData();
1450 wxCoord cx1
= ( x1
+ x2
) / 2;
1451 wxCoord cy1
= ( y1
+ y2
) / 2;
1453 path
->MoveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ) ;
1454 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , XLOG2DEVMAC( cy1
) ) ;
1457 while ((node
= node
->GetNext()) != NULL
)
1459 while ((node
= node
->GetNext()))
1460 #endif // !wxUSE_STL
1462 p
= (wxPoint
*)node
->GetData();
1467 wxCoord cx4
= (x1
+ x2
) / 2;
1468 wxCoord cy4
= (y1
+ y2
) / 2;
1470 path
->AddQuadCurveToPoint(
1471 XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ,
1472 XLOG2DEVMAC( cx4
) , XLOG2DEVMAC( cy4
) ) ;
1478 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , XLOG2DEVMAC( y2
) ) ;
1480 m_graphicContext
->StrokePath( path
) ;
1485 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1486 wxCoord xoffset
, wxCoord yoffset
,
1489 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1491 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1493 if ( m_logicalFunction
!= wxCOPY
)
1496 wxCoord x1
, x2
, y1
, y2
;
1497 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1498 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1500 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1501 path
->MoveToPoint( x1
, y1
) ;
1502 for (int i
= 1; i
< n
; i
++)
1504 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1505 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1507 path
->AddLineToPoint( x2
, y2
) ;
1510 if ( x1
!= x2
|| y1
!= y2
)
1511 path
->AddLineToPoint( x1
, y1
) ;
1513 path
->CloseSubpath() ;
1514 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1519 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1521 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1523 if ( m_logicalFunction
!= wxCOPY
)
1526 wxCoord xx
= XLOG2DEVMAC(x
);
1527 wxCoord yy
= YLOG2DEVMAC(y
);
1528 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1529 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1531 // CMB: draw nothing if transformed w or h is 0
1532 if (ww
== 0 || hh
== 0)
1535 // CMB: handle -ve width and/or height
1547 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1548 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1549 m_graphicContext
->DrawPath( path
) ;
1553 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1554 wxCoord width
, wxCoord height
,
1557 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1559 if ( m_logicalFunction
!= wxCOPY
)
1563 radius
= - radius
* ((width
< height
) ? width
: height
);
1564 wxCoord xx
= XLOG2DEVMAC(x
);
1565 wxCoord yy
= YLOG2DEVMAC(y
);
1566 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1567 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1569 // CMB: draw nothing if transformed w or h is 0
1570 if (ww
== 0 || hh
== 0)
1573 // CMB: handle -ve width and/or height
1585 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1586 CGContextRef ctx
= mctx
->GetNativeContext() ;
1587 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , radius
, radius
) ;
1588 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1591 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1593 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1595 if ( m_logicalFunction
!= wxCOPY
)
1598 wxCoord xx
= XLOG2DEVMAC(x
);
1599 wxCoord yy
= YLOG2DEVMAC(y
);
1600 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1601 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1603 // CMB: draw nothing if transformed w or h is 0
1604 if (ww
== 0 || hh
== 0)
1607 // CMB: handle -ve width and/or height
1619 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1620 CGContextRef ctx
= mctx
->GetNativeContext() ;
1621 CGContextSaveGState( ctx
) ;
1622 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1623 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1624 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2 * M_PI
, 0 );
1625 CGContextRestoreGState( ctx
) ;
1626 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1629 bool wxDC::CanDrawBitmap() const
1635 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1636 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1637 wxCoord xsrcMask
, wxCoord ysrcMask
)
1639 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
1640 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
1642 if ( logical_func
== wxNO_OP
)
1645 if (xsrcMask
== -1 && ysrcMask
== -1)
1651 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1652 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1653 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1654 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1656 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1657 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1658 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1659 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1661 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1662 if ( memdc
&& logical_func
== wxCOPY
)
1664 wxBitmap blit
= memdc
->GetSelectedObject() ;
1666 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1668 wxCoord bmpwidth
= blit
.GetWidth();
1669 wxCoord bmpheight
= blit
.GetHeight();
1671 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1673 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1674 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1675 if ( wwsrc
> 0 && hhsrc
> 0 )
1677 if ( xxsrc
>= 0 && yysrc
>= 0 )
1679 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1680 blit
= blit
.GetSubBitmap( subrect
) ;
1684 // in this case we'd probably have to adjust the different coordinates, but
1685 // we have to find out proper contract first
1686 blit
= wxNullBitmap
;
1691 blit
= wxNullBitmap
;
1697 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1698 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1699 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1700 HIViewDrawCGImage( cg
, &r
, image
) ;
1701 CGImageRelease( image
) ;
1707 CGContextRef cg
= (wxMacCGContext
*)(source
->GetGraphicContext())->GetNativeContext() ;
1708 void *data
= CGBitmapContextGetData( cg
) ;
1711 return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1717 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1720 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
1721 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
1723 if ( str
.Length() == 0 )
1725 if ( m_logicalFunction
!= wxCOPY
)
1728 OSStatus status
= noErr
;
1729 ATSUTextLayout atsuLayout
;
1730 UniCharCount chars
= str
.Length() ;
1731 UniChar
* ubuf
= NULL
;
1733 #if SIZEOF_WCHAR_T == 4
1734 wxMBConvUTF16 converter
;
1736 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1737 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1738 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1740 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1741 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1742 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1743 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1745 chars
= unicharlen
/ 2 ;
1748 ubuf
= (UniChar
*) str
.wc_str() ;
1750 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1751 chars
= wxWcslen( wchar
.data() ) ;
1752 ubuf
= (UniChar
*) wchar
.data() ;
1756 int drawX
= XLOG2DEVMAC(x
) ;
1757 int drawY
= YLOG2DEVMAC(y
) ;
1759 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1760 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1762 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1764 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1765 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1767 int iAngle
= int( angle
);
1768 if ( abs(iAngle
) > 0 )
1770 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1771 ATSUAttributeTag atsuTags
[] =
1773 kATSULineRotationTag
,
1775 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1779 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1783 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1784 atsuTags
, atsuSizes
, atsuValues
) ;
1788 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1789 ATSUAttributeTag atsuTags
[] =
1793 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1795 sizeof( CGContextRef
) ,
1797 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1801 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1802 atsuTags
, atsuSizes
, atsuValues
) ;
1805 ATSUTextMeasurement textBefore
, textAfter
;
1806 ATSUTextMeasurement ascent
, descent
;
1808 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1809 &textBefore
, &textAfter
, &ascent
, &descent
);
1811 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1815 if ( m_backgroundMode
== wxSOLID
)
1817 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1818 path
->MoveToPoint( drawX
, drawY
) ;
1819 path
->AddLineToPoint(
1820 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1821 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1822 path
->AddLineToPoint(
1823 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1824 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1825 path
->AddLineToPoint(
1826 (int) (drawX
+ cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1827 (int) (drawY
- sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1829 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1833 drawX
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1834 drawY
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1836 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1837 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1838 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1840 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1841 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1842 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1843 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1844 IntToFixed(0) , IntToFixed(0) );
1846 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1848 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1850 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1851 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1853 ::ATSUDisposeTextLayout(atsuLayout
);
1855 #if SIZEOF_WCHAR_T == 4
1860 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1862 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
1864 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1867 bool wxDC::CanGetTextExtent() const
1869 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
1874 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1875 wxCoord
*descent
, wxCoord
*externalLeading
,
1876 wxFont
*theFont
) const
1878 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
1880 wxFont formerFont
= m_font
;
1883 // work around the const-ness
1884 *((wxFont
*)(&m_font
)) = *theFont
;
1888 if ( str
.Length() == 0 )
1891 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1893 OSStatus status
= noErr
;
1894 ATSUTextLayout atsuLayout
;
1895 UniCharCount chars
= str
.Length() ;
1896 UniChar
* ubuf
= NULL
;
1898 #if SIZEOF_WCHAR_T == 4
1899 wxMBConvUTF16 converter
;
1901 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1902 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1903 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1905 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1906 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1907 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1908 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1910 chars
= unicharlen
/ 2 ;
1913 ubuf
= (UniChar
*) str
.wc_str() ;
1915 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1916 chars
= wxWcslen( wchar
.data() ) ;
1917 ubuf
= (UniChar
*) wchar
.data() ;
1921 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1922 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1924 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1926 ATSUTextMeasurement textBefore
, textAfter
;
1927 ATSUTextMeasurement textAscent
, textDescent
;
1929 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1930 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1933 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1935 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1936 if ( externalLeading
)
1937 *externalLeading
= 0 ;
1939 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1941 ::ATSUDisposeTextLayout(atsuLayout
);
1943 #if SIZEOF_WCHAR_T == 4
1949 // work around the constness
1950 *((wxFont
*)(&m_font
)) = formerFont
;
1955 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1957 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
1960 widths
.Add(0, text
.Length());
1962 if (text
.Length() == 0)
1965 ATSUTextLayout atsuLayout
;
1966 UniCharCount chars
= text
.Length() ;
1967 UniChar
* ubuf
= NULL
;
1969 #if SIZEOF_WCHAR_T == 4
1970 wxMBConvUTF16 converter
;
1972 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1973 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1974 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1976 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1977 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1978 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1979 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1981 chars
= unicharlen
/ 2 ;
1984 ubuf
= (UniChar
*) text
.wc_str() ;
1986 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1987 chars
= wxWcslen( wchar
.data() ) ;
1988 ubuf
= (UniChar
*) wchar
.data() ;
1993 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1994 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1996 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1998 unsigned long actualNumberOfBounds
= 0;
1999 ATSTrapezoid glyphBounds
;
2001 // We get a single bound, since the text should only require one. If it requires more, there is an issue
2003 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2004 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2005 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2008 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
2009 //unsigned char uch = s[i];
2012 ::ATSUDisposeTextLayout(atsuLayout
);
2016 wxCoord
wxDC::GetCharWidth(void) const
2019 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2024 wxCoord
wxDC::GetCharHeight(void) const
2027 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2032 void wxDC::Clear(void)
2034 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2036 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2038 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2039 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2040 switch ( m_backgroundBrush
.MacGetBrushKind() )
2042 case kwxMacBrushTheme
:
2044 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2045 if ( HIThemeSetFill
!= 0 )
2047 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2048 CGContextFillRect(cg
, rect
);
2055 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2056 CGContextSetRGBFillColor( cg
, (float) color
.red
/ 65536,
2057 (float) color
.green
/ 65536, (float) color
.blue
/ 65536, 1 );
2058 CGContextFillRect( cg
, rect
);
2061 // reset to normal value
2062 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2063 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2067 case kwxMacBrushThemeBackground
:
2069 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2071 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2072 if ( UMAGetSystemVersion() >= 0x1030 )
2074 HIThemeBackgroundDrawInfo drawInfo
;
2075 drawInfo
.version
= 0 ;
2076 drawInfo
.state
= kThemeStateActive
;
2077 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2078 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2080 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2081 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2088 case kwxMacBrushColour
:
2090 // FIXME: doesn't correctly render stippled brushes !!
2091 // FIXME: should this be replaced by ::SetBrush() ??
2093 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2094 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2095 CGContextFillRect(cg
, rect
);
2097 // reset to normal value
2098 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2099 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2104 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2110 void wxDC::MacInstallFont() const
2112 wxCHECK_RET( Ok(), wxT("wxDC(cg)::MacInstallFont - invalid DC") );
2114 if ( m_macATSUIStyle
)
2116 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2117 m_macATSUIStyle
= NULL
;
2124 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2126 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
2128 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2129 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2130 ATSUAttributeTag atsuTags
[] =
2135 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2138 sizeof( RGBColor
) ,
2140 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2146 status
= ::ATSUSetAttributes(
2147 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
2148 atsuTags
, atsuSizes
, atsuValues
);
2150 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
2156 // ---------------------------------------------------------------------------
2157 // coordinates transformations
2158 // ---------------------------------------------------------------------------
2160 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2162 return ((wxDC
*)this)->XDEV2LOG(x
);
2165 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2167 return ((wxDC
*)this)->YDEV2LOG(y
);
2170 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2172 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2175 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2177 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2180 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2182 return ((wxDC
*)this)->XLOG2DEV(x
);
2185 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2187 return ((wxDC
*)this)->YLOG2DEV(y
);
2190 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2192 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2195 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2197 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2200 #endif // wxMAC_USE_CORE_GRAPHICS