1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dccg.cpp
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
21 #include "wx/dcmemory.h"
22 #include "wx/dcprint.h"
23 #include "wx/region.h"
27 #include "wx/mac/uma.h"
33 // in case our functions were defined outside std, we make it known all the same
39 #include "wx/mac/private.h"
41 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
43 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
44 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
47 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
48 typedef float CGFloat
;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
57 const double M_PI
= 3.14159265358979 ;
61 const double RAD2DEG
= 180.0 / M_PI
;
62 const short kEmulatedMode
= -1 ;
63 const short kUnsupportedMode
= -2 ;
65 extern TECObjectRef s_TECNativeCToUnicode
;
69 // The textctrl implementation still needs that (needs what?) for the non-HIView implementation
71 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
72 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
74 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
75 m_formerClip
= NewRgn() ;
76 m_newClip
= NewRgn() ;
77 GetClip( m_formerClip
) ;
81 // guard against half constructed objects, this just leads to a empty clip
85 win
->MacWindowToRootWindow( &x
, &y
) ;
87 // get area including focus rect
88 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
89 if ( !EmptyRgn( m_newClip
) )
90 OffsetRgn( m_newClip
, x
, y
) ;
93 SetClip( m_newClip
) ;
97 wxMacWindowClipper::~wxMacWindowClipper()
99 SetPort( m_newPort
) ;
100 SetClip( m_formerClip
) ;
101 DisposeRgn( m_newClip
) ;
102 DisposeRgn( m_formerClip
) ;
105 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
106 wxMacWindowClipper( win
)
108 // the port is already set at this point
109 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
110 GetThemeDrawingState( &m_themeDrawingState
) ;
113 wxMacWindowStateSaver::~wxMacWindowStateSaver()
115 SetPort( m_newPort
) ;
116 SetThemeDrawingState( m_themeDrawingState
, true ) ;
119 // minimal implementation only used for appearance drawing < 10.3
121 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
122 m_ph( (GrafPtr
) dc
->m_macPort
)
124 wxASSERT( dc
->Ok() ) ;
127 // dc->MacSetupPort(&m_ph) ;
130 wxMacPortSetter::~wxMacPortSetter()
132 // m_dc->MacCleanupPort(&m_ph) ;
135 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
139 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
140 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
141 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
143 //-----------------------------------------------------------------------------
144 // device context implementation
146 // more and more of the dc functionality should be implemented by calling
147 // the appropricate wxMacCGContext, but we will have to do that step by step
148 // also coordinate conversions should be moved to native matrix ops
149 //-----------------------------------------------------------------------------
151 // we always stock two context states, one at entry, to be able to preserve the
152 // state we were called with, the other one after changing to HI Graphics orientation
153 // (this one is used for getting back clippings etc)
155 wxMacCGPath::wxMacCGPath()
157 m_path
= CGPathCreateMutable() ;
160 wxMacCGPath::~wxMacCGPath()
162 CGPathRelease( m_path
) ;
165 // opens (starts) a new subpath
166 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
168 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
171 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
173 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
176 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
178 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
181 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
183 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
184 CGPathAddRect( m_path
, NULL
, cgRect
) ;
187 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
189 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
192 // closes the current subpath
193 void wxMacCGPath::CloseSubpath()
195 CGPathCloseSubpath( m_path
) ;
198 CGPathRef
wxMacCGPath::GetPath() const
203 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
209 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
212 m_cgContext
= cgcontext
;
213 CGContextSaveGState( m_cgContext
) ;
214 CGContextSaveGState( m_cgContext
) ;
217 wxMacCGContext::wxMacCGContext()
223 wxMacCGContext::~wxMacCGContext()
227 CGContextSynchronize( m_cgContext
) ;
228 CGContextRestoreGState( m_cgContext
) ;
229 CGContextRestoreGState( m_cgContext
) ;
233 CGContextRelease( m_cgContext
) ;
237 void wxMacCGContext::Clip( const wxRegion
®ion
)
239 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
242 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
244 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
245 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
246 CGContextStrokePath( m_cgContext
) ;
249 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
251 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
252 CGPathDrawingMode mode
= m_mode
;
254 if ( fillStyle
== wxODDEVEN_RULE
)
256 if ( mode
== kCGPathFill
)
257 mode
= kCGPathEOFill
;
258 else if ( mode
== kCGPathFillStroke
)
259 mode
= kCGPathEOFillStroke
;
262 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
263 CGContextDrawPath( m_cgContext
, mode
) ;
266 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
268 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
269 CGContextSaveGState( m_cgContext
) ;
271 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
272 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
273 CGPathDrawingMode mode
= kCGPathFill
;
275 if ( fillStyle
== wxODDEVEN_RULE
)
276 mode
= kCGPathEOFill
;
278 CGContextBeginPath( m_cgContext
) ;
279 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
280 CGContextClosePath( m_cgContext
) ;
281 CGContextDrawPath( m_cgContext
, mode
) ;
283 CGContextRestoreGState( m_cgContext
) ;
286 wxGraphicPath
* wxMacCGContext::CreatePath()
288 // make sure that we now have a real cgref, before doing
289 // anything with paths
290 CGContextRef cg
= GetNativeContext() ;
293 return new wxMacCGPath() ;
296 // in case we only got a QDPort only create a cgref now
298 CGContextRef
wxMacCGContext::GetNativeContext()
300 if ( m_cgContext
== NULL
)
303 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
304 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
305 CGContextSaveGState( m_cgContext
) ;
307 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
309 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
310 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
312 CGContextSaveGState( m_cgContext
) ;
314 SetBrush( m_brush
) ;
320 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
322 // we allow either setting or clearing but not replacing
323 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
326 CGContextSaveGState( cg
) ;
331 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
333 // CGPattern wrapper class: always allocate on heap, never call destructor
340 // is guaranteed to be called only with a non-Null CGContextRef
341 virtual void Render( CGContextRef ctxRef
) = 0 ;
343 operator CGPatternRef() const { return m_patternRef
; }
346 virtual ~wxMacCGPattern()
348 // as this is called only when the m_patternRef is been released;
349 // don't release it again
352 static void _Render( void *info
, CGContextRef ctxRef
)
354 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
355 if ( self
&& ctxRef
)
356 self
->Render( ctxRef
) ;
359 static void _Dispose( void *info
)
361 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
365 CGPatternRef m_patternRef
;
367 static const CGPatternCallbacks ms_Callbacks
;
370 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
372 class ImagePattern
: public wxMacCGPattern
375 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
377 wxASSERT( bmp
&& bmp
->Ok() ) ;
379 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
382 // ImagePattern takes ownership of CGImageRef passed in
383 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
388 Init( image
, transform
) ;
391 virtual void Render( CGContextRef ctxRef
)
394 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
398 void Init( CGImageRef image
, CGAffineTransform transform
)
403 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) ) ;
404 m_patternRef
= CGPatternCreate(
405 this , m_imageBounds
, transform
,
406 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
407 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
414 CGImageRelease( m_image
) ;
418 CGRect m_imageBounds
;
421 class HatchPattern
: public wxMacCGPattern
424 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
426 m_hatch
= hatchstyle
;
427 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
428 m_patternRef
= CGPatternCreate(
429 this , m_imageBounds
, transform
,
430 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
431 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
434 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
436 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
437 if ( UMAGetSystemVersion() >= 0x1040 )
439 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
444 CGContextBeginPath( ctxRef
);
445 for (size_t i
= 0; i
< count
; i
+= 2)
447 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
448 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
450 CGContextStrokePath(ctxRef
);
454 virtual void Render( CGContextRef ctxRef
)
458 case wxBDIAGONAL_HATCH
:
462 { 8.0 , 0.0 } , { 0.0 , 8.0 }
464 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
468 case wxCROSSDIAG_HATCH
:
472 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
473 { 8.0 , 0.0 } , { 0.0 , 8.0 }
475 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
479 case wxFDIAGONAL_HATCH
:
483 { 0.0 , 0.0 } , { 8.0 , 8.0 }
485 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
493 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
494 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
496 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
500 case wxHORIZONTAL_HATCH
:
504 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
506 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
510 case wxVERTICAL_HATCH
:
514 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
516 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
528 CGRect m_imageBounds
;
534 void wxMacCGContext::SetPen( const wxPen
&pen
)
537 if ( m_cgContext
== NULL
)
540 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
541 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
544 // we can benchmark performance; should go into a setting eventually
545 CGContextSetShouldAntialias( m_cgContext
, false ) ;
551 m_mode
= kCGPathFill
; // just a default
555 CGContextSetRGBStrokeColor( m_cgContext
, pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
556 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 ) ;
558 // TODO: * m_dc->m_scaleX
559 CGFloat penWidth
= pen
.GetWidth();
562 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
565 switch ( pen
.GetCap() )
568 cap
= kCGLineCapRound
;
571 case wxCAP_PROJECTING
:
572 cap
= kCGLineCapSquare
;
576 cap
= kCGLineCapButt
;
580 cap
= kCGLineCapButt
;
585 switch ( pen
.GetJoin() )
588 join
= kCGLineJoinBevel
;
592 join
= kCGLineJoinMiter
;
596 join
= kCGLineJoinRound
;
600 join
= kCGLineJoinMiter
;
604 m_mode
= kCGPathStroke
;
607 const CGFloat
*lengths
= NULL
;
608 CGFloat
*userLengths
= NULL
;
610 const CGFloat dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
612 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
613 const CGFloat short_dashed
[] = { 9.0 , 6.0 };
614 const CGFloat dashed
[] = { 19.0 , 9.0 };
615 const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
617 switch ( pen
.GetStyle() )
624 count
= WXSIZEOF(dotted
);
629 count
= WXSIZEOF(dashed
) ;
633 lengths
= short_dashed
;
634 count
= WXSIZEOF(short_dashed
) ;
638 lengths
= dotted_dashed
;
639 count
= WXSIZEOF(dotted_dashed
);
644 count
= pen
.GetDashes( &dashes
) ;
645 if ((dashes
!= NULL
) && (count
> 0))
647 userLengths
= new CGFloat
[count
] ;
648 for ( int i
= 0 ; i
< count
; ++i
)
650 userLengths
[i
] = dashes
[i
] * dashUnit
;
652 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
653 userLengths
[i
] = dashUnit
+ 2.0 ;
654 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
655 userLengths
[i
] = dashUnit
;
658 lengths
= userLengths
;
663 CGFloat alphaArray
[1] = { 1.0 } ;
664 wxBitmap
* bmp
= pen
.GetStipple() ;
665 if ( bmp
&& bmp
->Ok() )
667 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
668 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
669 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
670 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
677 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
678 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
679 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
681 CGFloat colorArray
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
682 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
684 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
689 if ((lengths
!= NULL
) && (count
> 0))
691 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
692 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
693 cap
= kCGLineCapButt
;
697 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
700 CGContextSetLineCap( m_cgContext
, cap
) ;
701 CGContextSetLineJoin( m_cgContext
, join
) ;
703 delete[] userLengths
;
706 if ( fill
&& stroke
)
707 m_mode
= kCGPathFillStroke
;
711 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
714 if ( m_cgContext
== NULL
)
717 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
718 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
721 // we can benchmark performance, should go into a setting later
722 CGContextSetShouldAntialias( m_cgContext
, false ) ;
728 m_mode
= kCGPathFill
; // just a default
732 if ( brush
.GetStyle() == wxSOLID
)
734 CGContextSetRGBFillColor( m_cgContext
, brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
735 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 ) ;
737 else if ( brush
.IsHatch() )
739 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
740 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
741 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
743 CGFloat colorArray
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
744 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
746 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
750 // now brush is a bitmap
751 CGFloat alphaArray
[1] = { 1.0 } ;
752 wxBitmap
* bmp
= brush
.GetStipple() ;
753 if ( bmp
&& bmp
->Ok() )
755 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
756 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
757 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
758 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
762 m_mode
= kCGPathFill
;
765 if ( fill
&& stroke
)
766 m_mode
= kCGPathFillStroke
;
768 m_mode
= kCGPathStroke
;
772 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, CGFloat a
, CGFloat b
, CGFloat fromDegree
, CGFloat toDegree
)
774 CGContextSaveGState(c
);
775 CGContextTranslateCTM(c
, center
.x
, center
.y
);
776 CGContextScaleCTM(c
, a
, b
);
777 CGContextMoveToPoint(c
, 1, 0);
778 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
779 CGContextClosePath(c
);
780 CGContextRestoreGState(c
);
783 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, CGFloat ovalWidth
,
787 if (ovalWidth
== 0 || ovalHeight
== 0)
789 CGContextAddRect(c
, rect
);
793 CGContextSaveGState(c
);
794 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
795 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
797 fw
= CGRectGetWidth(rect
) / ovalWidth
;
798 fh
= CGRectGetHeight(rect
) / ovalHeight
;
800 CGContextMoveToPoint(c
, fw
, fh
/ 2);
801 CGContextAddArcToPoint(c
, fw
, fh
, fw
/ 2, fh
, 1);
802 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/ 2, 1);
803 CGContextAddArcToPoint(c
, 0, 0, fw
/ 2, 0, 1);
804 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/ 2, 1);
805 CGContextClosePath(c
);
806 CGContextRestoreGState(c
);
815 m_mm_to_pix_x
= mm2pt
;
816 m_mm_to_pix_y
= mm2pt
;
818 m_externalDeviceOriginX
= 0;
819 m_externalDeviceOriginY
= 0;
820 m_logicalScaleX
= 1.0;
821 m_logicalScaleY
= 1.0;
826 m_needComputeScaleX
=
827 m_needComputeScaleY
= false;
831 m_macLocalOrigin
.y
= 0 ;
833 m_pen
= *wxBLACK_PEN
;
834 m_font
= *wxNORMAL_FONT
;
835 m_brush
= *wxWHITE_BRUSH
;
837 m_macATSUIStyle
= NULL
;
838 m_graphicContext
= NULL
;
843 if ( m_macATSUIStyle
)
845 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
846 m_macATSUIStyle
= NULL
;
849 delete m_graphicContext
;
852 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
854 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
855 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
857 wxCoord xx
= XLOG2DEVMAC(x
);
858 wxCoord yy
= YLOG2DEVMAC(y
);
859 wxCoord w
= bmp
.GetWidth();
860 wxCoord h
= bmp
.GetHeight();
861 wxCoord ww
= XLOG2DEVREL(w
);
862 wxCoord hh
= YLOG2DEVREL(h
);
864 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
865 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
866 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
867 HIViewDrawCGImage( cg
, &r
, image
) ;
868 CGImageRelease( image
) ;
871 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
873 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
874 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
876 wxCoord xx
= XLOG2DEVMAC(x
);
877 wxCoord yy
= YLOG2DEVMAC(y
);
878 wxCoord w
= icon
.GetWidth();
879 wxCoord h
= icon
.GetHeight();
880 wxCoord ww
= XLOG2DEVREL(w
);
881 wxCoord hh
= YLOG2DEVREL(h
);
883 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
884 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
885 CGContextSaveGState( cg
);
886 CGContextTranslateCTM( cg
, xx
, yy
+ hh
);
887 CGContextScaleCTM( cg
, 1, -1 );
888 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
889 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
890 CGContextRestoreGState( cg
) ;
893 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
895 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
897 wxCoord xx
, yy
, ww
, hh
;
900 ww
= XLOG2DEVREL(width
);
901 hh
= YLOG2DEVREL(height
);
903 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
904 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
905 CGContextClipToRect( cgContext
, clipRect
) ;
907 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
908 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
912 m_clipX1
= wxMax( m_clipX1
, xx
);
913 m_clipY1
= wxMax( m_clipY1
, yy
);
914 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
915 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
927 // TODO: as soon as we don't reset the context for each operation anymore
928 // we have to update the context as well
931 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
933 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
937 DestroyClippingRegion();
942 region
.GetBox( x
, y
, w
, h
);
943 wxCoord xx
, yy
, ww
, hh
;
949 // if we have a scaling that we cannot map onto native regions
950 // we must use the box
951 if ( ww
!= w
|| hh
!= h
)
953 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
958 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
959 if ( xx
!= x
|| yy
!= y
)
960 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
961 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
966 m_clipX1
= wxMax( m_clipX1
, xx
);
967 m_clipY1
= wxMax( m_clipY1
, yy
);
968 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
969 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
983 void wxDC::DestroyClippingRegion()
985 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
987 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
988 CGContextRestoreGState( cgContext
);
989 CGContextSaveGState( cgContext
);
991 m_graphicContext
->SetPen( m_pen
) ;
992 m_graphicContext
->SetBrush( m_brush
) ;
997 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1003 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
1005 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1008 void wxDC::SetTextForeground( const wxColour
&col
)
1010 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1012 if ( col
!= m_textForegroundColour
)
1014 m_textForegroundColour
= col
;
1019 void wxDC::SetTextBackground( const wxColour
&col
)
1021 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1023 m_textBackgroundColour
= col
;
1026 void wxDC::SetMapMode( int mode
)
1031 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1035 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1039 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1043 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1048 SetLogicalScale( 1.0, 1.0 );
1052 if (mode
!= wxMM_TEXT
)
1054 m_needComputeScaleX
=
1055 m_needComputeScaleY
= true;
1059 void wxDC::SetUserScale( double x
, double y
)
1061 // allow negative ? -> no
1064 ComputeScaleAndOrigin();
1067 void wxDC::SetLogicalScale( double x
, double y
)
1070 m_logicalScaleX
= x
;
1071 m_logicalScaleY
= y
;
1072 ComputeScaleAndOrigin();
1075 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1077 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1078 m_logicalOriginY
= y
* m_signY
;
1079 ComputeScaleAndOrigin();
1082 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1084 m_externalDeviceOriginX
= x
;
1085 m_externalDeviceOriginY
= y
;
1086 ComputeScaleAndOrigin();
1089 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1091 m_signX
= (xLeftRight
? 1 : -1);
1092 m_signY
= (yBottomUp
? -1 : 1);
1093 ComputeScaleAndOrigin();
1096 wxSize
wxDC::GetPPI() const
1098 return wxSize(72, 72);
1101 int wxDC::GetDepth() const
1106 void wxDC::ComputeScaleAndOrigin()
1108 // CMB: copy scale to see if it changes
1109 double origScaleX
= m_scaleX
;
1110 double origScaleY
= m_scaleY
;
1111 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1112 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1113 m_deviceOriginX
= m_externalDeviceOriginX
;
1114 m_deviceOriginY
= m_externalDeviceOriginY
;
1116 // CMB: if scale has changed call SetPen to recalulate the line width
1117 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1119 // this is a bit artificial, but we need to force wxDC to think
1120 // the pen has changed
1121 wxPen
pen( GetPen() );
1128 void wxDC::SetPalette( const wxPalette
& palette
)
1132 void wxDC::SetBackgroundMode( int mode
)
1134 m_backgroundMode
= mode
;
1137 void wxDC::SetFont( const wxFont
&font
)
1143 void wxDC::SetPen( const wxPen
&pen
)
1149 if ( m_graphicContext
)
1151 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1153 m_graphicContext
->SetPen( m_pen
) ;
1157 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1158 // eg when using a wxScrollWindow and scrolling around
1159 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1160 int origX
= XLOG2DEVMAC( 0 ) ;
1161 int origY
= YLOG2DEVMAC( 0 ) ;
1162 CGContextTranslateCTM( cgContext
, origX
, origY
);
1163 m_graphicContext
->SetPen( m_pen
) ;
1164 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1169 void wxDC::SetBrush( const wxBrush
&brush
)
1171 if (m_brush
== brush
)
1175 if ( m_graphicContext
)
1177 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1179 m_graphicContext
->SetBrush( m_brush
) ;
1183 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1184 // eg when using a wxScrollWindow and scrolling around
1185 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1186 int origX
= XLOG2DEVMAC(0) ;
1187 int origY
= YLOG2DEVMAC(0) ;
1188 CGContextTranslateCTM( cgContext
, origX
, origY
);
1189 m_graphicContext
->SetBrush( m_brush
) ;
1190 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1195 void wxDC::SetBackground( const wxBrush
&brush
)
1197 if (m_backgroundBrush
== brush
)
1200 m_backgroundBrush
= brush
;
1201 if (!m_backgroundBrush
.Ok())
1205 void wxDC::SetLogicalFunction( int function
)
1207 if (m_logicalFunction
== function
)
1210 m_logicalFunction
= function
;
1211 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1212 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1213 if ( m_logicalFunction
== wxCOPY
)
1214 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1215 else if ( m_logicalFunction
== wxINVERT
)
1216 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1218 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1222 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1223 const wxColour
& col
, int style
);
1225 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1226 const wxColour
& col
, int style
)
1228 return wxDoFloodFill(this, x
, y
, col
, style
);
1231 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1233 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1235 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1238 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1240 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1241 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1243 // convert from Mac colour to wx
1244 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1249 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1251 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1253 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1254 if ( m_logicalFunction
!= wxCOPY
)
1258 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1259 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1260 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1261 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1263 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1264 path
->MoveToPoint( xx1
, yy1
) ;
1265 path
->AddLineToPoint( xx2
, yy2
) ;
1266 path
->CloseSubpath() ;
1267 m_graphicContext
->StrokePath( path
) ;
1270 CalcBoundingBox(x1
, y1
);
1271 CalcBoundingBox(x2
, y2
);
1274 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1276 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1278 if ( m_logicalFunction
!= wxCOPY
)
1284 wxCoord xx
= XLOG2DEVMAC(x
);
1285 wxCoord yy
= YLOG2DEVMAC(y
);
1287 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1288 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1289 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1290 path
->CloseSubpath() ;
1291 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1292 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1293 path
->CloseSubpath() ;
1294 m_graphicContext
->StrokePath( path
) ;
1297 CalcBoundingBox(x
, y
);
1298 CalcBoundingBox(x
+ w
, y
+ h
);
1301 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1302 wxCoord x2
, wxCoord y2
,
1303 wxCoord xc
, wxCoord yc
)
1305 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1307 if ( m_logicalFunction
!= wxCOPY
)
1310 wxCoord xx1
= XLOG2DEVMAC(x1
);
1311 wxCoord yy1
= YLOG2DEVMAC(y1
);
1312 wxCoord xx2
= XLOG2DEVMAC(x2
);
1313 wxCoord yy2
= YLOG2DEVMAC(y2
);
1314 wxCoord xxc
= XLOG2DEVMAC(xc
);
1315 wxCoord yyc
= YLOG2DEVMAC(yc
);
1317 double dx
= xx1
- xxc
;
1318 double dy
= yy1
- yyc
;
1319 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1320 wxCoord rad
= (wxCoord
)radius
;
1322 if (xx1
== xx2
&& yy1
== yy2
)
1327 else if (radius
== 0.0)
1333 sa
= (xx1
- xxc
== 0) ?
1334 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1335 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1336 ea
= (xx2
- xxc
== 0) ?
1337 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1338 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1341 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1342 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1343 CGContextRef ctx
= mctx
->GetNativeContext() ;
1344 CGContextSaveGState( ctx
) ;
1345 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1346 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1348 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1349 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0 );
1351 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1352 CGContextRestoreGState( ctx
) ;
1353 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1356 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1357 double sa
, double ea
)
1359 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1361 if ( m_logicalFunction
!= wxCOPY
)
1364 wxCoord xx
= XLOG2DEVMAC(x
);
1365 wxCoord yy
= YLOG2DEVMAC(y
);
1366 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1367 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1369 // handle -ve width and/or height
1381 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1383 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1384 CGContextRef ctx
= mctx
->GetNativeContext() ;
1386 CGContextSaveGState( ctx
) ;
1387 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1388 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1390 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1391 CGContextAddArc( ctx
, 0, 0, 1, DegToRad( sa
), DegToRad( ea
), 0 );
1393 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1394 CGContextRestoreGState( ctx
) ;
1395 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1398 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1400 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1402 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1405 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1406 wxCoord xoffset
, wxCoord yoffset
)
1408 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1410 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1411 if ( m_logicalFunction
!= wxCOPY
)
1415 wxCoord x1
, x2
, y1
, y2
;
1416 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1417 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1418 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1419 path
->MoveToPoint( x1
, y1
) ;
1420 for (int i
= 1; i
< n
; i
++)
1422 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1423 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1425 path
->AddLineToPoint( x2
, y2
) ;
1428 m_graphicContext
->StrokePath( path
) ;
1433 void wxDC::DoDrawSpline(wxList
*points
)
1435 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1437 if ( m_logicalFunction
!= wxCOPY
)
1440 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1442 wxList::compatibility_iterator node
= points
->GetFirst();
1443 if (node
== wxList::compatibility_iterator())
1447 wxPoint
*p
= (wxPoint
*)node
->GetData();
1452 node
= node
->GetNext();
1453 p
= (wxPoint
*)node
->GetData();
1457 wxCoord cx1
= ( x1
+ x2
) / 2;
1458 wxCoord cy1
= ( y1
+ y2
) / 2;
1460 path
->MoveToPoint( XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ) ;
1461 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , YLOG2DEVMAC( cy1
) ) ;
1464 while ((node
= node
->GetNext()) != NULL
)
1466 while ((node
= node
->GetNext()))
1467 #endif // !wxUSE_STL
1469 p
= (wxPoint
*)node
->GetData();
1474 wxCoord cx4
= (x1
+ x2
) / 2;
1475 wxCoord cy4
= (y1
+ y2
) / 2;
1477 path
->AddQuadCurveToPoint(
1478 XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ,
1479 XLOG2DEVMAC( cx4
) , YLOG2DEVMAC( cy4
) ) ;
1485 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , YLOG2DEVMAC( y2
) ) ;
1487 m_graphicContext
->StrokePath( path
) ;
1492 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1493 wxCoord xoffset
, wxCoord yoffset
,
1496 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1498 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1500 if ( m_logicalFunction
!= wxCOPY
)
1503 wxCoord x1
, x2
, y1
, y2
;
1504 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1505 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1507 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1508 path
->MoveToPoint( x1
, y1
) ;
1509 for (int i
= 1; i
< n
; i
++)
1511 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1512 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1514 path
->AddLineToPoint( x2
, y2
) ;
1517 if ( x1
!= x2
|| y1
!= y2
)
1518 path
->AddLineToPoint( x1
, y1
) ;
1520 path
->CloseSubpath() ;
1521 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1526 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1528 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1530 if ( m_logicalFunction
!= wxCOPY
)
1533 wxCoord xx
= XLOG2DEVMAC(x
);
1534 wxCoord yy
= YLOG2DEVMAC(y
);
1535 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1536 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1538 // CMB: draw nothing if transformed w or h is 0
1539 if (ww
== 0 || hh
== 0)
1542 // CMB: handle -ve width and/or height
1554 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1555 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1556 m_graphicContext
->DrawPath( path
) ;
1560 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1561 wxCoord width
, wxCoord height
,
1564 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1566 if ( m_logicalFunction
!= wxCOPY
)
1570 radius
= - radius
* ((width
< height
) ? width
: height
);
1571 wxCoord xx
= XLOG2DEVMAC(x
);
1572 wxCoord yy
= YLOG2DEVMAC(y
);
1573 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1574 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1576 // CMB: draw nothing if transformed w or h is 0
1577 if (ww
== 0 || hh
== 0)
1580 // CMB: handle -ve width and/or height
1592 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1593 CGContextRef ctx
= mctx
->GetNativeContext() ;
1594 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , radius
, radius
) ;
1595 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1598 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1600 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1602 if ( m_logicalFunction
!= wxCOPY
)
1605 wxCoord xx
= XLOG2DEVMAC(x
);
1606 wxCoord yy
= YLOG2DEVMAC(y
);
1607 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1608 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1610 // CMB: draw nothing if transformed w or h is 0
1611 if (ww
== 0 || hh
== 0)
1614 // CMB: handle -ve width and/or height
1626 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1627 CGContextRef ctx
= mctx
->GetNativeContext() ;
1628 CGContextSaveGState( ctx
) ;
1629 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1630 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1631 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2 * M_PI
, 0 );
1632 CGContextRestoreGState( ctx
) ;
1633 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1636 bool wxDC::CanDrawBitmap() const
1642 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1643 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1644 wxCoord xsrcMask
, wxCoord ysrcMask
)
1646 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
1647 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
1649 if ( logical_func
== wxNO_OP
)
1652 if (xsrcMask
== -1 && ysrcMask
== -1)
1658 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1659 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1660 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1661 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1663 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1664 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1665 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1666 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1668 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1669 if ( memdc
&& logical_func
== wxCOPY
)
1671 wxBitmap blit
= memdc
->GetSelectedObject() ;
1673 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1675 wxCoord bmpwidth
= blit
.GetWidth();
1676 wxCoord bmpheight
= blit
.GetHeight();
1678 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1680 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1681 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1682 if ( wwsrc
> 0 && hhsrc
> 0 )
1684 if ( xxsrc
>= 0 && yysrc
>= 0 )
1686 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1687 blit
= blit
.GetSubBitmap( subrect
) ;
1691 // in this case we'd probably have to adjust the different coordinates, but
1692 // we have to find out proper contract first
1693 blit
= wxNullBitmap
;
1698 blit
= wxNullBitmap
;
1704 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1705 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1706 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1707 HIViewDrawCGImage( cg
, &r
, image
) ;
1708 CGImageRelease( image
) ;
1714 CGContextRef cg
= (wxMacCGContext
*)(source
->GetGraphicContext())->GetNativeContext() ;
1715 void *data
= CGBitmapContextGetData( cg
) ;
1718 return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1724 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1727 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
1728 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
1730 if ( str
.length() == 0 )
1732 if ( m_logicalFunction
!= wxCOPY
)
1735 OSStatus status
= noErr
;
1736 ATSUTextLayout atsuLayout
;
1737 UniCharCount chars
= str
.length() ;
1738 UniChar
* ubuf
= NULL
;
1740 #if SIZEOF_WCHAR_T == 4
1741 wxMBConvUTF16 converter
;
1743 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1744 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1745 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1747 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1748 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1749 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1750 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1752 chars
= unicharlen
/ 2 ;
1755 ubuf
= (UniChar
*) str
.wc_str() ;
1757 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1758 chars
= wxWcslen( wchar
.data() ) ;
1759 ubuf
= (UniChar
*) wchar
.data() ;
1763 int drawX
= XLOG2DEVMAC(x
) ;
1764 int drawY
= YLOG2DEVMAC(y
) ;
1766 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1767 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1769 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1771 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1772 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1774 int iAngle
= int( angle
);
1775 if ( abs(iAngle
) > 0 )
1777 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1778 ATSUAttributeTag atsuTags
[] =
1780 kATSULineRotationTag
,
1782 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1786 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1790 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1791 atsuTags
, atsuSizes
, atsuValues
) ;
1795 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1796 ATSUAttributeTag atsuTags
[] =
1800 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1802 sizeof( CGContextRef
) ,
1804 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1808 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1809 atsuTags
, atsuSizes
, atsuValues
) ;
1812 ATSUTextMeasurement textBefore
, textAfter
;
1813 ATSUTextMeasurement ascent
, descent
;
1815 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1816 &textBefore
, &textAfter
, &ascent
, &descent
);
1818 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1822 if ( m_backgroundMode
== wxSOLID
)
1824 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1825 path
->MoveToPoint( drawX
, drawY
) ;
1826 path
->AddLineToPoint(
1827 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1828 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1829 path
->AddLineToPoint(
1830 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1831 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1832 path
->AddLineToPoint(
1833 (int) (drawX
+ cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1834 (int) (drawY
- sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1836 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1840 drawX
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1841 drawY
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1843 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1844 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1845 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1847 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1848 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1849 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1850 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1851 IntToFixed(0) , IntToFixed(0) );
1853 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1855 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1857 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1858 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1860 ::ATSUDisposeTextLayout(atsuLayout
);
1862 #if SIZEOF_WCHAR_T == 4
1867 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1869 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
1871 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1874 bool wxDC::CanGetTextExtent() const
1876 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
1881 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1882 wxCoord
*descent
, wxCoord
*externalLeading
,
1883 wxFont
*theFont
) const
1885 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
1887 wxFont formerFont
= m_font
;
1890 // work around the const-ness
1891 *((wxFont
*)(&m_font
)) = *theFont
;
1898 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1900 OSStatus status
= noErr
;
1901 ATSUTextLayout atsuLayout
;
1902 UniCharCount chars
= str
.length() ;
1903 UniChar
* ubuf
= NULL
;
1905 #if SIZEOF_WCHAR_T == 4
1906 wxMBConvUTF16 converter
;
1908 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1909 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1910 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1912 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1913 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1914 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1915 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1917 chars
= unicharlen
/ 2 ;
1920 ubuf
= (UniChar
*) str
.wc_str() ;
1922 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1923 chars
= wxWcslen( wchar
.data() ) ;
1924 ubuf
= (UniChar
*) wchar
.data() ;
1928 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1929 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1931 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1933 ATSUTextMeasurement textBefore
, textAfter
;
1934 ATSUTextMeasurement textAscent
, textDescent
;
1936 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1937 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1940 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1942 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1943 if ( externalLeading
)
1944 *externalLeading
= 0 ;
1946 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1948 ::ATSUDisposeTextLayout(atsuLayout
);
1950 #if SIZEOF_WCHAR_T == 4
1956 // work around the constness
1957 *((wxFont
*)(&m_font
)) = formerFont
;
1962 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1964 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
1967 widths
.Add(0, text
.length());
1972 ATSUTextLayout atsuLayout
;
1973 UniCharCount chars
= text
.length() ;
1974 UniChar
* ubuf
= NULL
;
1976 #if SIZEOF_WCHAR_T == 4
1977 wxMBConvUTF16 converter
;
1979 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1980 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1981 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1983 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1984 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1985 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1986 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1988 chars
= unicharlen
/ 2 ;
1991 ubuf
= (UniChar
*) text
.wc_str() ;
1993 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1994 chars
= wxWcslen( wchar
.data() ) ;
1995 ubuf
= (UniChar
*) wchar
.data() ;
2000 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
2001 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
2003 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
2005 unsigned long actualNumberOfBounds
= 0;
2006 ATSTrapezoid glyphBounds
;
2008 // We get a single bound, since the text should only require one. If it requires more, there is an issue
2010 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2011 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2012 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2015 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
2016 //unsigned char uch = s[i];
2019 ::ATSUDisposeTextLayout(atsuLayout
);
2023 wxCoord
wxDC::GetCharWidth(void) const
2026 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2031 wxCoord
wxDC::GetCharHeight(void) const
2034 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2039 void wxDC::Clear(void)
2041 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2043 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2045 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2046 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2047 switch ( m_backgroundBrush
.MacGetBrushKind() )
2049 case kwxMacBrushTheme
:
2051 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2052 if ( HIThemeSetFill
!= 0 )
2054 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2055 CGContextFillRect(cg
, rect
);
2062 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2063 CGContextSetRGBFillColor( cg
, (CGFloat
) color
.red
/ 65536,
2064 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 );
2065 CGContextFillRect( cg
, rect
);
2068 // reset to normal value
2069 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2070 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2074 case kwxMacBrushThemeBackground
:
2076 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2078 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2079 if ( UMAGetSystemVersion() >= 0x1030 )
2081 HIThemeBackgroundDrawInfo drawInfo
;
2082 drawInfo
.version
= 0 ;
2083 drawInfo
.state
= kThemeStateActive
;
2084 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2085 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2087 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2088 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2095 case kwxMacBrushColour
:
2097 // FIXME: doesn't correctly render stippled brushes !!
2098 // FIXME: should this be replaced by ::SetBrush() ??
2100 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2101 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2102 CGContextFillRect(cg
, rect
);
2104 // reset to normal value
2105 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2106 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2111 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2117 void wxDC::MacInstallFont() const
2119 wxCHECK_RET( Ok(), wxT("wxDC(cg)::MacInstallFont - invalid DC") );
2121 if ( m_macATSUIStyle
)
2123 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2124 m_macATSUIStyle
= NULL
;
2131 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2133 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
2135 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2136 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2137 ATSUAttributeTag atsuTags
[] =
2142 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2145 sizeof( RGBColor
) ,
2147 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2153 status
= ::ATSUSetAttributes(
2154 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
2155 atsuTags
, atsuSizes
, atsuValues
);
2157 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
2163 // ---------------------------------------------------------------------------
2164 // coordinates transformations
2165 // ---------------------------------------------------------------------------
2167 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2169 return ((wxDC
*)this)->XDEV2LOG(x
);
2172 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2174 return ((wxDC
*)this)->YDEV2LOG(y
);
2177 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2179 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2182 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2184 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2187 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2189 return ((wxDC
*)this)->XLOG2DEV(x
);
2192 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2194 return ((wxDC
*)this)->YLOG2DEV(y
);
2197 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2199 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2202 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2204 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2207 #endif // wxMAC_USE_CORE_GRAPHICS