1 /////////////////////////////////////////////////////////////////////////////
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
19 #include "wx/mac/uma.h"
20 #include "wx/dcmemory.h"
21 #include "wx/dcprint.h"
22 #include "wx/region.h"
32 #include "wx/mac/private.h"
34 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
42 const double M_PI
= 3.14159265358979 ;
45 const double RAD2DEG
= 180.0 / M_PI
;
46 const short kEmulatedMode
= -1 ;
47 const short kUnsupportedMode
= -2 ;
49 extern TECObjectRef s_TECNativeCToUnicode
;
52 // The text ctrl implementation still needs that for the non hiview implementation
54 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
55 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
57 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
58 m_formerClip
= NewRgn() ;
59 m_newClip
= NewRgn() ;
60 GetClip( m_formerClip
) ;
64 // guard against half constructed objects, this just leads to a empty clip
68 win
->MacWindowToRootWindow( &x
,&y
) ;
69 // get area including focus rect
70 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
71 if ( !EmptyRgn( m_newClip
) )
72 OffsetRgn( m_newClip
, x
, y
) ;
75 SetClip( m_newClip
) ;
79 wxMacWindowClipper::~wxMacWindowClipper()
81 SetPort( m_newPort
) ;
82 SetClip( m_formerClip
) ;
83 DisposeRgn( m_newClip
) ;
84 DisposeRgn( m_formerClip
) ;
87 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
88 wxMacWindowClipper( win
)
90 // the port is already set at this point
91 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
92 GetThemeDrawingState( &m_themeDrawingState
) ;
95 wxMacWindowStateSaver::~wxMacWindowStateSaver()
97 SetPort( m_newPort
) ;
98 SetThemeDrawingState( m_themeDrawingState
, true ) ;
101 // minimal implementation only used for appearance drawing < 10.3
103 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
104 m_ph( (GrafPtr
) dc
->m_macPort
)
106 wxASSERT( dc
->Ok() ) ;
108 // dc->MacSetupPort(&m_ph) ;
110 wxMacPortSetter::~wxMacPortSetter()
112 // m_dc->MacCleanupPort(&m_ph) ;
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
119 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
120 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
121 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
123 //-----------------------------------------------------------------------------
124 // device context implementation
126 // more and more of the dc functionality should be implemented by calling
127 // the appropricate wxMacCGContext, but we will have to do that step by step
128 // also coordinate conversions should be moved to native matrix ops
129 //-----------------------------------------------------------------------------
131 // we always stock two context states, one at entry, to be able to preserve the
132 // state we were called with, the other one after changing to HI Graphics orientation
133 // (this one is used for getting back clippings etc)
135 wxMacCGPath::wxMacCGPath()
137 m_path
= CGPathCreateMutable() ;
140 wxMacCGPath::~wxMacCGPath()
142 CGPathRelease( m_path
) ;
145 // Starts a new subpath at
146 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
148 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
151 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
153 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
156 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
158 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
161 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
163 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
164 CGPathAddRect( m_path
, NULL
, cgRect
) ;
167 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
169 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
172 // closes the current subpath
173 void wxMacCGPath::CloseSubpath()
175 CGPathCloseSubpath( m_path
) ;
178 CGPathRef
wxMacCGPath::GetPath() const
183 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
189 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
192 m_cgContext
= cgcontext
;
193 CGContextSaveGState( m_cgContext
) ;
194 CGContextSaveGState( m_cgContext
) ;
197 wxMacCGContext::wxMacCGContext()
203 wxMacCGContext::~wxMacCGContext()
207 CGContextSynchronize( m_cgContext
) ;
208 CGContextRestoreGState( m_cgContext
) ;
209 CGContextRestoreGState( m_cgContext
) ;
212 CGContextRelease( m_cgContext
) ;
216 void wxMacCGContext::Clip( const wxRegion
®ion
)
218 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
221 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
223 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
224 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
225 CGContextStrokePath( m_cgContext
) ;
228 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
230 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
231 CGPathDrawingMode mode
= m_mode
;
232 if ( fillStyle
== wxODDEVEN_RULE
)
234 if ( mode
== kCGPathFill
)
235 mode
= kCGPathEOFill
;
236 else if ( mode
== kCGPathFillStroke
)
237 mode
= kCGPathEOFillStroke
;
239 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
240 CGContextDrawPath( m_cgContext
, mode
) ;
243 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
245 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
246 CGContextSaveGState( m_cgContext
) ;
248 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
249 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
250 CGPathDrawingMode mode
= kCGPathFill
;
252 if ( fillStyle
== wxODDEVEN_RULE
)
253 mode
= kCGPathEOFill
;
255 CGContextBeginPath( m_cgContext
) ;
256 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
257 CGContextClosePath( m_cgContext
) ;
258 CGContextDrawPath( m_cgContext
, mode
) ;
260 CGContextRestoreGState( m_cgContext
) ;
263 wxGraphicPath
* wxMacCGContext::CreatePath()
265 // make sure that we now have a real cgref, before doing
266 // anything with paths
267 CGContextRef cg
= GetNativeContext() ;
269 return new wxMacCGPath() ;
272 // in case we only got a QDPort only create a cgref now
274 CGContextRef
wxMacCGContext::GetNativeContext()
276 if( m_cgContext
== NULL
)
279 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
280 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
281 CGContextSaveGState( m_cgContext
) ;
283 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
284 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
285 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
287 CGContextSaveGState( m_cgContext
) ;
289 SetBrush( m_brush
) ;
294 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
296 // we allow either setting or clearing but not replacing
297 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
299 CGContextSaveGState( cg
) ;
305 // Experimental support for dashes and patterned brushes
306 // uncomment the following lines to enable it
308 // #define _NEW_GC_DASHES_
309 // #define _NEW_GC_SUPPORT_
311 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
312 #define kCGColorSpaceGenericRGB CFSTR("kCGColorSpaceGenericRGB")
315 void EstablishPatternColorSpace(
320 CGColorSpaceRef baseSpace
, patternSpace
;
330 patternSpace
= CGColorSpaceCreatePattern( NULL
);
333 CGContextSetFillColorSpace( ctxRef
, patternSpace
);
335 CGContextSetStrokeColorSpace( ctxRef
, patternSpace
);
339 baseSpace
= CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
);
340 patternSpace
= CGColorSpaceCreatePattern( baseSpace
);
343 CGContextSetFillColorSpace( ctxRef
, patternSpace
);
345 CGContextSetStrokeColorSpace( ctxRef
, patternSpace
);
348 // NB: the context owns these now, and this code is finished with them
349 if (patternSpace
!= NULL
)
350 CGColorSpaceRelease( patternSpace
);
351 if (baseSpace
!= NULL
)
352 CGColorSpaceRelease( baseSpace
);
355 void ImagePatternRender(
357 CGContextRef ctxRef
)
362 CGImageRef imageRef
= (CGImageRef
)info
;
363 if (imageRef
!= NULL
)
365 CGRect boundsR
= CGRectMake( 0.0, 0.0, (float)CGImageGetWidth( imageRef
), (float)CGImageGetHeight( imageRef
) );
366 CGContextDrawImage( ctxRef
, boundsR
, imageRef
);
370 void ImagePatternDispose(
373 CGImageRef imageRef
= (CGImageRef
)info
;
374 if (imageRef
!= NULL
)
375 CGImageRelease( imageRef
);
378 // specifies the struct version value and the callback functions for draw and release
379 static const CGPatternCallbacks sImagePatternCallback
= { 0, &ImagePatternRender
, &ImagePatternDispose
};
381 long CreatePatternFromBitmap(
382 CGPatternRef
*patternRef
,
383 const wxBitmap
*rasterInfo
,
388 long errorStatus
, widthV
, heightV
, depthV
;
390 if (patternRef
== NULL
)
397 if ((rasterInfo
== NULL
) || !rasterInfo
->Ok())
400 if (errorStatus
== 0)
402 // build a usable bounding CGRect from the wxBitmap's bounds wxRect
403 widthV
= rasterInfo
->GetWidth();
404 heightV
= rasterInfo
->GetHeight();
405 if ((widthV
<= 0) || (heightV
<= 0))
409 if (errorStatus
== 0)
411 depthV
= rasterInfo
->GetDepth();
412 // isColored = (depthV > 1);
414 // FIXME: this is often <= 0 - why???
416 // errorStatus = (-4);
419 if (errorStatus
== 0)
421 imageRef
= (CGImageRef
)(rasterInfo
->CGImageCreate());
422 if (imageRef
== NULL
)
426 if (errorStatus
== 0)
428 // FIXME: switch when this routine belongs to a DC class...
429 boundsR
= CGRectMake( 0.0, 0.0, (float)widthV
, (float)heightV
);
430 // boundsR = CGRectMake( 0.0, 0.0, (float)XLOG2DEVREL( widthV ), (float)XLOG2DEVREL( heightV ) );
432 *patternRef
= CGPatternCreate(
435 CGAffineTransformIdentity
,
438 kCGPatternTilingNoDistortion
,
440 &sImagePatternCallback
);
442 if (*patternRef
== (CGPatternRef
)NULL
)
449 long CreatePatternFromDashes(
450 CGPatternRef
*patternRef
,
451 const wxDash
*sourceDash
,
457 if (patternRef
== NULL
)
461 if ((sourceDash
== NULL
) || (count
<= 0))
464 wxBitmap
dashBits( (char*)sourceDash
, 8, count
, 1 );
465 errorStatus
= CreatePatternFromBitmap( patternRef
, &dashBits
, useMultibit
);
470 long CreatePatternFromBrush(
471 CGPatternRef
*patternRef
,
472 const wxBrush
&sourceBrush
,
477 if (patternRef
== NULL
)
481 errorStatus
= CreatePatternFromBitmap( patternRef
, sourceBrush
.GetStipple(), useMultibit
);
486 long CreatePatternFromPen(
487 CGPatternRef
*patternRef
,
488 const wxPen
&sourcePen
,
493 if (patternRef
== NULL
)
497 errorStatus
= CreatePatternFromBitmap( patternRef
, sourcePen
.GetStipple(), useMultibit
);
505 // FIXME: the NEW_GC_SUPPORT part this routine is unfinished and needs lots of work !!
507 void wxMacCGContext::SetPen( const wxPen
&pen
)
510 if ( m_cgContext
== NULL
)
512 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
513 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
516 // we can benchmark performance, should go into a setting later
517 CGContextSetShouldAntialias( m_cgContext
, false ) ;
522 m_mode
= kCGPathFill
; // just a default
526 m_mode
= kCGPathFill
;
530 #if defined(_NEW_GC_SUPPORT_)
533 CGPatternRef patternRef
;
536 bool hasSetPattern
, useMultibit
;
538 hasSetPattern
= false;
540 result
= CreatePatternFromPen( &patternRef
, pen
, useMultibit
);
543 EstablishPatternColorSpace( m_cgContext
, useMultibit
, false );
546 CGContextSetStrokePattern( m_cgContext
, patternRef
, alphaArray
);
547 CGPatternRelease( patternRef
);
549 hasSetPattern
= true;
551 //wxLogDebug( wxT("CreatePatternFromPen succeeded!") );
554 // NB: the (-2) result is from wxPen instances that don't have a stipple wxBitmap
556 wxLogDebug( wxT("CreatePatternFromPen failed: result [%ld]"), result
);
563 col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() );
565 GetThemeBrushAsColor( pen
.MacGetTheme(), 32, true, &col
);
568 CGContextSetRGBStrokeColor(
569 m_cgContext
, (float) col
.red
/ 65536.0,
570 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
575 // original implementation
576 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
577 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
581 switch( pen
.GetCap() )
584 cap
= kCGLineCapRound
;
586 case wxCAP_PROJECTING
:
587 cap
= kCGLineCapSquare
;
590 cap
= kCGLineCapButt
;
593 cap
= kCGLineCapButt
;
596 CGContextSetLineCap( m_cgContext
, cap
) ;
599 switch( pen
.GetJoin() )
602 join
= kCGLineJoinBevel
;
605 join
= kCGLineJoinMiter
;
608 join
= kCGLineJoinRound
;
611 join
= kCGLineJoinMiter
;
614 CGContextSetLineJoin( m_cgContext
, join
) ;
616 /* TODO * m_dc->m_scaleX */
617 float penWidth
= pen
.GetWidth();
620 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
622 m_mode
= kCGPathStroke
;
625 #if defined(_NEW_GC_DASHES_)
626 const char *dashData
= NULL
;
627 char *userDashData
= NULL
;
630 const char dotted
[] = { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 };
631 const char dashed
[] = { 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00 };
632 const char short_dashed
[] = { 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 };
633 const char dotted_dashed
[] = { 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00 };
635 switch (pen
.GetStyle())
638 // default, undashed pen
643 count
= WXSIZEOF(dotted
);
647 count
= WXSIZEOF(dashed
);
650 dashData
= short_dashed
;
651 count
= WXSIZEOF(short_dashed
);
654 dashData
= dotted_dashed
;
655 count
= WXSIZEOF(dotted_dashed
);
658 count
= pen
.GetDashes( (wxDash
**)&userDashData
);
659 dashData
= userDashData
;
666 if ((dashData
!= NULL
) && (count
> 0))
668 CGPatternRef patternRef
;
674 result
= CreatePatternFromDashes( &patternRef
, (const wxDash
*)dashData
, count
, useMultibit
);
677 col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() );
678 CGContextSetRGBStrokeColor(
679 m_cgContext
, (float) col
.red
/ 65536.0,
680 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
682 EstablishPatternColorSpace( m_cgContext
, useMultibit
, false );
685 CGContextSetStrokePattern( m_cgContext
, patternRef
, alphaArray
);
686 CGPatternRelease( patternRef
);
690 wxLogDebug( wxT("CreatePatternFromDashes failed: result [%ld]"), result
);
693 const float *lengths
= NULL
;
694 float *userLengths
= NULL
;
696 const float dotted
[] = { 3 , 3 };
697 const float dashed
[] = { 19 , 9 };
698 const float short_dashed
[] = { 9 , 6 };
699 const float dotted_dashed
[] = { 9 , 6 , 3 , 3 };
701 switch( pen
.GetStyle() )
707 count
= WXSIZEOF(dotted
);
711 count
= WXSIZEOF(dashed
) ;
714 lengths
= short_dashed
;
715 count
= WXSIZEOF(short_dashed
) ;
718 lengths
= dotted_dashed
;
719 count
= WXSIZEOF(dotted_dashed
);
723 count
= pen
.GetDashes( &dashes
) ;
724 if ((dashes
!= NULL
) && (count
> 0))
726 userLengths
= new float[count
] ;
727 for( int i
= 0 ; i
< count
; ++i
)
729 userLengths
[i
] = (float)dashes
[i
] ;
730 if (userLengths
[i
] <= 0.0)
732 userLengths
[i
] = 1.0;
733 // wxLogDebug( wxT("wxMacCGContext::SetPen - bad dash length[%d] [%.2f]"), i, (float)dashes[i] );
737 lengths
= userLengths
;
743 if ((lengths
!= NULL
) && (count
> 0))
745 // we need to change the cap, otherwise everything overlaps
746 // and we get solid lines
747 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
748 CGContextSetLineCap( m_cgContext
, kCGLineCapButt
) ;
752 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
755 delete[] userLengths
;
758 if ( fill
&& stroke
)
760 m_mode
= kCGPathFillStroke
;
765 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
768 if ( m_cgContext
== NULL
)
771 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
772 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
775 // we can benchmark performance, should go into a setting later
776 CGContextSetShouldAntialias( m_cgContext
, false ) ;
782 m_mode
= kCGPathFill
; // just a default
786 #if defined(_NEW_GC_SUPPORT_)
789 CGPatternRef patternRef
;
792 bool hasSetPattern
, useMultibit
;
794 hasSetPattern
= false;
796 result
= CreatePatternFromBrush( &patternRef
, brush
, useMultibit
);
799 EstablishPatternColorSpace( m_cgContext
, useMultibit
, true );
802 CGContextSetFillPattern( m_cgContext
, patternRef
, alphaArray
);
803 CGPatternRelease( patternRef
);
805 hasSetPattern
= true;
807 //wxLogDebug( wxT("CreatePatternFromBrush succeeded!") );
810 // NB: the (-2) result is from wxBrush instances that don't have a stipple wxBitmap
812 wxLogDebug( wxT("CreatePatternFromBrush failed: result [%ld]"), result
);
819 col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
821 GetThemeBrushAsColor( brush
.MacGetTheme(), 32, true, &col
);
824 CGContextSetRGBFillColor(
825 m_cgContext
, (float) col
.red
/ 65536.0,
826 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
831 // original implementation
832 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
833 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
836 m_mode
= kCGPathFill
;
840 m_mode
= kCGPathStroke
;
842 if ( fill
&& stroke
)
844 m_mode
= kCGPathFillStroke
;
849 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
851 CGContextSaveGState(c
);
852 CGContextTranslateCTM(c
, center
.x
, center
.y
);
853 CGContextScaleCTM(c
, a
, b
);
854 CGContextMoveToPoint(c
, 1, 0);
855 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
856 CGContextClosePath(c
);
857 CGContextRestoreGState(c
);
860 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
864 if (ovalWidth
== 0 || ovalHeight
== 0)
866 CGContextAddRect(c
, rect
);
869 CGContextSaveGState(c
);
870 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
871 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
872 fw
= CGRectGetWidth(rect
) / ovalWidth
;
873 fh
= CGRectGetHeight(rect
) / ovalHeight
;
874 CGContextMoveToPoint(c
, fw
, fh
/2);
875 CGContextAddArcToPoint(c
, fw
, fh
, fw
/2, fh
, 1);
876 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/2, 1);
877 CGContextAddArcToPoint(c
, 0, 0, fw
/2, 0, 1);
878 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/2, 1);
879 CGContextClosePath(c
);
880 CGContextRestoreGState(c
);
887 m_mm_to_pix_x
= mm2pt
;
888 m_mm_to_pix_y
= mm2pt
;
889 m_internalDeviceOriginX
= 0;
890 m_internalDeviceOriginY
= 0;
891 m_externalDeviceOriginX
= 0;
892 m_externalDeviceOriginY
= 0;
893 m_logicalScaleX
= 1.0;
894 m_logicalScaleY
= 1.0;
899 m_needComputeScaleX
= FALSE
;
900 m_needComputeScaleY
= FALSE
;
904 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
906 m_pen
= *wxBLACK_PEN
;
907 m_font
= *wxNORMAL_FONT
;
908 m_brush
= *wxWHITE_BRUSH
;
910 m_macATSUIStyle
= NULL
;
912 m_graphicContext
= NULL
;
917 if( m_macATSUIStyle
)
919 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
920 m_macATSUIStyle
= NULL
;
923 delete m_graphicContext
;
926 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
928 wxCHECK_RET( Ok(), wxT("invalid window dc") );
929 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
930 wxCoord xx
= XLOG2DEVMAC(x
);
931 wxCoord yy
= YLOG2DEVMAC(y
);
932 wxCoord w
= bmp
.GetWidth();
933 wxCoord h
= bmp
.GetHeight();
934 wxCoord ww
= XLOG2DEVREL(w
);
935 wxCoord hh
= YLOG2DEVREL(h
);
937 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
938 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
939 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
940 HIViewDrawCGImage( cg
, &r
, image
) ;
941 CGImageRelease( image
) ;
944 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
946 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
947 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
949 wxCoord xx
= XLOG2DEVMAC(x
);
950 wxCoord yy
= YLOG2DEVMAC(y
);
951 wxCoord w
= icon
.GetWidth();
952 wxCoord h
= icon
.GetHeight();
953 wxCoord ww
= XLOG2DEVREL(w
);
954 wxCoord hh
= YLOG2DEVREL(h
);
956 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
957 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
958 CGContextSaveGState(cg
);
959 CGContextTranslateCTM(cg
, xx
, yy
+ hh
);
960 CGContextScaleCTM(cg
, 1, -1);
961 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
962 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
963 CGContextRestoreGState( cg
) ;
966 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
968 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
969 wxCoord xx
, yy
, ww
, hh
;
972 ww
= XLOG2DEVREL(width
);
973 hh
= YLOG2DEVREL(height
);
975 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
976 CGRect clipRect
= CGRectMake( xx
,yy
, ww
, hh
) ;
977 CGContextClipToRect( cgContext
, clipRect
) ;
979 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
980 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
983 m_clipX1
= wxMax( m_clipX1
, xx
);
984 m_clipY1
= wxMax( m_clipY1
, yy
);
985 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
986 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
996 // TODO as soon as we don't reset the context for each operation anymore
997 // we have to update the context as well
1000 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1002 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
1005 DestroyClippingRegion();
1009 region
.GetBox( x
, y
, w
, h
);
1010 wxCoord xx
, yy
, ww
, hh
;
1011 xx
= XLOG2DEVMAC(x
);
1012 yy
= YLOG2DEVMAC(y
);
1013 ww
= XLOG2DEVREL(w
);
1014 hh
= YLOG2DEVREL(h
);
1015 // if we have a scaling that we cannot map onto native regions
1016 // we must use the box
1017 if ( ww
!= w
|| hh
!= h
)
1019 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
1024 CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
1025 if ( xx != x || yy != y )
1027 OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
1029 SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1033 m_clipX1
= wxMax( m_clipX1
, xx
);
1034 m_clipY1
= wxMax( m_clipY1
, yy
);
1035 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
1036 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
1049 void wxDC::DestroyClippingRegion()
1051 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1052 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1053 CGContextRestoreGState( cgContext
);
1054 CGContextSaveGState( cgContext
);
1055 m_graphicContext
->SetPen( m_pen
) ;
1056 m_graphicContext
->SetBrush( m_brush
) ;
1060 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1065 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
1066 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
1069 void wxDC::SetTextForeground( const wxColour
&col
)
1071 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1072 if ( col
!= m_textForegroundColour
)
1074 m_textForegroundColour
= col
;
1079 void wxDC::SetTextBackground( const wxColour
&col
)
1081 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1082 m_textBackgroundColour
= col
;
1085 void wxDC::SetMapMode( int mode
)
1090 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
1093 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
1096 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1099 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
1103 SetLogicalScale( 1.0, 1.0 );
1106 if (mode
!= wxMM_TEXT
)
1108 m_needComputeScaleX
= TRUE
;
1109 m_needComputeScaleY
= TRUE
;
1113 void wxDC::SetUserScale( double x
, double y
)
1115 // allow negative ? -> no
1118 ComputeScaleAndOrigin();
1121 void wxDC::SetLogicalScale( double x
, double y
)
1124 m_logicalScaleX
= x
;
1125 m_logicalScaleY
= y
;
1126 ComputeScaleAndOrigin();
1129 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1131 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1132 m_logicalOriginY
= y
* m_signY
;
1133 ComputeScaleAndOrigin();
1136 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1138 m_externalDeviceOriginX
= x
;
1139 m_externalDeviceOriginY
= y
;
1140 ComputeScaleAndOrigin();
1143 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1145 m_signX
= (xLeftRight
? 1 : -1);
1146 m_signY
= (yBottomUp
? -1 : 1);
1147 ComputeScaleAndOrigin();
1150 wxSize
wxDC::GetPPI() const
1152 return wxSize(72, 72);
1155 int wxDC::GetDepth() const
1160 void wxDC::ComputeScaleAndOrigin()
1162 // CMB: copy scale to see if it changes
1163 double origScaleX
= m_scaleX
;
1164 double origScaleY
= m_scaleY
;
1165 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1166 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1167 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
1168 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
1169 // CMB: if scale has changed call SetPen to recalulate the line width
1170 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1172 // this is a bit artificial, but we need to force wxDC to think
1173 // the pen has changed
1174 wxPen
pen(GetPen());
1180 void wxDC::SetPalette( const wxPalette
& palette
)
1184 void wxDC::SetBackgroundMode( int mode
)
1186 m_backgroundMode
= mode
;
1189 void wxDC::SetFont( const wxFont
&font
)
1195 void wxDC::SetPen( const wxPen
&pen
)
1200 if ( m_graphicContext
)
1202 m_graphicContext
->SetPen( m_pen
) ;
1206 void wxDC::SetBrush( const wxBrush
&brush
)
1208 if (m_brush
== brush
)
1211 if ( m_graphicContext
)
1213 m_graphicContext
->SetBrush( m_brush
) ;
1217 void wxDC::SetBackground( const wxBrush
&brush
)
1219 if (m_backgroundBrush
== brush
)
1221 m_backgroundBrush
= brush
;
1222 if (!m_backgroundBrush
.Ok())
1226 void wxDC::SetLogicalFunction( int function
)
1228 if (m_logicalFunction
== function
)
1230 m_logicalFunction
= function
;
1233 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1234 const wxColour
& col
, int style
);
1236 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1237 const wxColour
& col
, int style
)
1239 return wxDoFloodFill(this, x
, y
, col
, style
);
1242 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1244 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
1245 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
1246 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1249 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1250 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1251 // Convert from Mac colour to wx
1252 col
->Set( colour
.red
>> 8,
1258 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1260 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1262 if ( m_logicalFunction
!= wxCOPY
)
1265 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1266 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1267 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1268 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1270 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1271 path
->MoveToPoint( xx1
, yy1
) ;
1272 path
->AddLineToPoint( xx2
, yy2
) ;
1273 path
->CloseSubpath() ;
1274 m_graphicContext
->StrokePath( path
) ;
1277 CalcBoundingBox(x1
, y1
);
1278 CalcBoundingBox(x2
, y2
);
1281 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1283 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
1285 if ( m_logicalFunction
!= wxCOPY
)
1291 wxCoord xx
= XLOG2DEVMAC(x
);
1292 wxCoord yy
= YLOG2DEVMAC(y
);
1294 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1295 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1296 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1297 path
->CloseSubpath() ;
1298 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1299 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1300 path
->CloseSubpath() ;
1301 m_graphicContext
->StrokePath( path
) ;
1304 CalcBoundingBox(x
, y
);
1305 CalcBoundingBox(x
+w
, y
+h
);
1308 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1309 wxCoord x2
, wxCoord y2
,
1310 wxCoord xc
, wxCoord yc
)
1312 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
1314 if ( m_logicalFunction
!= wxCOPY
)
1317 wxCoord xx1
= XLOG2DEVMAC(x1
);
1318 wxCoord yy1
= YLOG2DEVMAC(y1
);
1319 wxCoord xx2
= XLOG2DEVMAC(x2
);
1320 wxCoord yy2
= YLOG2DEVMAC(y2
);
1321 wxCoord xxc
= XLOG2DEVMAC(xc
);
1322 wxCoord yyc
= YLOG2DEVMAC(yc
);
1323 double dx
= xx1
- xxc
;
1324 double dy
= yy1
- yyc
;
1325 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1326 wxCoord rad
= (wxCoord
)radius
;
1328 if (xx1
== xx2
&& yy1
== yy2
)
1333 else if (radius
== 0.0)
1339 sa
= (xx1
- xxc
== 0) ?
1340 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1341 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
1342 ea
= (xx2
- xxc
== 0) ?
1343 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1344 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
1347 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1348 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1349 CGContextRef ctx
= mctx
->GetNativeContext() ;
1350 CGContextSaveGState( ctx
) ;
1351 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1352 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1354 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1355 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0);
1357 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1358 CGContextRestoreGState( ctx
) ;
1359 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1362 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1363 double sa
, double ea
)
1365 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
1367 if ( m_logicalFunction
!= wxCOPY
)
1370 wxCoord xx
= XLOG2DEVMAC(x
);
1371 wxCoord yy
= YLOG2DEVMAC(y
);
1372 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1373 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1374 // handle -ve width and/or height
1375 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1376 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1378 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1380 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1381 CGContextRef ctx
= mctx
->GetNativeContext() ;
1383 CGContextSaveGState( ctx
) ;
1384 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2);
1385 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1387 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1388 CGContextAddArc( ctx
, 0, 0, 1, DegToRad(sa
), DegToRad(ea
), 0);
1390 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1391 CGContextRestoreGState( ctx
) ;
1392 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1395 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1397 wxCHECK_RET(Ok(), wxT("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("Invalid DC"));
1406 if ( m_logicalFunction
!= wxCOPY
)
1409 wxCoord x1
, x2
, y1
, y2
;
1410 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1411 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1412 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1413 path
->MoveToPoint( x1
, y1
) ;
1414 for (int i
= 1; i
< n
; i
++)
1416 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1417 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1419 path
->AddLineToPoint( x2
, y2
) ;
1421 m_graphicContext
->StrokePath( path
) ;
1426 void wxDC::DoDrawSpline(wxList
*points
)
1428 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1430 if ( m_logicalFunction
!= wxCOPY
)
1433 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1435 wxList::compatibility_iterator node
= points
->GetFirst();
1436 if (node
== wxList::compatibility_iterator())
1440 wxPoint
*p
= (wxPoint
*)node
->GetData();
1445 node
= node
->GetNext();
1446 p
= (wxPoint
*)node
->GetData();
1450 wxCoord cx1
= ( x1
+ x2
) / 2;
1451 wxCoord cy1
= ( y1
+ y2
) / 2;
1453 path
->MoveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ) ;
1454 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , XLOG2DEVMAC( cy1
) ) ;
1457 while ((node
= node
->GetNext()) != NULL
)
1459 while ((node
= node
->GetNext()))
1460 #endif // !wxUSE_STL
1462 p
= (wxPoint
*)node
->GetData();
1467 wxCoord cx4
= (x1
+ x2
) / 2;
1468 wxCoord cy4
= (y1
+ y2
) / 2;
1470 path
->AddQuadCurveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ,
1471 XLOG2DEVMAC( cx4
) , XLOG2DEVMAC( cy4
) ) ;
1477 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , XLOG2DEVMAC( y2
) ) ;
1479 m_graphicContext
->StrokePath( path
) ;
1484 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1485 wxCoord xoffset
, wxCoord yoffset
,
1488 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1489 wxCoord x1
, x2
, y1
, y2
;
1490 if ( n
== 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1493 if ( m_logicalFunction
!= wxCOPY
)
1496 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1497 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1499 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1500 path
->MoveToPoint( x1
, y1
) ;
1501 for (int i
= 1; i
< n
; i
++)
1503 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1504 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1506 path
->AddLineToPoint( x2
, y2
) ;
1508 if ( x1
!= x2
|| y1
!= y2
)
1510 path
->AddLineToPoint( x1
,y1
) ;
1512 path
->CloseSubpath() ;
1513 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1517 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1519 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1521 if ( m_logicalFunction
!= wxCOPY
)
1524 wxCoord xx
= XLOG2DEVMAC(x
);
1525 wxCoord yy
= YLOG2DEVMAC(y
);
1526 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1527 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1528 // CMB: draw nothing if transformed w or h is 0
1529 if (ww
== 0 || hh
== 0)
1531 // CMB: handle -ve width and/or height
1542 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1543 path
->AddRectangle(xx
,yy
, ww
, hh
) ;
1544 m_graphicContext
->DrawPath( path
) ;
1548 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1549 wxCoord width
, wxCoord height
,
1552 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1554 if ( m_logicalFunction
!= wxCOPY
)
1559 radius
= - radius
* ((width
< height
) ? width
: height
);
1560 wxCoord xx
= XLOG2DEVMAC(x
);
1561 wxCoord yy
= YLOG2DEVMAC(y
);
1562 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1563 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1564 // CMB: draw nothing if transformed w or h is 0
1565 if (ww
== 0 || hh
== 0)
1567 // CMB: handle -ve width and/or height
1578 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1579 CGContextRef ctx
= mctx
->GetNativeContext() ;
1580 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , 16 ,16 ) ;
1581 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1584 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1586 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1588 if ( m_logicalFunction
!= wxCOPY
)
1591 wxCoord xx
= XLOG2DEVMAC(x
);
1592 wxCoord yy
= YLOG2DEVMAC(y
);
1593 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1594 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1595 // CMB: draw nothing if transformed w or h is 0
1596 if (ww
== 0 || hh
== 0)
1598 // CMB: handle -ve width and/or height
1610 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1611 CGContextRef ctx
= mctx
->GetNativeContext() ;
1612 CGContextSaveGState( ctx
) ;
1613 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2);
1614 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1615 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2*M_PI
, 0);
1616 CGContextRestoreGState( ctx
) ;
1617 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1620 bool wxDC::CanDrawBitmap(void) const
1625 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1626 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1627 wxCoord xsrcMask
, wxCoord ysrcMask
)
1629 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1630 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1631 if ( logical_func
== wxNO_OP
)
1633 if (xsrcMask
== -1 && ysrcMask
== -1)
1635 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1638 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1639 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1640 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1641 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1643 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1644 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1645 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1646 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1648 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1649 if ( memdc
&& logical_func
== wxCOPY
)
1651 wxBitmap blit
= memdc
->GetSelectedObject() ;
1652 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1654 wxCoord bmpwidth
= blit
.GetWidth();
1655 wxCoord bmpheight
= blit
.GetHeight();
1657 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1659 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1660 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1661 if ( wwsrc
> 0 && hhsrc
> 0 )
1663 if ( xxsrc
>= 0 && yysrc
>= 0 )
1665 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1666 blit
= blit
.GetSubBitmap( subrect
) ;
1670 // in this case we'd probably have to adjust the different coordinates, but
1671 // we have to find out proper contract first
1672 blit
= wxNullBitmap
;
1677 blit
= wxNullBitmap
;
1682 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1683 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1684 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1685 HIViewDrawCGImage( cg
, &r
, image
) ;
1686 CGImageRelease( image
) ;
1693 CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ;
1694 void *data = CGBitmapContextGetData( cg ) ;
1696 return FALSE
; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1701 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1704 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1706 if ( str
.Length() == 0 )
1709 if ( m_logicalFunction
!= wxCOPY
)
1712 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("No valid font set") ) ;
1714 OSStatus status
= noErr
;
1715 ATSUTextLayout atsuLayout
;
1716 UniCharCount chars
= str
.Length() ;
1717 UniChar
* ubuf
= NULL
;
1718 #if SIZEOF_WCHAR_T == 4
1719 wxMBConvUTF16 converter
;
1721 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1722 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1723 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1725 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1726 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1727 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1728 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1730 chars
= unicharlen
/ 2 ;
1733 ubuf
= (UniChar
*) str
.wc_str() ;
1735 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1736 chars
= wxWcslen( wchar
.data() ) ;
1737 ubuf
= (UniChar
*) wchar
.data() ;
1741 int drawX
= XLOG2DEVMAC(x
) ;
1742 int drawY
= YLOG2DEVMAC(y
) ;
1744 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1745 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1747 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1749 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1750 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1752 int iAngle
= int( angle
);
1753 if ( abs(iAngle
) > 0 )
1755 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1756 ATSUAttributeTag atsuTags
[] =
1758 kATSULineRotationTag
,
1760 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1764 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1768 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1769 atsuTags
, atsuSizes
, atsuValues
) ;
1772 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1773 ATSUAttributeTag atsuTags
[] =
1777 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1779 sizeof( CGContextRef
) ,
1781 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1785 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1786 atsuTags
, atsuSizes
, atsuValues
) ;
1789 ATSUTextMeasurement textBefore
;
1790 ATSUTextMeasurement textAfter
;
1791 ATSUTextMeasurement ascent
;
1792 ATSUTextMeasurement descent
;
1794 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1795 &textBefore
, &textAfter
, &ascent
, &descent
);
1796 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1800 if ( m_backgroundMode
== wxSOLID
)
1802 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1806 path
->AddLineToPoint(
1807 (int) (drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1808 (int) (drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1809 path
->AddLineToPoint(
1810 (int) (drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ,
1811 (int) (drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1812 path
->AddLineToPoint(
1813 (int) (drawX
+ cos(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ,
1814 (int) (drawY
- sin(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1816 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1820 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1821 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1823 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1824 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1825 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1827 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1828 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1829 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1830 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1831 IntToFixed(0) , IntToFixed(0) );
1832 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1833 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1835 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1836 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1838 ::ATSUDisposeTextLayout(atsuLayout
);
1839 #if SIZEOF_WCHAR_T == 4
1844 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1846 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1847 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1850 bool wxDC::CanGetTextExtent() const
1852 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1856 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1857 wxCoord
*descent
, wxCoord
*externalLeading
,
1858 wxFont
*theFont
) const
1860 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1861 wxFont formerFont
= m_font
;
1864 // work around the constness
1865 *((wxFont
*)(&m_font
)) = *theFont
;
1869 if ( str
.Length() == 0 )
1872 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("No valid font set") ) ;
1874 OSStatus status
= noErr
;
1875 ATSUTextLayout atsuLayout
;
1876 UniCharCount chars
= str
.Length() ;
1877 UniChar
* ubuf
= NULL
;
1878 #if SIZEOF_WCHAR_T == 4
1879 wxMBConvUTF16 converter
;
1881 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1882 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1883 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1885 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1886 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1887 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1888 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1890 chars
= unicharlen
/ 2 ;
1893 ubuf
= (UniChar
*) str
.wc_str() ;
1895 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1896 chars
= wxWcslen( wchar
.data() ) ;
1897 ubuf
= (UniChar
*) wchar
.data() ;
1902 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1903 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1905 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1907 ATSUTextMeasurement textBefore
;
1908 ATSUTextMeasurement textAfter
;
1909 ATSUTextMeasurement textAscent
;
1910 ATSUTextMeasurement textDescent
;
1912 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1913 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1916 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1918 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1919 if ( externalLeading
)
1920 *externalLeading
= 0 ;
1922 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1924 ::ATSUDisposeTextLayout(atsuLayout
);
1925 #if SIZEOF_WCHAR_T == 4
1930 // work around the constness
1931 *((wxFont
*)(&m_font
)) = formerFont
;
1937 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1939 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1942 widths
.Add(0, text
.Length());
1944 if (text
.Length() == 0)
1947 ATSUTextLayout atsuLayout
;
1948 UniCharCount chars
= text
.Length() ;
1949 UniChar
* ubuf
= NULL
;
1950 #if SIZEOF_WCHAR_T == 4
1951 wxMBConvUTF16 converter
;
1953 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1954 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1955 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1957 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1958 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1959 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1960 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1962 chars
= unicharlen
/ 2 ;
1965 ubuf
= (UniChar
*) text
.wc_str() ;
1967 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1968 chars
= wxWcslen( wchar
.data() ) ;
1969 ubuf
= (UniChar
*) wchar
.data() ;
1974 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1975 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1977 for ( int pos
= 0; pos
< (int)chars
; pos
++ ) {
1978 unsigned long actualNumberOfBounds
= 0;
1979 ATSTrapezoid glyphBounds
;
1981 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1983 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1, kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1984 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1989 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
1990 //unsigned char uch = s[i];
1993 ::ATSUDisposeTextLayout(atsuLayout
);
1997 wxCoord
wxDC::GetCharWidth(void) const
2000 DoGetTextExtent(wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2004 wxCoord
wxDC::GetCharHeight(void) const
2007 DoGetTextExtent(wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2011 void wxDC::Clear(void)
2013 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2015 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2017 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2018 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2019 switch( m_backgroundBrush
.MacGetBrushKind() )
2021 case kwxMacBrushTheme
:
2023 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2024 if ( HIThemeSetFill
!= 0 )
2026 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2027 CGContextFillRect(cg
, rect
);
2034 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2035 CGContextSetRGBFillColor( cg
, (float) color
.red
/ 65536,
2036 (float) color
.green
/ 65536, (float) color
.blue
/ 65536, 1 );
2037 CGContextFillRect( cg
, rect
);
2040 // reset to normal value
2041 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2042 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2045 case kwxMacBrushThemeBackground
:
2047 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2048 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2049 if ( UMAGetSystemVersion() >= 0x1030 )
2051 HIThemeBackgroundDrawInfo drawInfo
;
2052 drawInfo
.version
= 0 ;
2053 drawInfo
.state
= kThemeStateActive
;
2054 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground(NULL
) ;
2055 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2056 HIThemeDrawBackground( &rect
, &drawInfo
, cg
,
2057 kHIThemeOrientationNormal
) ;
2058 HIThemeApplyBackground( &rect
, &drawInfo
, cg
,
2059 kHIThemeOrientationNormal
) ;
2067 case kwxMacBrushColour
:
2069 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2070 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2071 CGContextFillRect(cg
, rect
);
2073 // reset to normal value
2074 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2075 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2082 void wxDC::MacInstallFont() const
2084 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2086 if( m_macATSUIStyle
)
2088 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2089 m_macATSUIStyle
= NULL
;
2094 OSStatus status
= noErr
;
2095 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2096 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
2098 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2099 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2100 ATSUAttributeTag atsuTags
[] =
2105 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2108 sizeof( RGBColor
) ,
2110 // Boolean kTrue = true ;
2111 // Boolean kFalse = false ;
2113 // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
2114 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2119 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
2120 atsuTags
, atsuSizes
, atsuValues
);
2122 wxASSERT_MSG( status
== noErr
, wxT("couldn't Modify ATSU style") ) ;
2126 // ---------------------------------------------------------------------------
2127 // coordinates transformations
2128 // ---------------------------------------------------------------------------
2130 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2132 return ((wxDC
*)this)->XDEV2LOG(x
);
2135 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2137 return ((wxDC
*)this)->YDEV2LOG(y
);
2140 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2142 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2145 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2147 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2150 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2152 return ((wxDC
*)this)->XLOG2DEV(x
);
2155 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2157 return ((wxDC
*)this)->YLOG2DEV(y
);
2160 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2162 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2165 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2167 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2170 #endif // wxMAC_USE_CORE_GRAPHICS