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"
34 #include "wx/mac/private.h"
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
44 const double M_PI
= 3.14159265358979 ;
47 const double RAD2DEG
= 180.0 / M_PI
;
48 const short kEmulatedMode
= -1 ;
49 const short kUnsupportedMode
= -2 ;
51 extern TECObjectRef s_TECNativeCToUnicode
;
54 // The text ctrl implementation still needs that for the non hiview implementation
56 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
57 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
59 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
60 m_formerClip
= NewRgn() ;
61 m_newClip
= NewRgn() ;
62 GetClip( m_formerClip
) ;
66 // guard against half constructed objects, this just leads to a empty clip
70 win
->MacWindowToRootWindow( &x
,&y
) ;
71 // get area including focus rect
72 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
73 if ( !EmptyRgn( m_newClip
) )
74 OffsetRgn( m_newClip
, x
, y
) ;
77 SetClip( m_newClip
) ;
81 wxMacWindowClipper::~wxMacWindowClipper()
83 SetPort( m_newPort
) ;
84 SetClip( m_formerClip
) ;
85 DisposeRgn( m_newClip
) ;
86 DisposeRgn( m_formerClip
) ;
89 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
90 wxMacWindowClipper( win
)
92 // the port is already set at this point
93 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
94 GetThemeDrawingState( &m_themeDrawingState
) ;
97 wxMacWindowStateSaver::~wxMacWindowStateSaver()
99 SetPort( m_newPort
) ;
100 SetThemeDrawingState( m_themeDrawingState
, true ) ;
103 // minimal implementation only used for appearance drawing < 10.3
105 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
106 m_ph( (GrafPtr
) dc
->m_macPort
)
108 wxASSERT( dc
->Ok() ) ;
110 // dc->MacSetupPort(&m_ph) ;
112 wxMacPortSetter::~wxMacPortSetter()
114 // m_dc->MacCleanupPort(&m_ph) ;
117 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
121 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
122 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
123 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
125 //-----------------------------------------------------------------------------
126 // device context implementation
128 // more and more of the dc functionality should be implemented by calling
129 // the appropricate wxMacCGContext, but we will have to do that step by step
130 // also coordinate conversions should be moved to native matrix ops
131 //-----------------------------------------------------------------------------
133 // we always stock two context states, one at entry, to be able to preserve the
134 // state we were called with, the other one after changing to HI Graphics orientation
135 // (this one is used for getting back clippings etc)
137 wxMacCGPath::wxMacCGPath()
139 m_path
= CGPathCreateMutable() ;
142 wxMacCGPath::~wxMacCGPath()
144 CGPathRelease( m_path
) ;
147 // Starts a new subpath at
148 void wxMacCGPath::MoveToPoint( wxCoord x1
, wxCoord y1
)
150 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
153 void wxMacCGPath::AddLineToPoint( wxCoord x1
, wxCoord y1
)
155 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
158 void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1
, wxCoord cy1
, wxCoord x1
, wxCoord y1
)
160 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x1
, y1
);
163 void wxMacCGPath::AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
165 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
166 CGPathAddRect( m_path
, NULL
, cgRect
) ;
169 void wxMacCGPath::AddCircle( wxCoord x
, wxCoord y
, wxCoord r
)
171 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true ) ;
174 // closes the current subpath
175 void wxMacCGPath::CloseSubpath()
177 CGPathCloseSubpath( m_path
) ;
180 CGPathRef
wxMacCGPath::GetPath() const
185 wxMacCGContext::wxMacCGContext( CGrafPtr port
)
191 wxMacCGContext::wxMacCGContext( CGContextRef cgcontext
)
194 m_cgContext
= cgcontext
;
195 CGContextSaveGState( m_cgContext
) ;
196 CGContextSaveGState( m_cgContext
) ;
199 wxMacCGContext::wxMacCGContext()
205 wxMacCGContext::~wxMacCGContext()
209 CGContextSynchronize( m_cgContext
) ;
210 CGContextRestoreGState( m_cgContext
) ;
211 CGContextRestoreGState( m_cgContext
) ;
214 CGContextRelease( m_cgContext
) ;
218 void wxMacCGContext::Clip( const wxRegion
®ion
)
220 // ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
223 void wxMacCGContext::StrokePath( const wxGraphicPath
*p
)
225 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
226 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
227 CGContextStrokePath( m_cgContext
) ;
230 void wxMacCGContext::DrawPath( const wxGraphicPath
*p
, int fillStyle
)
232 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
233 CGPathDrawingMode mode
= m_mode
;
234 if ( fillStyle
== wxODDEVEN_RULE
)
236 if ( mode
== kCGPathFill
)
237 mode
= kCGPathEOFill
;
238 else if ( mode
== kCGPathFillStroke
)
239 mode
= kCGPathEOFillStroke
;
241 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
242 CGContextDrawPath( m_cgContext
, mode
) ;
245 void wxMacCGContext::FillPath( const wxGraphicPath
*p
, const wxColor
&fillColor
, int fillStyle
)
247 const wxMacCGPath
* path
= dynamic_cast< const wxMacCGPath
*>( p
) ;
248 CGContextSaveGState( m_cgContext
) ;
250 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
251 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
252 CGPathDrawingMode mode
= kCGPathFill
;
254 if ( fillStyle
== wxODDEVEN_RULE
)
255 mode
= kCGPathEOFill
;
257 CGContextBeginPath( m_cgContext
) ;
258 CGContextAddPath( m_cgContext
, path
->GetPath() ) ;
259 CGContextClosePath( m_cgContext
) ;
260 CGContextDrawPath( m_cgContext
, mode
) ;
262 CGContextRestoreGState( m_cgContext
) ;
265 wxGraphicPath
* wxMacCGContext::CreatePath()
267 // make sure that we now have a real cgref, before doing
268 // anything with paths
269 CGContextRef cg
= GetNativeContext() ;
271 return new wxMacCGPath() ;
274 // in case we only got a QDPort only create a cgref now
276 CGContextRef
wxMacCGContext::GetNativeContext()
278 if( m_cgContext
== NULL
)
281 GetPortBounds( (CGrafPtr
) m_qdPort
, &bounds
) ;
282 OSStatus status
= CreateCGContextForPort((CGrafPtr
) m_qdPort
, &m_cgContext
) ;
283 CGContextSaveGState( m_cgContext
) ;
285 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
286 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
287 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
289 CGContextSaveGState( m_cgContext
) ;
291 SetBrush( m_brush
) ;
296 void wxMacCGContext::SetNativeContext( CGContextRef cg
)
298 // we allow either setting or clearing but not replacing
299 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
) ;
301 CGContextSaveGState( cg
) ;
307 // Experimental support for dashes and patterned brushes
308 // uncomment the following lines to enable it
310 // #define _NEW_GC_DASHES_
311 // #define _NEW_GC_SUPPORT_
313 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
314 #define kCGColorSpaceGenericRGB CFSTR("kCGColorSpaceGenericRGB")
317 void EstablishPatternColorSpace(
322 CGColorSpaceRef baseSpace
, patternSpace
;
332 patternSpace
= CGColorSpaceCreatePattern( NULL
);
335 CGContextSetFillColorSpace( ctxRef
, patternSpace
);
337 CGContextSetStrokeColorSpace( ctxRef
, patternSpace
);
341 baseSpace
= CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
);
342 patternSpace
= CGColorSpaceCreatePattern( baseSpace
);
345 CGContextSetFillColorSpace( ctxRef
, patternSpace
);
347 CGContextSetStrokeColorSpace( ctxRef
, patternSpace
);
350 // NB: the context owns these now, and this code is finished with them
351 if (patternSpace
!= NULL
)
352 CGColorSpaceRelease( patternSpace
);
353 if (baseSpace
!= NULL
)
354 CGColorSpaceRelease( baseSpace
);
357 void ImagePatternRender(
359 CGContextRef ctxRef
)
364 CGImageRef imageRef
= (CGImageRef
)info
;
365 if (imageRef
!= NULL
)
367 CGRect boundsR
= CGRectMake( 0.0, 0.0, (float)CGImageGetWidth( imageRef
), (float)CGImageGetHeight( imageRef
) );
368 CGContextDrawImage( ctxRef
, boundsR
, imageRef
);
372 void ImagePatternDispose(
375 CGImageRef imageRef
= (CGImageRef
)info
;
376 if (imageRef
!= NULL
)
377 CGImageRelease( imageRef
);
380 // specifies the struct version value and the callback functions for draw and release
381 static const CGPatternCallbacks sImagePatternCallback
= { 0, &ImagePatternRender
, &ImagePatternDispose
};
383 long CreatePatternFromBitmap(
384 CGPatternRef
*patternRef
,
385 const wxBitmap
*rasterInfo
,
390 long errorStatus
, widthV
, heightV
, depthV
;
392 if (patternRef
== NULL
)
399 if ((rasterInfo
== NULL
) || !rasterInfo
->Ok())
402 if (errorStatus
== 0)
404 // build a usable bounding CGRect from the wxBitmap's bounds wxRect
405 widthV
= rasterInfo
->GetWidth();
406 heightV
= rasterInfo
->GetHeight();
407 if ((widthV
<= 0) || (heightV
<= 0))
411 if (errorStatus
== 0)
413 depthV
= rasterInfo
->GetDepth();
414 // isColored = (depthV > 1);
416 // FIXME: this is often <= 0 - why???
418 // errorStatus = (-4);
421 if (errorStatus
== 0)
423 imageRef
= (CGImageRef
)(rasterInfo
->CGImageCreate());
424 if (imageRef
== NULL
)
428 if (errorStatus
== 0)
430 // FIXME: switch when this routine belongs to a DC class...
431 boundsR
= CGRectMake( 0.0, 0.0, (float)widthV
, (float)heightV
);
432 // boundsR = CGRectMake( 0.0, 0.0, (float)XLOG2DEVREL( widthV ), (float)XLOG2DEVREL( heightV ) );
434 *patternRef
= CGPatternCreate(
437 CGAffineTransformIdentity
,
440 kCGPatternTilingNoDistortion
,
442 &sImagePatternCallback
);
444 if (*patternRef
== (CGPatternRef
)NULL
)
451 long CreatePatternFromDashes(
452 CGPatternRef
*patternRef
,
453 const wxDash
*sourceDash
,
459 if (patternRef
== NULL
)
463 if ((sourceDash
== NULL
) || (count
<= 0))
466 wxBitmap
dashBits( (char*)sourceDash
, 8, count
, 1 );
467 errorStatus
= CreatePatternFromBitmap( patternRef
, &dashBits
, useMultibit
);
472 long CreatePatternFromBrush(
473 CGPatternRef
*patternRef
,
474 const wxBrush
&sourceBrush
,
479 if (patternRef
== NULL
)
483 errorStatus
= CreatePatternFromBitmap( patternRef
, sourceBrush
.GetStipple(), useMultibit
);
488 long CreatePatternFromPen(
489 CGPatternRef
*patternRef
,
490 const wxPen
&sourcePen
,
495 if (patternRef
== NULL
)
499 errorStatus
= CreatePatternFromBitmap( patternRef
, sourcePen
.GetStipple(), useMultibit
);
507 // FIXME: the NEW_GC_SUPPORT part this routine is unfinished and needs lots of work !!
509 void wxMacCGContext::SetPen( const wxPen
&pen
)
512 if ( m_cgContext
== NULL
)
514 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
515 bool stroke
= pen
.GetStyle() != wxTRANSPARENT
;
518 // we can benchmark performance, should go into a setting later
519 CGContextSetShouldAntialias( m_cgContext
, false ) ;
524 m_mode
= kCGPathFill
; // just a default
528 m_mode
= kCGPathFill
;
532 #if defined(_NEW_GC_SUPPORT_)
535 CGPatternRef patternRef
;
538 bool hasSetPattern
, useMultibit
;
540 hasSetPattern
= false;
542 result
= CreatePatternFromPen( &patternRef
, pen
, useMultibit
);
545 EstablishPatternColorSpace( m_cgContext
, useMultibit
, false );
548 CGContextSetStrokePattern( m_cgContext
, patternRef
, alphaArray
);
549 CGPatternRelease( patternRef
);
551 hasSetPattern
= true;
553 //wxLogDebug( wxT("CreatePatternFromPen succeeded!") );
556 // NB: the (-2) result is from wxPen instances that don't have a stipple wxBitmap
558 wxLogDebug( wxT("CreatePatternFromPen failed: result [%ld]"), result
);
565 col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() );
567 GetThemeBrushAsColor( pen
.MacGetTheme(), 32, true, &col
);
570 CGContextSetRGBStrokeColor(
571 m_cgContext
, (float) col
.red
/ 65536.0,
572 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
577 // original implementation
578 RGBColor col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() ) ;
579 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
583 switch( pen
.GetCap() )
586 cap
= kCGLineCapRound
;
588 case wxCAP_PROJECTING
:
589 cap
= kCGLineCapSquare
;
592 cap
= kCGLineCapButt
;
595 cap
= kCGLineCapButt
;
598 CGContextSetLineCap( m_cgContext
, cap
) ;
601 switch( pen
.GetJoin() )
604 join
= kCGLineJoinBevel
;
607 join
= kCGLineJoinMiter
;
610 join
= kCGLineJoinRound
;
613 join
= kCGLineJoinMiter
;
616 CGContextSetLineJoin( m_cgContext
, join
) ;
618 /* TODO * m_dc->m_scaleX */
619 float penWidth
= pen
.GetWidth();
622 CGContextSetLineWidth( m_cgContext
, penWidth
) ;
624 m_mode
= kCGPathStroke
;
627 #if defined(_NEW_GC_DASHES_)
628 const char *dashData
= NULL
;
629 char *userDashData
= NULL
;
632 const char dotted
[] = { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 };
633 const char dashed
[] = { 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00 };
634 const char short_dashed
[] = { 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 };
635 const char dotted_dashed
[] = { 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00 };
637 switch (pen
.GetStyle())
640 // default, undashed pen
645 count
= WXSIZEOF(dotted
);
649 count
= WXSIZEOF(dashed
);
652 dashData
= short_dashed
;
653 count
= WXSIZEOF(short_dashed
);
656 dashData
= dotted_dashed
;
657 count
= WXSIZEOF(dotted_dashed
);
660 count
= pen
.GetDashes( (wxDash
**)&userDashData
);
661 dashData
= userDashData
;
668 if ((dashData
!= NULL
) && (count
> 0))
670 CGPatternRef patternRef
;
676 result
= CreatePatternFromDashes( &patternRef
, (const wxDash
*)dashData
, count
, useMultibit
);
679 col
= MAC_WXCOLORREF( pen
.GetColour().GetPixel() );
680 CGContextSetRGBStrokeColor(
681 m_cgContext
, (float) col
.red
/ 65536.0,
682 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
684 EstablishPatternColorSpace( m_cgContext
, useMultibit
, false );
687 CGContextSetStrokePattern( m_cgContext
, patternRef
, alphaArray
);
688 CGPatternRelease( patternRef
);
692 wxLogDebug( wxT("CreatePatternFromDashes failed: result [%ld]"), result
);
695 const float *lengths
= NULL
;
696 float *userLengths
= NULL
;
698 const float dotted
[] = { 3 , 3 };
699 const float dashed
[] = { 19 , 9 };
700 const float short_dashed
[] = { 9 , 6 };
701 const float dotted_dashed
[] = { 9 , 6 , 3 , 3 };
703 switch( pen
.GetStyle() )
709 count
= WXSIZEOF(dotted
);
713 count
= WXSIZEOF(dashed
) ;
716 lengths
= short_dashed
;
717 count
= WXSIZEOF(short_dashed
) ;
720 lengths
= dotted_dashed
;
721 count
= WXSIZEOF(dotted_dashed
);
725 count
= pen
.GetDashes( &dashes
) ;
726 if ((dashes
!= NULL
) && (count
> 0))
728 userLengths
= new float[count
] ;
729 for( int i
= 0 ; i
< count
; ++i
)
731 userLengths
[i
] = (float)dashes
[i
] ;
732 if (userLengths
[i
] <= 0.0)
734 userLengths
[i
] = 1.0;
735 // wxLogDebug( wxT("wxMacCGContext::SetPen - bad dash length[%d] [%.2f]"), i, (float)dashes[i] );
739 lengths
= userLengths
;
745 if ((lengths
!= NULL
) && (count
> 0))
747 // we need to change the cap, otherwise everything overlaps
748 // and we get solid lines
749 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
750 CGContextSetLineCap( m_cgContext
, kCGLineCapButt
) ;
754 CGContextSetLineDash( m_cgContext
, 0 , NULL
, 0 ) ;
757 delete[] userLengths
;
760 if ( fill
&& stroke
)
762 m_mode
= kCGPathFillStroke
;
767 void wxMacCGContext::SetBrush( const wxBrush
&brush
)
770 if ( m_cgContext
== NULL
)
773 bool fill
= brush
.GetStyle() != wxTRANSPARENT
;
774 bool stroke
= m_pen
.GetStyle() != wxTRANSPARENT
;
777 // we can benchmark performance, should go into a setting later
778 CGContextSetShouldAntialias( m_cgContext
, false ) ;
784 m_mode
= kCGPathFill
; // just a default
788 #if defined(_NEW_GC_SUPPORT_)
791 CGPatternRef patternRef
;
794 bool hasSetPattern
, useMultibit
;
796 hasSetPattern
= false;
798 result
= CreatePatternFromBrush( &patternRef
, brush
, useMultibit
);
801 EstablishPatternColorSpace( m_cgContext
, useMultibit
, true );
804 CGContextSetFillPattern( m_cgContext
, patternRef
, alphaArray
);
805 CGPatternRelease( patternRef
);
807 hasSetPattern
= true;
809 //wxLogDebug( wxT("CreatePatternFromBrush succeeded!") );
812 // NB: the (-2) result is from wxBrush instances that don't have a stipple wxBitmap
814 wxLogDebug( wxT("CreatePatternFromBrush failed: result [%ld]"), result
);
821 col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() );
823 GetThemeBrushAsColor( brush
.MacGetTheme(), 32, true, &col
);
826 CGContextSetRGBFillColor(
827 m_cgContext
, (float) col
.red
/ 65536.0,
828 (float) col
.green
/ 65536.0, (float) col
.blue
/ 65536.0, 1.0 );
833 // original implementation
834 RGBColor col
= MAC_WXCOLORREF( brush
.GetColour().GetPixel() ) ;
835 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
838 m_mode
= kCGPathFill
;
842 m_mode
= kCGPathStroke
;
844 if ( fill
&& stroke
)
846 m_mode
= kCGPathFillStroke
;
851 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
853 CGContextSaveGState(c
);
854 CGContextTranslateCTM(c
, center
.x
, center
.y
);
855 CGContextScaleCTM(c
, a
, b
);
856 CGContextMoveToPoint(c
, 1, 0);
857 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
858 CGContextClosePath(c
);
859 CGContextRestoreGState(c
);
862 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
866 if (ovalWidth
== 0 || ovalHeight
== 0)
868 CGContextAddRect(c
, rect
);
871 CGContextSaveGState(c
);
872 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
873 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
874 fw
= CGRectGetWidth(rect
) / ovalWidth
;
875 fh
= CGRectGetHeight(rect
) / ovalHeight
;
876 CGContextMoveToPoint(c
, fw
, fh
/2);
877 CGContextAddArcToPoint(c
, fw
, fh
, fw
/2, fh
, 1);
878 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/2, 1);
879 CGContextAddArcToPoint(c
, 0, 0, fw
/2, 0, 1);
880 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/2, 1);
881 CGContextClosePath(c
);
882 CGContextRestoreGState(c
);
889 m_mm_to_pix_x
= mm2pt
;
890 m_mm_to_pix_y
= mm2pt
;
891 m_internalDeviceOriginX
= 0;
892 m_internalDeviceOriginY
= 0;
893 m_externalDeviceOriginX
= 0;
894 m_externalDeviceOriginY
= 0;
895 m_logicalScaleX
= 1.0;
896 m_logicalScaleY
= 1.0;
901 m_needComputeScaleX
= FALSE
;
902 m_needComputeScaleY
= FALSE
;
906 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
908 m_pen
= *wxBLACK_PEN
;
909 m_font
= *wxNORMAL_FONT
;
910 m_brush
= *wxWHITE_BRUSH
;
912 m_macATSUIStyle
= NULL
;
914 m_graphicContext
= NULL
;
919 if( m_macATSUIStyle
)
921 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
922 m_macATSUIStyle
= NULL
;
925 delete m_graphicContext
;
928 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
930 wxCHECK_RET( Ok(), wxT("invalid window dc") );
931 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
932 wxCoord xx
= XLOG2DEVMAC(x
);
933 wxCoord yy
= YLOG2DEVMAC(y
);
934 wxCoord w
= bmp
.GetWidth();
935 wxCoord h
= bmp
.GetHeight();
936 wxCoord ww
= XLOG2DEVREL(w
);
937 wxCoord hh
= YLOG2DEVREL(h
);
939 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
940 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() ) ;
941 HIRect r
= CGRectMake( xx
, yy
, ww
, hh
) ;
942 HIViewDrawCGImage( cg
, &r
, image
) ;
943 CGImageRelease( image
) ;
946 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
948 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
949 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
951 wxCoord xx
= XLOG2DEVMAC(x
);
952 wxCoord yy
= YLOG2DEVMAC(y
);
953 wxCoord w
= icon
.GetWidth();
954 wxCoord h
= icon
.GetHeight();
955 wxCoord ww
= XLOG2DEVREL(w
);
956 wxCoord hh
= YLOG2DEVREL(h
);
958 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
959 CGRect r
= CGRectMake( 00 , 00 , ww
, hh
) ;
960 CGContextSaveGState(cg
);
961 CGContextTranslateCTM(cg
, xx
, yy
+ hh
);
962 CGContextScaleCTM(cg
, 1, -1);
963 PlotIconRefInContext( cg
, &r
, kAlignNone
, kTransformNone
,
964 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
965 CGContextRestoreGState( cg
) ;
968 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
970 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
971 wxCoord xx
, yy
, ww
, hh
;
974 ww
= XLOG2DEVREL(width
);
975 hh
= YLOG2DEVREL(height
);
977 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
978 CGRect clipRect
= CGRectMake( xx
,yy
, ww
, hh
) ;
979 CGContextClipToRect( cgContext
, clipRect
) ;
981 // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
982 // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
985 m_clipX1
= wxMax( m_clipX1
, xx
);
986 m_clipY1
= wxMax( m_clipY1
, yy
);
987 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
988 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
998 // TODO as soon as we don't reset the context for each operation anymore
999 // we have to update the context as well
1002 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
1004 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
1007 DestroyClippingRegion();
1011 region
.GetBox( x
, y
, w
, h
);
1012 wxCoord xx
, yy
, ww
, hh
;
1013 xx
= XLOG2DEVMAC(x
);
1014 yy
= YLOG2DEVMAC(y
);
1015 ww
= XLOG2DEVREL(w
);
1016 hh
= YLOG2DEVREL(h
);
1017 // if we have a scaling that we cannot map onto native regions
1018 // we must use the box
1019 if ( ww
!= w
|| hh
!= h
)
1021 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
1026 CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
1027 if ( xx != x || yy != y )
1029 OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
1031 SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1035 m_clipX1
= wxMax( m_clipX1
, xx
);
1036 m_clipY1
= wxMax( m_clipY1
, yy
);
1037 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
1038 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
1051 void wxDC::DestroyClippingRegion()
1053 // CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
1054 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1055 CGContextRestoreGState( cgContext
);
1056 CGContextSaveGState( cgContext
);
1057 m_graphicContext
->SetPen( m_pen
) ;
1058 m_graphicContext
->SetBrush( m_brush
) ;
1062 void wxDC::DoGetSizeMM( int* width
, int* height
) const
1067 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
1068 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
1071 void wxDC::SetTextForeground( const wxColour
&col
)
1073 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1074 if ( col
!= m_textForegroundColour
)
1076 m_textForegroundColour
= col
;
1081 void wxDC::SetTextBackground( const wxColour
&col
)
1083 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1084 m_textBackgroundColour
= col
;
1087 void wxDC::SetMapMode( int mode
)
1092 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
1095 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
1098 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
1101 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
1105 SetLogicalScale( 1.0, 1.0 );
1108 if (mode
!= wxMM_TEXT
)
1110 m_needComputeScaleX
= TRUE
;
1111 m_needComputeScaleY
= TRUE
;
1115 void wxDC::SetUserScale( double x
, double y
)
1117 // allow negative ? -> no
1120 ComputeScaleAndOrigin();
1123 void wxDC::SetLogicalScale( double x
, double y
)
1126 m_logicalScaleX
= x
;
1127 m_logicalScaleY
= y
;
1128 ComputeScaleAndOrigin();
1131 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1133 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1134 m_logicalOriginY
= y
* m_signY
;
1135 ComputeScaleAndOrigin();
1138 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1140 m_externalDeviceOriginX
= x
;
1141 m_externalDeviceOriginY
= y
;
1142 ComputeScaleAndOrigin();
1145 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1147 m_signX
= (xLeftRight
? 1 : -1);
1148 m_signY
= (yBottomUp
? -1 : 1);
1149 ComputeScaleAndOrigin();
1152 wxSize
wxDC::GetPPI() const
1154 return wxSize(72, 72);
1157 int wxDC::GetDepth() const
1162 void wxDC::ComputeScaleAndOrigin()
1164 // CMB: copy scale to see if it changes
1165 double origScaleX
= m_scaleX
;
1166 double origScaleY
= m_scaleY
;
1167 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
1168 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
1169 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
1170 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
1171 // CMB: if scale has changed call SetPen to recalulate the line width
1172 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
1174 // this is a bit artificial, but we need to force wxDC to think
1175 // the pen has changed
1176 wxPen
pen(GetPen());
1182 void wxDC::SetPalette( const wxPalette
& palette
)
1186 void wxDC::SetBackgroundMode( int mode
)
1188 m_backgroundMode
= mode
;
1191 void wxDC::SetFont( const wxFont
&font
)
1197 void wxDC::SetPen( const wxPen
&pen
)
1202 if ( m_graphicContext
)
1204 m_graphicContext
->SetPen( m_pen
) ;
1208 void wxDC::SetBrush( const wxBrush
&brush
)
1210 if (m_brush
== brush
)
1213 if ( m_graphicContext
)
1215 m_graphicContext
->SetBrush( m_brush
) ;
1219 void wxDC::SetBackground( const wxBrush
&brush
)
1221 if (m_backgroundBrush
== brush
)
1223 m_backgroundBrush
= brush
;
1224 if (!m_backgroundBrush
.Ok())
1228 void wxDC::SetLogicalFunction( int function
)
1230 if (m_logicalFunction
== function
)
1232 m_logicalFunction
= function
;
1235 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
1236 const wxColour
& col
, int style
);
1238 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
1239 const wxColour
& col
, int style
)
1241 return wxDoFloodFill(this, x
, y
, col
, style
);
1244 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1246 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
1247 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
1248 wxMacPortSaver
helper((CGrafPtr
)m_macPort
) ;
1251 XLOG2DEVMAC(x
) + m_macLocalOriginInPort
.x
- m_macLocalOrigin
.x
,
1252 YLOG2DEVMAC(y
) + m_macLocalOriginInPort
.y
- m_macLocalOrigin
.y
, &colour
);
1253 // Convert from Mac colour to wx
1254 col
->Set( colour
.red
>> 8,
1260 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1262 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1264 if ( m_logicalFunction
!= wxCOPY
)
1267 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1268 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1269 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1270 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1272 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1273 path
->MoveToPoint( xx1
, yy1
) ;
1274 path
->AddLineToPoint( xx2
, yy2
) ;
1275 path
->CloseSubpath() ;
1276 m_graphicContext
->StrokePath( path
) ;
1279 CalcBoundingBox(x1
, y1
);
1280 CalcBoundingBox(x2
, y2
);
1283 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1285 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
1287 if ( m_logicalFunction
!= wxCOPY
)
1293 wxCoord xx
= XLOG2DEVMAC(x
);
1294 wxCoord yy
= YLOG2DEVMAC(y
);
1296 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1297 path
->MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1298 path
->AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1299 path
->CloseSubpath() ;
1300 path
->MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1301 path
->AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1302 path
->CloseSubpath() ;
1303 m_graphicContext
->StrokePath( path
) ;
1306 CalcBoundingBox(x
, y
);
1307 CalcBoundingBox(x
+w
, y
+h
);
1310 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1311 wxCoord x2
, wxCoord y2
,
1312 wxCoord xc
, wxCoord yc
)
1314 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
1316 if ( m_logicalFunction
!= wxCOPY
)
1319 wxCoord xx1
= XLOG2DEVMAC(x1
);
1320 wxCoord yy1
= YLOG2DEVMAC(y1
);
1321 wxCoord xx2
= XLOG2DEVMAC(x2
);
1322 wxCoord yy2
= YLOG2DEVMAC(y2
);
1323 wxCoord xxc
= XLOG2DEVMAC(xc
);
1324 wxCoord yyc
= YLOG2DEVMAC(yc
);
1325 double dx
= xx1
- xxc
;
1326 double dy
= yy1
- yyc
;
1327 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1328 wxCoord rad
= (wxCoord
)radius
;
1330 if (xx1
== xx2
&& yy1
== yy2
)
1335 else if (radius
== 0.0)
1341 sa
= (xx1
- xxc
== 0) ?
1342 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1343 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
1344 ea
= (xx2
- xxc
== 0) ?
1345 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1346 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
1349 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1350 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1351 CGContextRef ctx
= mctx
->GetNativeContext() ;
1352 CGContextSaveGState( ctx
) ;
1353 CGContextTranslateCTM( ctx
, xxc
, yyc
);
1354 CGContextScaleCTM( ctx
, 1 , -1 ) ;
1356 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1357 CGContextAddArc( ctx
, 0, 0 , rad
, DegToRad(sa
), DegToRad(ea
), 0);
1359 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1360 CGContextRestoreGState( ctx
) ;
1361 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1364 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1365 double sa
, double ea
)
1367 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
1369 if ( m_logicalFunction
!= wxCOPY
)
1372 wxCoord xx
= XLOG2DEVMAC(x
);
1373 wxCoord yy
= YLOG2DEVMAC(y
);
1374 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1375 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1376 // handle -ve width and/or height
1377 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1378 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1380 bool fill
= m_brush
.GetStyle() != wxTRANSPARENT
;
1382 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1383 CGContextRef ctx
= mctx
->GetNativeContext() ;
1385 CGContextSaveGState( ctx
) ;
1386 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2);
1387 CGContextScaleCTM( ctx
, 1 * ww
/ 2 , -1 * hh
/ 2 ) ;
1389 CGContextMoveToPoint( ctx
, 0 , 0 ) ;
1390 CGContextAddArc( ctx
, 0, 0, 1, DegToRad(sa
), DegToRad(ea
), 0);
1392 CGContextAddLineToPoint( ctx
, 0 , 0 ) ;
1393 CGContextRestoreGState( ctx
) ;
1394 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1397 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1399 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1400 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1403 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1404 wxCoord xoffset
, wxCoord yoffset
)
1406 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1408 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
) ;
1423 m_graphicContext
->StrokePath( path
) ;
1428 void wxDC::DoDrawSpline(wxList
*points
)
1430 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1432 if ( m_logicalFunction
!= wxCOPY
)
1435 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1437 wxList::compatibility_iterator node
= points
->GetFirst();
1438 if (node
== wxList::compatibility_iterator())
1442 wxPoint
*p
= (wxPoint
*)node
->GetData();
1447 node
= node
->GetNext();
1448 p
= (wxPoint
*)node
->GetData();
1452 wxCoord cx1
= ( x1
+ x2
) / 2;
1453 wxCoord cy1
= ( y1
+ y2
) / 2;
1455 path
->MoveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ) ;
1456 path
->AddLineToPoint( XLOG2DEVMAC( cx1
) , XLOG2DEVMAC( cy1
) ) ;
1459 while ((node
= node
->GetNext()) != NULL
)
1461 while ((node
= node
->GetNext()))
1462 #endif // !wxUSE_STL
1464 p
= (wxPoint
*)node
->GetData();
1469 wxCoord cx4
= (x1
+ x2
) / 2;
1470 wxCoord cy4
= (y1
+ y2
) / 2;
1472 path
->AddQuadCurveToPoint( XLOG2DEVMAC( x1
) , XLOG2DEVMAC( y1
) ,
1473 XLOG2DEVMAC( cx4
) , XLOG2DEVMAC( cy4
) ) ;
1479 path
->AddLineToPoint( XLOG2DEVMAC( x2
) , XLOG2DEVMAC( y2
) ) ;
1481 m_graphicContext
->StrokePath( path
) ;
1486 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1487 wxCoord xoffset
, wxCoord yoffset
,
1490 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1491 wxCoord x1
, x2
, y1
, y2
;
1492 if ( n
== 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1495 if ( m_logicalFunction
!= wxCOPY
)
1498 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1499 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1501 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1502 path
->MoveToPoint( x1
, y1
) ;
1503 for (int i
= 1; i
< n
; i
++)
1505 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1506 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1508 path
->AddLineToPoint( x2
, y2
) ;
1510 if ( x1
!= x2
|| y1
!= y2
)
1512 path
->AddLineToPoint( x1
,y1
) ;
1514 path
->CloseSubpath() ;
1515 m_graphicContext
->DrawPath( path
, fillStyle
) ;
1519 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1521 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1523 if ( m_logicalFunction
!= wxCOPY
)
1526 wxCoord xx
= XLOG2DEVMAC(x
);
1527 wxCoord yy
= YLOG2DEVMAC(y
);
1528 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1529 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1530 // CMB: draw nothing if transformed w or h is 0
1531 if (ww
== 0 || hh
== 0)
1533 // CMB: handle -ve width and/or height
1544 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1545 path
->AddRectangle(xx
,yy
, ww
, hh
) ;
1546 m_graphicContext
->DrawPath( path
) ;
1550 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1551 wxCoord width
, wxCoord height
,
1554 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1556 if ( m_logicalFunction
!= wxCOPY
)
1561 radius
= - radius
* ((width
< height
) ? width
: height
);
1562 wxCoord xx
= XLOG2DEVMAC(x
);
1563 wxCoord yy
= YLOG2DEVMAC(y
);
1564 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1565 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1566 // CMB: draw nothing if transformed w or h is 0
1567 if (ww
== 0 || hh
== 0)
1569 // CMB: handle -ve width and/or height
1580 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1581 CGContextRef ctx
= mctx
->GetNativeContext() ;
1582 AddRoundedRectToPath( ctx
, CGRectMake( xx
, yy
, ww
, hh
) , 16 ,16 ) ;
1583 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1586 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1588 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1590 if ( m_logicalFunction
!= wxCOPY
)
1593 wxCoord xx
= XLOG2DEVMAC(x
);
1594 wxCoord yy
= YLOG2DEVMAC(y
);
1595 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1596 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1597 // CMB: draw nothing if transformed w or h is 0
1598 if (ww
== 0 || hh
== 0)
1600 // CMB: handle -ve width and/or height
1612 wxMacCGContext
* mctx
= ((wxMacCGContext
*) m_graphicContext
) ;
1613 CGContextRef ctx
= mctx
->GetNativeContext() ;
1614 CGContextSaveGState( ctx
) ;
1615 CGContextTranslateCTM( ctx
, xx
+ ww
/ 2, yy
+ hh
/ 2);
1616 CGContextScaleCTM( ctx
, ww
/ 2 , hh
/ 2 ) ;
1617 CGContextAddArc( ctx
, 0, 0, 1, 0 , 2*M_PI
, 0);
1618 CGContextRestoreGState( ctx
) ;
1619 CGContextDrawPath( ctx
, mctx
->GetDrawingMode() ) ;
1622 bool wxDC::CanDrawBitmap(void) const
1627 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1628 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1629 wxCoord xsrcMask
, wxCoord ysrcMask
)
1631 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1632 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1633 if ( logical_func
== wxNO_OP
)
1635 if (xsrcMask
== -1 && ysrcMask
== -1)
1637 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1640 wxCoord yysrc
= source
->YLOG2DEVMAC(ysrc
) ;
1641 wxCoord xxsrc
= source
->XLOG2DEVMAC(xsrc
) ;
1642 wxCoord wwsrc
= source
->XLOG2DEVREL(width
) ;
1643 wxCoord hhsrc
= source
->YLOG2DEVREL(height
) ;
1645 wxCoord yydest
= YLOG2DEVMAC(ydest
) ;
1646 wxCoord xxdest
= XLOG2DEVMAC(xdest
) ;
1647 wxCoord wwdest
= XLOG2DEVREL(width
) ;
1648 wxCoord hhdest
= YLOG2DEVREL(height
) ;
1650 wxMemoryDC
* memdc
= dynamic_cast<wxMemoryDC
*>(source
) ;
1651 if ( memdc
&& logical_func
== wxCOPY
)
1653 wxBitmap blit
= memdc
->GetSelectedObject() ;
1654 wxASSERT_MSG( blit
.Ok() , wxT("Invalid bitmap for blitting") ) ;
1656 wxCoord bmpwidth
= blit
.GetWidth();
1657 wxCoord bmpheight
= blit
.GetHeight();
1659 if ( xxsrc
!= 0 || yysrc
!= 0 || bmpwidth
!= wwsrc
|| bmpheight
!= hhsrc
)
1661 wwsrc
= wxMin( wwsrc
, bmpwidth
- xxsrc
) ;
1662 hhsrc
= wxMin( hhsrc
, bmpheight
- yysrc
) ;
1663 if ( wwsrc
> 0 && hhsrc
> 0 )
1665 if ( xxsrc
>= 0 && yysrc
>= 0 )
1667 wxRect
subrect( xxsrc
, yysrc
, wwsrc
, hhsrc
) ;
1668 blit
= blit
.GetSubBitmap( subrect
) ;
1672 // in this case we'd probably have to adjust the different coordinates, but
1673 // we have to find out proper contract first
1674 blit
= wxNullBitmap
;
1679 blit
= wxNullBitmap
;
1684 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1685 CGImageRef image
= (CGImageRef
)( blit
.CGImageCreate() ) ;
1686 HIRect r
= CGRectMake( xxdest
, yydest
, wwdest
, hhdest
) ;
1687 HIViewDrawCGImage( cg
, &r
, image
) ;
1688 CGImageRelease( image
) ;
1695 CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ;
1696 void *data = CGBitmapContextGetData( cg ) ;
1698 return FALSE
; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
1703 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1706 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1708 if ( str
.Length() == 0 )
1711 if ( m_logicalFunction
!= wxCOPY
)
1714 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("No valid font set") ) ;
1716 OSStatus status
= noErr
;
1717 ATSUTextLayout atsuLayout
;
1718 UniCharCount chars
= str
.Length() ;
1719 UniChar
* ubuf
= NULL
;
1720 #if SIZEOF_WCHAR_T == 4
1721 wxMBConvUTF16 converter
;
1723 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1724 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1725 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1727 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1728 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1729 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1730 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1732 chars
= unicharlen
/ 2 ;
1735 ubuf
= (UniChar
*) str
.wc_str() ;
1737 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1738 chars
= wxWcslen( wchar
.data() ) ;
1739 ubuf
= (UniChar
*) wchar
.data() ;
1743 int drawX
= XLOG2DEVMAC(x
) ;
1744 int drawY
= YLOG2DEVMAC(y
) ;
1746 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1747 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1749 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1751 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1752 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1754 int iAngle
= int( angle
);
1755 if ( abs(iAngle
) > 0 )
1757 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1758 ATSUAttributeTag atsuTags
[] =
1760 kATSULineRotationTag
,
1762 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1766 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1770 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1771 atsuTags
, atsuSizes
, atsuValues
) ;
1774 CGContextRef cgContext
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
1775 ATSUAttributeTag atsuTags
[] =
1779 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1781 sizeof( CGContextRef
) ,
1783 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1787 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1788 atsuTags
, atsuSizes
, atsuValues
) ;
1791 ATSUTextMeasurement textBefore
;
1792 ATSUTextMeasurement textAfter
;
1793 ATSUTextMeasurement ascent
;
1794 ATSUTextMeasurement descent
;
1796 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1797 &textBefore
, &textAfter
, &ascent
, &descent
);
1798 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1802 if ( m_backgroundMode
== wxSOLID
)
1804 wxGraphicPath
* path
= m_graphicContext
->CreatePath() ;
1808 path
->AddLineToPoint(
1809 (int) (drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
)) ,
1810 (int) (drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
)) ) ;
1811 path
->AddLineToPoint(
1812 (int) (drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ,
1813 (int) (drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1814 path
->AddLineToPoint(
1815 (int) (drawX
+ cos(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ,
1816 (int) (drawY
- sin(angle
/RAD2DEG
) * FixedToInt(textAfter
)) ) ;
1818 m_graphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1822 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1823 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1825 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1826 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1827 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1829 CGContextSaveGState(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext());
1830 CGContextTranslateCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), drawX
, drawY
);
1831 CGContextScaleCTM(((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext(), 1, -1);
1832 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1833 IntToFixed(0) , IntToFixed(0) );
1834 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1835 CGContextRestoreGState( ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ) ;
1837 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1838 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1840 ::ATSUDisposeTextLayout(atsuLayout
);
1841 #if SIZEOF_WCHAR_T == 4
1846 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1848 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1849 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1852 bool wxDC::CanGetTextExtent() const
1854 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1858 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1859 wxCoord
*descent
, wxCoord
*externalLeading
,
1860 wxFont
*theFont
) const
1862 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1863 wxFont formerFont
= m_font
;
1866 // work around the constness
1867 *((wxFont
*)(&m_font
)) = *theFont
;
1871 if ( str
.Length() == 0 )
1874 wxCHECK_RET( m_macATSUIStyle
!= NULL
, wxT("No valid font set") ) ;
1876 OSStatus status
= noErr
;
1877 ATSUTextLayout atsuLayout
;
1878 UniCharCount chars
= str
.Length() ;
1879 UniChar
* ubuf
= NULL
;
1880 #if SIZEOF_WCHAR_T == 4
1881 wxMBConvUTF16 converter
;
1883 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1884 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1885 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1887 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1888 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1889 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1890 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1892 chars
= unicharlen
/ 2 ;
1895 ubuf
= (UniChar
*) str
.wc_str() ;
1897 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1898 chars
= wxWcslen( wchar
.data() ) ;
1899 ubuf
= (UniChar
*) wchar
.data() ;
1904 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1905 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1907 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1909 ATSUTextMeasurement textBefore
;
1910 ATSUTextMeasurement textAfter
;
1911 ATSUTextMeasurement textAscent
;
1912 ATSUTextMeasurement textDescent
;
1914 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1915 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1918 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1920 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1921 if ( externalLeading
)
1922 *externalLeading
= 0 ;
1924 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1926 ::ATSUDisposeTextLayout(atsuLayout
);
1927 #if SIZEOF_WCHAR_T == 4
1932 // work around the constness
1933 *((wxFont
*)(&m_font
)) = formerFont
;
1939 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1941 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1944 widths
.Add(0, text
.Length());
1946 if (text
.Length() == 0)
1949 ATSUTextLayout atsuLayout
;
1950 UniCharCount chars
= text
.Length() ;
1951 UniChar
* ubuf
= NULL
;
1952 #if SIZEOF_WCHAR_T == 4
1953 wxMBConvUTF16 converter
;
1955 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 ) ;
1956 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1957 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 ) ;
1959 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1960 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1961 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1962 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1964 chars
= unicharlen
/ 2 ;
1967 ubuf
= (UniChar
*) text
.wc_str() ;
1969 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
) ;
1970 chars
= wxWcslen( wchar
.data() ) ;
1971 ubuf
= (UniChar
*) wchar
.data() ;
1976 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1977 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1979 for ( int pos
= 0; pos
< (int)chars
; pos
++ ) {
1980 unsigned long actualNumberOfBounds
= 0;
1981 ATSTrapezoid glyphBounds
;
1983 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1985 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1, kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1986 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1991 widths
[pos
] = XDEV2LOGREL(FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
));
1992 //unsigned char uch = s[i];
1995 ::ATSUDisposeTextLayout(atsuLayout
);
1999 wxCoord
wxDC::GetCharWidth(void) const
2002 DoGetTextExtent(wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
2006 wxCoord
wxDC::GetCharHeight(void) const
2009 DoGetTextExtent(wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
2013 void wxDC::Clear(void)
2015 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2017 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
2019 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
2020 CGContextRef cg
= ((wxMacCGContext
*)(m_graphicContext
))->GetNativeContext() ;
2021 switch( m_backgroundBrush
.MacGetBrushKind() )
2023 case kwxMacBrushTheme
:
2025 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
2026 if ( HIThemeSetFill
!= 0 )
2028 HIThemeSetFill( m_backgroundBrush
.MacGetTheme(), NULL
, cg
, kHIThemeOrientationNormal
);
2029 CGContextFillRect(cg
, rect
);
2036 GetThemeBrushAsColor( m_backgroundBrush
.MacGetTheme(), 32, true, &color
);
2037 CGContextSetRGBFillColor( cg
, (float) color
.red
/ 65536,
2038 (float) color
.green
/ 65536, (float) color
.blue
/ 65536, 1 );
2039 CGContextFillRect( cg
, rect
);
2042 // reset to normal value
2043 RGBColor col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2044 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0, col
.green
/ 65536.0, col
.blue
/ 65536.0, 1.0 );
2047 case kwxMacBrushThemeBackground
:
2049 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
2050 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2051 if ( UMAGetSystemVersion() >= 0x1030 )
2053 HIThemeBackgroundDrawInfo drawInfo
;
2054 drawInfo
.version
= 0 ;
2055 drawInfo
.state
= kThemeStateActive
;
2056 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground(NULL
) ;
2057 if ( drawInfo
.kind
== kThemeBackgroundMetal
)
2058 HIThemeDrawBackground( &rect
, &drawInfo
, cg
,
2059 kHIThemeOrientationNormal
) ;
2060 HIThemeApplyBackground( &rect
, &drawInfo
, cg
,
2061 kHIThemeOrientationNormal
) ;
2069 case kwxMacBrushColour
:
2071 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
2072 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2073 CGContextFillRect(cg
, rect
);
2075 // reset to normal value
2076 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
2077 CGContextSetRGBFillColor( cg
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
2084 void wxDC::MacInstallFont() const
2086 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2088 if( m_macATSUIStyle
)
2090 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
2091 m_macATSUIStyle
= NULL
;
2096 OSStatus status
= noErr
;
2097 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
2098 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
2100 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2101 RGBColor atsuColor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ;
2102 ATSUAttributeTag atsuTags
[] =
2107 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2110 sizeof( RGBColor
) ,
2112 // Boolean kTrue = true ;
2113 // Boolean kFalse = false ;
2115 // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
2116 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2121 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
2122 atsuTags
, atsuSizes
, atsuValues
);
2124 wxASSERT_MSG( status
== noErr
, wxT("couldn't Modify ATSU style") ) ;
2128 // ---------------------------------------------------------------------------
2129 // coordinates transformations
2130 // ---------------------------------------------------------------------------
2132 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2134 return ((wxDC
*)this)->XDEV2LOG(x
);
2137 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2139 return ((wxDC
*)this)->YDEV2LOG(y
);
2142 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2144 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2147 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2149 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2152 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2154 return ((wxDC
*)this)->XLOG2DEV(x
);
2157 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2159 return ((wxDC
*)this)->YLOG2DEV(y
);
2162 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2164 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2167 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2169 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2172 #endif // wxMAC_USE_CORE_GRAPHICS