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
;
70 // The textctrl implementation still needs that (needs what?) for the non-HIView implementation
72 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
73 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
75 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
76 m_formerClip
= NewRgn() ;
77 m_newClip
= NewRgn() ;
78 GetClip( m_formerClip
) ;
82 // guard against half constructed objects, this just leads to a empty clip
86 win
->MacWindowToRootWindow( &x
, &y
) ;
88 // get area including focus rect
89 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
90 if ( !EmptyRgn( m_newClip
) )
91 OffsetRgn( m_newClip
, x
, y
) ;
94 SetClip( m_newClip
) ;
98 wxMacWindowClipper::~wxMacWindowClipper()
100 SetPort( m_newPort
) ;
101 SetClip( m_formerClip
) ;
102 DisposeRgn( m_newClip
) ;
103 DisposeRgn( m_formerClip
) ;
106 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
107 wxMacWindowClipper( win
)
109 // the port is already set at this point
110 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
111 GetThemeDrawingState( &m_themeDrawingState
) ;
114 wxMacWindowStateSaver::~wxMacWindowStateSaver()
116 SetPort( m_newPort
) ;
117 SetThemeDrawingState( m_themeDrawingState
, true ) ;
120 // minimal implementation only used for appearance drawing < 10.3
122 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
123 m_ph( (GrafPtr
) dc
->m_macPort
)
125 wxASSERT( dc
->Ok() ) ;
128 // dc->MacSetupPort(&m_ph) ;
131 wxMacPortSetter::~wxMacPortSetter()
133 // m_dc->MacCleanupPort(&m_ph) ;
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
141 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
142 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
143 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
145 //-----------------------------------------------------------------------------
146 // device context implementation
148 // more and more of the dc functionality should be implemented by calling
149 // the appropricate wxMacCGContext, but we will have to do that step by step
150 // also coordinate conversions should be moved to native matrix ops
151 //-----------------------------------------------------------------------------
153 // we always stock two context states, one at entry, to be able to preserve the
154 // state we were called with, the other one after changing to HI Graphics orientation
155 // (this one is used for getting back clippings etc)
157 //-----------------------------------------------------------------------------
158 // wxGraphicPath implementation
159 //-----------------------------------------------------------------------------
161 wxMacCGPath::wxMacCGPath()
163 m_path
= CGPathCreateMutable() ;
166 wxMacCGPath::~wxMacCGPath()
168 CGPathRelease( m_path
) ;
171 // opens (starts) a new subpath
172 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
174 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
177 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
179 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
182 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
184 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
187 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
189 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
190 CGPathAddRect( m_path
, NULL
, cgRect
) ;
193 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
195 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
198 // closes the current subpath
199 void wxMacCGPath::CloseSubpath()
201 CGPathCloseSubpath( m_path
) ;
204 CGPathRef
wxMacCGPath::GetPath() const
209 void wxMacCGPath::AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
)
211 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
214 void wxMacCGPath::AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
)
216 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, clockwise
);
219 //-----------------------------------------------------------------------------
220 // wxGraphicContext implementation
221 //-----------------------------------------------------------------------------
223 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
227 m_mode
= kCGPathFill
;
228 m_macATSUIStyle
= NULL
;
231 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
234 m_cgContext
= cgcontext
;
235 m_mode
= kCGPathFill
;
236 m_macATSUIStyle
= NULL
;
237 CGContextSaveGState( m_cgContext
) ;
238 CGContextSaveGState( m_cgContext
) ;
241 wxMacCGContext::wxMacCGContext()
245 m_mode
= kCGPathFill
;
246 m_macATSUIStyle
= NULL
;
249 wxMacCGContext::~wxMacCGContext()
253 CGContextSynchronize( m_cgContext
) ;
254 CGContextRestoreGState( m_cgContext
) ;
255 CGContextRestoreGState( m_cgContext
) ;
259 QDEndCGContext( m_qdPort
, &m_cgContext
) ;
264 void wxMacCGContext::Clip( const wxRegion
®ion
)
266 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
269 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
271 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
273 int width
= m_pen
.GetWidth();
276 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
279 bool offset
= ( width
% 2 ) == 1 ;
282 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
284 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
285 CGContextStrokePath( m_cgContext
) ;
288 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
291 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
293 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
294 CGPathDrawingMode mode
= m_mode
;
296 if ( fillStyle
== wxODDEVEN_RULE
)
298 if ( mode
== kCGPathFill
)
299 mode
= kCGPathEOFill
;
300 else if ( mode
== kCGPathFillStroke
)
301 mode
= kCGPathEOFillStroke
;
304 int width
= m_pen
.GetWidth();
307 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
310 bool offset
= ( width
% 2 ) == 1 ;
313 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
315 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
316 CGContextDrawPath( m_cgContext
, mode
) ;
319 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
322 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
324 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
325 CGContextSaveGState( m_cgContext
) ;
327 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
328 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
329 CGPathDrawingMode mode
= kCGPathFill
;
331 if ( fillStyle
== wxODDEVEN_RULE
)
332 mode
= kCGPathEOFill
;
334 CGContextBeginPath( m_cgContext
) ;
335 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
336 CGContextClosePath( m_cgContext
) ;
337 CGContextDrawPath( m_cgContext
, mode
) ;
339 CGContextRestoreGState( m_cgContext
) ;
342 wxGraphicPath
* wxMacCGContext::CreatePath()
344 // make sure that we now have a real cgref, before doing
345 // anything with paths
346 CGContextRef cg
= GetNativeContext() ;
349 return new wxMacCGPath() ;
352 // in case we only got a QDPort only create a cgref now
354 CGContextRef
wxMacCGContext::GetNativeContext()
356 if ( m_cgContext
== NULL
)
359 OSStatus status
= noErr
;
361 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
362 status
= QDBeginCGContext((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
364 CGContextSaveGState( m_cgContext
) ;
366 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
368 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
369 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
371 CGContextSaveGState( m_cgContext
) ;
373 SetBrush( m_brush
) ;
379 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
381 // we allow either setting or clearing but not replacing
382 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
385 CGContextSaveGState( cg
) ;
389 void wxMacCGContext::Translate( wxCoord dx
, wxCoord dy
)
391 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
394 void wxMacCGContext::Scale( wxCoord xScale
, wxCoord yScale
)
396 CGContextScaleCTM( m_cgContext
, xScale
, yScale
) ;
399 void wxMacCGContext::DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
401 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
402 HIRect r
= CGRectMake( 0 , 0 , w
, h
);
404 CGContextSaveGState( m_cgContext
);
405 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
406 CGContextScaleCTM( m_cgContext
, 1, -1 );
408 // in case image is a mask, set the foreground color
409 CGContextSetRGBFillColor( m_cgContext
, m_textForegroundColor
.Red() / 255.0 , m_textForegroundColor
.Green() / 255.0 ,
410 m_textForegroundColor
.Blue() / 255.0 , m_textForegroundColor
.Alpha() / 255.0 ) ;
411 CGContextDrawImage( m_cgContext
, r
, image
);
412 CGContextRestoreGState( m_cgContext
);
414 CGImageRelease( image
) ;
417 void wxMacCGContext::DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
419 CGRect r
= CGRectMake( 0 , 0 , w
, h
) ;
420 CGContextSaveGState( m_cgContext
);
421 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
422 CGContextScaleCTM( m_cgContext
, 1, -1 );
423 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
424 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
425 CGContextRestoreGState( m_cgContext
) ;
428 void wxMacCGContext::PushState()
430 CGContextSaveGState( m_cgContext
);
433 void wxMacCGContext::PopState()
435 CGContextRestoreGState( m_cgContext
);
438 void wxMacCGContext::SetTextColor( const wxColour
&col
)
440 m_textForegroundColor
= col
;
444 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
446 // CGPattern wrapper class: always allocate on heap, never call destructor
453 // is guaranteed to be called only with a non-Null CGContextRef
454 virtual void Render( CGContextRef ctxRef
) = 0 ;
456 operator CGPatternRef() const { return m_patternRef
; }
459 virtual ~wxMacCGPattern()
461 // as this is called only when the m_patternRef is been released;
462 // don't release it again
465 static void _Render( void *info
, CGContextRef ctxRef
)
467 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
468 if ( self
&& ctxRef
)
469 self
->Render( ctxRef
) ;
472 static void _Dispose( void *info
)
474 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
478 CGPatternRef m_patternRef
;
480 static const CGPatternCallbacks ms_Callbacks
;
483 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
485 class ImagePattern
: public wxMacCGPattern
488 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
490 wxASSERT( bmp
&& bmp
->Ok() ) ;
492 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
495 // ImagePattern takes ownership of CGImageRef passed in
496 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
501 Init( image
, transform
) ;
504 virtual void Render( CGContextRef ctxRef
)
507 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
511 void Init( CGImageRef image
, CGAffineTransform transform
)
516 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) ) ;
517 m_patternRef
= CGPatternCreate(
518 this , m_imageBounds
, transform
,
519 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
520 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
524 virtual ~ImagePattern()
527 CGImageRelease( m_image
) ;
531 CGRect m_imageBounds
;
534 class HatchPattern
: public wxMacCGPattern
537 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
539 m_hatch
= hatchstyle
;
540 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
541 m_patternRef
= CGPatternCreate(
542 this , m_imageBounds
, transform
,
543 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
544 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
547 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
549 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
550 if ( UMAGetSystemVersion() >= 0x1040 )
552 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
557 CGContextBeginPath( ctxRef
);
558 for (size_t i
= 0; i
< count
; i
+= 2)
560 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
561 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
563 CGContextStrokePath(ctxRef
);
567 virtual void Render( CGContextRef ctxRef
)
571 case wxBDIAGONAL_HATCH
:
575 { 8.0 , 0.0 } , { 0.0 , 8.0 }
577 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
581 case wxCROSSDIAG_HATCH
:
585 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
586 { 8.0 , 0.0 } , { 0.0 , 8.0 }
588 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
592 case wxFDIAGONAL_HATCH
:
596 { 0.0 , 0.0 } , { 8.0 , 8.0 }
598 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
606 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
607 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
609 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
613 case wxHORIZONTAL_HATCH
:
617 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
619 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
623 case wxVERTICAL_HATCH
:
627 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
629 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
639 virtual ~HatchPattern() {}
641 CGRect m_imageBounds
;
647 void wxMacCGContext::SetPen( const wxPen
&pen
)
650 if ( m_cgContext
== NULL
)
653 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
654 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
657 // we can benchmark performance; should go into a setting eventually
658 CGContextSetShouldAntialias( m_cgContext
, false ) ;
664 m_mode
= kCGPathFill
; // just a default
668 CGContextSetRGBStrokeColor( m_cgContext
, pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
669 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 ) ;
671 // TODO: * m_dc->m_scaleX
672 CGFloat penWidth
= pen
.GetWidth();
675 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
678 switch ( pen
.GetCap() )
681 cap
= kCGLineCapRound
;
684 case wxCAP_PROJECTING
:
685 cap
= kCGLineCapSquare
;
689 cap
= kCGLineCapButt
;
693 cap
= kCGLineCapButt
;
698 switch ( pen
.GetJoin() )
701 join
= kCGLineJoinBevel
;
705 join
= kCGLineJoinMiter
;
709 join
= kCGLineJoinRound
;
713 join
= kCGLineJoinMiter
;
717 m_mode
= kCGPathStroke
;
720 const CGFloat
*lengths
= NULL
;
721 CGFloat
*userLengths
= NULL
;
723 const CGFloat dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
725 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
726 const CGFloat short_dashed
[] = { 9.0 , 6.0 };
727 const CGFloat dashed
[] = { 19.0 , 9.0 };
728 const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
730 switch ( pen
.GetStyle() )
737 count
= WXSIZEOF(dotted
);
742 count
= WXSIZEOF(dashed
) ;
746 lengths
= short_dashed
;
747 count
= WXSIZEOF(short_dashed
) ;
751 lengths
= dotted_dashed
;
752 count
= WXSIZEOF(dotted_dashed
);
757 count
= pen
.GetDashes( &dashes
) ;
758 if ((dashes
!= NULL
) && (count
> 0))
760 userLengths
= new CGFloat
[count
] ;
761 for ( int i
= 0 ; i
< count
; ++i
)
763 userLengths
[i
] = dashes
[i
] * dashUnit
;
765 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
766 userLengths
[i
] = dashUnit
+ 2.0 ;
767 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
768 userLengths
[i
] = dashUnit
;
771 lengths
= userLengths
;
776 CGFloat alphaArray
[1] = { 1.0 } ;
777 wxBitmap
* bmp
= pen
.GetStipple() ;
778 if ( bmp
&& bmp
->Ok() )
780 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
781 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
782 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
783 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
790 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
791 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
792 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
794 CGFloat colorArray
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
795 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
797 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
802 if ((lengths
!= NULL
) && (count
> 0))
804 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
805 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
806 cap
= kCGLineCapButt
;
810 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
813 CGContextSetLineCap( m_cgContext
, cap
) ;
814 CGContextSetLineJoin( m_cgContext
, join
) ;
816 delete[] userLengths
;
819 if ( fill
&& stroke
)
820 m_mode
= kCGPathFillStroke
;
824 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
827 if ( m_cgContext
== NULL
)
830 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
831 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
834 // we can benchmark performance, should go into a setting later
835 CGContextSetShouldAntialias( m_cgContext
, false ) ;
841 m_mode
= kCGPathFill
; // just a default
845 if ( brush
.GetStyle() == wxSOLID
)
847 CGContextSetRGBFillColor( m_cgContext
, brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
848 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 ) ;
850 else if ( brush
.IsHatch() )
852 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
853 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
854 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
856 CGFloat colorArray
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
857 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
859 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
863 // now brush is a bitmap
864 CGFloat alphaArray
[1] = { 1.0 } ;
865 wxBitmap
* bmp
= brush
.GetStipple() ;
866 if ( bmp
&& bmp
->Ok() )
868 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
869 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
870 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
871 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
875 m_mode
= kCGPathFill
;
878 if ( fill
&& stroke
)
879 m_mode
= kCGPathFillStroke
;
881 m_mode
= kCGPathStroke
;
885 void wxMacCGContext::DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
)
887 OSStatus status
= noErr
;
888 ATSUTextLayout atsuLayout
;
889 UniCharCount chars
= str
.length() ;
890 UniChar
* ubuf
= NULL
;
892 #if SIZEOF_WCHAR_T == 4
893 wxMBConvUTF16 converter
;
895 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
896 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
897 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
899 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
900 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
901 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
902 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
904 chars
= unicharlen
/ 2 ;
907 ubuf
= (UniChar
*) str
.wc_str() ;
909 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
910 chars
= wxWcslen( wchar
.data() ) ;
911 ubuf
= (UniChar
*) wchar
.data() ;
915 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
916 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
918 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
920 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
921 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
923 int iAngle
= int( angle
);
924 if ( abs(iAngle
) > 0 )
926 Fixed atsuAngle
= IntToFixed( iAngle
) ;
927 ATSUAttributeTag atsuTags
[] =
929 kATSULineRotationTag
,
931 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
935 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
939 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
940 atsuTags
, atsuSizes
, atsuValues
) ;
944 ATSUAttributeTag atsuTags
[] =
948 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
950 sizeof( CGContextRef
) ,
952 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
956 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
957 atsuTags
, atsuSizes
, atsuValues
) ;
960 ATSUTextMeasurement textBefore
, textAfter
;
961 ATSUTextMeasurement ascent
, descent
;
963 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
964 &textBefore
, &textAfter
, &ascent
, &descent
);
966 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
971 if ( m_backgroundMode == wxSOLID )
973 wxGraphicPath* path = m_graphicContext->CreatePath() ;
974 path->MoveToPoint( drawX , drawY ) ;
975 path->AddLineToPoint(
976 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ,
977 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ;
978 path->AddLineToPoint(
979 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
980 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
981 path->AddLineToPoint(
982 (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
983 (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
985 m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
989 x
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
990 y
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
992 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
993 IntToFixed(x
) , IntToFixed(y
) , &rect
);
994 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
996 CGContextSaveGState(m_cgContext
);
997 CGContextTranslateCTM(m_cgContext
, x
, y
);
998 CGContextScaleCTM(m_cgContext
, 1, -1);
999 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1000 IntToFixed(0) , IntToFixed(0) );
1002 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1004 CGContextRestoreGState(m_cgContext
) ;
1006 ::ATSUDisposeTextLayout(atsuLayout
);
1008 #if SIZEOF_WCHAR_T == 4
1013 void wxMacCGContext::GetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1014 wxCoord
*descent
, wxCoord
*externalLeading
) const
1016 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1018 OSStatus status
= noErr
;
1020 ATSUTextLayout atsuLayout
;
1021 UniCharCount chars
= str
.length() ;
1022 UniChar
* ubuf
= NULL
;
1024 #if SIZEOF_WCHAR_T == 4
1025 wxMBConvUTF16 converter
;
1027 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1028 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1029 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1031 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1032 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1033 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1034 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1036 chars
= unicharlen
/ 2 ;
1039 ubuf
= (UniChar
*) str
.wc_str() ;
1041 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1042 chars
= wxWcslen( wchar
.data() ) ;
1043 ubuf
= (UniChar
*) wchar
.data() ;
1047 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1048 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1050 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1052 ATSUTextMeasurement textBefore
, textAfter
;
1053 ATSUTextMeasurement textAscent
, textDescent
;
1055 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1056 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1059 *height
= FixedToInt(textAscent
+ textDescent
) ;
1061 *descent
= FixedToInt(textDescent
) ;
1062 if ( externalLeading
)
1063 *externalLeading
= 0 ;
1065 *width
= FixedToInt(textAfter
- textBefore
) ;
1067 ::ATSUDisposeTextLayout(atsuLayout
);
1070 void wxMacCGContext::GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1073 widths
.Add(0, text
.length());
1078 ATSUTextLayout atsuLayout
;
1079 UniCharCount chars
= text
.length() ;
1080 UniChar
* ubuf
= NULL
;
1082 #if SIZEOF_WCHAR_T == 4
1083 wxMBConvUTF16 converter
;
1085 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1086 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1087 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1089 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1090 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1091 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1092 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1094 chars
= unicharlen
/ 2 ;
1097 ubuf
= (UniChar
*) text
.wc_str() ;
1099 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1100 chars
= wxWcslen( wchar
.data() ) ;
1101 ubuf
= (UniChar
*) wchar
.data() ;
1106 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1107 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1109 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1111 unsigned long actualNumberOfBounds
= 0;
1112 ATSTrapezoid glyphBounds
;
1114 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1116 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1117 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1118 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1121 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1122 //unsigned char uch = s[i];
1125 ::ATSUDisposeTextLayout(atsuLayout
);
1128 void wxMacCGContext::SetFont( const wxFont
&font
)
1130 if ( m_macATSUIStyle
)
1132 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1133 m_macATSUIStyle
= NULL
;
1140 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1142 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1144 // we need the scale here ...
1146 Fixed atsuSize
= IntToFixed( int( /*m_scaleY*/ 1 * font
.MacGetFontSize()) ) ;
1147 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColor
.GetPixel() ) ;
1148 ATSUAttributeTag atsuTags
[] =
1153 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1156 sizeof( RGBColor
) ,
1158 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1164 status
= ::ATSUSetAttributes(
1165 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
1166 atsuTags
, atsuSizes
, atsuValues
);
1168 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
1179 m_mm_to_pix_x
= mm2pt
;
1180 m_mm_to_pix_y
= mm2pt
;
1182 m_externalDeviceOriginX
= 0;
1183 m_externalDeviceOriginY
= 0;
1184 m_logicalScaleX
= 1.0;
1185 m_logicalScaleY
= 1.0;
1190 m_needComputeScaleX
=
1191 m_needComputeScaleY
= false;
1194 m_macLocalOrigin
.x
=
1195 m_macLocalOrigin
.y
= 0 ;
1197 m_pen
= *wxBLACK_PEN
;
1198 m_font
= *wxNORMAL_FONT
;
1199 m_brush
= *wxWHITE_BRUSH
;
1201 m_macATSUIStyle
= NULL
;
1202 m_graphicContext
= NULL
;
1207 if ( m_macATSUIStyle
)
1209 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1210 m_macATSUIStyle
= NULL
;
1213 delete m_graphicContext
;
1216 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
1218 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
1219 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
1221 wxCoord xx
= XLOG2DEVMAC(x
);
1222 wxCoord yy
= YLOG2DEVMAC(y
);
1223 wxCoord w
= bmp
.GetWidth();
1224 wxCoord h
= bmp
.GetHeight();
1225 wxCoord ww
= XLOG2DEVREL(w
);
1226 wxCoord hh
= YLOG2DEVREL(h
);
1228 if ( bmp
.GetDepth()==1 )
1230 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1231 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1232 m_graphicContext
->FillPath( path
, m_textBackgroundColour
, wxODDEVEN_RULE
) ;
1234 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
) ;
1238 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
) ;
1242 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1244 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
1245 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
1247 wxCoord xx
= XLOG2DEVMAC(x
);
1248 wxCoord yy
= YLOG2DEVMAC(y
);
1249 wxCoord w
= icon
.GetWidth();
1250 wxCoord h
= icon
.GetHeight();
1251 wxCoord ww
= XLOG2DEVREL(w
);
1252 wxCoord hh
= YLOG2DEVREL(h
);
1254 m_graphicContext
->DrawIcon( icon
, xx
, yy
, ww
, hh
) ;
1257 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1259 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
1261 wxCoord xx
, yy
, ww
, hh
;
1262 xx
= XLOG2DEVMAC(x
);
1263 yy
= YLOG2DEVMAC(y
);
1264 ww
= XLOG2DEVREL(width
);
1265 hh
= YLOG2DEVREL(height
);
1267 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1268 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
1269 CGContextClipToRect( cgContext
, clipRect
) ;
1271 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
1272 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1276 m_clipX1
= wxMax( m_clipX1
, xx
);
1277 m_clipY1
= wxMax( m_clipY1
, yy
);
1278 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1279 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1291 // TODO: as soon as we don't reset the context for each operation anymore
1292 // we have to update the context as well
1295 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1297 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
1301 DestroyClippingRegion();
1306 region
.GetBox( x
, y
, w
, h
);
1307 wxCoord xx
, yy
, ww
, hh
;
1308 xx
= XLOG2DEVMAC(x
);
1309 yy
= YLOG2DEVMAC(y
);
1310 ww
= XLOG2DEVREL(w
);
1311 hh
= YLOG2DEVREL(h
);
1313 // if we have a scaling that we cannot map onto native regions
1314 // we must use the box
1315 if ( ww
!= w
|| hh
!= h
)
1317 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
1322 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
1323 if ( xx
!= x
|| yy
!= y
)
1324 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
1325 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
1330 m_clipX1
= wxMax( m_clipX1
, xx
);
1331 m_clipY1
= wxMax( m_clipY1
, yy
);
1332 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1333 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1347 void wxDC::DestroyClippingRegion()
1349 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1351 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1352 CGContextRestoreGState( cgContext
);
1353 CGContextSaveGState( cgContext
);
1355 m_graphicContext
->SetPen( m_pen
) ;
1356 m_graphicContext
->SetBrush( m_brush
) ;
1361 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1367 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
1369 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1372 void wxDC::SetTextForeground( const wxColour
&col
)
1374 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1376 if ( col
!= m_textForegroundColour
)
1378 m_textForegroundColour
= col
;
1379 m_graphicContext
->SetTextColor( col
);
1380 // in the current implementation the font contains the text color
1381 m_graphicContext
->SetFont(m_font
);
1385 void wxDC::SetTextBackground( const wxColour
&col
)
1387 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1389 m_textBackgroundColour
= col
;
1392 void wxDC::SetMapMode( int mode
)
1397 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1401 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1405 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1409 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1414 SetLogicalScale( 1.0, 1.0 );
1418 if (mode
!= wxMM_TEXT
)
1420 m_needComputeScaleX
=
1421 m_needComputeScaleY
= true;
1425 void wxDC::SetUserScale( double x
, double y
)
1427 // allow negative ? -> no
1430 ComputeScaleAndOrigin();
1433 void wxDC::SetLogicalScale( double x
, double y
)
1436 m_logicalScaleX
= x
;
1437 m_logicalScaleY
= y
;
1438 ComputeScaleAndOrigin();
1441 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1443 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1444 m_logicalOriginY
= y
* m_signY
;
1445 ComputeScaleAndOrigin();
1448 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1450 m_externalDeviceOriginX
= x
;
1451 m_externalDeviceOriginY
= y
;
1452 ComputeScaleAndOrigin();
1455 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1457 m_signX
= (xLeftRight
? 1 : -1);
1458 m_signY
= (yBottomUp
? -1 : 1);
1459 ComputeScaleAndOrigin();
1462 wxSize
wxDC::GetPPI() const
1464 return wxSize(72, 72);
1467 int wxDC::GetDepth() const
1472 void wxDC::ComputeScaleAndOrigin()
1474 // CMB: copy scale to see if it changes
1475 double origScaleX
= m_scaleX
;
1476 double origScaleY
= m_scaleY
;
1477 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1478 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1479 m_deviceOriginX
= m_externalDeviceOriginX
;
1480 m_deviceOriginY
= m_externalDeviceOriginY
;
1482 // CMB: if scale has changed call SetPen to recalulate the line width
1483 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1485 // this is a bit artificial, but we need to force wxDC to think
1486 // the pen has changed
1487 wxPen
pen( GetPen() );
1494 void wxDC::SetPalette( const wxPalette
& palette
)
1498 void wxDC::SetBackgroundMode( int mode
)
1500 m_backgroundMode
= mode
;
1503 void wxDC::SetFont( const wxFont
&font
)
1506 if ( m_graphicContext
)
1507 m_graphicContext
->SetFont( font
) ;
1510 void wxDC::SetPen( const wxPen
&pen
)
1516 if ( m_graphicContext
)
1518 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1520 m_graphicContext
->SetPen( m_pen
) ;
1524 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1525 // eg when using a wxScrollWindow and scrolling around
1526 int origX
= XLOG2DEVMAC( 0 ) ;
1527 int origY
= YLOG2DEVMAC( 0 ) ;
1528 m_graphicContext
->Translate( origX
, origY
) ;
1529 m_graphicContext
->SetPen( m_pen
) ;
1530 m_graphicContext
->Translate( -origX
, -origY
) ;
1535 void wxDC::SetBrush( const wxBrush
&brush
)
1537 if (m_brush
== brush
)
1541 if ( m_graphicContext
)
1543 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1545 m_graphicContext
->SetBrush( m_brush
) ;
1549 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1550 // eg when using a wxScrollWindow and scrolling around
1551 int origX
= XLOG2DEVMAC(0) ;
1552 int origY
= YLOG2DEVMAC(0) ;
1553 m_graphicContext
->Translate( origX
, origY
) ;
1554 m_graphicContext
->SetBrush( m_brush
) ;
1555 m_graphicContext
->Translate( -origX
, -origY
) ;
1560 void wxDC::SetBackground( const wxBrush
&brush
)
1562 if (m_backgroundBrush
== brush
)
1565 m_backgroundBrush
= brush
;
1566 if (!m_backgroundBrush
.Ok())
1570 void wxDC::SetLogicalFunction( int function
)
1572 if (m_logicalFunction
== function
)
1575 m_logicalFunction
= function
;
1576 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1577 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1578 if ( m_logicalFunction
== wxCOPY
)
1579 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1580 else if ( m_logicalFunction
== wxINVERT
)
1581 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1583 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1587 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1588 const wxColour
& col
, int style
);
1590 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1591 const wxColour
& col
, int style
)
1593 return wxDoFloodFill(this, x
, y
, col
, style
);
1596 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1598 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1602 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1603 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1605 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1606 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1608 // convert from Mac colour to wx
1609 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1614 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1616 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1618 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1619 if ( m_logicalFunction
!= wxCOPY
)
1623 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1624 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1625 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1626 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1628 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1629 path
->MoveToPoint( xx1
, yy1
) ;
1630 path
->AddLineToPoint( xx2
, yy2
) ;
1631 path
->CloseSubpath() ;
1632 m_graphicContext
->StrokePath( path
) ;
1635 CalcBoundingBox(x1
, y1
);
1636 CalcBoundingBox(x2
, y2
);
1639 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1641 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1643 if ( m_logicalFunction
!= wxCOPY
)
1649 wxCoord xx
= XLOG2DEVMAC(x
);
1650 wxCoord yy
= YLOG2DEVMAC(y
);
1652 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1653 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1654 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1655 path
->CloseSubpath() ;
1656 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1657 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1658 path
->CloseSubpath() ;
1659 m_graphicContext
->StrokePath( path
) ;
1662 CalcBoundingBox(x
, y
);
1663 CalcBoundingBox(x
+ w
, y
+ h
);
1666 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1667 wxCoord x2
, wxCoord y2
,
1668 wxCoord xc
, wxCoord yc
)
1670 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1672 if ( m_logicalFunction
!= wxCOPY
)
1675 wxCoord xx1
= XLOG2DEVMAC(x1
);
1676 wxCoord yy1
= YLOG2DEVMAC(y1
);
1677 wxCoord xx2
= XLOG2DEVMAC(x2
);
1678 wxCoord yy2
= YLOG2DEVMAC(y2
);
1679 wxCoord xxc
= XLOG2DEVMAC(xc
);
1680 wxCoord yyc
= YLOG2DEVMAC(yc
);
1682 double dx
= xx1
- xxc
;
1683 double dy
= yy1
- yyc
;
1684 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1685 wxCoord rad
= (wxCoord
)radius
;
1687 if (xx1
== xx2
&& yy1
== yy2
)
1692 else if (radius
== 0.0)
1698 sa
= (xx1
- xxc
== 0) ?
1699 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1700 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1701 ea
= (xx2
- xxc
== 0) ?
1702 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1703 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1706 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1708 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1709 m_graphicContext
->PushState() ;
1710 m_graphicContext
->Translate( xxc
, yyc
) ;
1711 m_graphicContext
->Scale( 1, -1 ) ;
1713 path
->MoveToPoint( 0, 0 ) ;
1714 path
->AddArc( 0, 0, rad
, DegToRad(sa
) , DegToRad(ea
), false ) ;
1716 path
->AddLineToPoint( 0, 0 ) ;
1717 m_graphicContext
->DrawPath( path
) ;
1718 m_graphicContext
->PopState() ;
1722 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1723 double sa
, double ea
)
1725 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1727 if ( m_logicalFunction
!= wxCOPY
)
1730 wxCoord xx
= XLOG2DEVMAC(x
);
1731 wxCoord yy
= YLOG2DEVMAC(y
);
1732 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1733 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1735 // handle -ve width and/or height
1747 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1749 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1750 m_graphicContext
->PushState() ;
1751 m_graphicContext
->Translate( xx
+ ww
/ 2, yy
+ hh
/ 2 ) ;
1752 m_graphicContext
->Scale( 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1754 path
->MoveToPoint( 0, 0 ) ;
1755 path
->AddArc( 0, 0, 1 , DegToRad(sa
) , DegToRad(ea
), false ) ;
1757 path
->AddLineToPoint( 0, 0 ) ;
1758 m_graphicContext
->DrawPath( path
) ;
1759 m_graphicContext
->PopState() ;
1763 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1765 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1767 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1770 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1771 wxCoord xoffset
, wxCoord yoffset
)
1773 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1775 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1776 if ( m_logicalFunction
!= wxCOPY
)
1780 wxCoord x1
, x2
, y1
, y2
;
1781 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1782 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1783 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1784 path
->MoveToPoint( x1
, y1
) ;
1785 for (int i
= 1; i
< n
; i
++)
1787 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1788 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1790 path
->AddLineToPoint( x2
, y2
) ;
1793 m_graphicContext
->StrokePath( path
) ;
1798 void wxDC::DoDrawSpline(wxList
*points
)
1800 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1802 if ( m_logicalFunction
!= wxCOPY
)
1805 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1807 wxList::compatibility_iterator node
= points
->GetFirst();
1808 if (node
== wxList::compatibility_iterator())
1812 wxPoint
*p
= (wxPoint
*)node
->GetData();
1817 node
= node
->GetNext();
1818 p
= (wxPoint
*)node
->GetData();
1822 wxCoord cx1
= ( x1
+ x2
) / 2;
1823 wxCoord cy1
= ( y1
+ y2
) / 2;
1825 path
->MoveToPoint( XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ) ;
1826 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , YLOG2DEVMAC( cy1
) ) ;
1829 while ((node
= node
->GetNext()) != NULL
)
1831 while ((node
= node
->GetNext()))
1832 #endif // !wxUSE_STL
1834 p
= (wxPoint
*)node
->GetData();
1839 wxCoord cx4
= (x1
+ x2
) / 2;
1840 wxCoord cy4
= (y1
+ y2
) / 2;
1842 path
->AddQuadCurveToPoint(
1843 XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ,
1844 XLOG2DEVMAC( cx4
) , YLOG2DEVMAC( cy4
) ) ;
1850 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , YLOG2DEVMAC( y2
) ) ;
1852 m_graphicContext
->StrokePath( path
) ;
1857 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1858 wxCoord xoffset
, wxCoord yoffset
,
1861 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1863 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1865 if ( m_logicalFunction
!= wxCOPY
)
1868 wxCoord x1
, x2
, y1
, y2
;
1869 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1870 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1872 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1873 path
->MoveToPoint( x1
, y1
) ;
1874 for (int i
= 1; i
< n
; i
++)
1876 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1877 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1879 path
->AddLineToPoint( x2
, y2
) ;
1882 if ( x1
!= x2
|| y1
!= y2
)
1883 path
->AddLineToPoint( x1
, y1
) ;
1885 path
->CloseSubpath() ;
1886 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1891 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1893 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1895 if ( m_logicalFunction
!= wxCOPY
)
1898 wxCoord xx
= XLOG2DEVMAC(x
);
1899 wxCoord yy
= YLOG2DEVMAC(y
);
1900 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1901 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1903 // CMB: draw nothing if transformed w or h is 0
1904 if (ww
== 0 || hh
== 0)
1907 // CMB: handle -ve width and/or height
1919 int penwidth
= m_pen
.GetWidth();
1920 if ( penwidth
== 0 )
1922 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
1925 bool offset
= ( penwidth
% 2 ) == 1 ;
1927 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1928 // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1
1930 path
->AddRectangle( xx
, yy
, ww
-1 , hh
-1 ) ;
1932 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1934 m_graphicContext
->DrawPath( path
) ;
1938 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1939 wxCoord width
, wxCoord height
,
1942 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1944 if ( m_logicalFunction
!= wxCOPY
)
1948 radius
= - radius
* ((width
< height
) ? width
: height
);
1949 wxCoord xx
= XLOG2DEVMAC(x
);
1950 wxCoord yy
= YLOG2DEVMAC(y
);
1951 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1952 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1954 // CMB: draw nothing if transformed w or h is 0
1955 if (ww
== 0 || hh
== 0)
1958 // CMB: handle -ve width and/or height
1970 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1973 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1974 m_graphicContext
->DrawPath( path
) ;
1978 path
->MoveToPoint( xx
+ ww
, yy
+ hh
/ 2);
1979 path
->AddArcToPoint(xx
+ ww
, yy
+ hh
, xx
+ ww
/ 2,yy
+ hh
, radius
);
1980 path
->AddArcToPoint(xx
, yy
+ hh
, xx
, yy
+ hh
/ 2, radius
);
1981 path
->AddArcToPoint(xx
, yy
, xx
+ ww
/ 2, yy
, radius
);
1982 path
->AddArcToPoint(xx
+ ww
, yy
, xx
+ ww
, yy
+ hh
/ 2, radius
);
1983 path
->CloseSubpath();
1984 m_graphicContext
->DrawPath( path
) ;
1989 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1991 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1993 if ( m_logicalFunction
!= wxCOPY
)
1996 wxCoord xx
= XLOG2DEVMAC(x
);
1997 wxCoord yy
= YLOG2DEVMAC(y
);
1998 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1999 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
2001 // CMB: draw nothing if transformed w or h is 0
2002 if (ww
== 0 || hh
== 0)
2005 // CMB: handle -ve width and/or height
2017 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
2018 m_graphicContext
->PushState() ;
2019 m_graphicContext
->Translate(xx
+ ww
/ 2, yy
+ hh
/ 2);
2020 m_graphicContext
->Scale(ww
/ 2 , hh
/ 2);
2021 path
->AddArc( 0, 0, 1, 0 , 2 * M_PI
, false ) ;
2022 m_graphicContext
->DrawPath( path
) ;
2023 m_graphicContext
->PopState() ;
2027 bool wxDC::CanDrawBitmap() const
2033 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
2034 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
2035 wxCoord xsrcMask
, wxCoord ysrcMask
)
2037 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
2038 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
2040 if ( logical_func
== wxNO_OP
)
2043 if (xsrcMask
== -1 && ysrcMask
== -1)
2049 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
2050 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
2051 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
2052 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
2054 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
2055 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
2056 wxCoord wwdest
= XLOG2DEVREL(width
) ;
2057 wxCoord hhdest
= YLOG2DEVREL(height
) ;
2059 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
2060 if ( memdc
&& logical_func
== wxCOPY
)
2062 wxBitmap blit
= memdc
->GetSelectedObject() ;
2064 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
2066 wxCoord bmpwidth
= blit
.GetWidth();
2067 wxCoord bmpheight
= blit
.GetHeight();
2069 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
2071 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
2072 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
2073 if ( wwsrc
> 0 && hhsrc
> 0 )
2075 if ( xxsrc
>= 0 && yysrc
>= 0 )
2077 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
2078 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
2079 blit
= blit
.GetSubBitmap( subrect
) ;
2083 // in this case we'd probably have to adjust the different coordinates, but
2084 // we have to find out proper contract first
2085 blit
= wxNullBitmap
;
2090 blit
= wxNullBitmap
;
2096 m_graphicContext
->DrawBitmap( blit
, xxdest
, yydest
, wwdest
, hhdest
) ;
2101 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ;
2108 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
2111 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
2112 // wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
2114 if ( str
.length() == 0 )
2116 if ( m_logicalFunction
!= wxCOPY
)
2119 int drawX
= XLOG2DEVMAC(x
) ;
2120 int drawY
= YLOG2DEVMAC(y
) ;
2122 m_graphicContext
->DrawText( str
, drawX
,drawY
, angle
) ;
2125 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
2127 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
2129 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
2132 bool wxDC::CanGetTextExtent() const
2134 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
2139 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
2140 wxCoord
*descent
, wxCoord
*externalLeading
,
2141 wxFont
*theFont
) const
2143 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
2145 wxFont formerFont
= m_font
;
2148 m_graphicContext
->SetFont( *theFont
) ;
2151 wxCoord h
, d
, e
, w
;
2153 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
) ;
2156 *height
= YDEV2LOGREL( h
) ;
2158 *descent
=YDEV2LOGREL( d
);
2159 if ( externalLeading
)
2160 *externalLeading
= YDEV2LOGREL( e
);
2162 *width
= XDEV2LOGREL( w
) ;
2166 m_graphicContext
->SetFont( m_font
) ;
2170 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
2172 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
2174 m_graphicContext
->GetPartialTextExtents( text
, widths
) ;
2175 for ( size_t i
= 0 ; i
< widths
.GetCount() ; ++i
)
2176 widths
[i
] = XDEV2LOGREL( widths
[i
] );
2181 wxCoord
wxDC::GetCharWidth(void) const
2184 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2189 wxCoord
wxDC::GetCharHeight(void) const
2192 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2197 void wxDC::Clear(void)
2199 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2201 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2203 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2204 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2205 switch ( m_backgroundBrush
.MacGetBrushKind() )
2207 case kwxMacBrushTheme
:
2209 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2210 if ( HIThemeSetFill
!= 0 )
2212 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2213 CGContextFillRect(cg
, rect
);
2220 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2221 CGContextSetRGBFillColor( cg
, (CGFloat
) color
.red
/ 65536,
2222 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 );
2223 CGContextFillRect( cg
, rect
);
2226 // reset to normal value
2227 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2228 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2232 case kwxMacBrushThemeBackground
:
2234 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2236 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2237 if ( UMAGetSystemVersion() >= 0x1030 )
2239 HIThemeBackgroundDrawInfo drawInfo
;
2240 drawInfo
.version
= 0 ;
2241 drawInfo
.state
= kThemeStateActive
;
2242 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2243 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2245 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2246 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2253 case kwxMacBrushColour
:
2255 // FIXME: doesn't correctly render stippled brushes !!
2256 // FIXME: should this be replaced by ::SetBrush() ??
2258 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2259 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2260 CGContextFillRect(cg
, rect
);
2262 // reset to normal value
2263 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2264 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2269 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2277 // ---------------------------------------------------------------------------
2278 // coordinates transformations
2279 // ---------------------------------------------------------------------------
2281 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2283 return ((wxDC
*)this)->XDEV2LOG(x
);
2286 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2288 return ((wxDC
*)this)->YDEV2LOG(y
);
2291 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2293 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2296 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2298 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2301 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2303 return ((wxDC
*)this)->XLOG2DEV(x
);
2306 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2308 return ((wxDC
*)this)->YLOG2DEV(y
);
2311 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2313 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2316 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2318 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2321 #endif // wxMAC_USE_CORE_GRAPHICS