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
);
1353 // in the current implementation the font contains the text color
1354 m_graphicContext
->SetFont(m_font
);
1358 void wxDC::SetTextBackground( const wxColour
&col
)
1360 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1362 m_textBackgroundColour
= col
;
1365 void wxDC::SetMapMode( int mode
)
1370 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1374 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1378 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1382 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1387 SetLogicalScale( 1.0, 1.0 );
1391 if (mode
!= wxMM_TEXT
)
1393 m_needComputeScaleX
=
1394 m_needComputeScaleY
= true;
1398 void wxDC::SetUserScale( double x
, double y
)
1400 // allow negative ? -> no
1403 ComputeScaleAndOrigin();
1406 void wxDC::SetLogicalScale( double x
, double y
)
1409 m_logicalScaleX
= x
;
1410 m_logicalScaleY
= y
;
1411 ComputeScaleAndOrigin();
1414 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1416 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1417 m_logicalOriginY
= y
* m_signY
;
1418 ComputeScaleAndOrigin();
1421 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1423 m_externalDeviceOriginX
= x
;
1424 m_externalDeviceOriginY
= y
;
1425 ComputeScaleAndOrigin();
1428 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1430 m_signX
= (xLeftRight
? 1 : -1);
1431 m_signY
= (yBottomUp
? -1 : 1);
1432 ComputeScaleAndOrigin();
1435 wxSize
wxDC::GetPPI() const
1437 return wxSize(72, 72);
1440 int wxDC::GetDepth() const
1445 void wxDC::ComputeScaleAndOrigin()
1447 // CMB: copy scale to see if it changes
1448 double origScaleX
= m_scaleX
;
1449 double origScaleY
= m_scaleY
;
1450 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1451 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1452 m_deviceOriginX
= m_externalDeviceOriginX
;
1453 m_deviceOriginY
= m_externalDeviceOriginY
;
1455 // CMB: if scale has changed call SetPen to recalulate the line width
1456 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1458 // this is a bit artificial, but we need to force wxDC to think
1459 // the pen has changed
1460 wxPen
pen( GetPen() );
1467 void wxDC::SetPalette( const wxPalette
& palette
)
1471 void wxDC::SetBackgroundMode( int mode
)
1473 m_backgroundMode
= mode
;
1476 void wxDC::SetFont( const wxFont
&font
)
1479 if ( m_graphicContext
)
1480 m_graphicContext
->SetFont( font
) ;
1483 void wxDC::SetPen( const wxPen
&pen
)
1489 if ( m_graphicContext
)
1491 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1493 m_graphicContext
->SetPen( m_pen
) ;
1497 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1498 // eg when using a wxScrollWindow and scrolling around
1499 int origX
= XLOG2DEVMAC( 0 ) ;
1500 int origY
= YLOG2DEVMAC( 0 ) ;
1501 m_graphicContext
->Translate( origX
, origY
) ;
1502 m_graphicContext
->SetPen( m_pen
) ;
1503 m_graphicContext
->Translate( -origX
, -origY
) ;
1508 void wxDC::SetBrush( const wxBrush
&brush
)
1510 if (m_brush
== brush
)
1514 if ( m_graphicContext
)
1516 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1518 m_graphicContext
->SetBrush( m_brush
) ;
1522 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1523 // eg when using a wxScrollWindow and scrolling around
1524 int origX
= XLOG2DEVMAC(0) ;
1525 int origY
= YLOG2DEVMAC(0) ;
1526 m_graphicContext
->Translate( origX
, origY
) ;
1527 m_graphicContext
->SetBrush( m_brush
) ;
1528 m_graphicContext
->Translate( -origX
, -origY
) ;
1533 void wxDC::SetBackground( const wxBrush
&brush
)
1535 if (m_backgroundBrush
== brush
)
1538 m_backgroundBrush
= brush
;
1539 if (!m_backgroundBrush
.Ok())
1543 void wxDC::SetLogicalFunction( int function
)
1545 if (m_logicalFunction
== function
)
1548 m_logicalFunction
= function
;
1549 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1550 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1551 if ( m_logicalFunction
== wxCOPY
)
1552 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1553 else if ( m_logicalFunction
== wxINVERT
)
1554 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1556 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1560 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1561 const wxColour
& col
, int style
);
1563 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1564 const wxColour
& col
, int style
)
1566 return wxDoFloodFill(this, x
, y
, col
, style
);
1569 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1571 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1573 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1576 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1578 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1579 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1581 // convert from Mac colour to wx
1582 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1587 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1589 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1591 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1592 if ( m_logicalFunction
!= wxCOPY
)
1596 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1597 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1598 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1599 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1601 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1602 path
->MoveToPoint( xx1
, yy1
) ;
1603 path
->AddLineToPoint( xx2
, yy2
) ;
1604 path
->CloseSubpath() ;
1605 m_graphicContext
->StrokePath( path
) ;
1608 CalcBoundingBox(x1
, y1
);
1609 CalcBoundingBox(x2
, y2
);
1612 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1614 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1616 if ( m_logicalFunction
!= wxCOPY
)
1622 wxCoord xx
= XLOG2DEVMAC(x
);
1623 wxCoord yy
= YLOG2DEVMAC(y
);
1625 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1626 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1627 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1628 path
->CloseSubpath() ;
1629 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1630 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1631 path
->CloseSubpath() ;
1632 m_graphicContext
->StrokePath( path
) ;
1635 CalcBoundingBox(x
, y
);
1636 CalcBoundingBox(x
+ w
, y
+ h
);
1639 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1640 wxCoord x2
, wxCoord y2
,
1641 wxCoord xc
, wxCoord yc
)
1643 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1645 if ( m_logicalFunction
!= wxCOPY
)
1648 wxCoord xx1
= XLOG2DEVMAC(x1
);
1649 wxCoord yy1
= YLOG2DEVMAC(y1
);
1650 wxCoord xx2
= XLOG2DEVMAC(x2
);
1651 wxCoord yy2
= YLOG2DEVMAC(y2
);
1652 wxCoord xxc
= XLOG2DEVMAC(xc
);
1653 wxCoord yyc
= YLOG2DEVMAC(yc
);
1655 double dx
= xx1
- xxc
;
1656 double dy
= yy1
- yyc
;
1657 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1658 wxCoord rad
= (wxCoord
)radius
;
1660 if (xx1
== xx2
&& yy1
== yy2
)
1665 else if (radius
== 0.0)
1671 sa
= (xx1
- xxc
== 0) ?
1672 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1673 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1674 ea
= (xx2
- xxc
== 0) ?
1675 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1676 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1679 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1681 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1682 m_graphicContext
->PushState() ;
1683 m_graphicContext
->Translate( xxc
, yyc
) ;
1684 m_graphicContext
->Scale( 1, -1 ) ;
1686 path
->MoveToPoint( 0, 0 ) ;
1687 path
->AddArc( 0, 0, rad
, DegToRad(sa
) , DegToRad(ea
), false ) ;
1689 path
->AddLineToPoint( 0, 0 ) ;
1690 m_graphicContext
->DrawPath( path
) ;
1691 m_graphicContext
->PopState() ;
1695 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1696 double sa
, double ea
)
1698 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1700 if ( m_logicalFunction
!= wxCOPY
)
1703 wxCoord xx
= XLOG2DEVMAC(x
);
1704 wxCoord yy
= YLOG2DEVMAC(y
);
1705 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1706 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1708 // handle -ve width and/or height
1720 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1722 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1723 m_graphicContext
->PushState() ;
1724 m_graphicContext
->Translate( xx
+ ww
/ 2, yy
+ hh
/ 2 ) ;
1725 m_graphicContext
->Scale( 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1727 path
->MoveToPoint( 0, 0 ) ;
1728 path
->AddArc( 0, 0, 1 , DegToRad(sa
) , DegToRad(ea
), false ) ;
1730 path
->AddLineToPoint( 0, 0 ) ;
1731 m_graphicContext
->DrawPath( path
) ;
1732 m_graphicContext
->PopState() ;
1736 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1738 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1740 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1743 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1744 wxCoord xoffset
, wxCoord yoffset
)
1746 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1748 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1749 if ( m_logicalFunction
!= wxCOPY
)
1753 wxCoord x1
, x2
, y1
, y2
;
1754 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1755 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1756 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1757 path
->MoveToPoint( x1
, y1
) ;
1758 for (int i
= 1; i
< n
; i
++)
1760 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1761 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1763 path
->AddLineToPoint( x2
, y2
) ;
1766 m_graphicContext
->StrokePath( path
) ;
1771 void wxDC::DoDrawSpline(wxList
*points
)
1773 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1775 if ( m_logicalFunction
!= wxCOPY
)
1778 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1780 wxList::compatibility_iterator node
= points
->GetFirst();
1781 if (node
== wxList::compatibility_iterator())
1785 wxPoint
*p
= (wxPoint
*)node
->GetData();
1790 node
= node
->GetNext();
1791 p
= (wxPoint
*)node
->GetData();
1795 wxCoord cx1
= ( x1
+ x2
) / 2;
1796 wxCoord cy1
= ( y1
+ y2
) / 2;
1798 path
->MoveToPoint( XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ) ;
1799 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , YLOG2DEVMAC( cy1
) ) ;
1802 while ((node
= node
->GetNext()) != NULL
)
1804 while ((node
= node
->GetNext()))
1805 #endif // !wxUSE_STL
1807 p
= (wxPoint
*)node
->GetData();
1812 wxCoord cx4
= (x1
+ x2
) / 2;
1813 wxCoord cy4
= (y1
+ y2
) / 2;
1815 path
->AddQuadCurveToPoint(
1816 XLOG2DEVMAC( x1
) , YLOG2DEVMAC( y1
) ,
1817 XLOG2DEVMAC( cx4
) , YLOG2DEVMAC( cy4
) ) ;
1823 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , YLOG2DEVMAC( y2
) ) ;
1825 m_graphicContext
->StrokePath( path
) ;
1830 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1831 wxCoord xoffset
, wxCoord yoffset
,
1834 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1836 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1838 if ( m_logicalFunction
!= wxCOPY
)
1841 wxCoord x1
, x2
, y1
, y2
;
1842 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1843 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1845 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1846 path
->MoveToPoint( x1
, y1
) ;
1847 for (int i
= 1; i
< n
; i
++)
1849 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1850 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1852 path
->AddLineToPoint( x2
, y2
) ;
1855 if ( x1
!= x2
|| y1
!= y2
)
1856 path
->AddLineToPoint( x1
, y1
) ;
1858 path
->CloseSubpath() ;
1859 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1864 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1866 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1868 if ( m_logicalFunction
!= wxCOPY
)
1871 wxCoord xx
= XLOG2DEVMAC(x
);
1872 wxCoord yy
= YLOG2DEVMAC(y
);
1873 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1874 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1876 // CMB: draw nothing if transformed w or h is 0
1877 if (ww
== 0 || hh
== 0)
1880 // CMB: handle -ve width and/or height
1892 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1893 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1894 m_graphicContext
->DrawPath( path
) ;
1898 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1899 wxCoord width
, wxCoord height
,
1902 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1904 if ( m_logicalFunction
!= wxCOPY
)
1908 radius
= - radius
* ((width
< height
) ? width
: height
);
1909 wxCoord xx
= XLOG2DEVMAC(x
);
1910 wxCoord yy
= YLOG2DEVMAC(y
);
1911 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1912 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1914 // CMB: draw nothing if transformed w or h is 0
1915 if (ww
== 0 || hh
== 0)
1918 // CMB: handle -ve width and/or height
1930 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1933 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1934 m_graphicContext
->DrawPath( path
) ;
1938 m_graphicContext
->PushState() ;
1939 m_graphicContext
->Translate( xx
, yy
) ;
1940 m_graphicContext
->Scale( radius
, radius
) ;
1941 double fw
= ww
/ radius
;
1942 double fh
= hh
/ radius
;
1943 path
->MoveToPoint(fw
, fh
/ 2);
1944 path
->AddArcToPoint(fw
, fh
, fw
/ 2, fh
, 1);
1945 path
->AddArcToPoint(0, fh
, 0, fh
/ 2, 1);
1946 path
->AddArcToPoint(0, 0, fw
/ 2, 0, 1);
1947 path
->AddArcToPoint(fw
, 0, fw
, fh
/ 2, 1);
1948 path
->CloseSubpath();
1949 m_graphicContext
->DrawPath( path
) ;
1950 m_graphicContext
->PopState() ;
1955 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1957 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1959 if ( m_logicalFunction
!= wxCOPY
)
1962 wxCoord xx
= XLOG2DEVMAC(x
);
1963 wxCoord yy
= YLOG2DEVMAC(y
);
1964 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1965 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1967 // CMB: draw nothing if transformed w or h is 0
1968 if (ww
== 0 || hh
== 0)
1971 // CMB: handle -ve width and/or height
1983 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1984 m_graphicContext
->PushState() ;
1985 m_graphicContext
->Translate(xx
+ ww
/ 2, yy
+ hh
/ 2);
1986 m_graphicContext
->Scale(ww
/ 2 , hh
/ 2);
1987 path
->AddArc( 0, 0, 1, 0 , 2 * M_PI
, false ) ;
1988 m_graphicContext
->DrawPath( path
) ;
1989 m_graphicContext
->PopState() ;
1993 bool wxDC::CanDrawBitmap() const
1999 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
2000 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
2001 wxCoord xsrcMask
, wxCoord ysrcMask
)
2003 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
2004 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
2006 if ( logical_func
== wxNO_OP
)
2009 if (xsrcMask
== -1 && ysrcMask
== -1)
2015 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
2016 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
2017 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
2018 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
2020 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
2021 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
2022 wxCoord wwdest
= XLOG2DEVREL(width
) ;
2023 wxCoord hhdest
= YLOG2DEVREL(height
) ;
2025 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
2026 if ( memdc
&& logical_func
== wxCOPY
)
2028 wxBitmap blit
= memdc
->GetSelectedObject() ;
2030 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
2032 wxCoord bmpwidth
= blit
.GetWidth();
2033 wxCoord bmpheight
= blit
.GetHeight();
2035 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
2037 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
2038 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
2039 if ( wwsrc
> 0 && hhsrc
> 0 )
2041 if ( xxsrc
>= 0 && yysrc
>= 0 )
2043 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
2044 // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
2045 blit
= blit
.GetSubBitmap( subrect
) ;
2049 // in this case we'd probably have to adjust the different coordinates, but
2050 // we have to find out proper contract first
2051 blit
= wxNullBitmap
;
2056 blit
= wxNullBitmap
;
2062 m_graphicContext
->DrawBitmap( blit
, xxdest
, yydest
, wwdest
, hhdest
) ;
2067 wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ;
2074 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
2077 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
2078 // wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
2080 if ( str
.length() == 0 )
2082 if ( m_logicalFunction
!= wxCOPY
)
2085 int drawX
= XLOG2DEVMAC(x
) ;
2086 int drawY
= YLOG2DEVMAC(y
) ;
2088 m_graphicContext
->DrawText( str
, drawX
,drawY
, angle
) ;
2091 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
2093 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
2095 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
2098 bool wxDC::CanGetTextExtent() const
2100 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
2105 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
2106 wxCoord
*descent
, wxCoord
*externalLeading
,
2107 wxFont
*theFont
) const
2109 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
2111 wxFont formerFont
= m_font
;
2114 m_graphicContext
->SetFont( *theFont
) ;
2117 wxCoord h
, d
, e
, w
;
2119 m_graphicContext
->GetTextExtent( str
, &w
, &h
, &d
, &e
) ;
2122 *height
= YDEV2LOGREL( h
) ;
2124 *descent
=YDEV2LOGREL( d
);
2125 if ( externalLeading
)
2126 *externalLeading
= YDEV2LOGREL( e
);
2128 *width
= XDEV2LOGREL( w
) ;
2132 m_graphicContext
->SetFont( m_font
) ;
2136 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
2138 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
2140 m_graphicContext
->GetPartialTextExtents( text
, widths
) ;
2141 for ( size_t i
= 0 ; i
< widths
.GetCount() ; ++i
)
2142 widths
[i
] = XDEV2LOGREL( widths
[i
] );
2147 wxCoord
wxDC::GetCharWidth(void) const
2150 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2155 wxCoord
wxDC::GetCharHeight(void) const
2158 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2163 void wxDC::Clear(void)
2165 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2167 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2169 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2170 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2171 switch ( m_backgroundBrush
.MacGetBrushKind() )
2173 case kwxMacBrushTheme
:
2175 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2176 if ( HIThemeSetFill
!= 0 )
2178 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2179 CGContextFillRect(cg
, rect
);
2186 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2187 CGContextSetRGBFillColor( cg
, (CGFloat
) color
.red
/ 65536,
2188 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 );
2189 CGContextFillRect( cg
, rect
);
2192 // reset to normal value
2193 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2194 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2198 case kwxMacBrushThemeBackground
:
2200 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2202 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2203 if ( UMAGetSystemVersion() >= 0x1030 )
2205 HIThemeBackgroundDrawInfo drawInfo
;
2206 drawInfo
.version
= 0 ;
2207 drawInfo
.state
= kThemeStateActive
;
2208 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2209 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2211 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2212 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2219 case kwxMacBrushColour
:
2221 // FIXME: doesn't correctly render stippled brushes !!
2222 // FIXME: should this be replaced by ::SetBrush() ??
2224 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2225 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2226 CGContextFillRect(cg
, rect
);
2228 // reset to normal value
2229 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2230 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2235 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2243 // ---------------------------------------------------------------------------
2244 // coordinates transformations
2245 // ---------------------------------------------------------------------------
2247 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2249 return ((wxDC
*)this)->XDEV2LOG(x
);
2252 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2254 return ((wxDC
*)this)->YDEV2LOG(y
);
2257 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2259 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2262 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2264 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2267 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2269 return ((wxDC
*)this)->XLOG2DEV(x
);
2272 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2274 return ((wxDC
*)this)->YLOG2DEV(y
);
2277 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2279 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2282 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2284 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2287 #endif // wxMAC_USE_CORE_GRAPHICS