1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/region.h"
29 #include "wx/mac/private.h"
30 #include "ATSUnicode.h"
31 #include "TextCommon.h"
32 #include "TextEncodingConverter.h"
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 #define mm2inches 0.0393700787402
43 #define inches2mm 25.4
44 #define mm2twips 56.6929133859
45 #define twips2mm 0.0176388888889
46 #define mm2pt 2.83464566929
47 #define pt2mm 0.352777777778
49 const double M_PI
= 3.14159265358979 ;
51 const double RAD2DEG
= 180.0 / M_PI
;
52 const short kEmulatedMode
= -1 ;
53 const short kUnsupportedMode
= -2 ;
55 #define wxMAC_EXPERIMENTAL_PATTERN 0
57 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
58 m_ph( (GrafPtr
) dc
->m_macPort
)
60 wxASSERT( dc
->Ok() ) ;
62 dc
->MacSetupPort(&m_ph
) ;
65 wxMacPortSetter::~wxMacPortSetter()
67 m_dc
->MacCleanupPort(&m_ph
) ;
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
75 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
76 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 // this function emulates all wx colour manipulations, used to verify the implementation
83 // by setting the mode in the blitting functions to kEmulatedMode
85 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
86 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
88 switch ( logical_func
)
90 case wxAND
: // src AND dst
91 dstColor
.red
= dstColor
.red
& srcColor
.red
;
92 dstColor
.green
= dstColor
.green
& srcColor
.green
;
93 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
95 case wxAND_INVERT
: // (NOT src) AND dst
96 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
97 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
98 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
100 case wxAND_REVERSE
:// src AND (NOT dst)
101 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
102 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
103 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
111 dstColor
.red
= srcColor
.red
;
112 dstColor
.green
= srcColor
.green
;
113 dstColor
.blue
= srcColor
.blue
;
115 case wxEQUIV
: // (NOT src) XOR dst
116 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
117 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
118 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
120 case wxINVERT
: // NOT dst
121 dstColor
.red
= ~dstColor
.red
;
122 dstColor
.green
= ~dstColor
.green
;
123 dstColor
.blue
= ~dstColor
.blue
;
125 case wxNAND
: // (NOT src) OR (NOT dst)
126 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
127 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
128 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
130 case wxNOR
: // (NOT src) AND (NOT dst)
131 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
132 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
133 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
137 case wxOR
: // src OR dst
138 dstColor
.red
= dstColor
.red
| srcColor
.red
;
139 dstColor
.green
= dstColor
.green
| srcColor
.green
;
140 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
142 case wxOR_INVERT
: // (NOT src) OR dst
143 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
144 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
145 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
147 case wxOR_REVERSE
: // src OR (NOT dst)
148 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
149 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
150 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
153 dstColor
.red
= 0xFFFF ;
154 dstColor
.green
= 0xFFFF ;
155 dstColor
.blue
= 0xFFFF ;
157 case wxSRC_INVERT
: // (NOT src)
158 dstColor
.red
= ~srcColor
.red
;
159 dstColor
.green
= ~srcColor
.green
;
160 dstColor
.blue
= ~srcColor
.blue
;
162 case wxXOR
: // src XOR dst
163 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
164 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
165 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
176 m_mm_to_pix_x
= mm2pt
;
177 m_mm_to_pix_y
= mm2pt
;
179 m_internalDeviceOriginX
= 0;
180 m_internalDeviceOriginY
= 0;
181 m_externalDeviceOriginX
= 0;
182 m_externalDeviceOriginY
= 0;
184 m_logicalScaleX
= 1.0;
185 m_logicalScaleY
= 1.0;
191 m_needComputeScaleX
= FALSE
;
192 m_needComputeScaleY
= FALSE
;
198 m_macFontInstalled
= false ;
199 m_macBrushInstalled
= false ;
200 m_macPenInstalled
= false ;
202 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
203 m_macBoundaryClipRgn
= NewRgn() ;
204 m_macCurrentClipRgn
= NewRgn() ;
206 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
207 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
209 m_pen
= *wxBLACK_PEN
;
210 m_font
= *wxNORMAL_FONT
;
211 m_brush
= *wxWHITE_BRUSH
;
212 m_macCurrentPortStateHelper
= NULL
;
213 m_macATSUIStyle
= NULL
;
214 m_macAliasWasEnabled
= false;
215 m_macForegroundPixMap
= NULL
;
216 m_macBackgroundPixMap
= NULL
;
221 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
222 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
224 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
226 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
227 m_macCurrentPortStateHelper
= help
;
228 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
230 m_macFontInstalled
= false ;
231 m_macBrushInstalled
= false ;
232 m_macPenInstalled
= false ;
235 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
237 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
238 m_macCurrentPortStateHelper
= NULL
;
239 if( m_macATSUIStyle
)
241 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
242 m_macATSUIStyle
= NULL
;
244 if ( m_macAliasWasEnabled
)
246 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
247 m_macAliasWasEnabled
= false ;
249 if ( m_macForegroundPixMap
)
252 ::PenPat(GetQDGlobalsBlack(&blackColor
));
253 DisposePixMap( (PixMapHandle
) m_macForegroundPixMap
) ;
254 m_macForegroundPixMap
= NULL
;
256 if ( m_macBackgroundPixMap
)
259 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
260 DisposePixMap( (PixMapHandle
) m_macBackgroundPixMap
) ;
261 m_macBackgroundPixMap
= NULL
;
265 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
267 wxCHECK_RET( Ok(), wxT("invalid window dc") );
269 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
271 wxMacPortSetter
helper(this) ;
273 wxCoord xx
= XLOG2DEVMAC(x
);
274 wxCoord yy
= YLOG2DEVMAC(y
);
275 wxCoord w
= bmp
.GetWidth();
276 wxCoord h
= bmp
.GetHeight();
277 wxCoord ww
= XLOG2DEVREL(w
);
278 wxCoord hh
= YLOG2DEVREL(h
);
280 // Set up drawing mode
281 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
282 //m_logicalFunction == wxCLEAR ? WHITENESS :
283 //m_logicalFunction == wxSET ? BLACKNESS :
284 m_logicalFunction
== wxINVERT
? hilite
:
285 //m_logicalFunction == wxAND ? MERGECOPY :
286 m_logicalFunction
== wxOR
? srcOr
:
287 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
288 m_logicalFunction
== wxXOR
? srcXor
:
289 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
290 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
291 //m_logicalFunction == wxSRC_OR ? srcOr :
292 //m_logicalFunction == wxSRC_AND ? SRCAND :
295 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
296 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
297 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
298 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
300 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
302 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
303 PixMapHandle bmappixels
;
305 // Set foreground and background colours (for bitmaps depth = 1)
306 if(bmp
.GetDepth() == 1)
308 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
309 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
315 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
316 RGBColor black
= { 0,0,0} ;
317 RGBForeColor( &black
) ;
318 RGBBackColor( &white
) ;
321 bmappixels
= GetGWorldPixMap( bmapworld
) ;
323 wxCHECK_RET(LockPixels(bmappixels
),
324 wxT("DoDrawBitmap: Unable to lock pixels"));
326 Rect source
= { 0, 0, h
, w
};
327 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
329 if ( useMask
&& bmp
.GetMask() )
331 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
335 GetPortBitMapForCopyBits(bmapworld
),
336 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
337 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
338 &source
, &source
, &dest
, mode
, NULL
340 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
344 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
345 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
346 &source
, &dest
, mode
, NULL
) ;
348 UnlockPixels( bmappixels
) ;
350 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
352 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
353 OffsetRect( &bitmaprect
, xx
, yy
) ;
354 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
356 m_macPenInstalled
= false ;
357 m_macBrushInstalled
= false ;
358 m_macFontInstalled
= false ;
362 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
364 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
366 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
368 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
370 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
372 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
373 wxCoord xx
, yy
, ww
, hh
;
377 ww
= XLOG2DEVREL(width
);
378 hh
= YLOG2DEVREL(height
);
380 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
381 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
385 m_clipX1
= wxMax( m_clipX1
, xx
);
386 m_clipY1
= wxMax( m_clipY1
, yy
);
387 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
388 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
400 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
402 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
404 wxMacPortSetter
helper(this) ;
407 DestroyClippingRegion();
412 region
.GetBox( x
, y
, w
, h
);
413 wxCoord xx
, yy
, ww
, hh
;
420 // if we have a scaling that we cannot map onto native regions
421 // we must use the box
423 if ( ww
!= w
|| hh
!= h
)
425 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
429 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
430 if ( xx
!= x
|| yy
!= y
)
432 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
434 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
437 m_clipX1
= wxMax( m_clipX1
, xx
);
438 m_clipY1
= wxMax( m_clipY1
, yy
);
439 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
440 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
454 void wxDC::DestroyClippingRegion()
456 wxMacPortSetter
helper(this) ;
457 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
460 void wxDC::DoGetSize( int* width
, int* height
) const
462 *width
= m_maxX
-m_minX
;
463 *height
= m_maxY
-m_minY
;
465 void wxDC::DoGetSizeMM( int* width
, int* height
) const
470 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
471 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
473 void wxDC::SetTextForeground( const wxColour
&col
)
475 wxCHECK_RET(Ok(), wxT("Invalid DC"));
476 m_textForegroundColour
= col
;
477 m_macFontInstalled
= false ;
479 void wxDC::SetTextBackground( const wxColour
&col
)
481 wxCHECK_RET(Ok(), wxT("Invalid DC"));
482 m_textBackgroundColour
= col
;
483 m_macFontInstalled
= false ;
485 void wxDC::SetMapMode( int mode
)
490 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
493 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
496 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
499 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
503 SetLogicalScale( 1.0, 1.0 );
506 if (mode
!= wxMM_TEXT
)
508 m_needComputeScaleX
= TRUE
;
509 m_needComputeScaleY
= TRUE
;
512 void wxDC::SetUserScale( double x
, double y
)
514 // allow negative ? -> no
517 ComputeScaleAndOrigin();
519 void wxDC::SetLogicalScale( double x
, double y
)
524 ComputeScaleAndOrigin();
526 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
528 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
529 m_logicalOriginY
= y
* m_signY
;
530 ComputeScaleAndOrigin();
532 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
534 m_externalDeviceOriginX
= x
;
535 m_externalDeviceOriginY
= y
;
536 ComputeScaleAndOrigin();
540 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
542 m_internalDeviceOriginX
= x
;
543 m_internalDeviceOriginY
= y
;
544 ComputeScaleAndOrigin();
546 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
548 if (x
) *x
= m_internalDeviceOriginX
;
549 if (y
) *y
= m_internalDeviceOriginY
;
552 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
554 m_signX
= (xLeftRight
? 1 : -1);
555 m_signY
= (yBottomUp
? -1 : 1);
556 ComputeScaleAndOrigin();
559 wxSize
wxDC::GetPPI() const
561 return wxSize(72, 72);
564 int wxDC::GetDepth() const
566 return wxDisplayDepth() ;
569 void wxDC::ComputeScaleAndOrigin()
571 // CMB: copy scale to see if it changes
572 double origScaleX
= m_scaleX
;
573 double origScaleY
= m_scaleY
;
575 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
576 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
578 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
579 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
581 // CMB: if scale has changed call SetPen to recalulate the line width
582 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
584 // this is a bit artificial, but we need to force wxDC to think
585 // the pen has changed
586 wxPen
* pen
= & GetPen();
592 void wxDC::SetPalette( const wxPalette
& palette
)
596 void wxDC::SetBackgroundMode( int mode
)
598 m_backgroundMode
= mode
;
601 void wxDC::SetFont( const wxFont
&font
)
604 m_macFontInstalled
= false ;
607 void wxDC::SetPen( const wxPen
&pen
)
614 m_macPenInstalled
= false ;
617 void wxDC::SetBrush( const wxBrush
&brush
)
619 if (m_brush
== brush
)
623 m_macBrushInstalled
= false ;
626 void wxDC::SetBackground( const wxBrush
&brush
)
628 if (m_backgroundBrush
== brush
)
631 m_backgroundBrush
= brush
;
633 if (!m_backgroundBrush
.Ok())
635 m_macBrushInstalled
= false ;
638 void wxDC::SetLogicalFunction( int function
)
640 if (m_logicalFunction
== function
)
643 m_logicalFunction
= function
;
644 m_macFontInstalled
= false ;
645 m_macBrushInstalled
= false ;
646 m_macPenInstalled
= false ;
649 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
654 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
656 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
657 wxMacPortSetter
helper(this) ;
661 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
663 // Convert from Mac colour to wx
664 col
->Set( colour
.red
>> 8,
671 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
673 wxCHECK_RET(Ok(), wxT("Invalid DC"));
675 wxMacPortSetter
helper(this) ;
677 if (m_pen
.GetStyle() != wxTRANSPARENT
)
680 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
681 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
683 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
684 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
685 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
686 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
688 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
689 (m_pen
.GetWidth() <= 1))
691 // Implement LAST_NOT for MAC at least for
692 // orthogonal lines. RR.
714 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
716 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
718 if (m_pen
.GetStyle() != wxTRANSPARENT
)
723 wxCoord xx
= XLOG2DEVMAC(x
);
724 wxCoord yy
= YLOG2DEVMAC(y
);
727 ::MoveTo( XLOG2DEVMAC(0), yy
);
728 ::LineTo( XLOG2DEVMAC(w
), yy
);
729 ::MoveTo( xx
, YLOG2DEVMAC(0) );
730 ::LineTo( xx
, YLOG2DEVMAC(h
) );
732 CalcBoundingBox(x
, y
);
733 CalcBoundingBox(x
+w
, y
+h
);
739 * To draw arcs properly the angles need to be converted from the WX style:
740 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
741 * a normal axis on paper).
744 * Angles start on the +ve y axis and go clockwise.
745 * To achive this I work out which quadrant the angle lies in then map this to
746 * the equivalent quadrant on the Mac. (Sin and Cos values reveal which
747 * quadrant you are in).
749 static double wxConvertWXangleToMACangle(double angle
)
753 sin_a
= sin(angle
/ RAD2DEG
);
754 cos_a
= cos(angle
/ RAD2DEG
);
756 if( (sin_a
>= 0.0) && (cos_a
>= 0.0) ) {
757 angle
= acos(sin_a
) * RAD2DEG
;
759 else if( (sin_a
>= 0.0) && (cos_a
<= 0.0) ) {
761 angle
= acos(sin_a
) * RAD2DEG
+ 180;
763 else if( (sin_a
<= 0.0) && (cos_a
>= 0.0) ) {
764 angle
= acos(sin_a
) * RAD2DEG
+ 180;
766 else if( (sin_a
< 0.0) && (cos_a
< 0.0) ) {
768 angle
= acos(sin_a
) * RAD2DEG
+ 180;
773 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
774 wxCoord x2
, wxCoord y2
,
775 wxCoord xc
, wxCoord yc
)
777 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
779 wxCoord xx1
= XLOG2DEVMAC(x1
);
780 wxCoord yy1
= YLOG2DEVMAC(y1
);
781 wxCoord xx2
= XLOG2DEVMAC(x2
);
782 wxCoord yy2
= YLOG2DEVMAC(y2
);
783 wxCoord xxc
= XLOG2DEVMAC(xc
);
784 wxCoord yyc
= YLOG2DEVMAC(yc
);
785 double dx
= xx1
- xxc
;
786 double dy
= yy1
- yyc
;
787 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
788 wxCoord rad
= (wxCoord
)radius
;
789 double radius1
, radius2
;
791 if (xx1
== xx2
&& yy1
== yy2
)
796 else if (radius
== 0.0)
798 radius1
= radius2
= 0.0;
802 radius1
= (xx1
- xxc
== 0) ?
803 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
804 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
805 radius2
= (xx2
- xxc
== 0) ?
806 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
807 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
809 wxCoord alpha2
= wxCoord(radius2
- radius1
);
810 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
811 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
815 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
817 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
819 PaintArc(&r
, alpha1
, alpha2
);
821 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
823 FrameArc(&r
, alpha1
, alpha2
);
827 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
828 double sa
, double ea
)
830 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
833 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
835 wxCoord xx
= XLOG2DEVMAC(x
);
836 wxCoord yy
= YLOG2DEVMAC(y
);
837 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
838 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
840 // handle -ve width and/or height
841 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
842 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
844 sa
= wxConvertWXangleToMACangle(sa
);
851 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
853 PaintArc(&r
, (short)sa
, (short)angle
);
855 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
857 FrameArc(&r
, (short)sa
, (short)angle
);
861 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
863 wxCHECK_RET(Ok(), wxT("Invalid DC"));
865 wxMacPortSetter
helper(this) ;
867 if (m_pen
.GetStyle() != wxTRANSPARENT
)
870 wxCoord xx1
= XLOG2DEVMAC(x
);
871 wxCoord yy1
= YLOG2DEVMAC(y
);
874 ::LineTo(xx1
+1, yy1
+1);
878 void wxDC::DoDrawLines(int n
, wxPoint points
[],
879 wxCoord xoffset
, wxCoord yoffset
)
881 wxCHECK_RET(Ok(), wxT("Invalid DC"));
882 wxMacPortSetter
helper(this) ;
884 if (m_pen
.GetStyle() == wxTRANSPARENT
)
889 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
890 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
892 wxCoord x1
, x2
, y1
, y2
;
893 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
894 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
895 ::MoveTo(x1
- offset
, y1
- offset
);
897 for (int i
= 0; i
< n
-1; i
++)
899 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
900 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
901 ::LineTo( x2
- offset
, y2
- offset
);
905 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
906 wxCoord xoffset
, wxCoord yoffset
,
909 wxCHECK_RET(Ok(), wxT("Invalid DC"));
910 wxMacPortSetter
helper(this) ;
912 wxCoord x1
, x2
, y1
, y2
;
914 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
917 PolyHandle polygon
= OpenPoly();
919 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
920 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
923 for (int i
= 1; i
< n
; i
++)
925 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
926 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
930 // close the polyline if necessary
931 if ( x1
!= x2
|| y1
!= y2
)
938 if (m_brush
.GetStyle() != wxTRANSPARENT
)
942 ::PaintPoly( polygon
);
946 if (m_pen
.GetStyle() != wxTRANSPARENT
)
950 ::FramePoly( polygon
) ;
956 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
958 wxCHECK_RET(Ok(), wxT("Invalid DC"));
959 wxMacPortSetter
helper(this) ;
961 wxCoord xx
= XLOG2DEVMAC(x
);
962 wxCoord yy
= YLOG2DEVMAC(y
);
963 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
964 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
966 // CMB: draw nothing if transformed w or h is 0
967 if (ww
== 0 || hh
== 0)
970 // CMB: handle -ve width and/or height
983 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
985 if (m_brush
.GetStyle() != wxTRANSPARENT
)
988 ::PaintRect( &rect
) ;
991 if (m_pen
.GetStyle() != wxTRANSPARENT
)
994 ::FrameRect( &rect
) ;
998 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
999 wxCoord width
, wxCoord height
,
1002 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1003 wxMacPortSetter
helper(this) ;
1006 radius
= - radius
* ((width
< height
) ? width
: height
);
1008 wxCoord xx
= XLOG2DEVMAC(x
);
1009 wxCoord yy
= YLOG2DEVMAC(y
);
1010 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1011 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1013 // CMB: draw nothing if transformed w or h is 0
1014 if (ww
== 0 || hh
== 0)
1017 // CMB: handle -ve width and/or height
1030 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1032 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1035 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1038 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1041 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1045 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1047 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1048 wxMacPortSetter
helper(this) ;
1050 wxCoord xx
= XLOG2DEVMAC(x
);
1051 wxCoord yy
= YLOG2DEVMAC(y
);
1052 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1053 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1055 // CMB: draw nothing if transformed w or h is 0
1056 if (ww
== 0 || hh
== 0)
1059 // CMB: handle -ve width and/or height
1072 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1074 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1077 ::PaintOval( &rect
) ;
1080 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1083 ::FrameOval( &rect
) ;
1089 bool wxDC::CanDrawBitmap(void) const
1095 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1096 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1097 wxCoord xsrcMask
, wxCoord ysrcMask
)
1099 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1100 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1102 if ( logical_func
== wxNO_OP
)
1105 if (xsrcMask
== -1 && ysrcMask
== -1)
1107 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1110 // correct the parameter in case this dc does not have a mask at all
1112 if ( useMask
&& !source
->m_macMask
)
1115 Rect srcrect
, dstrect
;
1116 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1117 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1118 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1119 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1120 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1121 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1122 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1123 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1125 short mode
= kUnsupportedMode
;
1126 bool invertDestinationFirst
= false ;
1127 switch ( logical_func
)
1129 case wxAND
: // src AND dst
1130 mode
= srcOr
; // ok
1132 case wxAND_INVERT
: // (NOT src) AND dst
1133 mode
= notSrcOr
; // ok
1135 case wxAND_REVERSE
:// src AND (NOT dst)
1136 invertDestinationFirst
= true ;
1140 mode
= kEmulatedMode
;
1143 mode
= srcCopy
; // ok
1145 case wxEQUIV
: // (NOT src) XOR dst
1146 mode
= srcXor
; // ok
1148 case wxINVERT
: // NOT dst
1149 mode
= kEmulatedMode
; //or hilite ;
1151 case wxNAND
: // (NOT src) OR (NOT dst)
1152 invertDestinationFirst
= true ;
1155 case wxNOR
: // (NOT src) AND (NOT dst)
1156 invertDestinationFirst
= true ;
1159 case wxNO_OP
: // dst
1160 mode
= kEmulatedMode
; // this has already been handled upon entry
1162 case wxOR
: // src OR dst
1165 case wxOR_INVERT
: // (NOT src) OR dst
1168 case wxOR_REVERSE
: // src OR (NOT dst)
1169 invertDestinationFirst
= true ;
1173 mode
= kEmulatedMode
;
1175 case wxSRC_INVERT
: // (NOT src)
1176 mode
= notSrcCopy
; // ok
1178 case wxXOR
: // src XOR dst
1179 mode
= notSrcXor
; // ok
1187 if ( mode
== kUnsupportedMode
)
1189 wxFAIL_MSG("unsupported blitting mode" )
1193 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1194 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1195 if ( LockPixels(bmappixels
) )
1197 wxMacPortSetter
helper(this) ;
1198 RGBColor tempColor
;
1200 if ( source
->GetDepth() == 1 )
1202 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1203 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1207 // the modes need this, otherwise we'll end up having really nice colors...
1208 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1209 RGBColor black
= { 0,0,0} ;
1210 RGBForeColor( &black
) ;
1211 RGBBackColor( &white
) ;
1214 if ( useMask
&& source
->m_macMask
)
1216 if ( mode
== srcCopy
)
1218 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1220 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1221 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1222 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1223 &srcrect
, &srcrect
, &dstrect
) ;
1224 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1229 RgnHandle clipRgn
= NewRgn() ;
1230 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1231 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1232 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1233 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1234 if ( mode
== kEmulatedMode
)
1237 ::PenPat(GetQDGlobalsBlack(&pat
));
1238 if ( logical_func
== wxSET
)
1240 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1241 ::RGBForeColor( &col
) ;
1242 ::PaintRgn( clipRgn
) ;
1244 else if ( logical_func
== wxCLEAR
)
1246 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1247 ::RGBForeColor( &col
) ;
1248 ::PaintRgn( clipRgn
) ;
1250 else if ( logical_func
== wxINVERT
)
1252 MacInvertRgn( clipRgn
) ;
1256 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1258 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1260 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1261 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1262 if ( PtInRgn( dstPoint
, clipRgn
) )
1267 SetPort( (GrafPtr
) sourcePort
) ;
1268 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1269 SetPort( (GrafPtr
) m_macPort
) ;
1270 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1272 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1273 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1281 if ( invertDestinationFirst
)
1283 MacInvertRgn( clipRgn
) ;
1285 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1286 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1287 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1289 DisposeRgn( clipRgn
) ;
1294 RgnHandle clipRgn
= NewRgn() ;
1295 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1296 if ( mode
== kEmulatedMode
)
1299 ::PenPat(GetQDGlobalsBlack(&pat
));
1300 if ( logical_func
== wxSET
)
1302 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1303 ::RGBForeColor( &col
) ;
1304 ::PaintRgn( clipRgn
) ;
1306 else if ( logical_func
== wxCLEAR
)
1308 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1309 ::RGBForeColor( &col
) ;
1310 ::PaintRgn( clipRgn
) ;
1312 else if ( logical_func
== wxINVERT
)
1314 MacInvertRgn( clipRgn
) ;
1318 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1320 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1322 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1323 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1329 SetPort( (GrafPtr
) sourcePort
) ;
1330 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1331 SetPort( (GrafPtr
) m_macPort
) ;
1332 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1334 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1335 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1344 if ( invertDestinationFirst
)
1346 MacInvertRgn( clipRgn
) ;
1348 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1349 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1350 &srcrect
, &dstrect
, mode
, NULL
) ;
1352 DisposeRgn( clipRgn
) ;
1354 UnlockPixels( bmappixels
) ;
1357 m_macPenInstalled
= false ;
1358 m_macBrushInstalled
= false ;
1359 m_macFontInstalled
= false ;
1364 inline Fixed
IntToFixed( int inInt
)
1366 return (((SInt32
) inInt
) << 16);
1370 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1373 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1377 DrawText(str
, x
, y
);
1381 wxMacPortSetter
helper(this) ;
1385 if ( wxApp::s_macDefaultEncodingIsPC
)
1387 text
= wxMacMakeMacStringFromPC( str
) ;
1394 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1397 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1398 SetAntiAliasedTextEnabled(true, m_scaleY
* font
->m_macFontSize
);
1399 m_macAliasWasEnabled
= true ;
1402 OSStatus status
= noErr
;
1405 status
= TECCreateConverter(&ec
, kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1406 wxASSERT_MSG( status
== noErr
, "couldn't start converter" ) ;
1408 ByteCount byteOutLen
;
1409 ByteCount byteInLen
= text
.Length() ;
1410 ByteCount byteBufferLen
= byteInLen
*2 ;
1411 char* buf
= new char[byteBufferLen
] ;
1413 status
= TECConvertText(ec
, (ConstTextPtr
)text
.c_str() , byteInLen
, &byteInLen
,
1414 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1416 wxASSERT_MSG( status
== noErr
, "couldn't convert text" ) ;
1417 status
= TECDisposeConverter(ec
);
1418 wxASSERT_MSG( status
== noErr
, "couldn't dispose converter" ) ;
1420 ATSUTextLayout atsuLayout
;
1421 UniCharCount chars
= byteOutLen
/ 2 ;
1422 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1423 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1424 wxASSERT_MSG( status
== noErr
, "couldn't create the layout of the rotated text" );
1426 Fixed atsuAngle
= IntToFixed( angle
) ;
1427 ByteCount angleSize
= sizeof(Fixed
) ;
1428 ATSUAttributeTag rotationTag
= kATSULineRotationTag
;
1429 ATSUAttributeValuePtr angleValue
= &atsuAngle
;
1430 status
= ::ATSUSetLayoutControls(atsuLayout
, 1 , &rotationTag
, &angleSize
, &angleValue
) ;
1432 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1433 IntToFixed(XLOG2DEVMAC(x
) ) , IntToFixed(YLOG2DEVMAC(y
) ) );
1434 wxASSERT_MSG( status
== noErr
, "couldn't draw the rotated text" );
1436 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1437 IntToFixed(XLOG2DEVMAC(x
) ) , IntToFixed(YLOG2DEVMAC(y
) ) , &rect
);
1438 wxASSERT_MSG( status
== noErr
, "couldn't measure the rotated text" );
1440 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1441 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1442 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1443 ::ATSUDisposeTextLayout(atsuLayout
);
1447 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1449 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1450 wxMacPortSetter
helper(this) ;
1452 long xx
= XLOG2DEVMAC(x
);
1453 long yy
= YLOG2DEVMAC(y
);
1458 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1459 SetAntiAliasedTextEnabled(true, 8);
1460 m_macAliasWasEnabled
= true ;
1464 ::GetFontInfo( &fi
) ;
1467 ::MoveTo( xx
, yy
);
1468 if ( m_backgroundMode
== wxTRANSPARENT
)
1470 ::TextMode( srcOr
) ;
1474 ::TextMode( srcCopy
) ;
1477 const char *text
= NULL
;
1481 if ( wxApp::s_macDefaultEncodingIsPC
)
1483 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1485 length
= macText
.Length() ;
1490 length
= strtext
.Length() ;
1499 if( text
[i
] == 13 || text
[i
] == 10)
1501 ::DrawText( text
, laststop
, i
- laststop
) ;
1503 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1509 ::DrawText( text
, laststop
, i
- laststop
) ;
1510 ::TextMode( srcOr
) ;
1513 bool wxDC::CanGetTextExtent() const
1515 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1520 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1521 wxCoord
*descent
, wxCoord
*externalLeading
,
1522 wxFont
*theFont
) const
1524 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1525 wxMacPortSetter
helper(this) ;
1527 wxFont formerFont
= m_font
;
1531 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1535 ::TextFont( font
->m_macFontNum
) ;
1536 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1537 ::TextFace( font
->m_macFontStyle
) ;
1546 ::GetFontInfo( &fi
) ;
1549 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1551 *descent
=YDEV2LOGREL( fi
.descent
);
1552 if ( externalLeading
)
1553 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1555 const char *text
= NULL
;
1558 if ( wxApp::s_macDefaultEncodingIsPC
)
1560 macText
= wxMacMakeMacStringFromPC( string
) ;
1562 length
= macText
.Length() ;
1567 length
= string
.Length() ;
1579 if( text
[i
] == 13 || text
[i
] == 10)
1582 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1583 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1584 if ( curwidth
> *width
)
1585 *width
= XDEV2LOGREL( curwidth
) ;
1591 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1592 if ( curwidth
> *width
)
1593 *width
= XDEV2LOGREL( curwidth
) ;
1598 m_macFontInstalled
= false ;
1602 wxCoord
wxDC::GetCharWidth(void) const
1604 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1606 wxMacPortSetter
helper(this) ;
1610 int width
= ::TextWidth( "n" , 0 , 1 ) ;
1612 return YDEV2LOGREL(width
) ;
1615 wxCoord
wxDC::GetCharHeight(void) const
1617 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1619 wxMacPortSetter
helper(this) ;
1624 ::GetFontInfo( &fi
) ;
1626 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1629 void wxDC::Clear(void)
1631 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1632 wxMacPortSetter
helper(this) ;
1633 Rect rect
= { -32000 , -32000 , 32000 , 32000 } ;
1635 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1638 //MacInstallBrush() ;
1639 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1640 ::EraseRect( &rect
) ;
1644 void wxDC::MacInstallFont() const
1646 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1647 // if ( m_macFontInstalled )
1649 Pattern blackColor
;
1651 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1655 ::TextFont( font
->m_macFontNum
) ;
1656 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1657 ::TextFace( font
->m_macFontStyle
) ;
1659 m_macFontInstalled
= true ;
1660 m_macBrushInstalled
= false ;
1661 m_macPenInstalled
= false ;
1663 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1664 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1665 ::RGBForeColor( &forecolor
);
1666 ::RGBBackColor( &backcolor
);
1672 GetFNum( "\pGeneva" , &fontnum
) ;
1673 ::TextFont( fontnum
) ;
1674 ::TextSize( short(m_scaleY
* 10) ) ;
1677 // todo reset after spacing changes - or store the current spacing somewhere
1679 m_macFontInstalled
= true ;
1680 m_macBrushInstalled
= false ;
1681 m_macPenInstalled
= false ;
1683 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1684 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1685 ::RGBForeColor( &forecolor
);
1686 ::RGBBackColor( &backcolor
);
1689 short mode
= patCopy
;
1693 switch( m_logicalFunction
)
1698 case wxINVERT
: // NOT dst
1699 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1702 case wxXOR
: // src XOR dst
1705 case wxOR_REVERSE
: // src OR (NOT dst)
1708 case wxSRC_INVERT
: // (NOT src)
1715 case wxAND_REVERSE
:// src AND (NOT dst)
1716 case wxAND
: // src AND dst
1717 case wxAND_INVERT
: // (NOT src) AND dst
1718 case wxNO_OP
: // dst
1719 case wxNOR
: // (NOT src) AND (NOT dst)
1720 case wxEQUIV
: // (NOT src) XOR dst
1721 case wxOR_INVERT
: // (NOT src) OR dst
1722 case wxNAND
: // (NOT src) OR (NOT dst)
1723 case wxOR
: // src OR dst
1725 // case wxSRC_OR: // source _bitmap_ OR destination
1726 // case wxSRC_AND: // source _bitmap_ AND destination
1731 OSStatus status
= noErr
;
1733 Fixed atsuSize
= IntToFixed(m_scaleY
* font
->m_macFontSize
) ;
1735 Style qdStyle
= font
->m_macFontStyle
;
1736 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1738 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1739 wxASSERT_MSG( status
== noErr
, "couldn't create ATSU style" ) ;
1741 ATSUAttributeTag atsuTags
[] =
1747 kATSUQDBoldfaceTag
,
1749 kATSUQDUnderlineTag
,
1750 kATSUQDCondensedTag
,
1751 kATSUQDExtendedTag
,
1755 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1757 sizeof( ATSUFontID
) ,
1759 sizeof( RGBColor
) ,
1767 Boolean kTrue
= true ;
1768 Boolean kFalse
= false ;
1770 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1774 &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() ) ,
1776 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1777 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1778 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1779 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1780 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1783 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1784 atsuTags
, atsuSizes
, atsuValues
);
1785 wxASSERT_MSG( status
== noErr
, "couldn't set create ATSU style" ) ;
1789 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1791 // we have our own pattern list now
1792 int thePatListID
= 128;
1796 case wxBDIAGONAL_HATCH
:
1799 case wxFDIAGONAL_HATCH
:
1805 case wxHORIZONTAL_HATCH
:
1808 case wxVERTICAL_HATCH
:
1811 case wxCROSSDIAG_HATCH
:
1815 theIndex
= 1; // solid pattern
1818 GetIndPattern( pattern
, thePatListID
, theIndex
);
1821 void wxDC::MacInstallPen() const
1823 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1827 // if ( m_macPenInstalled )
1830 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1831 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1832 ::RGBForeColor( &forecolor
);
1833 ::RGBBackColor( &backcolor
);
1836 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1838 // null means only one pixel, at whatever resolution
1839 if ( penWidth
== 0 )
1841 ::PenSize(penWidth
, penWidth
);
1843 int penStyle
= m_pen
.GetStyle();
1845 if (penStyle
== wxSOLID
)
1847 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1849 else if (IS_HATCH(penStyle
))
1852 wxMacGetHatchPattern(penStyle
, &pat
);
1857 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1861 for ( int i
= 0 ; i
< 8 ; ++i
)
1867 for ( int i
= 0 ; i
< 8 ; ++i
)
1873 for ( int i
= 0 ; i
< 8 ; ++i
)
1879 for ( int i
= 0 ; i
< 8 ; ++i
)
1887 int number
= m_pen
.GetDashes(&dash
) ;
1888 // right now we don't allocate larger pixmaps
1889 for ( int i
= 0 ; i
< 8 ; ++i
)
1891 pat
.pat
[i
] = dash
[0] ;
1899 short mode
= patCopy
;
1903 switch( m_logicalFunction
)
1905 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1908 case wxINVERT
: // NOT dst
1909 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1912 case wxXOR
: // src XOR dst
1915 case wxOR_REVERSE
: // src OR (NOT dst)
1918 case wxSRC_INVERT
: // (NOT src)
1925 case wxAND_REVERSE
:// src AND (NOT dst)
1926 case wxAND
: // src AND dst
1927 case wxAND_INVERT
: // (NOT src) AND dst
1928 case wxNO_OP
: // dst
1929 case wxNOR
: // (NOT src) AND (NOT dst)
1930 case wxEQUIV
: // (NOT src) XOR dst
1931 case wxOR_INVERT
: // (NOT src) OR dst
1932 case wxNAND
: // (NOT src) OR (NOT dst)
1933 case wxOR
: // src OR dst
1935 // case wxSRC_OR: // source _bitmap_ OR destination
1936 // case wxSRC_AND: // source _bitmap_ AND destination
1940 m_macPenInstalled
= true ;
1941 m_macBrushInstalled
= false ;
1942 m_macFontInstalled
= false ;
1945 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1947 Pattern whiteColor
;
1948 switch( background
.MacGetBrushKind() )
1950 case kwxMacBrushTheme
:
1952 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1955 case kwxMacBrushThemeBackground
:
1958 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1959 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1962 case kwxMacBrushColour
:
1964 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1965 int brushStyle
= background
.GetStyle();
1966 if (brushStyle
== wxSOLID
)
1967 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1968 else if (IS_HATCH(brushStyle
))
1971 wxMacGetHatchPattern(brushStyle
, &pat
);
1976 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1983 void wxDC::MacInstallBrush() const
1985 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1987 Pattern blackColor
;
1988 // if ( m_macBrushInstalled )
1993 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1995 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1996 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1998 int brushStyle
= m_brush
.GetStyle();
1999 if (brushStyle
== wxSOLID
)
2001 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2003 else if (IS_HATCH(brushStyle
))
2006 wxMacGetHatchPattern(brushStyle
, &pat
);
2009 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2011 // we force this in order to be compliant with wxMSW
2012 backgroundTransparent
= false ;
2013 // for these the text fore (and back for MASK_OPAQUE) colors are used
2014 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2015 int width
= bitmap
->GetWidth() ;
2016 int height
= bitmap
->GetHeight() ;
2017 GWorldPtr gw
= NULL
;
2019 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2020 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2022 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2024 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2025 LockPixels( gwpixmaphandle
) ;
2027 bool isMonochrome
= !IsPortColor( gw
) ;
2029 if ( !isMonochrome
)
2031 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2032 isMonochrome
= true ;
2035 if ( isMonochrome
&& width
== 8 && height
== 8 )
2037 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2038 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2039 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2040 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2041 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2043 for ( int i
= 0 ; i
< 8 ; ++i
)
2045 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2047 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2052 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2053 // caching scheme before putting this into production
2056 PixPatHandle pixpat
= NewPixPat() ;
2058 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2059 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2060 ((**(**pixpat
).patMap
).bounds
.bottom
-
2061 (**(**pixpat
).patMap
).bounds
.top
);
2063 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2064 (**pixpat
).patData
= image
;
2067 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2068 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2069 if ( ctspec
[0].rgb
.red
== 0x0000 )
2071 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2072 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2076 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2077 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2079 ::CTabChanged( ctable
) ;
2081 ::PenPixPat(pixpat
);
2082 m_macForegroundPixMap
= pixpat
;
2084 UnlockPixels( gwpixmaphandle
) ;
2088 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2091 short mode
= patCopy
;
2092 switch( m_logicalFunction
)
2095 if ( backgroundTransparent
)
2100 case wxINVERT
: // NOT dst
2101 if ( !backgroundTransparent
)
2103 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2107 case wxXOR
: // src XOR dst
2110 case wxOR_REVERSE
: // src OR (NOT dst)
2113 case wxSRC_INVERT
: // (NOT src)
2120 case wxAND_REVERSE
:// src AND (NOT dst)
2121 case wxAND
: // src AND dst
2122 case wxAND_INVERT
: // (NOT src) AND dst
2123 case wxNO_OP
: // dst
2124 case wxNOR
: // (NOT src) AND (NOT dst)
2125 case wxEQUIV
: // (NOT src) XOR dst
2126 case wxOR_INVERT
: // (NOT src) OR dst
2127 case wxNAND
: // (NOT src) OR (NOT dst)
2128 case wxOR
: // src OR dst
2130 // case wxSRC_OR: // source _bitmap_ OR destination
2131 // case wxSRC_AND: // source _bitmap_ AND destination
2135 m_macBrushInstalled
= true ;
2136 m_macPenInstalled
= false ;
2137 m_macFontInstalled
= false ;
2140 // ---------------------------------------------------------------------------
2141 // coordinates transformations
2142 // ---------------------------------------------------------------------------
2145 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2147 return ((wxDC
*)this)->XDEV2LOG(x
);
2150 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2152 return ((wxDC
*)this)->YDEV2LOG(y
);
2155 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2157 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2160 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2162 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2165 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2167 return ((wxDC
*)this)->XLOG2DEV(x
);
2170 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2172 return ((wxDC
*)this)->YLOG2DEV(y
);
2175 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2177 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2180 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2182 return ((wxDC
*)this)->YLOG2DEVREL(y
);