1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
21 #include "wx/region.h"
30 #include "wx/mac/private.h"
31 #include <ATSUnicode.h>
32 #include <TextCommon.h>
33 #include <TextEncodingConverter.h>
35 #include <CGContext.h>
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
47 const double M_PI
= 3.14159265358979 ;
50 const double RAD2DEG
= 180.0 / M_PI
;
51 const short kEmulatedMode
= -1 ;
52 const short kUnsupportedMode
= -2 ;
54 extern TECObjectRef s_TECNativeCToUnicode
;
56 // set to 0 if problems arise
57 #define wxMAC_EXPERIMENTAL_DC 1
59 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
60 m_ph( (GrafPtr
) dc
->m_macPort
)
62 wxASSERT( dc
->Ok() ) ;
64 dc
->MacSetupPort(&m_ph
) ;
66 wxMacPortSetter::~wxMacPortSetter()
68 m_dc
->MacCleanupPort(&m_ph
) ;
71 #if wxMAC_EXPERIMENTAL_DC
72 class wxMacFastPortSetter
75 wxMacFastPortSetter( const wxDC
*dc
)
77 wxASSERT( dc
->Ok() ) ;
78 GetPort( &m_oldPort
) ;
79 SetPort( (GrafPtr
) dc
->m_macPort
) ;
80 m_clipRgn
= NewRgn() ;
81 GetClip( m_clipRgn
) ;
83 dc
->MacSetupPort( NULL
) ;
85 ~wxMacFastPortSetter()
87 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
88 SetClip( m_clipRgn
) ;
89 SetPort( m_oldPort
) ;
90 m_dc
->MacCleanupPort( NULL
) ;
91 DisposeRgn( m_clipRgn
) ;
100 typedef wxMacPortSetter wxMacFastPortSetter
;
103 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
104 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
106 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
107 m_formerClip
= NewRgn() ;
108 m_newClip
= NewRgn() ;
109 GetClip( m_formerClip
) ;
114 win
->MacWindowToRootWindow( &x
,&y
) ;
115 // get area including focus rect
116 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
117 if ( !EmptyRgn( m_newClip
) )
118 OffsetRgn( m_newClip
, x
, y
) ;
120 SetClip( m_newClip
) ;
124 wxMacWindowClipper::~wxMacWindowClipper()
126 SetPort( m_newPort
) ;
127 SetClip( m_formerClip
) ;
128 DisposeRgn( m_newClip
) ;
129 DisposeRgn( m_formerClip
) ;
132 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
133 wxMacWindowClipper( win
)
135 // the port is already set at this point
136 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
137 GetThemeDrawingState( &m_themeDrawingState
) ;
140 wxMacWindowStateSaver::~wxMacWindowStateSaver()
142 SetPort( m_newPort
) ;
143 SetThemeDrawingState( m_themeDrawingState
, true ) ;
146 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
149 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
150 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
151 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
153 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
156 // this function emulates all wx colour manipulations, used to verify the implementation
157 // by setting the mode in the blitting functions to kEmulatedMode
158 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
160 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
162 switch ( logical_func
)
164 case wxAND
: // src AND dst
165 dstColor
.red
= dstColor
.red
& srcColor
.red
;
166 dstColor
.green
= dstColor
.green
& srcColor
.green
;
167 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
169 case wxAND_INVERT
: // (NOT src) AND dst
170 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
171 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
172 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
174 case wxAND_REVERSE
:// src AND (NOT dst)
175 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
176 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
177 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
185 dstColor
.red
= srcColor
.red
;
186 dstColor
.green
= srcColor
.green
;
187 dstColor
.blue
= srcColor
.blue
;
189 case wxEQUIV
: // (NOT src) XOR dst
190 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
191 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
192 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
194 case wxINVERT
: // NOT dst
195 dstColor
.red
= ~dstColor
.red
;
196 dstColor
.green
= ~dstColor
.green
;
197 dstColor
.blue
= ~dstColor
.blue
;
199 case wxNAND
: // (NOT src) OR (NOT dst)
200 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
201 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
202 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
204 case wxNOR
: // (NOT src) AND (NOT dst)
205 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
206 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
207 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
211 case wxOR
: // src OR dst
212 dstColor
.red
= dstColor
.red
| srcColor
.red
;
213 dstColor
.green
= dstColor
.green
| srcColor
.green
;
214 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
216 case wxOR_INVERT
: // (NOT src) OR dst
217 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
218 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
219 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
221 case wxOR_REVERSE
: // src OR (NOT dst)
222 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
223 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
224 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
227 dstColor
.red
= 0xFFFF ;
228 dstColor
.green
= 0xFFFF ;
229 dstColor
.blue
= 0xFFFF ;
231 case wxSRC_INVERT
: // (NOT src)
232 dstColor
.red
= ~srcColor
.red
;
233 dstColor
.green
= ~srcColor
.green
;
234 dstColor
.blue
= ~srcColor
.blue
;
236 case wxXOR
: // src XOR dst
237 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
238 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
239 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
244 class WXDLLEXPORT wxMacCGPath
246 DECLARE_NO_COPY_CLASS(wxMacCGPath
)
251 m_path
= CGPathCreateMutable() ;
256 CGPathRelease( m_path
) ;
259 // Starts a new subpath at
260 void MoveToPoint( wxCoord x1
, wxCoord y1
)
262 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
) ;
265 void AddLineToPoint( wxCoord x1
, wxCoord y1
)
267 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
) ;
270 void AddRectangle( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
272 CGRect cgRect
= { { x
, y
} , { w
, h
} } ;
273 CGPathAddRect( m_path
, NULL
, cgRect
) ;
276 void AddRectangle( CGRect cgRect
)
278 CGPathAddRect( m_path
, NULL
, cgRect
) ;
281 void AddCircle( CGPoint center
, float r
)
283 CGPathAddArc( m_path
, NULL
, center
.x
, center
.y
, r
, 0.0 , 2 * M_PI
, true ) ;
286 // closes the current subpath
289 CGPathCloseSubpath( m_path
) ;
292 CGPathRef
GetPath() const
297 CGMutablePathRef m_path
;
300 class WXDLLEXPORT wxMacCGContext
302 DECLARE_NO_COPY_CLASS(wxMacCGContext
)
305 wxMacCGContext( const wxDC
* dc
) ;
308 void StrokePath( const wxMacCGPath
&path
)
311 CGContextBeginPath( m_cgContext
) ;
312 CGContextAddPath( m_cgContext
, path
.GetPath() ) ;
313 CGContextClosePath( m_cgContext
) ;
314 CGContextStrokePath( m_cgContext
) ;
317 void DrawPath( const wxMacCGPath
&path
, int fillStyle
= wxWINDING_RULE
)
319 CGPathDrawingMode mode
= m_mode
;
320 if ( fillStyle
== wxODDEVEN_RULE
)
322 if ( mode
== kCGPathFill
)
323 mode
= kCGPathEOFill
;
324 else if ( mode
== kCGPathFillStroke
)
325 mode
= kCGPathEOFillStroke
;
327 CGContextBeginPath( m_cgContext
) ;
328 CGContextAddPath( m_cgContext
, path
.GetPath() ) ;
329 CGContextClosePath( m_cgContext
) ;
330 CGContextDrawPath( m_cgContext
, mode
) ;
333 void FillPath( const wxMacCGPath
&path
, const wxColor
&fillColor
, int fillStyle
= wxWINDING_RULE
)
335 RGBColor col
= MAC_WXCOLORREF( fillColor
.GetPixel() ) ;
336 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
337 CGPathDrawingMode mode
= kCGPathFill
;
339 if ( fillStyle
== wxODDEVEN_RULE
)
340 mode
= kCGPathEOFill
;
342 CGContextBeginPath( m_cgContext
) ;
343 CGContextAddPath( m_cgContext
, path
.GetPath() ) ;
344 CGContextClosePath( m_cgContext
) ;
345 CGContextDrawPath( m_cgContext
, mode
) ;
346 if ( m_dc
->GetBrush().GetStyle() )
348 RGBColor col
= MAC_WXCOLORREF( m_dc
->GetBrush().GetColour().GetPixel() ) ;
349 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
353 void SetupPenAndBrush() ;
354 CGContextRef
GetNativeContext() { return m_cgContext
; }
356 CGContextRef m_cgContext
;
357 CGPathDrawingMode m_mode
;
361 wxMacCGContext::wxMacCGContext( const wxDC
* dc
)
363 wxASSERT( dc
->Ok() ) ;
366 GetPortBounds( (CGrafPtr
) dc
->m_macPort
, &bounds
) ;
367 OSStatus status
= QDBeginCGContext( (CGrafPtr
) dc
->m_macPort
, &m_cgContext
) ;
368 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") ) ;
369 ClipCGContextToRegion ( m_cgContext
, &bounds
, (RgnHandle
) dc
->m_macCurrentClipRgn
) ;
371 CGContextTranslateCTM( m_cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
372 CGContextScaleCTM( m_cgContext
, 1 , -1 ) ;
378 void wxMacCGContext::SetupPenAndBrush()
380 bool fill
= m_dc
->GetBrush().GetStyle() != wxTRANSPARENT
;
381 bool stroke
= m_dc
->GetPen().GetStyle() != wxTRANSPARENT
;
387 m_mode
= kCGPathFill
; // just a default
391 RGBColor col
= MAC_WXCOLORREF( m_dc
->GetBrush().GetColour().GetPixel() ) ;
392 CGContextSetRGBFillColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
393 m_mode
= kCGPathFill
;
397 RGBColor col
= MAC_WXCOLORREF( m_dc
->GetPen().GetColour().GetPixel() ) ;
398 CGContextSetRGBStrokeColor( m_cgContext
, col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
401 switch( m_dc
->GetPen().GetCap() )
404 cap
= kCGLineCapRound
;
406 case wxCAP_PROJECTING
:
407 cap
= kCGLineCapSquare
;
410 cap
= kCGLineCapButt
;
413 cap
= kCGLineCapButt
;
416 CGContextSetLineCap( m_cgContext
, cap
) ;
419 switch( m_dc
->GetPen().GetJoin() )
422 join
= kCGLineJoinBevel
;
425 join
= kCGLineJoinMiter
;
428 join
= kCGLineJoinRound
;
431 join
= kCGLineJoinMiter
;
434 CGContextSetLineJoin( m_cgContext
, join
) ;
436 CGContextSetLineWidth( m_cgContext
, m_dc
->GetPen().GetWidth() == 0 ? 0.1 : m_dc
->GetPen().GetWidth() /* TODO * m_dc->m_scaleX */ ) ;
438 m_mode
= kCGPathStroke
;
440 const float *lengths
= NULL
;
441 float *userLengths
= NULL
;
443 switch( m_dc
->GetPen().GetStyle() )
448 const float dotted
[] = { 3 , 3 };
450 count
= WXSIZEOF(dotted
);
453 const float dashed
[] = { 19 , 9 };
455 count
= WXSIZEOF(dashed
) ;
458 const float short_dashed
[] = { 9 , 6 };
459 lengths
= short_dashed
;
460 count
= WXSIZEOF(short_dashed
) ;
463 const float dotted_dashed
[] = { 9 , 6 , 3 , 3 };
464 lengths
= dotted_dashed
;
465 count
= WXSIZEOF(dotted_dashed
);
469 count
= m_dc
->GetPen().GetDashes( &dashes
) ;
472 userLengths
= new float[count
] ;
473 for( int i
= 0 ; i
< count
; ++i
)
474 userLengths
[i
] = dashes
[i
] ;
476 lengths
= userLengths
;
482 CGContextSetLineDash( m_cgContext
, 0 , lengths
, count
) ;
483 delete[] userLengths
;
484 // we need to change the cap, otherwise everything overlaps
485 // and we get solid lines
487 CGContextSetLineCap( m_cgContext
, kCGLineCapButt
) ;
489 if ( fill
&& stroke
)
491 m_mode
= kCGPathFillStroke
;
497 wxMacCGContext::~wxMacCGContext()
499 QDEndCGContext( (CGrafPtr
) m_dc
->m_macPort
, &m_cgContext
) ;
503 #define wxMacGraphicContext wxMacCGContext
504 #define wxMacGraphicPath wxMacCGPath
506 void AddEllipticArcToPath(CGContextRef c
, CGPoint center
, float a
, float b
, float fromDegree
, float toDegree
)
508 CGContextSaveGState(c
);
509 CGContextTranslateCTM(c
, center
.x
, center
.y
);
510 CGContextScaleCTM(c
, a
, b
);
511 CGContextMoveToPoint(c
, 1, 0);
512 CGContextAddArc(c
, 0, 0, 1, DegToRad(fromDegree
), DegToRad(toDegree
), 0);
513 CGContextClosePath(c
);
514 CGContextRestoreGState(c
);
517 void AddRoundedRectToPath(CGContextRef c
, CGRect rect
, float ovalWidth
,
521 if (ovalWidth
== 0 || ovalHeight
== 0)
523 CGContextAddRect(c
, rect
);
526 CGContextSaveGState(c
);
527 CGContextTranslateCTM(c
, CGRectGetMinX(rect
), CGRectGetMinY(rect
));
528 CGContextScaleCTM(c
, ovalWidth
, ovalHeight
);
529 fw
= CGRectGetWidth(rect
) / ovalWidth
;
530 fh
= CGRectGetHeight(rect
) / ovalHeight
;
531 CGContextMoveToPoint(c
, fw
, fh
/2);
532 CGContextAddArcToPoint(c
, fw
, fh
, fw
/2, fh
, 1);
533 CGContextAddArcToPoint(c
, 0, fh
, 0, fh
/2, 1);
534 CGContextAddArcToPoint(c
, 0, 0, fw
/2, 0, 1);
535 CGContextAddArcToPoint(c
, fw
, 0, fw
, fh
/2, 1);
536 CGContextClosePath(c
);
537 CGContextRestoreGState(c
);
544 m_mm_to_pix_x
= mm2pt
;
545 m_mm_to_pix_y
= mm2pt
;
546 m_internalDeviceOriginX
= 0;
547 m_internalDeviceOriginY
= 0;
548 m_externalDeviceOriginX
= 0;
549 m_externalDeviceOriginY
= 0;
550 m_logicalScaleX
= 1.0;
551 m_logicalScaleY
= 1.0;
556 m_needComputeScaleX
= FALSE
;
557 m_needComputeScaleY
= FALSE
;
561 m_macFontInstalled
= false ;
562 m_macBrushInstalled
= false ;
563 m_macPenInstalled
= false ;
564 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
565 m_macBoundaryClipRgn
= NewRgn() ;
566 m_macCurrentClipRgn
= NewRgn() ;
567 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
568 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
569 m_pen
= *wxBLACK_PEN
;
570 m_font
= *wxNORMAL_FONT
;
571 m_brush
= *wxWHITE_BRUSH
;
573 // needed to debug possible errors with two active drawing methods at the same time on
575 m_macCurrentPortStateHelper
= NULL
;
577 m_macATSUIStyle
= NULL
;
578 m_macAliasWasEnabled
= false;
579 m_macForegroundPixMap
= NULL
;
580 m_macBackgroundPixMap
= NULL
;
581 m_macGraphicContext
= NULL
;
586 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
587 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
588 delete m_macGraphicContext
;
592 void wxDC::MacSetupGraphicContext()
594 m_macGraphicContext
= new wxMacCGContext( this ) ;
597 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
600 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
601 m_macCurrentPortStateHelper
= help
;
603 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
604 #if ! wxMAC_EXPERIMENTAL_DC
605 m_macFontInstalled
= false ;
606 m_macBrushInstalled
= false ;
607 m_macPenInstalled
= false ;
610 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
613 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
614 m_macCurrentPortStateHelper
= NULL
;
616 if( m_macATSUIStyle
)
618 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
619 m_macATSUIStyle
= NULL
;
621 if ( m_macAliasWasEnabled
)
623 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
624 m_macAliasWasEnabled
= false ;
626 if ( m_macForegroundPixMap
)
629 ::PenPat(GetQDGlobalsBlack(&blackColor
));
630 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
631 m_macForegroundPixMap
= NULL
;
633 if ( m_macBackgroundPixMap
)
636 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
637 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
638 m_macBackgroundPixMap
= NULL
;
642 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
644 wxCHECK_RET( Ok(), wxT("invalid window dc") );
645 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
646 wxCoord xx
= XLOG2DEVMAC(x
);
647 wxCoord yy
= YLOG2DEVMAC(y
);
648 wxCoord w
= bmp
.GetWidth();
649 wxCoord h
= bmp
.GetHeight();
650 wxCoord ww
= XLOG2DEVREL(w
);
651 wxCoord hh
= YLOG2DEVREL(h
);
652 // Set up drawing mode
653 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
654 //m_logicalFunction == wxCLEAR ? WHITENESS :
655 //m_logicalFunction == wxSET ? BLACKNESS :
656 m_logicalFunction
== wxINVERT
? hilite
:
657 //m_logicalFunction == wxAND ? MERGECOPY :
658 m_logicalFunction
== wxOR
? srcOr
:
659 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
660 m_logicalFunction
== wxXOR
? srcXor
:
661 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
662 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
663 //m_logicalFunction == wxSRC_OR ? srcOr :
664 //m_logicalFunction == wxSRC_AND ? SRCAND :
666 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
667 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
668 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
669 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
671 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
673 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
674 PixMapHandle bmappixels
;
675 // Set foreground and background colours (for bitmaps depth = 1)
676 if(bmp
.GetDepth() == 1)
678 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
679 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
685 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
686 RGBColor black
= { 0,0,0} ;
687 RGBForeColor( &black
) ;
688 RGBBackColor( &white
) ;
690 bmappixels
= GetGWorldPixMap( bmapworld
) ;
691 wxCHECK_RET(LockPixels(bmappixels
),
692 wxT("DoDrawBitmap: Unable to lock pixels"));
693 Rect source
= { 0, 0, h
, w
};
694 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
695 if ( useMask
&& bmp
.GetMask() )
697 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
701 GetPortBitMapForCopyBits(bmapworld
),
702 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
703 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
704 &source
, &source
, &dest
, mode
, NULL
706 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
710 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
711 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
712 &source
, &dest
, mode
, NULL
) ;
714 UnlockPixels( bmappixels
) ;
716 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
718 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
719 OffsetRect( &bitmaprect
, xx
, yy
) ;
720 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
722 m_macPenInstalled
= false ;
723 m_macBrushInstalled
= false ;
724 m_macFontInstalled
= false ;
727 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
729 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
730 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
731 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
734 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
736 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
737 wxCoord xx
, yy
, ww
, hh
;
740 ww
= XLOG2DEVREL(width
);
741 hh
= YLOG2DEVREL(height
);
742 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
743 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
746 m_clipX1
= wxMax( m_clipX1
, xx
);
747 m_clipY1
= wxMax( m_clipY1
, yy
);
748 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
749 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
759 // TODO as soon as we don't reset the context for each operation anymore
760 // we have to update the context as well
763 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
765 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
768 DestroyClippingRegion();
772 region
.GetBox( x
, y
, w
, h
);
773 wxCoord xx
, yy
, ww
, hh
;
778 // if we have a scaling that we cannot map onto native regions
779 // we must use the box
780 if ( ww
!= w
|| hh
!= h
)
782 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
786 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
787 if ( xx
!= x
|| yy
!= y
)
789 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
791 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
794 m_clipX1
= wxMax( m_clipX1
, xx
);
795 m_clipY1
= wxMax( m_clipY1
, yy
);
796 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
797 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
810 void wxDC::DestroyClippingRegion()
812 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
816 void wxDC::DoGetSizeMM( int* width
, int* height
) const
821 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
822 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
825 void wxDC::SetTextForeground( const wxColour
&col
)
827 wxCHECK_RET(Ok(), wxT("Invalid DC"));
828 m_textForegroundColour
= col
;
829 m_macFontInstalled
= false ;
832 void wxDC::SetTextBackground( const wxColour
&col
)
834 wxCHECK_RET(Ok(), wxT("Invalid DC"));
835 m_textBackgroundColour
= col
;
836 m_macFontInstalled
= false ;
839 void wxDC::SetMapMode( int mode
)
844 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
847 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
850 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
853 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
857 SetLogicalScale( 1.0, 1.0 );
860 if (mode
!= wxMM_TEXT
)
862 m_needComputeScaleX
= TRUE
;
863 m_needComputeScaleY
= TRUE
;
867 void wxDC::SetUserScale( double x
, double y
)
869 // allow negative ? -> no
872 ComputeScaleAndOrigin();
875 void wxDC::SetLogicalScale( double x
, double y
)
880 ComputeScaleAndOrigin();
883 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
885 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
886 m_logicalOriginY
= y
* m_signY
;
887 ComputeScaleAndOrigin();
890 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
892 m_externalDeviceOriginX
= x
;
893 m_externalDeviceOriginY
= y
;
894 ComputeScaleAndOrigin();
897 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
899 m_signX
= (xLeftRight
? 1 : -1);
900 m_signY
= (yBottomUp
? -1 : 1);
901 ComputeScaleAndOrigin();
904 wxSize
wxDC::GetPPI() const
906 return wxSize(72, 72);
909 int wxDC::GetDepth() const
911 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
913 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
918 void wxDC::ComputeScaleAndOrigin()
920 // CMB: copy scale to see if it changes
921 double origScaleX
= m_scaleX
;
922 double origScaleY
= m_scaleY
;
923 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
924 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
925 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
926 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
927 // CMB: if scale has changed call SetPen to recalulate the line width
928 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
930 // this is a bit artificial, but we need to force wxDC to think
931 // the pen has changed
938 void wxDC::SetPalette( const wxPalette
& palette
)
942 void wxDC::SetBackgroundMode( int mode
)
944 m_backgroundMode
= mode
;
947 void wxDC::SetFont( const wxFont
&font
)
950 m_macFontInstalled
= false ;
953 void wxDC::SetPen( const wxPen
&pen
)
958 m_macPenInstalled
= false ;
959 m_macGraphicContext
->SetupPenAndBrush() ;
962 void wxDC::SetBrush( const wxBrush
&brush
)
964 if (m_brush
== brush
)
967 m_macBrushInstalled
= false ;
968 m_macGraphicContext
->SetupPenAndBrush() ;
971 void wxDC::SetBackground( const wxBrush
&brush
)
973 if (m_backgroundBrush
== brush
)
975 m_backgroundBrush
= brush
;
976 if (!m_backgroundBrush
.Ok())
978 m_macBrushInstalled
= false ;
981 void wxDC::SetLogicalFunction( int function
)
983 if (m_logicalFunction
== function
)
985 m_logicalFunction
= function
;
986 m_macFontInstalled
= false ;
987 m_macBrushInstalled
= false ;
988 m_macPenInstalled
= false ;
991 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
992 const wxColour
& col
, int style
);
994 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
995 const wxColour
& col
, int style
)
997 return wxDoFloodFill(this, x
, y
, col
, style
);
1000 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
1002 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
1004 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
1005 // Convert from Mac colour to wx
1006 col
->Set( colour
.red
>> 8,
1012 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
1014 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1016 wxCoord xx1
= XLOG2DEVMAC(x1
) ;
1017 wxCoord yy1
= YLOG2DEVMAC(y1
) ;
1018 wxCoord xx2
= XLOG2DEVMAC(x2
) ;
1019 wxCoord yy2
= YLOG2DEVMAC(y2
) ;
1021 wxMacGraphicPath path
;
1022 path
.MoveToPoint( xx1
, yy1
) ;
1023 path
.AddLineToPoint( xx2
, yy2
) ;
1024 path
.CloseSubpath() ;
1025 m_macGraphicContext
->StrokePath( path
) ;
1027 CalcBoundingBox(x1
, y1
);
1028 CalcBoundingBox(x2
, y2
);
1031 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
1033 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
1039 wxCoord xx
= XLOG2DEVMAC(x
);
1040 wxCoord yy
= YLOG2DEVMAC(y
);
1042 wxMacGraphicPath path
;
1043 path
.MoveToPoint( XLOG2DEVMAC(0), yy
) ;
1044 path
.AddLineToPoint( XLOG2DEVMAC(w
), yy
) ;
1045 path
.CloseSubpath() ;
1046 path
.MoveToPoint( xx
, YLOG2DEVMAC(0) ) ;
1047 path
.AddLineToPoint( xx
, YLOG2DEVMAC(h
) ) ;
1048 path
.CloseSubpath() ;
1049 m_macGraphicContext
->StrokePath( path
) ;
1051 CalcBoundingBox(x
, y
);
1052 CalcBoundingBox(x
+w
, y
+h
);
1056 * To draw arcs properly the angles need to be converted from the WX style:
1057 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
1058 * a normal axis on paper).
1061 * Angles start on the +ve y axis and go clockwise.
1064 static double wxConvertWXangleToMACangle(double angle
)
1066 double newAngle
= 90 - angle
;
1072 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
1073 wxCoord x2
, wxCoord y2
,
1074 wxCoord xc
, wxCoord yc
)
1076 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
1077 wxCoord xx1
= XLOG2DEVMAC(x1
);
1078 wxCoord yy1
= YLOG2DEVMAC(y1
);
1079 wxCoord xx2
= XLOG2DEVMAC(x2
);
1080 wxCoord yy2
= YLOG2DEVMAC(y2
);
1081 wxCoord xxc
= XLOG2DEVMAC(xc
);
1082 wxCoord yyc
= YLOG2DEVMAC(yc
);
1083 double dx
= xx1
- xxc
;
1084 double dy
= yy1
- yyc
;
1085 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
1086 wxCoord rad
= (wxCoord
)radius
;
1087 double radius1
, radius2
;
1088 if (xx1
== xx2
&& yy1
== yy2
)
1093 else if (radius
== 0.0)
1095 radius1
= radius2
= 0.0;
1099 radius1
= (xx1
- xxc
== 0) ?
1100 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
1101 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
1102 radius2
= (xx2
- xxc
== 0) ?
1103 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
1104 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
1106 wxCoord alpha2
= wxCoord(radius2
- radius1
);
1107 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
1108 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
1111 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
1113 CGPathDrawingMode mode ;
1114 CGContextRef cgContext = wxBeginCGContext( this , &mode ) ;
1116 AddEllipticArcToPath( cgContext , CGPointMake( xxc , yyc ) , rad , rad , 0 , 180 ) ;
1118 CGContextDrawPath( cgContext , mode ) ;
1120 QDEndCGContext( (CGrafPtr) m_macPort , &cgContext ) ;
1124 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1125 double sa
, double ea
)
1127 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
1129 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
1130 // we have to make sure that the filling is always counter-clockwise
1133 wxCoord xx
= XLOG2DEVMAC(x
);
1134 wxCoord yy
= YLOG2DEVMAC(y
);
1135 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
1136 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
1137 // handle -ve width and/or height
1138 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
1139 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
1140 sa
= wxConvertWXangleToMACangle(sa
);
1142 CGPathDrawingMode mode ;
1143 CGContextRef cgContext = wxBeginCGContext( this , &mode ) ;
1145 AddEllipticArcToPath( cgContext , CGPointMake( xx + ww / 2 , yy + hh / 2 ) , ww / 2 , hh / 2 , sa , angle) ;
1147 CGContextDrawPath( cgContext , mode ) ;
1149 QDEndCGContext( (CGrafPtr) m_macPort , &cgContext ) ;
1153 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
1155 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1156 DoDrawLine( x
, y
, x
+ 1 , y
+ 1 ) ;
1159 void wxDC::DoDrawLines(int n
, wxPoint points
[],
1160 wxCoord xoffset
, wxCoord yoffset
)
1162 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1164 wxCoord x1
, x2
, y1
, y2
;
1165 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1166 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1167 wxMacGraphicPath path
;
1168 path
.MoveToPoint( x1
, y1
) ;
1169 for (int i
= 1; i
< n
; i
++)
1171 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1172 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1174 path
.AddLineToPoint( x2
, y2
) ;
1176 path
.CloseSubpath() ;
1177 m_macGraphicContext
->StrokePath( path
) ;
1180 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1181 wxCoord xoffset
, wxCoord yoffset
,
1184 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1185 wxCoord x1
, x2
, y1
, y2
;
1186 if ( n
== 0 || (m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
) )
1189 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1190 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1192 wxMacGraphicPath path
;
1193 path
.MoveToPoint( x1
, y1
) ;
1194 for (int i
= 1; i
< n
; i
++)
1196 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1197 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1199 path
.AddLineToPoint( x2
, y2
) ;
1201 if ( x1
!= x2
|| y1
!= y2
)
1203 path
.AddLineToPoint( x1
,y1
) ;
1205 path
.CloseSubpath() ;
1206 m_macGraphicContext
->DrawPath( path
, fillStyle
) ;
1209 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1211 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1212 wxCoord xx
= XLOG2DEVMAC(x
);
1213 wxCoord yy
= YLOG2DEVMAC(y
);
1214 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1215 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1216 // CMB: draw nothing if transformed w or h is 0
1217 if (ww
== 0 || hh
== 0)
1219 // CMB: handle -ve width and/or height
1230 wxMacGraphicPath path
;
1231 path
.AddRectangle(xx
,yy
, ww
, hh
) ;
1232 path
.CloseSubpath() ;
1233 m_macGraphicContext
->DrawPath( path
) ;
1236 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1237 wxCoord width
, wxCoord height
,
1240 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1242 radius
= - radius
* ((width
< height
) ? width
: height
);
1243 wxCoord xx
= XLOG2DEVMAC(x
);
1244 wxCoord yy
= YLOG2DEVMAC(y
);
1245 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1246 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1247 // CMB: draw nothing if transformed w or h is 0
1248 if (ww
== 0 || hh
== 0)
1250 // CMB: handle -ve width and/or height
1261 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1262 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1265 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1267 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1270 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1274 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1276 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1277 wxCoord xx
= XLOG2DEVMAC(x
);
1278 wxCoord yy
= YLOG2DEVMAC(y
);
1279 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1280 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1281 // CMB: draw nothing if transformed w or h is 0
1282 if (ww
== 0 || hh
== 0)
1284 // CMB: handle -ve width and/or height
1295 CGPoint center
= CGPointMake( xx
+ ww
/ 2 , yy
+ hh
/ 2 ) ;
1297 wxMacGraphicPath path
;
1298 if ( width
== height
)
1299 path
.AddCircle( center
, width
/ 2.0 ) ;
1300 path
.CloseSubpath() ;
1301 m_macGraphicContext
->DrawPath( path
) ;
1304 CGPathDrawingMode mode ;
1305 CGContextRef cgContext = wxBeginCGContext( this , &mode ) ;
1307 AddEllipticArcToPath( cgContext , CGPointMake( xx + ww / 2 , yy + hh / 2 ) , ww / 2 , hh / 2 , 0 , 360) ;
1309 CGContextDrawPath( cgContext , mode ) ;
1311 QDEndCGContext( (CGrafPtr) m_macPort , &cgContext ) ;
1315 bool wxDC::CanDrawBitmap(void) const
1320 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1321 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1322 wxCoord xsrcMask
, wxCoord ysrcMask
)
1324 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1325 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1326 if ( logical_func
== wxNO_OP
)
1328 if (xsrcMask
== -1 && ysrcMask
== -1)
1330 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1332 // correct the parameter in case this dc does not have a mask at all
1333 if ( useMask
&& !source
->m_macMask
)
1335 Rect srcrect
, dstrect
;
1336 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1337 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1338 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1339 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1340 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1341 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1342 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1343 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1344 short mode
= kUnsupportedMode
;
1345 bool invertDestinationFirst
= false ;
1346 switch ( logical_func
)
1348 case wxAND
: // src AND dst
1349 mode
= adMin
; // ok
1351 case wxAND_INVERT
: // (NOT src) AND dst
1352 mode
= notSrcOr
; // ok
1354 case wxAND_REVERSE
:// src AND (NOT dst)
1355 invertDestinationFirst
= true ;
1359 mode
= kEmulatedMode
;
1362 mode
= srcCopy
; // ok
1364 case wxEQUIV
: // (NOT src) XOR dst
1365 mode
= srcXor
; // ok
1367 case wxINVERT
: // NOT dst
1368 mode
= kEmulatedMode
; //or hilite ;
1370 case wxNAND
: // (NOT src) OR (NOT dst)
1371 invertDestinationFirst
= true ;
1374 case wxNOR
: // (NOT src) AND (NOT dst)
1375 invertDestinationFirst
= true ;
1378 case wxNO_OP
: // dst
1379 mode
= kEmulatedMode
; // this has already been handled upon entry
1381 case wxOR
: // src OR dst
1384 case wxOR_INVERT
: // (NOT src) OR dst
1387 case wxOR_REVERSE
: // src OR (NOT dst)
1388 invertDestinationFirst
= true ;
1392 mode
= kEmulatedMode
;
1394 case wxSRC_INVERT
: // (NOT src)
1395 mode
= notSrcCopy
; // ok
1397 case wxXOR
: // src XOR dst
1398 mode
= notSrcXor
; // ok
1403 if ( mode
== kUnsupportedMode
)
1405 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1408 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1409 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1410 if ( LockPixels(bmappixels
) )
1412 if ( source
->GetDepth() == 1 )
1414 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1415 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1419 // the modes need this, otherwise we'll end up having really nice colors...
1420 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1421 RGBColor black
= { 0,0,0} ;
1422 RGBForeColor( &black
) ;
1423 RGBBackColor( &white
) ;
1425 if ( useMask
&& source
->m_macMask
)
1427 if ( mode
== srcCopy
)
1429 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1431 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1432 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1433 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1434 &srcrect
, &srcrect
, &dstrect
) ;
1435 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1440 RgnHandle clipRgn
= NewRgn() ;
1441 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1442 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1443 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1444 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1445 if ( mode
== kEmulatedMode
)
1448 ::PenPat(GetQDGlobalsBlack(&pat
));
1449 if ( logical_func
== wxSET
)
1451 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1452 ::RGBForeColor( &col
) ;
1453 ::PaintRgn( clipRgn
) ;
1455 else if ( logical_func
== wxCLEAR
)
1457 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1458 ::RGBForeColor( &col
) ;
1459 ::PaintRgn( clipRgn
) ;
1461 else if ( logical_func
== wxINVERT
)
1463 MacInvertRgn( clipRgn
) ;
1467 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1469 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1471 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1472 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1473 if ( PtInRgn( dstPoint
, clipRgn
) )
1477 SetPort( (GrafPtr
) sourcePort
) ;
1478 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1479 SetPort( (GrafPtr
) m_macPort
) ;
1480 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1481 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1482 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1490 if ( invertDestinationFirst
)
1492 MacInvertRgn( clipRgn
) ;
1494 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1495 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1496 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1498 DisposeRgn( clipRgn
) ;
1503 RgnHandle clipRgn
= NewRgn() ;
1504 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1505 if ( mode
== kEmulatedMode
)
1508 ::PenPat(GetQDGlobalsBlack(&pat
));
1509 if ( logical_func
== wxSET
)
1511 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1512 ::RGBForeColor( &col
) ;
1513 ::PaintRgn( clipRgn
) ;
1515 else if ( logical_func
== wxCLEAR
)
1517 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1518 ::RGBForeColor( &col
) ;
1519 ::PaintRgn( clipRgn
) ;
1521 else if ( logical_func
== wxINVERT
)
1523 MacInvertRgn( clipRgn
) ;
1527 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1529 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1531 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1532 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1536 SetPort( (GrafPtr
) sourcePort
) ;
1537 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1538 SetPort( (GrafPtr
) m_macPort
) ;
1539 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1540 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1541 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1549 if ( invertDestinationFirst
)
1551 MacInvertRgn( clipRgn
) ;
1553 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1554 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1555 &srcrect
, &dstrect
, mode
, NULL
) ;
1557 DisposeRgn( clipRgn
) ;
1559 UnlockPixels( bmappixels
) ;
1561 m_macPenInstalled
= false ;
1562 m_macBrushInstalled
= false ;
1563 m_macFontInstalled
= false ;
1568 // as macro in FixMath.h for 10.3
1569 inline Fixed
IntToFixed( int inInt
)
1571 return (((SInt32
) inInt
) << 16);
1574 inline int FixedToInt( Fixed inFixed
)
1576 return (((SInt32
) inFixed
) >> 16);
1580 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1583 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1585 if ( str
.Length() == 0 )
1588 OSStatus status
= noErr
;
1589 ATSUTextLayout atsuLayout
;
1590 UniCharCount chars
= str
.Length() ;
1591 UniChar
* ubuf
= NULL
;
1592 #if SIZEOF_WCHAR_T == 4
1593 wxMBConvUTF16BE converter
;
1595 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1596 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1597 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1599 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1600 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1601 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1602 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1604 chars
= unicharlen
/ 2 ;
1607 ubuf
= (UniChar
*) str
.wc_str() ;
1609 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1610 chars
= wxWcslen( wchar
.data() ) ;
1611 ubuf
= (UniChar
*) wchar
.data() ;
1615 int drawX
= XLOG2DEVMAC(x
) ;
1616 int drawY
= YLOG2DEVMAC(y
) ;
1620 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1621 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1623 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1624 int iAngle
= int( angle
);
1628 CGContextSaveGState(m_macGraphicContext
->GetNativeContext());
1629 if ( abs(iAngle
) > 0 )
1631 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1632 ATSUAttributeTag atsuTags
[] =
1634 kATSULineRotationTag
,
1636 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1640 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1644 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1645 atsuTags
, atsuSizes
, atsuValues
) ;
1648 CGContextRef cgContext
= m_macGraphicContext
->GetNativeContext() ;
1649 ATSUAttributeTag atsuTags
[] =
1653 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1655 sizeof( CGContextRef
) ,
1657 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1661 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1662 atsuTags
, atsuSizes
, atsuValues
) ;
1665 ATSUTextMeasurement textBefore
;
1666 ATSUTextMeasurement textAfter
;
1667 ATSUTextMeasurement ascent
;
1668 ATSUTextMeasurement descent
;
1670 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1671 &textBefore
, &textAfter
, &ascent
, &descent
);
1672 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1676 if ( m_backgroundMode
== wxSOLID
)
1678 wxMacGraphicPath path
;
1682 path
.AddLineToPoint(
1683 drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) ,
1684 drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) ) ;
1685 path
.AddLineToPoint(
1686 drawX
+ sin(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) + cos(angle
/RAD2DEG
) * FixedToInt(textAfter
) ,
1687 drawY
+ cos(angle
/RAD2DEG
) * FixedToInt(ascent
+ descent
) - sin(angle
/RAD2DEG
) * FixedToInt(textAfter
) ) ;
1688 path
.AddLineToPoint(
1689 drawX
+ cos(angle
/RAD2DEG
) * FixedToInt(textAfter
) ,
1690 drawY
- sin(angle
/RAD2DEG
) * FixedToInt(textAfter
) ) ;
1692 m_macGraphicContext
->FillPath( path
, m_textBackgroundColour
) ;
1695 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1696 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1697 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1698 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1699 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1701 CGContextTranslateCTM(m_macGraphicContext
->GetNativeContext(), drawX
, drawY
);
1702 CGContextScaleCTM(m_macGraphicContext
->GetNativeContext(), 1, -1);
1703 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1704 IntToFixed(0) , IntToFixed(0) );
1705 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1707 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1708 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1710 ::ATSUDisposeTextLayout(atsuLayout
);
1711 #if SIZEOF_WCHAR_T == 4
1714 CGContextRestoreGState( m_macGraphicContext
->GetNativeContext() ) ;
1717 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1719 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1720 DoDrawRotatedText( strtext
, x
, y
, 0.0 ) ;
1723 bool wxDC::CanGetTextExtent() const
1725 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1729 void wxDC::DoGetTextExtent( const wxString
&str
, wxCoord
*width
, wxCoord
*height
,
1730 wxCoord
*descent
, wxCoord
*externalLeading
,
1731 wxFont
*theFont
) const
1733 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1734 wxFont formerFont
= m_font
;
1737 // work around the constness
1738 *((wxFont
*)(&m_font
)) = *theFont
;
1742 if ( str
.Length() == 0 )
1745 OSStatus status
= noErr
;
1746 ATSUTextLayout atsuLayout
;
1747 UniCharCount chars
= str
.Length() ;
1748 UniChar
* ubuf
= NULL
;
1749 #if SIZEOF_WCHAR_T == 4
1750 wxMBConvUTF16BE converter
;
1752 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1753 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1754 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1756 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1757 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1758 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1759 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1761 chars
= unicharlen
/ 2 ;
1764 ubuf
= (UniChar
*) str
.wc_str() ;
1766 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1767 chars
= wxWcslen( wchar
.data() ) ;
1768 ubuf
= (UniChar
*) wchar
.data() ;
1774 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1775 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1777 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1779 ATSUTextMeasurement textBefore
;
1780 ATSUTextMeasurement textAfter
;
1781 ATSUTextMeasurement textAscent
;
1782 ATSUTextMeasurement textDescent
;
1784 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1785 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1788 *height
= YDEV2LOGREL( FixedToInt(textAscent
+ textDescent
) ) ;
1790 *descent
=YDEV2LOGREL( FixedToInt(textDescent
) );
1791 if ( externalLeading
)
1792 *externalLeading
= 0 ;
1794 *width
= XDEV2LOGREL( FixedToInt(textAfter
- textBefore
) ) ;
1796 ::ATSUDisposeTextLayout(atsuLayout
);
1797 #if SIZEOF_WCHAR_T == 4
1802 // work around the constness
1803 *((wxFont
*)(&m_font
)) = formerFont
;
1804 m_macFontInstalled
= false ;
1809 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1811 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1814 widths
.Add(0, text
.Length());
1816 if (text
.Length() == 0)
1821 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1822 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1823 useGetThemeText
= false ;
1825 if ( useGetThemeText
)
1827 // If anybody knows how to do this more efficiently yet still handle
1828 // the fractional glyph widths that may be present when using AA
1829 // fonts, please change it. Currently it is measuring from the
1830 // begining of the string for each succeding substring, which is much
1831 // slower than this should be.
1832 for (size_t i
=0; i
<text
.Length(); i
++)
1834 wxString
str(text
.Left(i
+1));
1835 Point bounds
= {0,0};
1837 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1838 ::GetThemeTextDimensions( mString
,
1839 kThemeCurrentPortFont
,
1844 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1850 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1851 size_t len
= strlen(buff
);
1852 short* measurements
= new short[len
+1];
1853 MeasureText(len
, buff
.data(), measurements
);
1855 // Copy to widths, starting at measurements[1]
1856 // NOTE: this doesn't take into account any multi-byte characters
1857 // in buff, it probabkly should...
1858 for (size_t i
=0; i
<text
.Length(); i
++)
1859 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1861 delete [] measurements
;
1869 wxCoord
wxDC::GetCharWidth(void) const
1872 DoGetTextExtent(wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
) ;
1876 wxCoord
wxDC::GetCharHeight(void) const
1879 DoGetTextExtent(wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
) ;
1883 void wxDC::Clear(void)
1885 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1887 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1889 HIRect rect
= CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
1890 switch( m_backgroundBrush
.MacGetBrushKind() )
1892 case kwxMacBrushTheme
:
1896 case kwxMacBrushThemeBackground
:
1898 HIThemeBackgroundDrawInfo drawInfo
;
1899 drawInfo
.version
= 0 ;
1900 drawInfo
.state
= kThemeStateActive
;
1901 drawInfo
.kind
= m_backgroundBrush
.MacGetThemeBackground(NULL
) ;
1902 HIThemeDrawBackground( &rect
, &drawInfo
, m_macGraphicContext
->GetNativeContext() ,
1903 kHIThemeOrientationNormal
) ;
1907 case kwxMacBrushColour
:
1909 RGBColor col
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ;
1910 CGContextSetRGBFillColor( m_macGraphicContext
->GetNativeContext() , col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
1911 CGContextFillRect(m_macGraphicContext
->GetNativeContext(), rect
);
1913 // reset to normal value
1914 col
= MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
1915 CGContextSetRGBFillColor( m_macGraphicContext
->GetNativeContext() , col
.red
/ 65536.0 , col
.green
/ 65536.0 , col
.blue
/ 65536.0 , 1.0 ) ;
1922 void wxDC::MacInstallFont() const
1924 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1927 // if ( m_macFontInstalled )
1929 Pattern blackColor ;
1930 MacSetupBackgroundForCurrentPort(m_backgroundBrush) ;
1933 ::TextFont( m_font.MacGetFontNum() ) ;
1934 ::TextSize( (short)(m_scaleY * m_font.MacGetFontSize()) ) ;
1935 ::TextFace( m_font.MacGetFontStyle() ) ;
1936 m_macFontInstalled = true ;
1937 m_macBrushInstalled = false ;
1938 m_macPenInstalled = false ;
1939 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1940 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
1941 ::RGBForeColor( &forecolor );
1942 ::RGBBackColor( &backcolor );
1946 FontFamilyID fontId ;
1950 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
1951 GetFNum( fontName, &fontId );
1952 ::TextFont( fontId ) ;
1953 ::TextSize( short(m_scaleY * fontSize) ) ;
1954 ::TextFace( fontStyle ) ;
1955 // todo reset after spacing changes - or store the current spacing somewhere
1956 m_macFontInstalled = true ;
1957 m_macBrushInstalled = false ;
1958 m_macPenInstalled = false ;
1959 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1960 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
1961 ::RGBForeColor( &forecolor );
1962 ::RGBBackColor( &backcolor );
1964 short mode = patCopy ;
1966 switch( m_logicalFunction )
1971 case wxINVERT: // NOT dst
1972 ::PenPat(GetQDGlobalsBlack(&blackColor));
1975 case wxXOR: // src XOR dst
1978 case wxOR_REVERSE: // src OR (NOT dst)
1981 case wxSRC_INVERT: // (NOT src)
1984 case wxAND: // src AND dst
1989 case wxAND_REVERSE:// src AND (NOT dst)
1990 case wxAND_INVERT: // (NOT src) AND dst
1991 case wxNO_OP: // dst
1992 case wxNOR: // (NOT src) AND (NOT dst)
1993 case wxEQUIV: // (NOT src) XOR dst
1994 case wxOR_INVERT: // (NOT src) OR dst
1995 case wxNAND: // (NOT src) OR (NOT dst)
1996 case wxOR: // src OR dst
1998 // case wxSRC_OR: // source _bitmap_ OR destination
1999 // case wxSRC_AND: // source _bitmap_ AND destination
2004 OSStatus status
= noErr
;
2005 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
2006 Style qdStyle
= m_font
.MacGetFontStyle() ;
2007 ATSUFontID atsuFont
= m_font
.MacGetATSUFontID() ;
2008 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
2009 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
2010 ATSUAttributeTag atsuTags
[] =
2015 // kATSUBaselineClassTag ,
2016 kATSUVerticalCharacterTag
,
2017 kATSUQDBoldfaceTag
,
2019 kATSUQDUnderlineTag
,
2020 kATSUQDCondensedTag
,
2021 kATSUQDExtendedTag
,
2023 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2025 sizeof( ATSUFontID
) ,
2027 sizeof( RGBColor
) ,
2028 // sizeof( BslnBaselineClass ) ,
2029 sizeof( ATSUVerticalCharacterType
),
2036 Boolean kTrue
= true ;
2037 Boolean kFalse
= false ;
2038 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
2039 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
2040 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
2044 &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ,
2045 // &kBaselineDefault ,
2047 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
2048 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
2049 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
2050 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
2051 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
2053 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
2054 atsuTags
, atsuSizes
, atsuValues
);
2055 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
2058 Pattern gPatterns
[] =
2060 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
2061 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
2062 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
2063 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
2064 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
2065 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
2066 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
2068 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
2069 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
2070 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
2071 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
2074 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
2076 int index
= 0; // solid pattern by default
2080 case wxBDIAGONAL_HATCH
: index
= 1; break;
2081 case wxFDIAGONAL_HATCH
: index
= 2; break;
2082 case wxCROSS_HATCH
: index
= 3; break;
2083 case wxHORIZONTAL_HATCH
: index
= 4; break;
2084 case wxVERTICAL_HATCH
: index
= 5; break;
2085 case wxCROSSDIAG_HATCH
: index
= 6; break;
2087 case wxDOT
: index
= 7; break;
2088 case wxLONG_DASH
: index
= 8; break;
2089 case wxSHORT_DASH
: index
= 9; break;
2090 case wxDOT_DASH
: index
= 10; break;
2092 *pattern
= gPatterns
[index
];
2095 void wxDC::MacInstallPen() const
2098 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2099 //Pattern blackColor;
2100 // if ( m_macPenInstalled )
2102 RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
2103 RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
2104 ::RGBForeColor( &forecolor );
2105 ::RGBBackColor( &backcolor );
2107 int penWidth = (int) (m_pen.GetWidth() * m_scaleX) ; ;
2108 // null means only one pixel, at whatever resolution
2109 if ( penWidth == 0 )
2111 ::PenSize(penWidth, penWidth);
2113 int penStyle = m_pen.GetStyle();
2115 if (penStyle == wxUSER_DASH)
2117 // FIXME: there should be exactly 8 items in the dash
2119 int number = m_pen.GetDashes(&dash) ;
2121 for ( int i = 0 ; i < 8 ; ++i )
2123 pat.pat[i] = dash[index] ;
2124 if (index < number - 1)
2130 wxMacGetPattern(penStyle, &pat);
2134 short mode = patCopy ;
2136 switch( m_logicalFunction )
2138 case wxCOPY: // only foreground color, leave background (thus not patCopy)
2141 case wxINVERT: // NOT dst
2142 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2145 case wxXOR: // src XOR dst
2148 case wxOR_REVERSE: // src OR (NOT dst)
2151 case wxSRC_INVERT: // (NOT src)
2154 case wxAND: // src AND dst
2159 case wxAND_REVERSE:// src AND (NOT dst)
2160 case wxAND_INVERT: // (NOT src) AND dst
2161 case wxNO_OP: // dst
2162 case wxNOR: // (NOT src) AND (NOT dst)
2163 case wxEQUIV: // (NOT src) XOR dst
2164 case wxOR_INVERT: // (NOT src) OR dst
2165 case wxNAND: // (NOT src) OR (NOT dst)
2166 case wxOR: // src OR dst
2168 // case wxSRC_OR: // source _bitmap_ OR destination
2169 // case wxSRC_AND: // source _bitmap_ AND destination
2173 m_macPenInstalled = true ;
2174 m_macBrushInstalled = false ;
2175 m_macFontInstalled = false ;
2179 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2181 Pattern whiteColor
;
2182 switch( background
.MacGetBrushKind() )
2184 case kwxMacBrushTheme
:
2186 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
2189 case kwxMacBrushThemeBackground
:
2192 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
2193 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2196 case kwxMacBrushColour
:
2198 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2199 int brushStyle
= background
.GetStyle();
2200 if (brushStyle
== wxSOLID
)
2201 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2202 else if (IS_HATCH(brushStyle
))
2205 wxMacGetPattern(brushStyle
, &pat
);
2210 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2217 void wxDC::MacInstallBrush() const
2219 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2220 Pattern blackColor
;
2221 // if ( m_macBrushInstalled )
2224 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2225 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2226 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2227 int brushStyle
= m_brush
.GetStyle();
2228 if (brushStyle
== wxSOLID
)
2230 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2232 else if (IS_HATCH(brushStyle
))
2235 wxMacGetPattern(brushStyle
, &pat
);
2238 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2240 // we force this in order to be compliant with wxMSW
2241 backgroundTransparent
= false ;
2242 // for these the text fore (and back for MASK_OPAQUE) colors are used
2243 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2244 int width
= bitmap
->GetWidth() ;
2245 int height
= bitmap
->GetHeight() ;
2246 GWorldPtr gw
= NULL
;
2247 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2248 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2250 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2251 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2252 LockPixels( gwpixmaphandle
) ;
2253 bool isMonochrome
= !IsPortColor( gw
) ;
2254 if ( !isMonochrome
)
2256 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2257 isMonochrome
= true ;
2259 if ( isMonochrome
&& width
== 8 && height
== 8 )
2261 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2262 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2263 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2264 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2265 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2267 for ( int i
= 0 ; i
< 8 ; ++i
)
2269 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2271 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2276 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2277 // caching scheme before putting this into production
2280 PixPatHandle pixpat
= NewPixPat() ;
2281 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2282 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2283 ((**(**pixpat
).patMap
).bounds
.bottom
-
2284 (**(**pixpat
).patMap
).bounds
.top
);
2285 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2286 (**pixpat
).patData
= image
;
2289 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2290 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2291 if ( ctspec
[0].rgb
.red
== 0x0000 )
2293 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2294 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2298 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2299 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2301 ::CTabChanged( ctable
) ;
2303 ::PenPixPat(pixpat
);
2304 m_macForegroundPixMap
= pixpat
;
2306 UnlockPixels( gwpixmaphandle
) ;
2310 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2312 short mode
= patCopy
;
2313 switch( m_logicalFunction
)
2316 if ( backgroundTransparent
)
2321 case wxINVERT
: // NOT dst
2322 if ( !backgroundTransparent
)
2324 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2328 case wxXOR
: // src XOR dst
2331 case wxOR_REVERSE
: // src OR (NOT dst)
2334 case wxSRC_INVERT
: // (NOT src)
2337 case wxAND
: // src AND dst
2342 case wxAND_REVERSE
:// src AND (NOT dst)
2343 case wxAND_INVERT
: // (NOT src) AND dst
2344 case wxNO_OP
: // dst
2345 case wxNOR
: // (NOT src) AND (NOT dst)
2346 case wxEQUIV
: // (NOT src) XOR dst
2347 case wxOR_INVERT
: // (NOT src) OR dst
2348 case wxNAND
: // (NOT src) OR (NOT dst)
2349 case wxOR
: // src OR dst
2351 // case wxSRC_OR: // source _bitmap_ OR destination
2352 // case wxSRC_AND: // source _bitmap_ AND destination
2356 m_macBrushInstalled
= true ;
2357 m_macPenInstalled
= false ;
2358 m_macFontInstalled
= false ;
2361 // ---------------------------------------------------------------------------
2362 // coordinates transformations
2363 // ---------------------------------------------------------------------------
2365 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2367 return ((wxDC
*)this)->XDEV2LOG(x
);
2370 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2372 return ((wxDC
*)this)->YDEV2LOG(y
);
2375 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2377 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2380 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2382 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2385 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2387 return ((wxDC
*)this)->XLOG2DEV(x
);
2390 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2392 return ((wxDC
*)this)->YLOG2DEV(y
);
2395 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2397 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2400 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2402 return ((wxDC
*)this)->YLOG2DEVREL(y
);