1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dccg.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #if wxMAC_USE_CORE_GRAPHICS
21 #include "wx/dcmemory.h"
22 #include "wx/dcprint.h"
23 #include "wx/region.h"
27 #include "wx/mac/uma.h"
33 // in case our functions were defined outside std, we make it known all the same
39 #include "wx/mac/private.h"
41 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
43 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
44 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
47 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
48 typedef float CGFloat
;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
57 const double M_PI
= 3.14159265358979 ;
61 const double RAD2DEG
= 180.0 / M_PI
;
62 const short kEmulatedMode
= -1 ;
63 const short kUnsupportedMode
= -2 ;
65 extern TECObjectRef s_TECNativeCToUnicode
;
69 // The textctrl implementation still needs that (needs what?) for the non-HIView implementation
71 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
72 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
74 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
75 m_formerClip
= NewRgn() ;
76 m_newClip
= NewRgn() ;
77 GetClip( m_formerClip
) ;
81 // guard against half constructed objects, this just leads to a empty clip
85 win
->MacWindowToRootWindow( &x
, &y
) ;
87 // get area including focus rect
88 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
89 if ( !EmptyRgn( m_newClip
) )
90 OffsetRgn( m_newClip
, x
, y
) ;
93 SetClip( m_newClip
) ;
97 wxMacWindowClipper::~wxMacWindowClipper()
99 SetPort( m_newPort
) ;
100 SetClip( m_formerClip
) ;
101 DisposeRgn( m_newClip
) ;
102 DisposeRgn( m_formerClip
) ;
105 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
106 wxMacWindowClipper( win
)
108 // the port is already set at this point
109 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
110 GetThemeDrawingState( &m_themeDrawingState
) ;
113 wxMacWindowStateSaver::~wxMacWindowStateSaver()
115 SetPort( m_newPort
) ;
116 SetThemeDrawingState( m_themeDrawingState
, true ) ;
119 // minimal implementation only used for appearance drawing < 10.3
121 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
122 m_ph( (GrafPtr
) dc
->m_macPort
)
124 wxASSERT( dc
->Ok() ) ;
127 // dc->MacSetupPort(&m_ph) ;
130 wxMacPortSetter::~wxMacPortSetter()
132 // m_dc->MacCleanupPort(&m_ph) ;
135 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
139 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
140 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
141 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
143 //-----------------------------------------------------------------------------
144 // device context implementation
146 // more and more of the dc functionality should be implemented by calling
147 // the appropricate wxMacCGContext, but we will have to do that step by step
148 // also coordinate conversions should be moved to native matrix ops
149 //-----------------------------------------------------------------------------
151 // we always stock two context states, one at entry, to be able to preserve the
152 // state we were called with, the other one after changing to HI Graphics orientation
153 // (this one is used for getting back clippings etc)
155 //-----------------------------------------------------------------------------
156 // wxGraphicPath implementation
157 //-----------------------------------------------------------------------------
159 wxMacCGPath::wxMacCGPath()
161 m_path
= CGPathCreateMutable() ;
164 wxMacCGPath::~wxMacCGPath()
166 CGPathRelease( m_path
) ;
169 // opens (starts) a new subpath
170 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
172 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
175 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
177 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
180 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
182 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
185 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
187 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
188 CGPathAddRect( m_path
, NULL
, cgRect
) ;
191 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
193 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
196 // closes the current subpath
197 void wxMacCGPath::CloseSubpath()
199 CGPathCloseSubpath( m_path
) ;
202 CGPathRef
wxMacCGPath::GetPath() const
207 void wxMacCGPath::AddArcToPoint( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord r
)
209 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
212 void wxMacCGPath::AddArc( wxCoord x
, wxCoord y
, wxCoord r
, double startAngle
, double endAngle
, bool clockwise
)
214 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, clockwise
);
217 //-----------------------------------------------------------------------------
218 // wxGraphicContext implementation
219 //-----------------------------------------------------------------------------
221 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
225 m_mode
= kCGPathFill
;
226 m_macATSUIStyle
= NULL
;
229 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
232 m_cgContext
= cgcontext
;
233 m_mode
= kCGPathFill
;
234 m_macATSUIStyle
= NULL
;
235 CGContextSaveGState( m_cgContext
) ;
236 CGContextSaveGState( m_cgContext
) ;
239 wxMacCGContext::wxMacCGContext()
243 m_mode
= kCGPathFill
;
244 m_macATSUIStyle
= NULL
;
247 wxMacCGContext::~wxMacCGContext()
251 CGContextSynchronize( m_cgContext
) ;
252 CGContextRestoreGState( m_cgContext
) ;
253 CGContextRestoreGState( m_cgContext
) ;
257 QDEndCGContext( m_qdPort
, &m_cgContext
) ;
261 void wxMacCGContext::Clip( const wxRegion
®ion
)
263 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
266 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
268 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
270 int width
= m_pen
.GetWidth();
273 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
276 bool offset
= ( width
% 2 ) == 1 ;
279 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
281 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
282 CGContextStrokePath( m_cgContext
) ;
285 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
288 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
290 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
291 CGPathDrawingMode mode
= m_mode
;
293 if ( fillStyle
== wxODDEVEN_RULE
)
295 if ( mode
== kCGPathFill
)
296 mode
= kCGPathEOFill
;
297 else if ( mode
== kCGPathFillStroke
)
298 mode
= kCGPathEOFillStroke
;
301 int width
= m_pen
.GetWidth();
304 if ( m_pen
.GetStyle() == wxTRANSPARENT
)
307 bool offset
= ( width
% 2 ) == 1 ;
310 CGContextTranslateCTM( m_cgContext
, 0.5, 0.5 );
312 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
313 CGContextDrawPath( m_cgContext
, mode
) ;
316 CGContextTranslateCTM( m_cgContext
, -0.5, -0.5 );
319 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
321 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
322 CGContextSaveGState( m_cgContext
) ;
324 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
325 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
326 CGPathDrawingMode mode
= kCGPathFill
;
328 if ( fillStyle
== wxODDEVEN_RULE
)
329 mode
= kCGPathEOFill
;
331 CGContextBeginPath( m_cgContext
) ;
332 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
333 CGContextClosePath( m_cgContext
) ;
334 CGContextDrawPath( m_cgContext
, mode
) ;
336 CGContextRestoreGState( m_cgContext
) ;
339 wxGraphicPath
* wxMacCGContext::CreatePath()
341 // make sure that we now have a real cgref, before doing
342 // anything with paths
343 CGContextRef cg
= GetNativeContext() ;
346 return new wxMacCGPath() ;
349 // in case we only got a QDPort only create a cgref now
351 CGContextRef
wxMacCGContext::GetNativeContext()
353 if ( m_cgContext
== NULL
)
356 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
357 OSStatus status
= QDBeginCGContext((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
358 CGContextSaveGState( m_cgContext
) ;
360 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
362 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
363 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
365 CGContextSaveGState( m_cgContext
) ;
367 SetBrush( m_brush
) ;
373 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
375 // we allow either setting or clearing but not replacing
376 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
379 CGContextSaveGState( cg
) ;
383 void wxMacCGContext::Translate( wxCoord dx
, wxCoord dy
)
385 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
388 void wxMacCGContext::Scale( wxCoord xScale
, wxCoord yScale
)
390 CGContextScaleCTM( m_cgContext
, xScale
, yScale
) ;
393 void wxMacCGContext::DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
395 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
396 HIRect r
= CGRectMake( x
, y
, w
, h
) ;
397 HIViewDrawCGImage( m_cgContext
, &r
, image
) ;
398 CGImageRelease( image
) ;
401 void wxMacCGContext::DrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
403 CGRect r
= CGRectMake( 00 , 00 , w
, h
) ;
404 CGContextSaveGState( m_cgContext
);
405 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
406 CGContextScaleCTM( m_cgContext
, 1, -1 );
407 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
408 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
409 CGContextRestoreGState( m_cgContext
) ;
412 void wxMacCGContext::PushState()
414 CGContextSaveGState( m_cgContext
);
417 void wxMacCGContext::PopState()
419 CGContextRestoreGState( m_cgContext
);
422 void wxMacCGContext::SetTextColor( const wxColour
&col
)
424 m_textForegroundColor
= col
;
428 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
430 // CGPattern wrapper class: always allocate on heap, never call destructor
437 // is guaranteed to be called only with a non-Null CGContextRef
438 virtual void Render( CGContextRef ctxRef
) = 0 ;
440 operator CGPatternRef() const { return m_patternRef
; }
443 virtual ~wxMacCGPattern()
445 // as this is called only when the m_patternRef is been released;
446 // don't release it again
449 static void _Render( void *info
, CGContextRef ctxRef
)
451 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
452 if ( self
&& ctxRef
)
453 self
->Render( ctxRef
) ;
456 static void _Dispose( void *info
)
458 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
462 CGPatternRef m_patternRef
;
464 static const CGPatternCallbacks ms_Callbacks
;
467 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
469 class ImagePattern
: public wxMacCGPattern
472 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
474 wxASSERT( bmp
&& bmp
->Ok() ) ;
476 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
479 // ImagePattern takes ownership of CGImageRef passed in
480 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
485 Init( image
, transform
) ;
488 virtual void Render( CGContextRef ctxRef
)
491 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
495 void Init( CGImageRef image
, CGAffineTransform transform
)
500 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) ) ;
501 m_patternRef
= CGPatternCreate(
502 this , m_imageBounds
, transform
,
503 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
504 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
508 virtual ~ImagePattern()
511 CGImageRelease( m_image
) ;
515 CGRect m_imageBounds
;
518 class HatchPattern
: public wxMacCGPattern
521 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
523 m_hatch
= hatchstyle
;
524 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
525 m_patternRef
= CGPatternCreate(
526 this , m_imageBounds
, transform
,
527 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
528 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
531 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
533 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
534 if ( UMAGetSystemVersion() >= 0x1040 )
536 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
541 CGContextBeginPath( ctxRef
);
542 for (size_t i
= 0; i
< count
; i
+= 2)
544 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
545 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
547 CGContextStrokePath(ctxRef
);
551 virtual void Render( CGContextRef ctxRef
)
555 case wxBDIAGONAL_HATCH
:
559 { 8.0 , 0.0 } , { 0.0 , 8.0 }
561 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
565 case wxCROSSDIAG_HATCH
:
569 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
570 { 8.0 , 0.0 } , { 0.0 , 8.0 }
572 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
576 case wxFDIAGONAL_HATCH
:
580 { 0.0 , 0.0 } , { 8.0 , 8.0 }
582 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
590 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
591 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
593 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
597 case wxHORIZONTAL_HATCH
:
601 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
603 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
607 case wxVERTICAL_HATCH
:
611 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
613 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
623 virtual ~HatchPattern() {}
625 CGRect m_imageBounds
;
631 void wxMacCGContext::SetPen( const wxPen
&pen
)
634 if ( m_cgContext
== NULL
)
637 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
638 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
641 // we can benchmark performance; should go into a setting eventually
642 CGContextSetShouldAntialias( m_cgContext
, false ) ;
648 m_mode
= kCGPathFill
; // just a default
652 CGContextSetRGBStrokeColor( m_cgContext
, pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
653 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 ) ;
655 // TODO: * m_dc->m_scaleX
656 CGFloat penWidth
= pen
.GetWidth();
659 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
662 switch ( pen
.GetCap() )
665 cap
= kCGLineCapRound
;
668 case wxCAP_PROJECTING
:
669 cap
= kCGLineCapSquare
;
673 cap
= kCGLineCapButt
;
677 cap
= kCGLineCapButt
;
682 switch ( pen
.GetJoin() )
685 join
= kCGLineJoinBevel
;
689 join
= kCGLineJoinMiter
;
693 join
= kCGLineJoinRound
;
697 join
= kCGLineJoinMiter
;
701 m_mode
= kCGPathStroke
;
704 const CGFloat
*lengths
= NULL
;
705 CGFloat
*userLengths
= NULL
;
707 const CGFloat dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
709 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
710 const CGFloat short_dashed
[] = { 9.0 , 6.0 };
711 const CGFloat dashed
[] = { 19.0 , 9.0 };
712 const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
714 switch ( pen
.GetStyle() )
721 count
= WXSIZEOF(dotted
);
726 count
= WXSIZEOF(dashed
) ;
730 lengths
= short_dashed
;
731 count
= WXSIZEOF(short_dashed
) ;
735 lengths
= dotted_dashed
;
736 count
= WXSIZEOF(dotted_dashed
);
741 count
= pen
.GetDashes( &dashes
) ;
742 if ((dashes
!= NULL
) && (count
> 0))
744 userLengths
= new CGFloat
[count
] ;
745 for ( int i
= 0 ; i
< count
; ++i
)
747 userLengths
[i
] = dashes
[i
] * dashUnit
;
749 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
750 userLengths
[i
] = dashUnit
+ 2.0 ;
751 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
752 userLengths
[i
] = dashUnit
;
755 lengths
= userLengths
;
760 CGFloat alphaArray
[1] = { 1.0 } ;
761 wxBitmap
* bmp
= pen
.GetStipple() ;
762 if ( bmp
&& bmp
->Ok() )
764 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
765 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
766 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
767 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
774 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
775 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
776 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
778 CGFloat colorArray
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
779 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
781 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
786 if ((lengths
!= NULL
) && (count
> 0))
788 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
789 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
790 cap
= kCGLineCapButt
;
794 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
797 CGContextSetLineCap( m_cgContext
, cap
) ;
798 CGContextSetLineJoin( m_cgContext
, join
) ;
800 delete[] userLengths
;
803 if ( fill
&& stroke
)
804 m_mode
= kCGPathFillStroke
;
808 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
811 if ( m_cgContext
== NULL
)
814 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
815 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
818 // we can benchmark performance, should go into a setting later
819 CGContextSetShouldAntialias( m_cgContext
, false ) ;
825 m_mode
= kCGPathFill
; // just a default
829 if ( brush
.GetStyle() == wxSOLID
)
831 CGContextSetRGBFillColor( m_cgContext
, brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
832 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 ) ;
834 else if ( brush
.IsHatch() )
836 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
837 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
838 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
840 CGFloat colorArray
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
841 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
843 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
847 // now brush is a bitmap
848 CGFloat alphaArray
[1] = { 1.0 } ;
849 wxBitmap
* bmp
= brush
.GetStipple() ;
850 if ( bmp
&& bmp
->Ok() )
852 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
853 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
854 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
855 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
859 m_mode
= kCGPathFill
;
862 if ( fill
&& stroke
)
863 m_mode
= kCGPathFillStroke
;
865 m_mode
= kCGPathStroke
;
869 void wxMacCGContext::DrawText( const wxString
&str
, wxCoord x
, wxCoord y
, double angle
)
871 OSStatus status
= noErr
;
872 ATSUTextLayout atsuLayout
;
873 UniCharCount chars
= str
.length() ;
874 UniChar
* ubuf
= NULL
;
876 #if SIZEOF_WCHAR_T == 4
877 wxMBConvUTF16 converter
;
879 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
880 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
881 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
883 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
884 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
885 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
886 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
888 chars
= unicharlen
/ 2 ;
891 ubuf
= (UniChar
*) str
.wc_str() ;
893 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
894 chars
= wxWcslen( wchar
.data() ) ;
895 ubuf
= (UniChar
*) wchar
.data() ;
899 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
900 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
902 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
904 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
905 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
907 int iAngle
= int( angle
);
908 if ( abs(iAngle
) > 0 )
910 Fixed atsuAngle
= IntToFixed( iAngle
) ;
911 ATSUAttributeTag atsuTags
[] =
913 kATSULineRotationTag
,
915 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
919 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
923 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
924 atsuTags
, atsuSizes
, atsuValues
) ;
928 ATSUAttributeTag atsuTags
[] =
932 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
934 sizeof( CGContextRef
) ,
936 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
940 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
941 atsuTags
, atsuSizes
, atsuValues
) ;
944 ATSUTextMeasurement textBefore
, textAfter
;
945 ATSUTextMeasurement ascent
, descent
;
947 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
948 &textBefore
, &textAfter
, &ascent
, &descent
);
950 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
955 if ( m_backgroundMode == wxSOLID )
957 wxGraphicPath* path = m_graphicContext->CreatePath() ;
958 path->MoveToPoint( drawX , drawY ) ;
959 path->AddLineToPoint(
960 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ,
961 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ;
962 path->AddLineToPoint(
963 (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
964 (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
965 path->AddLineToPoint(
966 (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
967 (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
969 m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
973 x
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
974 y
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
976 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
977 IntToFixed(x
) , IntToFixed(y
) , &rect
);
978 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
980 CGContextSaveGState(m_cgContext
);
981 CGContextTranslateCTM(m_cgContext
, x
, y
);
982 CGContextScaleCTM(m_cgContext
, 1, -1);
983 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
984 IntToFixed(0) , IntToFixed(0) );
986 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
988 CGContextRestoreGState(m_cgContext
) ;
990 ::ATSUDisposeTextLayout(atsuLayout
);
992 #if SIZEOF_WCHAR_T == 4
997 void wxMacCGContext::GetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
998 wxCoord
*descent
, wxCoord
*externalLeading
) const
1000 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1002 OSStatus status
= noErr
;
1004 ATSUTextLayout atsuLayout
;
1005 UniCharCount chars
= str
.length() ;
1006 UniChar
* ubuf
= NULL
;
1008 #if SIZEOF_WCHAR_T == 4
1009 wxMBConvUTF16 converter
;
1011 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1012 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1013 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1015 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1016 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1017 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1018 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1020 chars
= unicharlen
/ 2 ;
1023 ubuf
= (UniChar
*) str
.wc_str() ;
1025 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1026 chars
= wxWcslen( wchar
.data() ) ;
1027 ubuf
= (UniChar
*) wchar
.data() ;
1031 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1032 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1034 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1036 ATSUTextMeasurement textBefore
, textAfter
;
1037 ATSUTextMeasurement textAscent
, textDescent
;
1039 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1040 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1043 *height
= FixedToInt(textAscent
+ textDescent
) ;
1045 *descent
= FixedToInt(textDescent
) ;
1046 if ( externalLeading
)
1047 *externalLeading
= 0 ;
1049 *width
= FixedToInt(textAfter
- textBefore
) ;
1051 ::ATSUDisposeTextLayout(atsuLayout
);
1054 void wxMacCGContext::GetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1057 widths
.Add(0, text
.length());
1062 ATSUTextLayout atsuLayout
;
1063 UniCharCount chars
= text
.length() ;
1064 UniChar
* ubuf
= NULL
;
1066 #if SIZEOF_WCHAR_T == 4
1067 wxMBConvUTF16 converter
;
1069 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1070 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1071 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1073 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1074 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1075 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1076 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1078 chars
= unicharlen
/ 2 ;
1081 ubuf
= (UniChar
*) text
.wc_str() ;
1083 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1084 chars
= wxWcslen( wchar
.data() ) ;
1085 ubuf
= (UniChar
*) wchar
.data() ;
1090 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1091 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1093 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1095 unsigned long actualNumberOfBounds
= 0;
1096 ATSTrapezoid glyphBounds
;
1098 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1100 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1101 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1102 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1105 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1106 //unsigned char uch = s[i];
1109 ::ATSUDisposeTextLayout(atsuLayout
);
1112 void wxMacCGContext::SetFont( const wxFont
&font
)
1114 if ( m_macATSUIStyle
)
1116 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1117 m_macATSUIStyle
= NULL
;
1124 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1126 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1128 // we need the scale here ...
1130 Fixed atsuSize
= IntToFixed( int( /*m_scaleY*/ 1 * font
.MacGetFontSize()) ) ;
1131 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColor
.GetPixel() ) ;
1132 ATSUAttributeTag atsuTags
[] =
1137 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1140 sizeof( RGBColor
) ,
1142 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1148 status
= ::ATSUSetAttributes(
1149 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
1150 atsuTags
, atsuSizes
, atsuValues
);
1152 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
1163 m_mm_to_pix_x
= mm2pt
;
1164 m_mm_to_pix_y
= mm2pt
;
1166 m_externalDeviceOriginX
= 0;
1167 m_externalDeviceOriginY
= 0;
1168 m_logicalScaleX
= 1.0;
1169 m_logicalScaleY
= 1.0;
1174 m_needComputeScaleX
=
1175 m_needComputeScaleY
= false;
1178 m_macLocalOrigin
.x
=
1179 m_macLocalOrigin
.y
= 0 ;
1181 m_pen
= *wxBLACK_PEN
;
1182 m_font
= *wxNORMAL_FONT
;
1183 m_brush
= *wxWHITE_BRUSH
;
1185 m_macATSUIStyle
= NULL
;
1186 m_graphicContext
= NULL
;
1191 if ( m_macATSUIStyle
)
1193 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
1194 m_macATSUIStyle
= NULL
;
1197 delete m_graphicContext
;
1200 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
1202 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
1203 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
1205 wxCoord xx
= XLOG2DEVMAC(x
);
1206 wxCoord yy
= YLOG2DEVMAC(y
);
1207 wxCoord w
= bmp
.GetWidth();
1208 wxCoord h
= bmp
.GetHeight();
1209 wxCoord ww
= XLOG2DEVREL(w
);
1210 wxCoord hh
= YLOG2DEVREL(h
);
1212 m_graphicContext
->DrawBitmap( bmp
, xx
, yy
, ww
, hh
) ;
1215 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
1217 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
1218 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
1220 wxCoord xx
= XLOG2DEVMAC(x
);
1221 wxCoord yy
= YLOG2DEVMAC(y
);
1222 wxCoord w
= icon
.GetWidth();
1223 wxCoord h
= icon
.GetHeight();
1224 wxCoord ww
= XLOG2DEVREL(w
);
1225 wxCoord hh
= YLOG2DEVREL(h
);
1227 m_graphicContext
->DrawIcon( icon
, xx
, yy
, ww
, hh
) ;
1230 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1232 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
1234 wxCoord xx
, yy
, ww
, hh
;
1235 xx
= XLOG2DEVMAC(x
);
1236 yy
= YLOG2DEVMAC(y
);
1237 ww
= XLOG2DEVREL(width
);
1238 hh
= YLOG2DEVREL(height
);
1240 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1241 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
1242 CGContextClipToRect( cgContext
, clipRect
) ;
1244 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
1245 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1249 m_clipX1
= wxMax( m_clipX1
, xx
);
1250 m_clipY1
= wxMax( m_clipY1
, yy
);
1251 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1252 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1264 // TODO: as soon as we don't reset the context for each operation anymore
1265 // we have to update the context as well
1268 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1270 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
1274 DestroyClippingRegion();
1279 region
.GetBox( x
, y
, w
, h
);
1280 wxCoord xx
, yy
, ww
, hh
;
1281 xx
= XLOG2DEVMAC(x
);
1282 yy
= YLOG2DEVMAC(y
);
1283 ww
= XLOG2DEVREL(w
);
1284 hh
= YLOG2DEVREL(h
);
1286 // if we have a scaling that we cannot map onto native regions
1287 // we must use the box
1288 if ( ww
!= w
|| hh
!= h
)
1290 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
1295 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
1296 if ( xx
!= x
|| yy
!= y
)
1297 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
1298 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
1303 m_clipX1
= wxMax( m_clipX1
, xx
);
1304 m_clipY1
= wxMax( m_clipY1
, yy
);
1305 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
1306 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
1320 void wxDC::DestroyClippingRegion()
1322 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1324 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1325 CGContextRestoreGState( cgContext
);
1326 CGContextSaveGState( cgContext
);
1328 m_graphicContext
->SetPen( m_pen
) ;
1329 m_graphicContext
->SetBrush( m_brush
) ;
1334 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1340 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
1342 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1345 void wxDC::SetTextForeground( const wxColour
&col
)
1347 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1349 if ( col
!= m_textForegroundColour
)
1351 m_textForegroundColour
= col
;
1352 m_graphicContext
->SetTextColor( col
) ;
1356 void wxDC::SetTextBackground( const wxColour
&col
)
1358 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1360 m_textBackgroundColour
= col
;
1363 void wxDC::SetMapMode( int mode
)
1368 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1372 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1376 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1380 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1385 SetLogicalScale( 1.0, 1.0 );
1389 if (mode
!= wxMM_TEXT
)
1391 m_needComputeScaleX
=
1392 m_needComputeScaleY
= true;
1396 void wxDC::SetUserScale( double x
, double y
)
1398 // allow negative ? -> no
1401 ComputeScaleAndOrigin();
1404 void wxDC::SetLogicalScale( double x
, double y
)
1407 m_logicalScaleX
= x
;
1408 m_logicalScaleY
= y
;
1409 ComputeScaleAndOrigin();
1412 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1414 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1415 m_logicalOriginY
= y
* m_signY
;
1416 ComputeScaleAndOrigin();
1419 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1421 m_externalDeviceOriginX
= x
;
1422 m_externalDeviceOriginY
= y
;
1423 ComputeScaleAndOrigin();
1426 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1428 m_signX
= (xLeftRight
? 1 : -1);
1429 m_signY
= (yBottomUp
? -1 : 1);
1430 ComputeScaleAndOrigin();
1433 wxSize
wxDC::GetPPI() const
1435 return wxSize(72, 72);
1438 int wxDC::GetDepth() const
1443 void wxDC::ComputeScaleAndOrigin()
1445 // CMB: copy scale to see if it changes
1446 double origScaleX
= m_scaleX
;
1447 double origScaleY
= m_scaleY
;
1448 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1449 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1450 m_deviceOriginX
= m_externalDeviceOriginX
;
1451 m_deviceOriginY
= m_externalDeviceOriginY
;
1453 // CMB: if scale has changed call SetPen to recalulate the line width
1454 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1456 // this is a bit artificial, but we need to force wxDC to think
1457 // the pen has changed
1458 wxPen
pen( GetPen() );
1465 void wxDC::SetPalette( const wxPalette
& palette
)
1469 void wxDC::SetBackgroundMode( int mode
)
1471 m_backgroundMode
= mode
;
1474 void wxDC::SetFont( const wxFont
&font
)
1477 if ( m_graphicContext
)
1478 m_graphicContext
->SetFont( font
) ;
1481 void wxDC::SetPen( const wxPen
&pen
)
1487 if ( m_graphicContext
)
1489 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1491 m_graphicContext
->SetPen( m_pen
) ;
1495 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1496 // eg when using a wxScrollWindow and scrolling around
1497 int origX
= XLOG2DEVMAC( 0 ) ;
1498 int origY
= YLOG2DEVMAC( 0 ) ;
1499 m_graphicContext
->Translate( origX
, origY
) ;
1500 m_graphicContext
->SetPen( m_pen
) ;
1501 m_graphicContext
->Translate( -origX
, -origY
) ;
1506 void wxDC::SetBrush( const wxBrush
&brush
)
1508 if (m_brush
== brush
)
1512 if ( m_graphicContext
)
1514 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1516 m_graphicContext
->SetBrush( m_brush
) ;
1520 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1521 // eg when using a wxScrollWindow and scrolling around
1522 int origX
= XLOG2DEVMAC(0) ;
1523 int origY
= YLOG2DEVMAC(0) ;
1524 m_graphicContext
->Translate( origX
, origY
) ;
1525 m_graphicContext
->SetBrush( m_brush
) ;
1526 m_graphicContext
->Translate( -origX
, -origY
) ;
1531 void wxDC::SetBackground( const wxBrush
&brush
)
1533 if (m_backgroundBrush
== brush
)
1536 m_backgroundBrush
= brush
;
1537 if (!m_backgroundBrush
.Ok())
1541 void wxDC::SetLogicalFunction( int function
)
1543 if (m_logicalFunction
== function
)
1546 m_logicalFunction
= function
;
1547 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1548 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1549 if ( m_logicalFunction
== wxCOPY
)
1550 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1551 else if ( m_logicalFunction
== wxINVERT
)
1552 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1554 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1558 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1559 const wxColour
& col
, int style
);
1561 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1562 const wxColour
& col
, int style
)
1564 return wxDoFloodFill(this, x
, y
, col
, style
);
1567 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1569 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1571 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1574 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1576 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1577 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1579 // convert from Mac colour to wx
1580 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1585 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1587 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1589 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1590 if ( m_logicalFunction
!= wxCOPY
)
1594 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1595 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1596 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1597 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1599 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1600 path
->MoveToPoint( xx1
, yy1
) ;
1601 path
->AddLineToPoint( xx2
, yy2
) ;
1602 path
->CloseSubpath() ;
1603 m_graphicContext
->StrokePath( path
) ;
1606 CalcBoundingBox(x1
, y1
);
1607 CalcBoundingBox(x2
, y2
);
1610 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1612 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1614 if ( m_logicalFunction
!= wxCOPY
)
1620 wxCoord xx
= XLOG2DEVMAC(x
);
1621 wxCoord yy
= YLOG2DEVMAC(y
);
1623 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1624 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1625 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1626 path
->CloseSubpath() ;
1627 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1628 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1629 path
->CloseSubpath() ;
1630 m_graphicContext
->StrokePath( path
) ;
1633 CalcBoundingBox(x
, y
);
1634 CalcBoundingBox(x
+ w
, y
+ h
);
1637 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1638 wxCoord x2
, wxCoord y2
,
1639 wxCoord xc
, wxCoord yc
)
1641 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1643 if ( m_logicalFunction
!= wxCOPY
)
1646 wxCoord xx1
= XLOG2DEVMAC(x1
);
1647 wxCoord yy1
= YLOG2DEVMAC(y1
);
1648 wxCoord xx2
= XLOG2DEVMAC(x2
);
1649 wxCoord yy2
= YLOG2DEVMAC(y2
);
1650 wxCoord xxc
= XLOG2DEVMAC(xc
);
1651 wxCoord yyc
= YLOG2DEVMAC(yc
);
1653 double dx
= xx1
- xxc
;
1654 double dy
= yy1
- yyc
;
1655 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1656 wxCoord rad
= (wxCoord
)radius
;
1658 if (xx1
== xx2
&& yy1
== yy2
)
1663 else if (radius
== 0.0)
1669 sa
= (xx1
- xxc
== 0) ?
1670 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1671 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1672 ea
= (xx2
- xxc
== 0) ?
1673 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1674 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1677 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1679 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1680 m_graphicContext
->PushState() ;
1681 m_graphicContext
->Translate( xxc
, yyc
) ;
1682 m_graphicContext
->Scale( 1, -1 ) ;
1684 path
->MoveToPoint( 0, 0 ) ;
1685 path
->AddArc( 0, 0, rad
, DegToRad(sa
) , DegToRad(ea
), false ) ;
1687 path
->AddLineToPoint( 0, 0 ) ;
1688 m_graphicContext
->DrawPath( path
) ;
1689 m_graphicContext
->PopState() ;
1693 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1694 double sa
, double ea
)
1696 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1698 if ( m_logicalFunction
!= wxCOPY
)
1701 wxCoord xx
= XLOG2DEVMAC(x
);
1702 wxCoord yy
= YLOG2DEVMAC(y
);
1703 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1704 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1706 // handle -ve width and/or height
1718 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1720 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1721 m_graphicContext
->PushState() ;
1722 m_graphicContext
->Translate( xx
+ ww
/ 2, yy
+ hh
/ 2 ) ;
1723 m_graphicContext
->Scale( 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1725 path
->MoveToPoint( 0, 0 ) ;
1726 path
->AddArc( 0, 0, 1 , DegToRad(sa
) , DegToRad(ea
), false ) ;
1728 path
->AddLineToPoint( 0, 0 ) ;
1729 m_graphicContext
->DrawPath( path
) ;
1730 m_graphicContext
->PopState() ;
1734 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1736 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1738 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1741 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1742 wxCoord xoffset
, wxCoord yoffset
)
1744 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1746 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1747 if ( m_logicalFunction
!= wxCOPY
)
1751 wxCoord x1
, x2
, y1
, y2
;
1752 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1753 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1754 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1755 path
->MoveToPoint( x1
, y1
) ;
1756 for (int i
= 1; i
< n
; i
++)
1758 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1759 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1761 path
->AddLineToPoint( x2
, y2
) ;
1764 m_graphicContext
->StrokePath( path
) ;
1769 void wxDC::DoDrawSpline(wxList
*points
)
1771 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1773 if ( m_logicalFunction
!= wxCOPY
)
1776 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1778 wxList::compatibility_iterator node
= points
->GetFirst();
1779 if (node
== wxList::compatibility_iterator())
1783 wxPoint
*p
= (wxPoint
*)node
->GetData();
1788 node
= node
->GetNext();
1789 p
= (wxPoint
*)node
->GetData();
1793 wxCoord cx1
= ( x1
+ x2
) / 2;
1794 wxCoord cy1
= ( y1
+ y2
) / 2;
1796 path
->MoveToPoint( XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ) ;
1797 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , YLOG2DEVMAC( cy1
) ) ;
1800 while ((node
= node
->GetNext()) != NULL
)
1802 while ((node
= node
->GetNext()))
1803 #endif // !wxUSE_STL
1805 p
= (wxPoint
*)node
->GetData();
1810 wxCoord cx4
= (x1
+ x2
) / 2;
1811 wxCoord cy4
= (y1
+ y2
) / 2;
1813 path
->AddQuadCurveToPoint(
1814 XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ,
1815 XLOG2DEVMAC( cx4
) , YLOG2DEVMAC( cy4
) ) ;
1821 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , YLOG2DEVMAC( y2
) ) ;
1823 m_graphicContext
->StrokePath( path
) ;
1828 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1829 wxCoord xoffset
, wxCoord yoffset
,
1832 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1834 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1836 if ( m_logicalFunction
!= wxCOPY
)
1839 wxCoord x1
, x2
, y1
, y2
;
1840 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1841 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1843 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1844 path
->MoveToPoint( x1
, y1
) ;
1845 for (int i
= 1; i
< n
; i
++)
1847 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1848 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1850 path
->AddLineToPoint( x2
, y2
) ;
1853 if ( x1
!= x2
|| y1
!= y2
)
1854 path
->AddLineToPoint( x1
, y1
) ;
1856 path
->CloseSubpath() ;
1857 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1862 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1864 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1866 if ( m_logicalFunction
!= wxCOPY
)
1869 wxCoord xx
= XLOG2DEVMAC(x
);
1870 wxCoord yy
= YLOG2DEVMAC(y
);
1871 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1872 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1874 // CMB: draw nothing if transformed w or h is 0
1875 if (ww
== 0 || hh
== 0)
1878 // CMB: handle -ve width and/or height
1890 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1891 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1892 m_graphicContext
->DrawPath( path
) ;
1896 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1897 wxCoord width
, wxCoord height
,
1900 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1902 if ( m_logicalFunction
!= wxCOPY
)
1906 radius
= - radius
* ((width
< height
) ? width
: height
);
1907 wxCoord xx
= XLOG2DEVMAC(x
);
1908 wxCoord yy
= YLOG2DEVMAC(y
);
1909 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1910 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1912 // CMB: draw nothing if transformed w or h is 0
1913 if (ww
== 0 || hh
== 0)
1916 // CMB: handle -ve width and/or height
1928 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1931 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1932 m_graphicContext
->DrawPath( path
) ;
1936 m_graphicContext
->PushState() ;
1937 m_graphicContext
->Translate( xx
, yy
) ;
1938 m_graphicContext
->Scale( radius
, radius
) ;
1939 double fw
= ww
/ radius
;
1940 double fh
= hh
/ radius
;
1941 path
->MoveToPoint(fw
, fh
/ 2);
1942 path
->AddArcToPoint(fw
, fh
, fw
/ 2, fh
, 1);
1943 path
->AddArcToPoint(0, fh
, 0, fh
/ 2, 1);
1944 path
->AddArcToPoint(0, 0, fw
/ 2, 0, 1);
1945 path
->AddArcToPoint(fw
, 0, fw
, fh
/ 2, 1);
1946 path
->CloseSubpath();
1947 m_graphicContext
->DrawPath( path
) ;
1948 m_graphicContext
->PopState() ;
1953 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1955 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1957 if ( m_logicalFunction
!= wxCOPY
)
1960 wxCoord xx
= XLOG2DEVMAC(x
);
1961 wxCoord yy
= YLOG2DEVMAC(y
);
1962 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1963 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1965 // CMB: draw nothing if transformed w or h is 0
1966 if (ww
== 0 || hh
== 0)
1969 // CMB: handle -ve width and/or height
1981 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1982 m_graphicContext
->PushState() ;
1983 m_graphicContext
->Translate(xx
+ ww
/ 2, yy
+ hh
/ 2);
1984 m_graphicContext
->Scale(ww
/ 2 , hh
/ 2);
1985 path
->AddArc( 0, 0, 1, 0 , 2 * M_PI
, false ) ;
1986 m_graphicContext
->DrawPath( path
) ;
1987 m_graphicContext
->PopState() ;
1991 bool wxDC::CanDrawBitmap() const
1997 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1998 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1999 wxCoord xsrcMask
, wxCoord ysrcMask
)
2001 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
2002 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
2004 if ( logical_func
== wxNO_OP
)
2007 if (xsrcMask
== -1 && ysrcMask
== -1)
2013 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
2014 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
2015 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
2016 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
2018 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
2019 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
2020 wxCoord wwdest
= XLOG2DEVREL(width
) ;
2021 wxCoord hhdest
= YLOG2DEVREL(height
) ;
2023 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
2024 if ( memdc
&& logical_func
== wxCOPY
)
2026 wxBitmap blit
= memdc
->GetSelectedObject() ;
2028 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
2030 wxCoord bmpwidth
= blit
.GetWidth();
2031 wxCoord bmpheight
= blit
.GetHeight();
2033 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
2035 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
2036 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
2037 if ( wwsrc
> 0 && hhsrc
> 0 )
2039 if ( xxsrc
>= 0 && yysrc
>= 0 )
2041 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
2042 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
2043 blit
= blit
.GetSubBitmap( subrect
) ;
2047 // in this case we'd probably have to adjust the different coordinates, but
2048 // we have to find out proper contract first
2049 blit
= wxNullBitmap
;
2054 blit
= wxNullBitmap
;
2060 m_graphicContext
->DrawBitmap( blit
, xxdest
, yydest
, wwdest
, hhdest
) ;
2065 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ;
2072 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
2075 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
2076 // wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
2078 if ( str
.length() == 0 )
2080 if ( m_logicalFunction
!= wxCOPY
)
2083 int drawX
= XLOG2DEVMAC(x
) ;
2084 int drawY
= YLOG2DEVMAC(y
) ;
2086 m_graphicContext
->DrawText( str
, drawX
,drawY
, angle
) ;
2089 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
2091 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
2093 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
2096 bool wxDC::CanGetTextExtent() const
2098 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
2103 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
2104 wxCoord
*descent
, wxCoord
*externalLeading
,
2105 wxFont
*theFont
) const
2107 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
2109 wxFont formerFont
= m_font
;
2112 m_graphicContext
->SetFont( *theFont
) ;
2115 wxCoord h
, d
, e
, w
;
2117 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
) ;
2120 *height
= YDEV2LOGREL( h
) ;
2122 *descent
=YDEV2LOGREL( d
);
2123 if ( externalLeading
)
2124 *externalLeading
= YDEV2LOGREL( e
);
2126 *width
= XDEV2LOGREL( w
) ;
2130 m_graphicContext
->SetFont( m_font
) ;
2134 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
2136 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
2138 m_graphicContext
->GetPartialTextExtents( text
, widths
) ;
2139 for ( size_t i
= 0 ; i
< widths
.GetCount() ; ++i
)
2140 widths
[i
] = XDEV2LOGREL( widths
[i
] );
2145 wxCoord
wxDC::GetCharWidth(void) const
2148 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2153 wxCoord
wxDC::GetCharHeight(void) const
2156 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2161 void wxDC::Clear(void)
2163 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2165 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2167 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2168 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2169 switch ( m_backgroundBrush
.MacGetBrushKind() )
2171 case kwxMacBrushTheme
:
2173 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2174 if ( HIThemeSetFill
!= 0 )
2176 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2177 CGContextFillRect(cg
, rect
);
2184 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2185 CGContextSetRGBFillColor( cg
, (CGFloat
) color
.red
/ 65536,
2186 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 );
2187 CGContextFillRect( cg
, rect
);
2190 // reset to normal value
2191 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2192 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2196 case kwxMacBrushThemeBackground
:
2198 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2200 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2201 if ( UMAGetSystemVersion() >= 0x1030 )
2203 HIThemeBackgroundDrawInfo drawInfo
;
2204 drawInfo
.version
= 0 ;
2205 drawInfo
.state
= kThemeStateActive
;
2206 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2207 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2209 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2210 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2217 case kwxMacBrushColour
:
2219 // FIXME: doesn't correctly render stippled brushes !!
2220 // FIXME: should this be replaced by ::SetBrush() ??
2222 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2223 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2224 CGContextFillRect(cg
, rect
);
2226 // reset to normal value
2227 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2228 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2233 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2241 // ---------------------------------------------------------------------------
2242 // coordinates transformations
2243 // ---------------------------------------------------------------------------
2245 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2247 return ((wxDC
*)this)->XDEV2LOG(x
);
2250 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2252 return ((wxDC
*)this)->YDEV2LOG(y
);
2255 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2257 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2260 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2262 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2265 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2267 return ((wxDC
*)this)->XLOG2DEV(x
);
2270 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2272 return ((wxDC
*)this)->YLOG2DEV(y
);
2275 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2277 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2280 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2282 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2285 #endif // wxMAC_USE_CORE_GRAPHICS