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 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
53 const double M_PI
= 3.14159265358979 ;
57 const double RAD2DEG
= 180.0 / M_PI
;
58 const short kEmulatedMode
= -1 ;
59 const short kUnsupportedMode
= -2 ;
61 extern TECObjectRef s_TECNativeCToUnicode
;
65 // The textctrl implementation still needs that (needs what?) for the non-HIView implementation
67 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
68 wxMacPortSaver( (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) )
70 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
71 m_formerClip
= NewRgn() ;
72 m_newClip
= NewRgn() ;
73 GetClip( m_formerClip
) ;
77 // guard against half constructed objects, this just leads to a empty clip
81 win
->MacWindowToRootWindow( &x
, &y
) ;
83 // get area including focus rect
84 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
85 if ( !EmptyRgn( m_newClip
) )
86 OffsetRgn( m_newClip
, x
, y
) ;
89 SetClip( m_newClip
) ;
93 wxMacWindowClipper::~wxMacWindowClipper()
95 SetPort( m_newPort
) ;
96 SetClip( m_formerClip
) ;
97 DisposeRgn( m_newClip
) ;
98 DisposeRgn( m_formerClip
) ;
101 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
102 wxMacWindowClipper( win
)
104 // the port is already set at this point
105 m_newPort
= (GrafPtr
) GetWindowPort( (WindowRef
) win
->MacGetTopLevelWindowRef() ) ;
106 GetThemeDrawingState( &m_themeDrawingState
) ;
109 wxMacWindowStateSaver::~wxMacWindowStateSaver()
111 SetPort( m_newPort
) ;
112 SetThemeDrawingState( m_themeDrawingState
, true ) ;
115 // minimal implementation only used for appearance drawing < 10.3
117 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
118 m_ph( (GrafPtr
) dc
->m_macPort
)
120 wxASSERT( dc
->Ok() ) ;
123 // dc->MacSetupPort(&m_ph) ;
126 wxMacPortSetter::~wxMacPortSetter()
128 // m_dc->MacCleanupPort(&m_ph) ;
131 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
135 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
136 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
137 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
139 //-----------------------------------------------------------------------------
140 // device context implementation
142 // more and more of the dc functionality should be implemented by calling
143 // the appropricate wxMacCGContext, but we will have to do that step by step
144 // also coordinate conversions should be moved to native matrix ops
145 //-----------------------------------------------------------------------------
147 // we always stock two context states, one at entry, to be able to preserve the
148 // state we were called with, the other one after changing to HI Graphics orientation
149 // (this one is used for getting back clippings etc)
151 wxMacCGPath::wxMacCGPath()
153 m_path
= CGPathCreateMutable() ;
156 wxMacCGPath::~wxMacCGPath()
158 CGPathRelease( m_path
) ;
161 // opens (starts) a new subpath
162 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
164 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
167 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
169 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
172 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
174 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
177 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
179 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
180 CGPathAddRect( m_path
, NULL
, cgRect
) ;
183 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
185 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
188 // closes the current subpath
189 void wxMacCGPath::CloseSubpath()
191 CGPathCloseSubpath( m_path
) ;
194 CGPathRef
wxMacCGPath::GetPath() const
199 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
205 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
208 m_cgContext
= cgcontext
;
209 CGContextSaveGState( m_cgContext
) ;
210 CGContextSaveGState( m_cgContext
) ;
213 wxMacCGContext::wxMacCGContext()
219 wxMacCGContext::~wxMacCGContext()
223 CGContextSynchronize( m_cgContext
) ;
224 CGContextRestoreGState( m_cgContext
) ;
225 CGContextRestoreGState( m_cgContext
) ;
229 CGContextRelease( m_cgContext
) ;
233 void wxMacCGContext::Clip( const wxRegion
®ion
)
235 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
238 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
240 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
241 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
242 CGContextStrokePath( m_cgContext
) ;
245 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
247 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
248 CGPathDrawingMode mode
= m_mode
;
250 if ( fillStyle
== wxODDEVEN_RULE
)
252 if ( mode
== kCGPathFill
)
253 mode
= kCGPathEOFill
;
254 else if ( mode
== kCGPathFillStroke
)
255 mode
= kCGPathEOFillStroke
;
258 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
259 CGContextDrawPath( m_cgContext
, mode
) ;
262 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
264 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
265 CGContextSaveGState( m_cgContext
) ;
267 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
268 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
269 CGPathDrawingMode mode
= kCGPathFill
;
271 if ( fillStyle
== wxODDEVEN_RULE
)
272 mode
= kCGPathEOFill
;
274 CGContextBeginPath( m_cgContext
) ;
275 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
276 CGContextClosePath( m_cgContext
) ;
277 CGContextDrawPath( m_cgContext
, mode
) ;
279 CGContextRestoreGState( m_cgContext
) ;
282 wxGraphicPath
* wxMacCGContext::CreatePath()
284 // make sure that we now have a real cgref, before doing
285 // anything with paths
286 CGContextRef cg
= GetNativeContext() ;
289 return new wxMacCGPath() ;
292 // in case we only got a QDPort only create a cgref now
294 CGContextRef
wxMacCGContext::GetNativeContext()
296 if ( m_cgContext
== NULL
)
299 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
300 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
301 CGContextSaveGState( m_cgContext
) ;
303 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
305 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
306 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
308 CGContextSaveGState( m_cgContext
) ;
310 SetBrush( m_brush
) ;
316 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
318 // we allow either setting or clearing but not replacing
319 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
322 CGContextSaveGState( cg
) ;
327 #pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
329 // CGPattern wrapper class: always allocate on heap, never call destructor
336 // is guaranteed to be called only with a non-Null CGContextRef
337 virtual void Render( CGContextRef ctxRef
) = 0 ;
339 operator CGPatternRef() const { return m_patternRef
; }
342 virtual ~wxMacCGPattern()
344 // as this is called only when the m_patternRef is been released;
345 // don't release it again
348 static void _Render( void *info
, CGContextRef ctxRef
)
350 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
351 if ( self
&& ctxRef
)
352 self
->Render( ctxRef
) ;
355 static void _Dispose( void *info
)
357 wxMacCGPattern
* self
= (wxMacCGPattern
*) info
;
361 CGPatternRef m_patternRef
;
363 static const CGPatternCallbacks ms_Callbacks
;
366 const CGPatternCallbacks
wxMacCGPattern::ms_Callbacks
= { 0, &wxMacCGPattern::_Render
, &wxMacCGPattern::_Dispose
};
368 class ImagePattern
: public wxMacCGPattern
371 ImagePattern( const wxBitmap
* bmp
, CGAffineTransform transform
)
373 wxASSERT( bmp
&& bmp
->Ok() ) ;
375 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
) ;
378 // ImagePattern takes ownership of CGImageRef passed in
379 ImagePattern( CGImageRef image
, CGAffineTransform transform
)
384 Init( image
, transform
) ;
387 virtual void Render( CGContextRef ctxRef
)
390 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
394 void Init( CGImageRef image
, CGAffineTransform transform
)
399 m_imageBounds
= CGRectMake( 0.0, 0.0, (float)CGImageGetWidth( m_image
), (float)CGImageGetHeight( m_image
) ) ;
400 m_patternRef
= CGPatternCreate(
401 this , m_imageBounds
, transform
,
402 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
403 kCGPatternTilingNoDistortion
, true , &wxMacCGPattern::ms_Callbacks
) ;
410 CGImageRelease( m_image
) ;
414 CGRect m_imageBounds
;
417 class HatchPattern
: public wxMacCGPattern
420 HatchPattern( int hatchstyle
, CGAffineTransform transform
)
422 m_hatch
= hatchstyle
;
423 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
424 m_patternRef
= CGPatternCreate(
425 this , m_imageBounds
, transform
,
426 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
427 kCGPatternTilingNoDistortion
, false , &wxMacCGPattern::ms_Callbacks
) ;
430 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
432 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
433 if ( UMAGetSystemVersion() >= 0x1040 )
435 CGContextStrokeLineSegments( ctxRef
, pts
, count
) ;
440 CGContextBeginPath( ctxRef
);
441 for (size_t i
= 0; i
< count
; i
+= 2)
443 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
444 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
446 CGContextStrokePath(ctxRef
);
450 virtual void Render( CGContextRef ctxRef
)
454 case wxBDIAGONAL_HATCH
:
458 { 8.0 , 0.0 } , { 0.0 , 8.0 }
460 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
464 case wxCROSSDIAG_HATCH
:
468 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
469 { 8.0 , 0.0 } , { 0.0 , 8.0 }
471 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
475 case wxFDIAGONAL_HATCH
:
479 { 0.0 , 0.0 } , { 8.0 , 8.0 }
481 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
489 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
490 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
492 StrokeLineSegments( ctxRef
, pts
, 4 ) ;
496 case wxHORIZONTAL_HATCH
:
500 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
502 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
506 case wxVERTICAL_HATCH
:
510 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
512 StrokeLineSegments( ctxRef
, pts
, 2 ) ;
524 CGRect m_imageBounds
;
530 void wxMacCGContext::SetPen( const wxPen
&pen
)
533 if ( m_cgContext
== NULL
)
536 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
537 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
540 // we can benchmark performance; should go into a setting eventually
541 CGContextSetShouldAntialias( m_cgContext
, false ) ;
547 m_mode
= kCGPathFill
; // just a default
551 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
552 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
554 // TODO: * m_dc->m_scaleX
555 float penWidth
= pen
.GetWidth();
558 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
561 switch ( pen
.GetCap() )
564 cap
= kCGLineCapRound
;
567 case wxCAP_PROJECTING
:
568 cap
= kCGLineCapSquare
;
572 cap
= kCGLineCapButt
;
576 cap
= kCGLineCapButt
;
581 switch ( pen
.GetJoin() )
584 join
= kCGLineJoinBevel
;
588 join
= kCGLineJoinMiter
;
592 join
= kCGLineJoinRound
;
596 join
= kCGLineJoinMiter
;
600 m_mode
= kCGPathStroke
;
603 const float *lengths
= NULL
;
604 float *userLengths
= NULL
;
606 const float dashUnit
= penWidth
< 1.0 ? 1.0 : penWidth
;
608 const float dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
609 const float short_dashed
[] = { 9.0 , 6.0 };
610 const float dashed
[] = { 19.0 , 9.0 };
611 const float dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
613 switch ( pen
.GetStyle() )
620 count
= WXSIZEOF(dotted
);
625 count
= WXSIZEOF(dashed
) ;
629 lengths
= short_dashed
;
630 count
= WXSIZEOF(short_dashed
) ;
634 lengths
= dotted_dashed
;
635 count
= WXSIZEOF(dotted_dashed
);
640 count
= pen
.GetDashes( &dashes
) ;
641 if ((dashes
!= NULL
) && (count
> 0))
643 userLengths
= new float[count
] ;
644 for ( int i
= 0 ; i
< count
; ++i
)
646 userLengths
[i
] = dashes
[i
] * dashUnit
;
648 if ( i
% 2 == 1 && userLengths
[i
] < dashUnit
+ 2.0 )
649 userLengths
[i
] = dashUnit
+ 2.0 ;
650 else if ( i
% 2 == 0 && userLengths
[i
] < dashUnit
)
651 userLengths
[i
] = dashUnit
;
654 lengths
= userLengths
;
659 float alphaArray
[1] = { 1.0 } ;
660 wxBitmap
* bmp
= pen
.GetStipple() ;
661 if ( bmp
&& bmp
->Ok() )
663 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
664 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
665 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
666 CGContextSetStrokePattern( m_cgContext
, pattern
, alphaArray
) ;
673 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
674 CGContextSetStrokeColorSpace( m_cgContext
, patternSpace
) ;
675 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( pen
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
677 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
678 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
680 CGContextSetStrokePattern( m_cgContext
, pattern
, colorArray
) ;
685 if ((lengths
!= NULL
) && (count
> 0))
687 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
688 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
689 cap
= kCGLineCapButt
;
693 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
696 CGContextSetLineCap( m_cgContext
, cap
) ;
697 CGContextSetLineJoin( m_cgContext
, join
) ;
699 delete[] userLengths
;
702 if ( fill
&& stroke
)
703 m_mode
= kCGPathFillStroke
;
707 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
710 if ( m_cgContext
== NULL
)
713 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
714 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
717 // we can benchmark performance, should go into a setting later
718 CGContextSetShouldAntialias( m_cgContext
, false ) ;
724 m_mode
= kCGPathFill
; // just a default
728 if ( brush
.GetStyle() == wxSOLID
)
730 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
731 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
733 else if ( brush
.IsHatch() )
735 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
736 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
737 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new HatchPattern( brush
.GetStyle() , CGContextGetCTM( m_cgContext
) ) ) );
739 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
740 float colorArray
[4] = { col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 } ;
742 CGContextSetFillPattern( m_cgContext
, pattern
, colorArray
) ;
746 // now brush is a bitmap
747 float alphaArray
[1] = { 1.0 } ;
748 wxBitmap
* bmp
= brush
.GetStipple() ;
749 if ( bmp
&& bmp
->Ok() )
751 wxMacCFRefHolder
<CGColorSpaceRef
> patternSpace( CGColorSpaceCreatePattern( NULL
) ) ;
752 CGContextSetFillColorSpace( m_cgContext
, patternSpace
) ;
753 wxMacCFRefHolder
<CGPatternRef
> pattern( *( new ImagePattern( bmp
, CGContextGetCTM( m_cgContext
) ) ) );
754 CGContextSetFillPattern( m_cgContext
, pattern
, alphaArray
) ;
758 m_mode
= kCGPathFill
;
761 if ( fill
&& stroke
)
762 m_mode
= kCGPathFillStroke
;
764 m_mode
= kCGPathStroke
;
768 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
770 CGContextSaveGState(c
);
771 CGContextTranslateCTM(c
, center
.x
, center
.y
);
772 CGContextScaleCTM(c
, a
, b
);
773 CGContextMoveToPoint(c
, 1, 0);
774 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
775 CGContextClosePath(c
);
776 CGContextRestoreGState(c
);
779 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
783 if (ovalWidth
== 0 || ovalHeight
== 0)
785 CGContextAddRect(c
, rect
);
789 CGContextSaveGState(c
);
790 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
791 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
793 fw
= CGRectGetWidth(rect
) / ovalWidth
;
794 fh
= CGRectGetHeight(rect
) / ovalHeight
;
796 CGContextMoveToPoint(c
, fw
, fh
/ 2);
797 CGContextAddArcToPoint(c
, fw
, fh
, fw
/ 2, fh
, 1);
798 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/ 2, 1);
799 CGContextAddArcToPoint(c
, 0, 0, fw
/ 2, 0, 1);
800 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/ 2, 1);
801 CGContextClosePath(c
);
802 CGContextRestoreGState(c
);
811 m_mm_to_pix_x
= mm2pt
;
812 m_mm_to_pix_y
= mm2pt
;
814 m_externalDeviceOriginX
= 0;
815 m_externalDeviceOriginY
= 0;
816 m_logicalScaleX
= 1.0;
817 m_logicalScaleY
= 1.0;
822 m_needComputeScaleX
=
823 m_needComputeScaleY
= false;
827 m_macLocalOrigin
.y
= 0 ;
829 m_pen
= *wxBLACK_PEN
;
830 m_font
= *wxNORMAL_FONT
;
831 m_brush
= *wxWHITE_BRUSH
;
833 m_macATSUIStyle
= NULL
;
834 m_graphicContext
= NULL
;
839 if ( m_macATSUIStyle
)
841 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
842 m_macATSUIStyle
= NULL
;
845 delete m_graphicContext
;
848 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
850 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
851 wxCHECK_RET( bmp
.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
853 wxCoord xx
= XLOG2DEVMAC(x
);
854 wxCoord yy
= YLOG2DEVMAC(y
);
855 wxCoord w
= bmp
.GetWidth();
856 wxCoord h
= bmp
.GetHeight();
857 wxCoord ww
= XLOG2DEVREL(w
);
858 wxCoord hh
= YLOG2DEVREL(h
);
860 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
861 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
862 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
863 HIViewDrawCGImage( cg
, &r
, image
) ;
864 CGImageRelease( image
) ;
867 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
869 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
870 wxCHECK_RET( icon
.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
872 wxCoord xx
= XLOG2DEVMAC(x
);
873 wxCoord yy
= YLOG2DEVMAC(y
);
874 wxCoord w
= icon
.GetWidth();
875 wxCoord h
= icon
.GetHeight();
876 wxCoord ww
= XLOG2DEVREL(w
);
877 wxCoord hh
= YLOG2DEVREL(h
);
879 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
880 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
881 CGContextSaveGState( cg
);
882 CGContextTranslateCTM( cg
, xx
, yy
+ hh
);
883 CGContextScaleCTM( cg
, 1, -1 );
884 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
885 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
886 CGContextRestoreGState( cg
) ;
889 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
891 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
893 wxCoord xx
, yy
, ww
, hh
;
896 ww
= XLOG2DEVREL(width
);
897 hh
= YLOG2DEVREL(height
);
899 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
900 CGRect clipRect
= CGRectMake( xx
, yy
, ww
, hh
) ;
901 CGContextClipToRect( cgContext
, clipRect
) ;
903 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
904 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
908 m_clipX1
= wxMax( m_clipX1
, xx
);
909 m_clipY1
= wxMax( m_clipY1
, yy
);
910 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
911 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
923 // TODO: as soon as we don't reset the context for each operation anymore
924 // we have to update the context as well
927 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
929 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
933 DestroyClippingRegion();
938 region
.GetBox( x
, y
, w
, h
);
939 wxCoord xx
, yy
, ww
, hh
;
945 // if we have a scaling that we cannot map onto native regions
946 // we must use the box
947 if ( ww
!= w
|| hh
!= h
)
949 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
954 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
955 if ( xx
!= x
|| yy
!= y
)
956 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
957 SectRgn( (RgnHandle
)m_macCurrentClipRgn
, (RgnHandle
)m_macBoundaryClipRgn
, (RgnHandle
)m_macCurrentClipRgn
) ;
962 m_clipX1
= wxMax( m_clipX1
, xx
);
963 m_clipY1
= wxMax( m_clipY1
, yy
);
964 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
965 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
979 void wxDC::DestroyClippingRegion()
981 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
983 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
984 CGContextRestoreGState( cgContext
);
985 CGContextSaveGState( cgContext
);
987 m_graphicContext
->SetPen( m_pen
) ;
988 m_graphicContext
->SetBrush( m_brush
) ;
993 void wxDC::DoGetSizeMM( int* width
, int* height
) const
999 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
1001 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
1004 void wxDC::SetTextForeground( const wxColour
&col
)
1006 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextForeground - invalid DC") );
1008 if ( col
!= m_textForegroundColour
)
1010 m_textForegroundColour
= col
;
1015 void wxDC::SetTextBackground( const wxColour
&col
)
1017 wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
1019 m_textBackgroundColour
= col
;
1022 void wxDC::SetMapMode( int mode
)
1027 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
1031 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
1035 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1039 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
1044 SetLogicalScale( 1.0, 1.0 );
1048 if (mode
!= wxMM_TEXT
)
1050 m_needComputeScaleX
=
1051 m_needComputeScaleY
= true;
1055 void wxDC::SetUserScale( double x
, double y
)
1057 // allow negative ? -> no
1060 ComputeScaleAndOrigin();
1063 void wxDC::SetLogicalScale( double x
, double y
)
1066 m_logicalScaleX
= x
;
1067 m_logicalScaleY
= y
;
1068 ComputeScaleAndOrigin();
1071 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1073 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1074 m_logicalOriginY
= y
* m_signY
;
1075 ComputeScaleAndOrigin();
1078 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1080 m_externalDeviceOriginX
= x
;
1081 m_externalDeviceOriginY
= y
;
1082 ComputeScaleAndOrigin();
1085 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1087 m_signX
= (xLeftRight
? 1 : -1);
1088 m_signY
= (yBottomUp
? -1 : 1);
1089 ComputeScaleAndOrigin();
1092 wxSize
wxDC::GetPPI() const
1094 return wxSize(72, 72);
1097 int wxDC::GetDepth() const
1102 void wxDC::ComputeScaleAndOrigin()
1104 // CMB: copy scale to see if it changes
1105 double origScaleX
= m_scaleX
;
1106 double origScaleY
= m_scaleY
;
1107 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1108 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1109 m_deviceOriginX
= m_externalDeviceOriginX
;
1110 m_deviceOriginY
= m_externalDeviceOriginY
;
1112 // CMB: if scale has changed call SetPen to recalulate the line width
1113 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1115 // this is a bit artificial, but we need to force wxDC to think
1116 // the pen has changed
1117 wxPen
pen( GetPen() );
1124 void wxDC::SetPalette( const wxPalette
& palette
)
1128 void wxDC::SetBackgroundMode( int mode
)
1130 m_backgroundMode
= mode
;
1133 void wxDC::SetFont( const wxFont
&font
)
1139 void wxDC::SetPen( const wxPen
&pen
)
1145 if ( m_graphicContext
)
1147 if ( m_pen
.GetStyle() == wxSOLID
|| m_pen
.GetStyle() == wxTRANSPARENT
)
1149 m_graphicContext
->SetPen( m_pen
) ;
1153 // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
1154 // eg when using a wxScrollWindow and scrolling around
1155 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1156 int origX
= XLOG2DEVMAC( 0 ) ;
1157 int origY
= YLOG2DEVMAC( 0 ) ;
1158 CGContextTranslateCTM( cgContext
, origX
, origY
);
1159 m_graphicContext
->SetPen( m_pen
) ;
1160 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1165 void wxDC::SetBrush( const wxBrush
&brush
)
1167 if (m_brush
== brush
)
1171 if ( m_graphicContext
)
1173 if ( brush
.GetStyle() == wxSOLID
|| brush
.GetStyle() == wxTRANSPARENT
)
1175 m_graphicContext
->SetBrush( m_brush
) ;
1179 // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
1180 // eg when using a wxScrollWindow and scrolling around
1181 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1182 int origX
= XLOG2DEVMAC(0) ;
1183 int origY
= YLOG2DEVMAC(0) ;
1184 CGContextTranslateCTM( cgContext
, origX
, origY
);
1185 m_graphicContext
->SetBrush( m_brush
) ;
1186 CGContextTranslateCTM( cgContext
, -origX
, -origY
);
1191 void wxDC::SetBackground( const wxBrush
&brush
)
1193 if (m_backgroundBrush
== brush
)
1196 m_backgroundBrush
= brush
;
1197 if (!m_backgroundBrush
.Ok())
1201 void wxDC::SetLogicalFunction( int function
)
1203 if (m_logicalFunction
== function
)
1206 m_logicalFunction
= function
;
1207 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1208 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1209 if ( m_logicalFunction
== wxCOPY
)
1210 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1211 else if ( m_logicalFunction
== wxINVERT
)
1212 CGContextSetBlendMode( cgContext
, kCGBlendModeExclusion
) ;
1214 CGContextSetBlendMode( cgContext
, kCGBlendModeNormal
) ;
1218 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1219 const wxColour
& col
, int style
);
1221 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1222 const wxColour
& col
, int style
)
1224 return wxDoFloodFill(this, x
, y
, col
, style
);
1227 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1229 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
1231 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1234 // NB: GetCPixel is a deprecated QD call, and a slow one at that
1236 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1237 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1239 // convert from Mac colour to wx
1240 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8 );
1245 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1247 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
1249 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1250 if ( m_logicalFunction
!= wxCOPY
)
1254 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1255 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1256 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1257 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1259 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1260 path
->MoveToPoint( xx1
, yy1
) ;
1261 path
->AddLineToPoint( xx2
, yy2
) ;
1262 path
->CloseSubpath() ;
1263 m_graphicContext
->StrokePath( path
) ;
1266 CalcBoundingBox(x1
, y1
);
1267 CalcBoundingBox(x2
, y2
);
1270 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1272 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
1274 if ( m_logicalFunction
!= wxCOPY
)
1280 wxCoord xx
= XLOG2DEVMAC(x
);
1281 wxCoord yy
= YLOG2DEVMAC(y
);
1283 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1284 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1285 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1286 path
->CloseSubpath() ;
1287 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1288 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1289 path
->CloseSubpath() ;
1290 m_graphicContext
->StrokePath( path
) ;
1293 CalcBoundingBox(x
, y
);
1294 CalcBoundingBox(x
+ w
, y
+ h
);
1297 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1298 wxCoord x2
, wxCoord y2
,
1299 wxCoord xc
, wxCoord yc
)
1301 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
1303 if ( m_logicalFunction
!= wxCOPY
)
1306 wxCoord xx1
= XLOG2DEVMAC(x1
);
1307 wxCoord yy1
= YLOG2DEVMAC(y1
);
1308 wxCoord xx2
= XLOG2DEVMAC(x2
);
1309 wxCoord yy2
= YLOG2DEVMAC(y2
);
1310 wxCoord xxc
= XLOG2DEVMAC(xc
);
1311 wxCoord yyc
= YLOG2DEVMAC(yc
);
1313 double dx
= xx1
- xxc
;
1314 double dy
= yy1
- yyc
;
1315 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
1316 wxCoord rad
= (wxCoord
)radius
;
1318 if (xx1
== xx2
&& yy1
== yy2
)
1323 else if (radius
== 0.0)
1329 sa
= (xx1
- xxc
== 0) ?
1330 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1331 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
1332 ea
= (xx2
- xxc
== 0) ?
1333 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1334 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
1337 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1338 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1339 CGContextRef ctx
= mctx
->GetNativeContext() ;
1340 CGContextSaveGState( ctx
) ;
1341 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1342 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1344 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1345 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0 );
1347 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1348 CGContextRestoreGState( ctx
) ;
1349 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1352 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1353 double sa
, double ea
)
1355 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
1357 if ( m_logicalFunction
!= wxCOPY
)
1360 wxCoord xx
= XLOG2DEVMAC(x
);
1361 wxCoord yy
= YLOG2DEVMAC(y
);
1362 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1363 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1365 // handle -ve width and/or height
1377 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1379 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1380 CGContextRef ctx
= mctx
->GetNativeContext() ;
1382 CGContextSaveGState( ctx
) ;
1383 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1384 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1386 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1387 CGContextAddArc( ctx
, 0, 0, 1, DegToRad( sa
), DegToRad( ea
), 0 );
1389 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1390 CGContextRestoreGState( ctx
) ;
1391 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1394 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1396 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
1398 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1401 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1402 wxCoord xoffset
, wxCoord yoffset
)
1404 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
1406 #if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1407 if ( m_logicalFunction
!= wxCOPY
)
1411 wxCoord x1
, x2
, y1
, y2
;
1412 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1413 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1414 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1415 path
->MoveToPoint( x1
, y1
) ;
1416 for (int i
= 1; i
< n
; i
++)
1418 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1419 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1421 path
->AddLineToPoint( x2
, y2
) ;
1424 m_graphicContext
->StrokePath( path
) ;
1429 void wxDC::DoDrawSpline(wxList
*points
)
1431 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
1433 if ( m_logicalFunction
!= wxCOPY
)
1436 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1438 wxList::compatibility_iterator node
= points
->GetFirst();
1439 if (node
== wxList::compatibility_iterator())
1443 wxPoint
*p
= (wxPoint
*)node
->GetData();
1448 node
= node
->GetNext();
1449 p
= (wxPoint
*)node
->GetData();
1453 wxCoord cx1
= ( x1
+ x2
) / 2;
1454 wxCoord cy1
= ( y1
+ y2
) / 2;
1456 path
->MoveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ) ;
1457 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , XLOG2DEVMAC( cy1
) ) ;
1460 while ((node
= node
->GetNext()) != NULL
)
1462 while ((node
= node
->GetNext()))
1463 #endif // !wxUSE_STL
1465 p
= (wxPoint
*)node
->GetData();
1470 wxCoord cx4
= (x1
+ x2
) / 2;
1471 wxCoord cy4
= (y1
+ y2
) / 2;
1473 path
->AddQuadCurveToPoint(
1474 XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ,
1475 XLOG2DEVMAC( cx4
) , XLOG2DEVMAC( cy4
) ) ;
1481 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , XLOG2DEVMAC( y2
) ) ;
1483 m_graphicContext
->StrokePath( path
) ;
1488 void wxDC::DoDrawPolygon( int n
, wxPoint points
[],
1489 wxCoord xoffset
, wxCoord yoffset
,
1492 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
1494 if ( n
<= 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1496 if ( m_logicalFunction
!= wxCOPY
)
1499 wxCoord x1
, x2
, y1
, y2
;
1500 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1501 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1503 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1504 path
->MoveToPoint( x1
, y1
) ;
1505 for (int i
= 1; i
< n
; i
++)
1507 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1508 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1510 path
->AddLineToPoint( x2
, y2
) ;
1513 if ( x1
!= x2
|| y1
!= y2
)
1514 path
->AddLineToPoint( x1
, y1
) ;
1516 path
->CloseSubpath() ;
1517 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1522 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1524 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
1526 if ( m_logicalFunction
!= wxCOPY
)
1529 wxCoord xx
= XLOG2DEVMAC(x
);
1530 wxCoord yy
= YLOG2DEVMAC(y
);
1531 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1532 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1534 // CMB: draw nothing if transformed w or h is 0
1535 if (ww
== 0 || hh
== 0)
1538 // CMB: handle -ve width and/or height
1550 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1551 path
->AddRectangle( xx
, yy
, ww
, hh
) ;
1552 m_graphicContext
->DrawPath( path
) ;
1556 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1557 wxCoord width
, wxCoord height
,
1560 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1562 if ( m_logicalFunction
!= wxCOPY
)
1566 radius
= - radius
* ((width
< height
) ? width
: height
);
1567 wxCoord xx
= XLOG2DEVMAC(x
);
1568 wxCoord yy
= YLOG2DEVMAC(y
);
1569 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1570 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1572 // CMB: draw nothing if transformed w or h is 0
1573 if (ww
== 0 || hh
== 0)
1576 // CMB: handle -ve width and/or height
1588 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1589 CGContextRef ctx
= mctx
->GetNativeContext() ;
1590 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , radius
, radius
) ;
1591 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1594 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1596 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
1598 if ( m_logicalFunction
!= wxCOPY
)
1601 wxCoord xx
= XLOG2DEVMAC(x
);
1602 wxCoord yy
= YLOG2DEVMAC(y
);
1603 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1604 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1606 // CMB: draw nothing if transformed w or h is 0
1607 if (ww
== 0 || hh
== 0)
1610 // CMB: handle -ve width and/or height
1622 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1623 CGContextRef ctx
= mctx
->GetNativeContext() ;
1624 CGContextSaveGState( ctx
) ;
1625 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2 );
1626 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1627 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2 * M_PI
, 0 );
1628 CGContextRestoreGState( ctx
) ;
1629 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1632 bool wxDC::CanDrawBitmap() const
1638 wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1639 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1640 wxCoord xsrcMask
, wxCoord ysrcMask
)
1642 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoBlit - invalid DC") );
1643 wxCHECK_MSG( source
->Ok(), false, wxT("wxDC(cg)::DoBlit - invalid source DC") );
1645 if ( logical_func
== wxNO_OP
)
1648 if (xsrcMask
== -1 && ysrcMask
== -1)
1654 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1655 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1656 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1657 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1659 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1660 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1661 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1662 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1664 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1665 if ( memdc
&& logical_func
== wxCOPY
)
1667 wxBitmap blit
= memdc
->GetSelectedObject() ;
1669 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1671 wxCoord bmpwidth
= blit
.GetWidth();
1672 wxCoord bmpheight
= blit
.GetHeight();
1674 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1676 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1677 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1678 if ( wwsrc
> 0 && hhsrc
> 0 )
1680 if ( xxsrc
>= 0 && yysrc
>= 0 )
1682 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1683 blit
= blit
.GetSubBitmap( subrect
) ;
1687 // in this case we'd probably have to adjust the different coordinates, but
1688 // we have to find out proper contract first
1689 blit
= wxNullBitmap
;
1694 blit
= wxNullBitmap
;
1700 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1701 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1702 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1703 HIViewDrawCGImage( cg
, &r
, image
) ;
1704 CGImageRelease( image
) ;
1710 CGContextRef cg
= (wxMacCGContext
*)(source
->GetGraphicContext())->GetNativeContext() ;
1711 void *data
= CGBitmapContextGetData( cg
) ;
1714 return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1720 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1723 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
1724 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
1726 if ( str
.length() == 0 )
1728 if ( m_logicalFunction
!= wxCOPY
)
1731 OSStatus status
= noErr
;
1732 ATSUTextLayout atsuLayout
;
1733 UniCharCount chars
= str
.length() ;
1734 UniChar
* ubuf
= NULL
;
1736 #if SIZEOF_WCHAR_T == 4
1737 wxMBConvUTF16 converter
;
1739 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1740 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1741 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1743 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1744 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1745 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1746 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1748 chars
= unicharlen
/ 2 ;
1751 ubuf
= (UniChar
*) str
.wc_str() ;
1753 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1754 chars
= wxWcslen( wchar
.data() ) ;
1755 ubuf
= (UniChar
*) wchar
.data() ;
1759 int drawX
= XLOG2DEVMAC(x
) ;
1760 int drawY
= YLOG2DEVMAC(y
) ;
1762 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1763 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1765 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1767 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1768 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1770 int iAngle
= int( angle
);
1771 if ( abs(iAngle
) > 0 )
1773 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1774 ATSUAttributeTag atsuTags
[] =
1776 kATSULineRotationTag
,
1778 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1782 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1786 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1787 atsuTags
, atsuSizes
, atsuValues
) ;
1791 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1792 ATSUAttributeTag atsuTags
[] =
1796 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1798 sizeof( CGContextRef
) ,
1800 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1804 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1805 atsuTags
, atsuSizes
, atsuValues
) ;
1808 ATSUTextMeasurement textBefore
, textAfter
;
1809 ATSUTextMeasurement ascent
, descent
;
1811 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1812 &textBefore
, &textAfter
, &ascent
, &descent
);
1814 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1818 if ( m_backgroundMode
== wxSOLID
)
1820 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1821 path
->MoveToPoint( drawX
, drawY
) ;
1822 path
->AddLineToPoint(
1823 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1824 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1825 path
->AddLineToPoint(
1826 (int) (drawX
+ sin(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1827 (int) (drawY
+ cos(angle
/ RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1828 path
->AddLineToPoint(
1829 (int) (drawX
+ cos(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ,
1830 (int) (drawY
- sin(angle
/ RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1832 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1836 drawX
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1837 drawY
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1839 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1840 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1841 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1843 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1844 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1845 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1846 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1847 IntToFixed(0) , IntToFixed(0) );
1849 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1851 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1853 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1854 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1856 ::ATSUDisposeTextLayout(atsuLayout
);
1858 #if SIZEOF_WCHAR_T == 4
1863 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1865 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
1867 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1870 bool wxDC::CanGetTextExtent() const
1872 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
1877 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1878 wxCoord
*descent
, wxCoord
*externalLeading
,
1879 wxFont
*theFont
) const
1881 wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
1883 wxFont formerFont
= m_font
;
1886 // work around the const-ness
1887 *((wxFont
*)(&m_font
)) = *theFont
;
1894 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
1896 OSStatus status
= noErr
;
1897 ATSUTextLayout atsuLayout
;
1898 UniCharCount chars
= str
.length() ;
1899 UniChar
* ubuf
= NULL
;
1901 #if SIZEOF_WCHAR_T == 4
1902 wxMBConvUTF16 converter
;
1904 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1905 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1906 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1908 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1909 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1910 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1911 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1913 chars
= unicharlen
/ 2 ;
1916 ubuf
= (UniChar
*) str
.wc_str() ;
1918 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1919 chars
= wxWcslen( wchar
.data() ) ;
1920 ubuf
= (UniChar
*) wchar
.data() ;
1924 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1925 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1927 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1929 ATSUTextMeasurement textBefore
, textAfter
;
1930 ATSUTextMeasurement textAscent
, textDescent
;
1932 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1933 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1936 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1938 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1939 if ( externalLeading
)
1940 *externalLeading
= 0 ;
1942 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1944 ::ATSUDisposeTextLayout(atsuLayout
);
1946 #if SIZEOF_WCHAR_T == 4
1952 // work around the constness
1953 *((wxFont
*)(&m_font
)) = formerFont
;
1958 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1960 wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
1963 widths
.Add(0, text
.length());
1968 ATSUTextLayout atsuLayout
;
1969 UniCharCount chars
= text
.length() ;
1970 UniChar
* ubuf
= NULL
;
1972 #if SIZEOF_WCHAR_T == 4
1973 wxMBConvUTF16 converter
;
1975 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1976 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1977 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1979 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1980 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1981 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1982 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1984 chars
= unicharlen
/ 2 ;
1987 ubuf
= (UniChar
*) text
.wc_str() ;
1989 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1990 chars
= wxWcslen( wchar
.data() ) ;
1991 ubuf
= (UniChar
*) wchar
.data() ;
1996 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1997 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1999 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
2001 unsigned long actualNumberOfBounds
= 0;
2002 ATSTrapezoid glyphBounds
;
2004 // We get a single bound, since the text should only require one. If it requires more, there is an issue
2006 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2007 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2008 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2011 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
2012 //unsigned char uch = s[i];
2015 ::ATSUDisposeTextLayout(atsuLayout
);
2019 wxCoord
wxDC::GetCharWidth(void) const
2022 DoGetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2027 wxCoord
wxDC::GetCharHeight(void) const
2030 DoGetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2035 void wxDC::Clear(void)
2037 wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
2039 if (m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2041 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2042 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2043 switch ( m_backgroundBrush
.MacGetBrushKind() )
2045 case kwxMacBrushTheme
:
2047 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2048 if ( HIThemeSetFill
!= 0 )
2050 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2051 CGContextFillRect(cg
, rect
);
2058 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2059 CGContextSetRGBFillColor( cg
, (float) color
.red
/ 65536,
2060 (float) color
.green
/ 65536, (float) color
.blue
/ 65536, 1 );
2061 CGContextFillRect( cg
, rect
);
2064 // reset to normal value
2065 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2066 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2070 case kwxMacBrushThemeBackground
:
2072 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2074 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2075 if ( UMAGetSystemVersion() >= 0x1030 )
2077 HIThemeBackgroundDrawInfo drawInfo
;
2078 drawInfo
.version
= 0 ;
2079 drawInfo
.state
= kThemeStateActive
;
2080 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground( NULL
) ;
2081 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2083 HIThemeDrawBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2084 HIThemeApplyBackground( &rect
, &drawInfo
, cg
, kHIThemeOrientationNormal
) ;
2091 case kwxMacBrushColour
:
2093 // FIXME: doesn't correctly render stippled brushes !!
2094 // FIXME: should this be replaced by ::SetBrush() ??
2096 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2097 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2098 CGContextFillRect(cg
, rect
);
2100 // reset to normal value
2101 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2102 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2107 wxFAIL_MSG( wxT("unknown brush kind") ) ;
2113 void wxDC::MacInstallFont() const
2115 wxCHECK_RET( Ok(), wxT("wxDC(cg)::MacInstallFont - invalid DC") );
2117 if ( m_macATSUIStyle
)
2119 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2120 m_macATSUIStyle
= NULL
;
2127 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2129 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
2131 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2132 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2133 ATSUAttributeTag atsuTags
[] =
2138 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2141 sizeof( RGBColor
) ,
2143 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
2149 status
= ::ATSUSetAttributes(
2150 (ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
2151 atsuTags
, atsuSizes
, atsuValues
);
2153 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
2159 // ---------------------------------------------------------------------------
2160 // coordinates transformations
2161 // ---------------------------------------------------------------------------
2163 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2165 return ((wxDC
*)this)->XDEV2LOG(x
);
2168 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2170 return ((wxDC
*)this)->YDEV2LOG(y
);
2173 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2175 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2178 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2180 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2183 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2185 return ((wxDC
*)this)->XLOG2DEV(x
);
2188 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2190 return ((wxDC
*)this)->YLOG2DEV(y
);
2193 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2195 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2198 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2200 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2203 #endif // wxMAC_USE_CORE_GRAPHICS