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
20 #include "wx/dcmemory.h"
21 #include "wx/region.h"
24 #include "wx/mac/uma.h"
29 // in case our functions were defined outside std, we make it known all the same
35 #include "wx/mac/private.h"
37 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
39 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
40 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
43 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
44 typedef float CGFloat
;
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
53 const double M_PI
= 3.14159265358979 ;
57 static const double RAD2DEG
= 180.0 / M_PI
;
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) ;
129 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
133 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
135 //-----------------------------------------------------------------------------
136 // device context implementation
138 // more and more of the dc functionality should be implemented by calling
139 // the appropricate wxMacCGContext, but we will have to do that step by step
140 // also coordinate conversions should be moved to native matrix ops
141 //-----------------------------------------------------------------------------
143 // we always stock two context states, one at entry, to be able to preserve the
144 // state we were called with, the other one after changing to HI Graphics orientation
145 // (this one is used for getting back clippings etc)
147 //-----------------------------------------------------------------------------
148 // wxGraphicPath implementation
149 //-----------------------------------------------------------------------------
151 wxMacCGPath::wxMacCGPath()
153 m_path
= CGPathCreateMutable() ;
156 wxMacCGPath::~wxMacCGPath()
158 CGPathRelease( m_path
) ;
161 // opens (starts) a new subpath
162 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
164 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
167 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
169 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
172 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
174 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
177 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
179 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
180 CGPathAddRect( m_path
, NULL
, cgRect
) ;
183 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
185 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
188 // closes the current subpath
189 void wxMacCGPath::CloseSubpath()
191 CGPathCloseSubpath( m_path
) ;
194 CGPathRef
wxMacCGPath::GetPath() const
199 void wxMacCGPath::AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
)
201 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
204 void wxMacCGPath::AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
)
206 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, clockwise
);
209 //-----------------------------------------------------------------------------
210 // wxGraphicContext implementation
211 //-----------------------------------------------------------------------------
213 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
217 m_mode
= kCGPathFill
;
218 m_macATSUIStyle
= NULL
;
221 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
224 m_cgContext
= cgcontext
;
225 m_mode
= kCGPathFill
;
226 m_macATSUIStyle
= NULL
;
227 CGContextSaveGState( m_cgContext
) ;
228 CGContextSaveGState( m_cgContext
) ;
231 wxMacCGContext::wxMacCGContext()
235 m_mode
= kCGPathFill
;
236 m_macATSUIStyle
= NULL
;
239 wxMacCGContext::~wxMacCGContext()
243 CGContextSynchronize( m_cgContext
) ;
244 CGContextRestoreGState( m_cgContext
) ;
245 CGContextRestoreGState( m_cgContext
) ;
249 QDEndCGContext( m_qdPort
, &m_cgContext
) ;
254 void wxMacCGContext::Clip( const wxRegion
®ion
)
256 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
259 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
261 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
263 int width
= m_pen
.GetWidth();
266 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
269 bool offset
= ( width
% 2 ) == 1 ;
272 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
274 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
275 CGContextStrokePath( m_cgContext
) ;
278 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
281 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
283 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
284 CGPathDrawingMode mode
= m_mode
;
286 if ( fillStyle
== wxODDEVEN_RULE
)
288 if ( mode
== kCGPathFill
)
289 mode
= kCGPathEOFill
;
290 else if ( mode
== kCGPathFillStroke
)
291 mode
= kCGPathEOFillStroke
;
294 int width
= m_pen
.GetWidth();
297 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
300 bool offset
= ( width
% 2 ) == 1 ;
303 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
305 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
306 CGContextDrawPath( m_cgContext
, mode
) ;
309 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
312 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
314 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
315 CGContextSaveGState( m_cgContext
) ;
317 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
318 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
319 CGPathDrawingMode mode
= kCGPathFill
;
321 if ( fillStyle
== wxODDEVEN_RULE
)
322 mode
= kCGPathEOFill
;
324 CGContextBeginPath( m_cgContext
) ;
325 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
326 CGContextClosePath( m_cgContext
) ;
327 CGContextDrawPath( m_cgContext
, mode
) ;
329 CGContextRestoreGState( m_cgContext
) ;
332 wxGraphicPath
* wxMacCGContext::CreatePath()
334 // make sure that we now have a real cgref, before doing
335 // anything with paths
336 CGContextRef cg
= GetNativeContext() ;
339 return new wxMacCGPath() ;
342 // in case we only got a QDPort only create a cgref now
344 CGContextRef
wxMacCGContext::GetNativeContext()
346 if ( m_cgContext
== NULL
)
349 OSStatus status
= noErr
;
351 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
352 status
= QDBeginCGContext((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
354 CGContextSaveGState( m_cgContext
) ;
356 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
358 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
359 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
361 CGContextSaveGState( m_cgContext
) ;
363 SetBrush( m_brush
) ;
369 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
371 // we allow either setting or clearing but not replacing
372 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
375 CGContextSaveGState( cg
) ;
379 void wxMacCGContext::Translate( wxCoord dx
, wxCoord dy
)
381 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
384 void wxMacCGContext::Scale( wxCoord xScale
, wxCoord yScale
)
386 CGContextScaleCTM( m_cgContext
, xScale
, yScale
) ;
389 void wxMacCGContext::DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
391 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
392 HIRect r
= CGRectMake( 0 , 0 , w
, h
);
394 CGContextSaveGState( m_cgContext
);
395 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
396 CGContextScaleCTM( m_cgContext
, 1, -1 );
398 // in case image is a mask, set the foreground color
399 CGContextSetRGBFillColor( m_cgContext
, m_textForegroundColor
.Red() / 255.0 , m_textForegroundColor
.Green() / 255.0 ,
400 m_textForegroundColor
.Blue() / 255.0 , m_textForegroundColor
.Alpha() / 255.0 ) ;
401 CGContextDrawImage( m_cgContext
, r
, image
);
402 CGContextRestoreGState( m_cgContext
);
404 CGImageRelease( image
) ;
407 void wxMacCGContext::DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
409 CGRect r
= CGRectMake( 0 , 0 , w
, h
) ;
410 CGContextSaveGState( m_cgContext
);
411 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
412 CGContextScaleCTM( m_cgContext
, 1, -1 );
413 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
414 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
415 CGContextRestoreGState( m_cgContext
) ;
418 void wxMacCGContext::PushState()
420 CGContextSaveGState( m_cgContext
);
423 void wxMacCGContext::PopState()
425 CGContextRestoreGState( m_cgContext
);
428 void wxMacCGContext::SetTextColor( const wxColour
&col
)
430 m_textForegroundColor
= col
;
434 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
436 // CGPattern wrapper class: always allocate on heap, never call destructor
443 // is guaranteed to be called only with a non-Null CGContextRef
444 virtual void Render( CGContextRef ctxRef
) = 0 ;
446 operator CGPatternRef() const { return m_patternRef
; }
449 virtual ~wxMacCGPattern()
451 // as this is called only when the m_patternRef is been released;
452 // don't release it again
455 static void _Render( void *info
, CGContextRef ctxRef
)
457 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
458 if ( self
&& ctxRef
)
459 self
->Render( ctxRef
) ;
462 static void _Dispose( void *info
)
464 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
468 CGPatternRef m_patternRef
;
470 static const CGPatternCallbacks ms_Callbacks
;
473 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
475 class ImagePattern
: public wxMacCGPattern
478 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
480 wxASSERT( bmp
&& bmp
->Ok() ) ;
482 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
485 // ImagePattern takes ownership of CGImageRef passed in
486 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
491 Init( image
, transform
) ;
494 virtual void Render( CGContextRef ctxRef
)
497 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
501 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
506 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) ) ;
507 m_patternRef
= CGPatternCreate(
508 this , m_imageBounds
, transform
,
509 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
510 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
514 virtual ~ImagePattern()
517 CGImageRelease( m_image
) ;
521 CGRect m_imageBounds
;
524 class HatchPattern
: public wxMacCGPattern
527 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
529 m_hatch
= hatchstyle
;
530 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
531 m_patternRef
= CGPatternCreate(
532 this , m_imageBounds
, transform
,
533 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
534 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
537 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
539 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
540 if ( UMAGetSystemVersion() >= 0x1040 )
542 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
547 CGContextBeginPath( ctxRef
);
548 for (size_t i
= 0; i
< count
; i
+= 2)
550 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
551 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
553 CGContextStrokePath(ctxRef
);
557 virtual void Render( CGContextRef ctxRef
)
561 case wxBDIAGONAL_HATCH
:
565 { 8.0 , 0.0 } , { 0.0 , 8.0 }
567 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
571 case wxCROSSDIAG_HATCH
:
575 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
576 { 8.0 , 0.0 } , { 0.0 , 8.0 }
578 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
582 case wxFDIAGONAL_HATCH
:
586 { 0.0 , 0.0 } , { 8.0 , 8.0 }
588 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
596 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
597 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
599 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
603 case wxHORIZONTAL_HATCH
:
607 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
609 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
613 case wxVERTICAL_HATCH
:
617 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
619 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
629 virtual ~HatchPattern() {}
631 CGRect m_imageBounds
;
637 void wxMacCGContext::SetPen( const wxPen
&pen
)
640 if ( m_cgContext
== NULL
)
643 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
644 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
647 // we can benchmark performance; should go into a setting eventually
648 CGContextSetShouldAntialias( m_cgContext
, false ) ;
651 if ( fill
|| stroke
)
654 m_mode
= kCGPathFill
; // just a default
658 CGContextSetRGBStrokeColor( m_cgContext
, pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
659 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 ) ;
661 // TODO: * m_dc->m_scaleX
662 CGFloat penWidth
= pen
.GetWidth();
665 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
668 switch ( pen
.GetCap() )
671 cap
= kCGLineCapRound
;
674 case wxCAP_PROJECTING
:
675 cap
= kCGLineCapSquare
;
679 cap
= kCGLineCapButt
;
683 cap
= kCGLineCapButt
;
688 switch ( pen
.GetJoin() )
691 join
= kCGLineJoinBevel
;
695 join
= kCGLineJoinMiter
;
699 join
= kCGLineJoinRound
;
703 join
= kCGLineJoinMiter
;
707 m_mode
= kCGPathStroke
;
710 const CGFloat
*lengths
= NULL
;
711 CGFloat
*userLengths
= NULL
;
713 const CGFloat dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
715 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
716 const CGFloat short_dashed
[] = { 9.0 , 6.0 };
717 const CGFloat dashed
[] = { 19.0 , 9.0 };
718 const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
720 switch ( pen
.GetStyle() )
727 count
= WXSIZEOF(dotted
);
732 count
= WXSIZEOF(dashed
) ;
736 lengths
= short_dashed
;
737 count
= WXSIZEOF(short_dashed
) ;
741 lengths
= dotted_dashed
;
742 count
= WXSIZEOF(dotted_dashed
);
747 count
= pen
.GetDashes( &dashes
) ;
748 if ((dashes
!= NULL
) && (count
> 0))
750 userLengths
= new CGFloat
[count
] ;
751 for ( int i
= 0 ; i
< count
; ++i
)
753 userLengths
[i
] = dashes
[i
] * dashUnit
;
755 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
756 userLengths
[i
] = dashUnit
+ 2.0 ;
757 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
758 userLengths
[i
] = dashUnit
;
761 lengths
= userLengths
;
766 CGFloat alphaArray
[1] = { 1.0 } ;
767 wxBitmap
* bmp
= pen
.GetStipple() ;
768 if ( bmp
&& bmp
->Ok() )
770 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
771 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
772 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
773 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
780 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
781 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
782 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
784 CGFloat colorArray
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
785 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
787 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
792 if ((lengths
!= NULL
) && (count
> 0))
794 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
795 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
796 cap
= kCGLineCapButt
;
800 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
803 CGContextSetLineCap( m_cgContext
, cap
) ;
804 CGContextSetLineJoin( m_cgContext
, join
) ;
806 delete[] userLengths
;
809 if ( fill
&& stroke
)
810 m_mode
= kCGPathFillStroke
;
814 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
817 if ( m_cgContext
== NULL
)
820 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
821 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
824 // we can benchmark performance, should go into a setting later
825 CGContextSetShouldAntialias( m_cgContext
, false ) ;
828 if ( fill
|| stroke
)
831 m_mode
= kCGPathFill
; // just a default
835 if ( brush
.GetStyle() == wxSOLID
)
837 CGContextSetRGBFillColor( m_cgContext
, brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
838 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 ) ;
840 else if ( brush
.IsHatch() )
842 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
843 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
844 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
846 CGFloat colorArray
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
847 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
849 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
853 // now brush is a bitmap
854 CGFloat alphaArray
[1] = { 1.0 } ;
855 wxBitmap
* bmp
= brush
.GetStipple() ;
856 if ( bmp
&& bmp
->Ok() )
858 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
859 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
860 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
861 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
865 m_mode
= kCGPathFill
;
868 if ( fill
&& stroke
)
869 m_mode
= kCGPathFillStroke
;
871 m_mode
= kCGPathStroke
;
875 void wxMacCGContext::DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
)
877 OSStatus status
= noErr
;
878 ATSUTextLayout atsuLayout
;
879 UniCharCount chars
= str
.length() ;
880 UniChar
* ubuf
= NULL
;
882 #if SIZEOF_WCHAR_T == 4
883 wxMBConvUTF16 converter
;
885 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
886 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
887 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
889 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
890 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
891 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
892 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
894 chars
= unicharlen
/ 2 ;
897 ubuf
= (UniChar
*) str
.wc_str() ;
899 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
900 chars
= wxWcslen( wchar
.data() ) ;
901 ubuf
= (UniChar
*) wchar
.data() ;
905 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
906 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
908 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
910 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
911 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
913 int iAngle
= int( angle
);
914 if ( abs(iAngle
) > 0 )
916 Fixed atsuAngle
= IntToFixed( iAngle
) ;
917 ATSUAttributeTag atsuTags
[] =
919 kATSULineRotationTag
,
921 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
925 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
929 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
930 atsuTags
, atsuSizes
, atsuValues
) ;
934 ATSUAttributeTag atsuTags
[] =
938 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
940 sizeof( CGContextRef
) ,
942 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
946 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
947 atsuTags
, atsuSizes
, atsuValues
) ;
950 ATSUTextMeasurement textBefore
, textAfter
;
951 ATSUTextMeasurement ascent
, descent
;
953 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
954 &textBefore
, &textAfter
, &ascent
, &descent
);
956 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
961 if ( m_backgroundMode == wxSOLID )
963 wxGraphicPath* path = m_graphicContext->CreatePath() ;
964 path->MoveToPoint( drawX , drawY ) ;
965 path->AddLineToPoint(
966 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ,
967 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ;
968 path->AddLineToPoint(
969 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
970 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
971 path->AddLineToPoint(
972 (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
973 (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
975 m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
979 x
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
980 y
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
982 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
983 IntToFixed(x
) , IntToFixed(y
) , &rect
);
984 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
986 CGContextSaveGState(m_cgContext
);
987 CGContextTranslateCTM(m_cgContext
, x
, y
);
988 CGContextScaleCTM(m_cgContext
, 1, -1);
989 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
990 IntToFixed(0) , IntToFixed(0) );
992 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
994 CGContextRestoreGState(m_cgContext
) ;
996 ::ATSUDisposeTextLayout(atsuLayout
);
998 #if SIZEOF_WCHAR_T == 4
1003 void wxMacCGContext::GetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1004 wxCoord
*descent
, wxCoord
*externalLeading
) const
1006 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1008 OSStatus status
= noErr
;
1010 ATSUTextLayout atsuLayout
;
1011 UniCharCount chars
= str
.length() ;
1012 UniChar
* ubuf
= NULL
;
1014 #if SIZEOF_WCHAR_T == 4
1015 wxMBConvUTF16 converter
;
1017 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1018 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1019 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1021 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1022 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1023 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1024 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1026 chars
= unicharlen
/ 2 ;
1029 ubuf
= (UniChar
*) str
.wc_str() ;
1031 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1032 chars
= wxWcslen( wchar
.data() ) ;
1033 ubuf
= (UniChar
*) wchar
.data() ;
1037 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1038 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1040 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1042 ATSUTextMeasurement textBefore
, textAfter
;
1043 ATSUTextMeasurement textAscent
, textDescent
;
1045 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1046 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1049 *height
= FixedToInt(textAscent
+ textDescent
) ;
1051 *descent
= FixedToInt(textDescent
) ;
1052 if ( externalLeading
)
1053 *externalLeading
= 0 ;
1055 *width
= FixedToInt(textAfter
- textBefore
) ;
1057 ::ATSUDisposeTextLayout(atsuLayout
);
1060 void wxMacCGContext::GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1063 widths
.Add(0, text
.length());
1068 ATSUTextLayout atsuLayout
;
1069 UniCharCount chars
= text
.length() ;
1070 UniChar
* ubuf
= NULL
;
1072 #if SIZEOF_WCHAR_T == 4
1073 wxMBConvUTF16 converter
;
1075 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1076 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1077 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1079 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1080 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1081 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1082 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1084 chars
= unicharlen
/ 2 ;
1087 ubuf
= (UniChar
*) text
.wc_str() ;
1089 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1090 chars
= wxWcslen( wchar
.data() ) ;
1091 ubuf
= (UniChar
*) wchar
.data() ;
1095 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1096 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1098 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1100 unsigned long actualNumberOfBounds
= 0;
1101 ATSTrapezoid glyphBounds
;
1103 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1105 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1106 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1107 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1110 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1111 //unsigned char uch = s[i];
1114 ::ATSUDisposeTextLayout(atsuLayout
);
1117 void wxMacCGContext::SetFont( const wxFont
&font
)
1119 if ( m_macATSUIStyle
)
1121 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1122 m_macATSUIStyle
= NULL
;
1129 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1131 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1133 // we need the scale here ...
1135 Fixed atsuSize
= IntToFixed( int( /*m_scaleY*/ 1 * font
.MacGetFontSize()) ) ;
1136 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColor
.GetPixel() ) ;
1137 ATSUAttributeTag atsuTags
[] =
1142 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1145 sizeof( RGBColor
) ,
1147 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1153 status
= ::ATSUSetAttributes(
1154 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
1155 atsuTags
, atsuSizes
, atsuValues
);
1157 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
1168 m_mm_to_pix_x
= mm2pt
;
1169 m_mm_to_pix_y
= mm2pt
;
1171 m_externalDeviceOriginX
= 0;
1172 m_externalDeviceOriginY
= 0;
1173 m_logicalScaleX
= 1.0;
1174 m_logicalScaleY
= 1.0;
1179 m_needComputeScaleX
=
1180 m_needComputeScaleY
= false;
1183 m_macLocalOrigin
.x
=
1184 m_macLocalOrigin
.y
= 0 ;
1186 m_pen
= *wxBLACK_PEN
;
1187 m_font
= *wxNORMAL_FONT
;
1188 m_brush
= *wxWHITE_BRUSH
;
1190 m_macATSUIStyle
= NULL
;
1191 m_graphicContext
= NULL
;
1196 if ( m_macATSUIStyle
)
1198 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1199 m_macATSUIStyle
= NULL
;
1202 delete m_graphicContext
;
1205 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
1207 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
1208 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
1210 wxCoord xx
= XLOG2DEVMAC(x
);
1211 wxCoord yy
= YLOG2DEVMAC(y
);
1212 wxCoord w
= bmp
.GetWidth();
1213 wxCoord h
= bmp
.GetHeight();
1214 wxCoord ww
= XLOG2DEVREL(w
);
1215 wxCoord hh
= YLOG2DEVREL(h
);
1217 if ( bmp
.GetDepth()==1 )
1219 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1220 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1221 m_graphicContext
->FillPath( path
, m_textBackgroundColour
, wxODDEVEN_RULE
) ;
1223 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
) ;
1227 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
) ;
1231 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1233 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
1234 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
1236 wxCoord xx
= XLOG2DEVMAC(x
);
1237 wxCoord yy
= YLOG2DEVMAC(y
);
1238 wxCoord w
= icon
.GetWidth();
1239 wxCoord h
= icon
.GetHeight();
1240 wxCoord ww
= XLOG2DEVREL(w
);
1241 wxCoord hh
= YLOG2DEVREL(h
);
1243 m_graphicContext
->DrawIcon( icon
, xx
, yy
, ww
, hh
) ;
1246 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1248 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
1250 wxCoord xx
, yy
, ww
, hh
;
1251 xx
= XLOG2DEVMAC(x
);
1252 yy
= YLOG2DEVMAC(y
);
1253 ww
= XLOG2DEVREL(width
);
1254 hh
= YLOG2DEVREL(height
);
1256 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1257 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
1258 CGContextClipToRect( cgContext
, clipRect
) ;
1260 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
1261 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1265 m_clipX1
= wxMax( m_clipX1
, xx
);
1266 m_clipY1
= wxMax( m_clipY1
, yy
);
1267 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1268 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1280 // TODO: as soon as we don't reset the context for each operation anymore
1281 // we have to update the context as well
1284 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1286 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
1290 DestroyClippingRegion();
1295 region
.GetBox( x
, y
, w
, h
);
1296 wxCoord xx
, yy
, ww
, hh
;
1297 xx
= XLOG2DEVMAC(x
);
1298 yy
= YLOG2DEVMAC(y
);
1299 ww
= XLOG2DEVREL(w
);
1300 hh
= YLOG2DEVREL(h
);
1302 // if we have a scaling that we cannot map onto native regions
1303 // we must use the box
1304 if ( ww
!= w
|| hh
!= h
)
1306 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
1311 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
1312 if ( xx
!= x
|| yy
!= y
)
1313 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
1314 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
1319 m_clipX1
= wxMax( m_clipX1
, xx
);
1320 m_clipY1
= wxMax( m_clipY1
, yy
);
1321 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1322 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1336 void wxDC::DestroyClippingRegion()
1338 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1340 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1341 CGContextRestoreGState( cgContext
);
1342 CGContextSaveGState( cgContext
);
1344 m_graphicContext
->SetPen( m_pen
) ;
1345 m_graphicContext
->SetBrush( m_brush
) ;
1350 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1356 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
1358 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1361 void wxDC::SetTextForeground( const wxColour
&col
)
1363 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1365 if ( col
!= m_textForegroundColour
)
1367 m_textForegroundColour
= col
;
1368 m_graphicContext
->SetTextColor( col
);
1369 // in the current implementation the font contains the text color
1370 m_graphicContext
->SetFont(m_font
);
1374 void wxDC::SetTextBackground( const wxColour
&col
)
1376 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1378 m_textBackgroundColour
= col
;
1381 void wxDC::SetMapMode( int mode
)
1386 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1390 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1394 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1398 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1403 SetLogicalScale( 1.0, 1.0 );
1407 if (mode
!= wxMM_TEXT
)
1409 m_needComputeScaleX
=
1410 m_needComputeScaleY
= true;
1414 void wxDC::SetUserScale( double x
, double y
)
1416 // allow negative ? -> no
1419 ComputeScaleAndOrigin();
1422 void wxDC::SetLogicalScale( double x
, double y
)
1425 m_logicalScaleX
= x
;
1426 m_logicalScaleY
= y
;
1427 ComputeScaleAndOrigin();
1430 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1432 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1433 m_logicalOriginY
= y
* m_signY
;
1434 ComputeScaleAndOrigin();
1437 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1439 m_externalDeviceOriginX
= x
;
1440 m_externalDeviceOriginY
= y
;
1441 ComputeScaleAndOrigin();
1444 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1446 m_signX
= (xLeftRight
? 1 : -1);
1447 m_signY
= (yBottomUp
? -1 : 1);
1448 ComputeScaleAndOrigin();
1451 wxSize
wxDC::GetPPI() const
1453 return wxSize(72, 72);
1456 int wxDC::GetDepth() const
1461 void wxDC::ComputeScaleAndOrigin()
1463 // CMB: copy scale to see if it changes
1464 double origScaleX
= m_scaleX
;
1465 double origScaleY
= m_scaleY
;
1466 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1467 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1468 m_deviceOriginX
= m_externalDeviceOriginX
;
1469 m_deviceOriginY
= m_externalDeviceOriginY
;
1471 // CMB: if scale has changed call SetPen to recalulate the line width
1472 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1474 // this is a bit artificial, but we need to force wxDC to think
1475 // the pen has changed
1476 wxPen
pen( GetPen() );
1483 void wxDC::SetPalette( const wxPalette
& palette
)
1487 void wxDC::SetBackgroundMode( int mode
)
1489 m_backgroundMode
= mode
;
1492 void wxDC::SetFont( const wxFont
&font
)
1495 if ( m_graphicContext
)
1496 m_graphicContext
->SetFont( font
) ;
1499 void wxDC::SetPen( const wxPen
&pen
)
1505 if ( m_graphicContext
)
1507 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1509 m_graphicContext
->SetPen( m_pen
) ;
1513 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1514 // eg when using a wxScrollWindow and scrolling around
1515 int origX
= XLOG2DEVMAC( 0 ) ;
1516 int origY
= YLOG2DEVMAC( 0 ) ;
1517 m_graphicContext
->Translate( origX
, origY
) ;
1518 m_graphicContext
->SetPen( m_pen
) ;
1519 m_graphicContext
->Translate( -origX
, -origY
) ;
1524 void wxDC::SetBrush( const wxBrush
&brush
)
1526 if (m_brush
== brush
)
1530 if ( m_graphicContext
)
1532 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1534 m_graphicContext
->SetBrush( m_brush
) ;
1538 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1539 // eg when using a wxScrollWindow and scrolling around
1540 int origX
= XLOG2DEVMAC(0) ;
1541 int origY
= YLOG2DEVMAC(0) ;
1542 m_graphicContext
->Translate( origX
, origY
) ;
1543 m_graphicContext
->SetBrush( m_brush
) ;
1544 m_graphicContext
->Translate( -origX
, -origY
) ;
1549 void wxDC::SetBackground( const wxBrush
&brush
)
1551 if (m_backgroundBrush
== brush
)
1554 m_backgroundBrush
= brush
;
1555 if (!m_backgroundBrush
.Ok())
1559 void wxDC::SetLogicalFunction( int function
)
1561 if (m_logicalFunction
== function
)
1564 m_logicalFunction
= function
;
1565 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1566 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1567 if ( m_logicalFunction
== wxCOPY
)
1568 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1569 else if ( m_logicalFunction
== wxINVERT
)
1570 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1572 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1576 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1577 const wxColour
& col
, int style
);
1579 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1580 const wxColour
& col
, int style
)
1582 return wxDoFloodFill(this, x
, y
, col
, style
);
1585 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1587 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1591 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1592 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1594 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1595 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1597 // convert from Mac colour to wx
1598 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1603 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1605 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1607 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1608 if ( m_logicalFunction
!= wxCOPY
)
1612 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1613 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1614 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1615 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1617 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1618 path
->MoveToPoint( xx1
, yy1
) ;
1619 path
->AddLineToPoint( xx2
, yy2
) ;
1620 path
->CloseSubpath() ;
1621 m_graphicContext
->StrokePath( path
) ;
1624 CalcBoundingBox(x1
, y1
);
1625 CalcBoundingBox(x2
, y2
);
1628 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1630 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1632 if ( m_logicalFunction
!= wxCOPY
)
1638 wxCoord xx
= XLOG2DEVMAC(x
);
1639 wxCoord yy
= YLOG2DEVMAC(y
);
1641 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1642 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1643 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1644 path
->CloseSubpath() ;
1645 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1646 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1647 path
->CloseSubpath() ;
1648 m_graphicContext
->StrokePath( path
) ;
1651 CalcBoundingBox(x
, y
);
1652 CalcBoundingBox(x
+ w
, y
+ h
);
1655 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1656 wxCoord x2
, wxCoord y2
,
1657 wxCoord xc
, wxCoord yc
)
1659 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1661 if ( m_logicalFunction
!= wxCOPY
)
1664 wxCoord xx1
= XLOG2DEVMAC(x1
);
1665 wxCoord yy1
= YLOG2DEVMAC(y1
);
1666 wxCoord xx2
= XLOG2DEVMAC(x2
);
1667 wxCoord yy2
= YLOG2DEVMAC(y2
);
1668 wxCoord xxc
= XLOG2DEVMAC(xc
);
1669 wxCoord yyc
= YLOG2DEVMAC(yc
);
1671 double dx
= xx1
- xxc
;
1672 double dy
= yy1
- yyc
;
1673 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1674 wxCoord rad
= (wxCoord
)radius
;
1676 if (xx1
== xx2
&& yy1
== yy2
)
1681 else if (radius
== 0.0)
1687 sa
= (xx1
- xxc
== 0) ?
1688 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1689 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1690 ea
= (xx2
- xxc
== 0) ?
1691 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1692 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1695 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1697 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1698 m_graphicContext
->PushState() ;
1699 m_graphicContext
->Translate( xxc
, yyc
) ;
1700 m_graphicContext
->Scale( 1, -1 ) ;
1702 path
->MoveToPoint( 0, 0 ) ;
1703 path
->AddArc( 0, 0, rad
, DegToRad(sa
) , DegToRad(ea
), false ) ;
1705 path
->AddLineToPoint( 0, 0 ) ;
1706 m_graphicContext
->DrawPath( path
) ;
1707 m_graphicContext
->PopState() ;
1711 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1712 double sa
, double ea
)
1714 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1716 if ( m_logicalFunction
!= wxCOPY
)
1719 wxCoord xx
= XLOG2DEVMAC(x
);
1720 wxCoord yy
= YLOG2DEVMAC(y
);
1721 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1722 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1724 // handle -ve width and/or height
1736 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1738 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1739 m_graphicContext
->PushState() ;
1740 m_graphicContext
->Translate( xx
+ ww
/ 2, yy
+ hh
/ 2 ) ;
1741 m_graphicContext
->Scale( 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1743 path
->MoveToPoint( 0, 0 ) ;
1744 path
->AddArc( 0, 0, 1 , DegToRad(sa
) , DegToRad(ea
), false ) ;
1746 path
->AddLineToPoint( 0, 0 ) ;
1747 m_graphicContext
->DrawPath( path
) ;
1748 m_graphicContext
->PopState() ;
1752 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1754 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1756 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1759 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1760 wxCoord xoffset
, wxCoord yoffset
)
1762 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1764 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1765 if ( m_logicalFunction
!= wxCOPY
)
1769 wxCoord x1
, x2
, y1
, y2
;
1770 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1771 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1772 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1773 path
->MoveToPoint( x1
, y1
) ;
1774 for (int i
= 1; i
< n
; i
++)
1776 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1777 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1779 path
->AddLineToPoint( x2
, y2
) ;
1782 m_graphicContext
->StrokePath( path
) ;
1787 void wxDC::DoDrawSpline(wxList
*points
)
1789 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1791 if ( m_logicalFunction
!= wxCOPY
)
1794 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1796 wxList::compatibility_iterator node
= points
->GetFirst();
1797 if (node
== wxList::compatibility_iterator())
1801 wxPoint
*p
= (wxPoint
*)node
->GetData();
1806 node
= node
->GetNext();
1807 p
= (wxPoint
*)node
->GetData();
1811 wxCoord cx1
= ( x1
+ x2
) / 2;
1812 wxCoord cy1
= ( y1
+ y2
) / 2;
1814 path
->MoveToPoint( XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ) ;
1815 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , YLOG2DEVMAC( cy1
) ) ;
1818 while ((node
= node
->GetNext()) != NULL
)
1820 while ((node
= node
->GetNext()))
1821 #endif // !wxUSE_STL
1823 p
= (wxPoint
*)node
->GetData();
1828 wxCoord cx4
= (x1
+ x2
) / 2;
1829 wxCoord cy4
= (y1
+ y2
) / 2;
1831 path
->AddQuadCurveToPoint(
1832 XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ,
1833 XLOG2DEVMAC( cx4
) , YLOG2DEVMAC( cy4
) ) ;
1839 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , YLOG2DEVMAC( y2
) ) ;
1841 m_graphicContext
->StrokePath( path
) ;
1846 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1847 wxCoord xoffset
, wxCoord yoffset
,
1850 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1852 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1854 if ( m_logicalFunction
!= wxCOPY
)
1857 wxCoord x1
, x2
, y1
, y2
;
1858 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1859 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1861 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1862 path
->MoveToPoint( x1
, y1
) ;
1863 for (int i
= 1; i
< n
; i
++)
1865 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1866 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1868 path
->AddLineToPoint( x2
, y2
) ;
1871 if ( x1
!= x2
|| y1
!= y2
)
1872 path
->AddLineToPoint( x1
, y1
) ;
1874 path
->CloseSubpath() ;
1875 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1880 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1882 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1884 if ( m_logicalFunction
!= wxCOPY
)
1887 wxCoord xx
= XLOG2DEVMAC(x
);
1888 wxCoord yy
= YLOG2DEVMAC(y
);
1889 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1890 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1892 // CMB: draw nothing if transformed w or h is 0
1893 if (ww
== 0 || hh
== 0)
1896 // CMB: handle -ve width and/or height
1908 int penwidth
= m_pen
.GetWidth();
1909 if ( penwidth
== 0 )
1911 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
1914 bool offset
= ( penwidth
% 2 ) == 1 ;
1916 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1917 // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1
1919 path
->AddRectangle( xx
, yy
, ww
-1 , hh
-1 ) ;
1921 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1923 m_graphicContext
->DrawPath( path
) ;
1927 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1928 wxCoord width
, wxCoord height
,
1931 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1933 if ( m_logicalFunction
!= wxCOPY
)
1937 radius
= - radius
* ((width
< height
) ? width
: height
);
1938 wxCoord xx
= XLOG2DEVMAC(x
);
1939 wxCoord yy
= YLOG2DEVMAC(y
);
1940 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1941 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1943 // CMB: draw nothing if transformed w or h is 0
1944 if (ww
== 0 || hh
== 0)
1947 // CMB: handle -ve width and/or height
1959 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1962 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1963 m_graphicContext
->DrawPath( path
) ;
1967 path
->MoveToPoint( xx
+ ww
, yy
+ hh
/ 2);
1968 path
->AddArcToPoint(xx
+ ww
, yy
+ hh
, xx
+ ww
/ 2,yy
+ hh
, radius
);
1969 path
->AddArcToPoint(xx
, yy
+ hh
, xx
, yy
+ hh
/ 2, radius
);
1970 path
->AddArcToPoint(xx
, yy
, xx
+ ww
/ 2, yy
, radius
);
1971 path
->AddArcToPoint(xx
+ ww
, yy
, xx
+ ww
, yy
+ hh
/ 2, radius
);
1972 path
->CloseSubpath();
1973 m_graphicContext
->DrawPath( path
) ;
1978 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1980 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1982 if ( m_logicalFunction
!= wxCOPY
)
1985 wxCoord xx
= XLOG2DEVMAC(x
);
1986 wxCoord yy
= YLOG2DEVMAC(y
);
1987 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1988 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1990 // CMB: draw nothing if transformed w or h is 0
1991 if (ww
== 0 || hh
== 0)
1994 // CMB: handle -ve width and/or height
2006 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
2007 m_graphicContext
->PushState() ;
2008 m_graphicContext
->Translate(xx
+ ww
/ 2, yy
+ hh
/ 2);
2009 m_graphicContext
->Scale(ww
/ 2 , hh
/ 2);
2010 path
->AddArc( 0, 0, 1, 0 , 2 * M_PI
, false ) ;
2011 m_graphicContext
->DrawPath( path
) ;
2012 m_graphicContext
->PopState() ;
2016 bool wxDC::CanDrawBitmap() const
2022 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
2023 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
2024 wxCoord xsrcMask
, wxCoord ysrcMask
)
2026 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
2027 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
2029 if ( logical_func
== wxNO_OP
)
2032 if (xsrcMask
== -1 && ysrcMask
== -1)
2038 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
2039 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
2040 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
2041 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
2043 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
2044 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
2045 wxCoord wwdest
= XLOG2DEVREL(width
) ;
2046 wxCoord hhdest
= YLOG2DEVREL(height
) ;
2048 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
2049 if ( memdc
&& logical_func
== wxCOPY
)
2051 wxBitmap blit
= memdc
->GetSelectedObject() ;
2053 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
2055 wxCoord bmpwidth
= blit
.GetWidth();
2056 wxCoord bmpheight
= blit
.GetHeight();
2058 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
2060 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
2061 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
2062 if ( wwsrc
> 0 && hhsrc
> 0 )
2064 if ( xxsrc
>= 0 && yysrc
>= 0 )
2066 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
2067 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
2068 blit
= blit
.GetSubBitmap( subrect
) ;
2072 // in this case we'd probably have to adjust the different coordinates, but
2073 // we have to find out proper contract first
2074 blit
= wxNullBitmap
;
2079 blit
= wxNullBitmap
;
2085 m_graphicContext
->DrawBitmap( blit
, xxdest
, yydest
, wwdest
, hhdest
) ;
2090 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ;
2097 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
2100 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
2101 // wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
2103 if ( str
.length() == 0 )
2105 if ( m_logicalFunction
!= wxCOPY
)
2108 int drawX
= XLOG2DEVMAC(x
) ;
2109 int drawY
= YLOG2DEVMAC(y
) ;
2111 m_graphicContext
->DrawText( str
, drawX
,drawY
, angle
) ;
2114 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
2116 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
2118 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
2121 bool wxDC::CanGetTextExtent() const
2123 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
2128 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
2129 wxCoord
*descent
, wxCoord
*externalLeading
,
2130 wxFont
*theFont
) const
2132 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
2136 m_graphicContext
->SetFont( *theFont
) ;
2139 wxCoord h
, d
, e
, w
;
2141 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
) ;
2144 *height
= YDEV2LOGREL( h
) ;
2146 *descent
=YDEV2LOGREL( d
);
2147 if ( externalLeading
)
2148 *externalLeading
= YDEV2LOGREL( e
);
2150 *width
= XDEV2LOGREL( w
) ;
2154 m_graphicContext
->SetFont( m_font
) ;
2158 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
2160 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
2162 m_graphicContext
->GetPartialTextExtents( text
, widths
) ;
2163 for ( size_t i
= 0 ; i
< widths
.GetCount() ; ++i
)
2164 widths
[i
] = XDEV2LOGREL( widths
[i
] );
2169 wxCoord
wxDC::GetCharWidth(void) const
2172 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2177 wxCoord
wxDC::GetCharHeight(void) const
2180 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2185 void wxDC::Clear(void)
2187 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2189 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2191 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2192 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2193 switch ( m_backgroundBrush
.MacGetBrushKind() )
2195 case kwxMacBrushTheme
:
2197 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2198 if ( HIThemeSetFill
!= 0 )
2200 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2201 CGContextFillRect(cg
, rect
);
2208 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2209 CGContextSetRGBFillColor( cg
, (CGFloat
) color
.red
/ 65536,
2210 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 );
2211 CGContextFillRect( cg
, rect
);
2214 // reset to normal value
2215 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2216 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2220 case kwxMacBrushThemeBackground
:
2222 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2224 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2225 if ( UMAGetSystemVersion() >= 0x1030 )
2227 HIThemeBackgroundDrawInfo drawInfo
;
2228 drawInfo
.version
= 0 ;
2229 drawInfo
.state
= kThemeStateActive
;
2230 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2231 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2233 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2234 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2241 case kwxMacBrushColour
:
2243 // FIXME: doesn't correctly render stippled brushes !!
2244 // FIXME: should this be replaced by ::SetBrush() ??
2246 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2247 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2248 CGContextFillRect(cg
, rect
);
2250 // reset to normal value
2251 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2252 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2257 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2265 // ---------------------------------------------------------------------------
2266 // coordinates transformations
2267 // ---------------------------------------------------------------------------
2269 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2271 return ((wxDC
*)this)->XDEV2LOG(x
);
2274 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2276 return ((wxDC
*)this)->YDEV2LOG(y
);
2279 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2281 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2284 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2286 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2289 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2291 return ((wxDC
*)this)->XLOG2DEV(x
);
2294 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2296 return ((wxDC
*)this)->YLOG2DEV(y
);
2299 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2301 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2304 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2306 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2309 #endif // wxMAC_USE_CORE_GRAPHICS