1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/dc.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
21 #include "wx/mac/uma.h"
22 #include "wx/dcmemory.h"
23 #include "wx/dcprint.h"
24 #include "wx/region.h"
32 #include "wx/mac/private.h"
33 #include <ATSUnicode.h>
34 #include <TextCommon.h>
35 #include <TextEncodingConverter.h>
38 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 const double RAD2DEG
= 180.0 / M_PI
;
45 const short kEmulatedMode
= -1 ;
46 const short kUnsupportedMode
= -2 ;
48 extern TECObjectRef s_TECNativeCToUnicode
;
50 // set to 0 if problems arise
51 #define wxMAC_EXPERIMENTAL_DC 1
53 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
54 m_ph( (GrafPtr
) dc
->m_macPort
)
56 wxASSERT( dc
->Ok() ) ;
58 dc
->MacSetupPort(&m_ph
) ;
60 wxMacPortSetter::~wxMacPortSetter()
62 m_dc
->MacCleanupPort(&m_ph
) ;
65 #if wxMAC_EXPERIMENTAL_DC
66 class wxMacFastPortSetter
69 wxMacFastPortSetter( const wxDC
*dc
)
71 wxASSERT( dc
->Ok() ) ;
72 GetPort( &m_oldPort
) ;
73 SetPort( (GrafPtr
) dc
->m_macPort
) ;
74 m_clipRgn
= NewRgn() ;
75 GetClip( m_clipRgn
) ;
77 dc
->MacSetupPort( NULL
) ;
79 ~wxMacFastPortSetter()
81 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
82 SetClip( m_clipRgn
) ;
83 SetPort( m_oldPort
) ;
84 m_dc
->MacCleanupPort( NULL
) ;
85 DisposeRgn( m_clipRgn
) ;
94 typedef wxMacPortSetter wxMacFastPortSetter
;
99 // start moving to a dual implementation for QD and CGContextRef
101 class wxMacGraphicsContext
104 void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
) = 0 ;
105 void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0 ;
106 void SetClippingRegion( const wxRegion
®ion
) = 0 ;
107 void DestroyClippingRegion() = 0 ;
108 void SetTextForeground( const wxColour
&col
) = 0 ;
109 void SetTextBackground( const wxColour
&col
) = 0 ;
110 void SetLogicalScale( double x
, double y
) = 0 ;
111 void SetUserScale( double x
, double y
) = 0;
114 class wxMacQuickDrawContext
: public wxMacGraphicsContext
121 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
123 m_formerClip
= NewRgn() ;
124 m_newClip
= NewRgn() ;
125 GetClip( m_formerClip
) ;
130 // this clipping area was set to the parent window's drawing area, lead to problems
131 // with MacOSX controls drawing outside their wx' rectangle
132 RgnHandle insidergn
= NewRgn() ;
134 wxWindow
*parent
= win
->GetParent() ;
135 parent
->MacWindowToRootWindow( &x
,&y
) ;
136 wxSize size
= parent
->GetSize() ;
137 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
138 size
.x
- parent
->MacGetRightBorderSize(),
139 size
.y
- parent
->MacGetBottomBorderSize()) ;
140 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
141 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
142 OffsetRgn( m_newClip
, x
, y
) ;
143 SetClip( m_newClip
) ;
144 DisposeRgn( insidergn
) ;
147 win
->MacWindowToRootWindow( &x
,&y
) ;
148 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
149 OffsetRgn( m_newClip
, x
, y
) ;
150 SetClip( m_newClip
) ;
155 wxMacWindowClipper::~wxMacWindowClipper()
157 SetClip( m_formerClip
) ;
158 DisposeRgn( m_newClip
) ;
159 DisposeRgn( m_formerClip
) ;
162 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
165 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
166 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
167 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
169 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
172 // this function emulates all wx colour manipulations, used to verify the implementation
173 // by setting the mode in the blitting functions to kEmulatedMode
174 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
176 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
178 switch ( logical_func
)
180 case wxAND
: // src AND dst
181 dstColor
.red
= dstColor
.red
& srcColor
.red
;
182 dstColor
.green
= dstColor
.green
& srcColor
.green
;
183 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
185 case wxAND_INVERT
: // (NOT src) AND dst
186 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
187 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
188 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
190 case wxAND_REVERSE
:// src AND (NOT dst)
191 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
192 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
193 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
201 dstColor
.red
= srcColor
.red
;
202 dstColor
.green
= srcColor
.green
;
203 dstColor
.blue
= srcColor
.blue
;
205 case wxEQUIV
: // (NOT src) XOR dst
206 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
207 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
208 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
210 case wxINVERT
: // NOT dst
211 dstColor
.red
= ~dstColor
.red
;
212 dstColor
.green
= ~dstColor
.green
;
213 dstColor
.blue
= ~dstColor
.blue
;
215 case wxNAND
: // (NOT src) OR (NOT dst)
216 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
217 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
218 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
220 case wxNOR
: // (NOT src) AND (NOT dst)
221 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
222 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
223 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
227 case wxOR
: // src OR dst
228 dstColor
.red
= dstColor
.red
| srcColor
.red
;
229 dstColor
.green
= dstColor
.green
| srcColor
.green
;
230 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
232 case wxOR_INVERT
: // (NOT src) OR dst
233 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
234 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
235 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
237 case wxOR_REVERSE
: // src OR (NOT dst)
238 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
239 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
240 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
243 dstColor
.red
= 0xFFFF ;
244 dstColor
.green
= 0xFFFF ;
245 dstColor
.blue
= 0xFFFF ;
247 case wxSRC_INVERT
: // (NOT src)
248 dstColor
.red
= ~srcColor
.red
;
249 dstColor
.green
= ~srcColor
.green
;
250 dstColor
.blue
= ~srcColor
.blue
;
252 case wxXOR
: // src XOR dst
253 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
254 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
255 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
264 m_mm_to_pix_x
= mm2pt
;
265 m_mm_to_pix_y
= mm2pt
;
266 m_internalDeviceOriginX
= 0;
267 m_internalDeviceOriginY
= 0;
268 m_externalDeviceOriginX
= 0;
269 m_externalDeviceOriginY
= 0;
270 m_logicalScaleX
= 1.0;
271 m_logicalScaleY
= 1.0;
276 m_needComputeScaleX
= false;
277 m_needComputeScaleY
= false;
281 m_macFontInstalled
= false ;
282 m_macBrushInstalled
= false ;
283 m_macPenInstalled
= false ;
284 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
285 m_macBoundaryClipRgn
= NewRgn() ;
286 m_macCurrentClipRgn
= NewRgn() ;
287 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
288 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
289 m_pen
= *wxBLACK_PEN
;
290 m_font
= *wxNORMAL_FONT
;
291 m_brush
= *wxWHITE_BRUSH
;
293 // needed to debug possible errors with two active drawing methods at the same time on
295 m_macCurrentPortStateHelper
= NULL
;
297 m_macATSUIStyle
= NULL
;
298 m_macAliasWasEnabled
= false;
299 m_macForegroundPixMap
= NULL
;
300 m_macBackgroundPixMap
= NULL
;
305 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
306 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
309 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
312 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
313 m_macCurrentPortStateHelper
= help
;
315 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
316 #if ! wxMAC_EXPERIMENTAL_DC
317 m_macFontInstalled
= false ;
318 m_macBrushInstalled
= false ;
319 m_macPenInstalled
= false ;
322 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
325 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
326 m_macCurrentPortStateHelper
= NULL
;
328 if( m_macATSUIStyle
)
330 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
331 m_macATSUIStyle
= NULL
;
333 if ( m_macAliasWasEnabled
)
335 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
336 m_macAliasWasEnabled
= false ;
338 if ( m_macForegroundPixMap
)
341 ::PenPat(GetQDGlobalsBlack(&blackColor
));
342 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
343 m_macForegroundPixMap
= NULL
;
345 if ( m_macBackgroundPixMap
)
348 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
349 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
350 m_macBackgroundPixMap
= NULL
;
354 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
356 wxCHECK_RET( Ok(), wxT("invalid window dc") );
357 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
358 wxMacFastPortSetter
helper(this) ;
359 wxCoord xx
= XLOG2DEVMAC(x
);
360 wxCoord yy
= YLOG2DEVMAC(y
);
361 wxCoord w
= bmp
.GetWidth();
362 wxCoord h
= bmp
.GetHeight();
363 wxCoord ww
= XLOG2DEVREL(w
);
364 wxCoord hh
= YLOG2DEVREL(h
);
365 // Set up drawing mode
366 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
367 //m_logicalFunction == wxCLEAR ? WHITENESS :
368 //m_logicalFunction == wxSET ? BLACKNESS :
369 m_logicalFunction
== wxINVERT
? hilite
:
370 //m_logicalFunction == wxAND ? MERGECOPY :
371 m_logicalFunction
== wxOR
? srcOr
:
372 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
373 m_logicalFunction
== wxXOR
? srcXor
:
374 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
375 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
376 //m_logicalFunction == wxSRC_OR ? srcOr :
377 //m_logicalFunction == wxSRC_AND ? SRCAND :
379 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
380 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
381 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
382 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
384 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
386 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
387 PixMapHandle bmappixels
;
388 // Set foreground and background colours (for bitmaps depth = 1)
389 if(bmp
.GetDepth() == 1)
391 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
392 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
398 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
399 RGBColor black
= { 0,0,0} ;
400 RGBForeColor( &black
) ;
401 RGBBackColor( &white
) ;
403 bmappixels
= GetGWorldPixMap( bmapworld
) ;
404 wxCHECK_RET(LockPixels(bmappixels
),
405 wxT("DoDrawBitmap: Unable to lock pixels"));
406 Rect source
= { 0, 0, h
, w
};
407 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
408 if ( useMask
&& bmp
.GetMask() )
410 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
414 GetPortBitMapForCopyBits(bmapworld
),
415 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
416 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
417 &source
, &source
, &dest
, mode
, NULL
419 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
423 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
424 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
425 &source
, &dest
, mode
, NULL
) ;
427 UnlockPixels( bmappixels
) ;
429 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
431 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
432 OffsetRect( &bitmaprect
, xx
, yy
) ;
433 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
435 m_macPenInstalled
= false ;
436 m_macBrushInstalled
= false ;
437 m_macFontInstalled
= false ;
440 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
442 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
443 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
444 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
447 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
449 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
450 wxCoord xx
, yy
, ww
, hh
;
453 ww
= XLOG2DEVREL(width
);
454 hh
= YLOG2DEVREL(height
);
455 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
456 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
459 m_clipX1
= wxMax( m_clipX1
, xx
);
460 m_clipY1
= wxMax( m_clipY1
, yy
);
461 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
462 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
474 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
476 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
479 DestroyClippingRegion();
482 wxMacFastPortSetter
helper(this) ;
484 region
.GetBox( x
, y
, w
, h
);
485 wxCoord xx
, yy
, ww
, hh
;
490 // if we have a scaling that we cannot map onto native regions
491 // we must use the box
492 if ( ww
!= w
|| hh
!= h
)
494 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
498 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
499 if ( xx
!= x
|| yy
!= y
)
501 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
503 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
506 m_clipX1
= wxMax( m_clipX1
, xx
);
507 m_clipY1
= wxMax( m_clipY1
, yy
);
508 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
509 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
522 void wxDC::DestroyClippingRegion()
524 wxMacFastPortSetter
helper(this) ;
525 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
529 void wxDC::DoGetSizeMM( int* width
, int* height
) const
534 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
535 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
538 void wxDC::SetTextForeground( const wxColour
&col
)
540 wxCHECK_RET(Ok(), wxT("Invalid DC"));
541 m_textForegroundColour
= col
;
542 m_macFontInstalled
= false ;
545 void wxDC::SetTextBackground( const wxColour
&col
)
547 wxCHECK_RET(Ok(), wxT("Invalid DC"));
548 m_textBackgroundColour
= col
;
549 m_macFontInstalled
= false ;
552 void wxDC::SetMapMode( int mode
)
557 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
560 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
563 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
566 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
570 SetLogicalScale( 1.0, 1.0 );
573 if (mode
!= wxMM_TEXT
)
575 m_needComputeScaleX
= true;
576 m_needComputeScaleY
= true;
580 void wxDC::SetUserScale( double x
, double y
)
582 // allow negative ? -> no
585 ComputeScaleAndOrigin();
588 void wxDC::SetLogicalScale( double x
, double y
)
593 ComputeScaleAndOrigin();
596 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
598 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
599 m_logicalOriginY
= y
* m_signY
;
600 ComputeScaleAndOrigin();
603 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
605 m_externalDeviceOriginX
= x
;
606 m_externalDeviceOriginY
= y
;
607 ComputeScaleAndOrigin();
611 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
613 m_internalDeviceOriginX
= x
;
614 m_internalDeviceOriginY
= y
;
615 ComputeScaleAndOrigin();
617 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
619 if (x
) *x
= m_internalDeviceOriginX
;
620 if (y
) *y
= m_internalDeviceOriginY
;
624 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
626 m_signX
= (xLeftRight
? 1 : -1);
627 m_signY
= (yBottomUp
? -1 : 1);
628 ComputeScaleAndOrigin();
631 wxSize
wxDC::GetPPI() const
633 return wxSize(72, 72);
636 int wxDC::GetDepth() const
638 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
640 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
645 void wxDC::ComputeScaleAndOrigin()
647 // CMB: copy scale to see if it changes
648 double origScaleX
= m_scaleX
;
649 double origScaleY
= m_scaleY
;
650 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
651 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
652 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
653 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
654 // CMB: if scale has changed call SetPen to recalulate the line width
655 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
657 // this is a bit artificial, but we need to force wxDC to think
658 // the pen has changed
659 wxPen
* pen
= & GetPen();
666 void wxDC::SetPalette( const wxPalette
& palette
)
670 void wxDC::SetBackgroundMode( int mode
)
672 m_backgroundMode
= mode
;
675 void wxDC::SetFont( const wxFont
&font
)
678 m_macFontInstalled
= false ;
681 void wxDC::SetPen( const wxPen
&pen
)
686 m_macPenInstalled
= false ;
689 void wxDC::SetBrush( const wxBrush
&brush
)
691 if (m_brush
== brush
)
694 m_macBrushInstalled
= false ;
697 void wxDC::SetBackground( const wxBrush
&brush
)
699 if (m_backgroundBrush
== brush
)
701 m_backgroundBrush
= brush
;
702 if (!m_backgroundBrush
.Ok())
704 m_macBrushInstalled
= false ;
707 void wxDC::SetLogicalFunction( int function
)
709 if (m_logicalFunction
== function
)
711 m_logicalFunction
= function
;
712 m_macFontInstalled
= false ;
713 m_macBrushInstalled
= false ;
714 m_macPenInstalled
= false ;
717 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
718 const wxColour
& col
, int style
);
720 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
721 const wxColour
& col
, int style
)
723 return wxDoFloodFill(this, x
, y
, col
, style
);
726 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
728 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
729 wxMacFastPortSetter
helper(this) ;
731 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
732 // Convert from Mac colour to wx
733 col
->Set( colour
.red
>> 8,
739 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
741 wxCHECK_RET(Ok(), wxT("Invalid DC"));
742 wxMacFastPortSetter
helper(this) ;
743 if (m_pen
.GetStyle() != wxTRANSPARENT
)
746 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
747 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
748 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
749 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
750 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
751 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
752 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
753 (m_pen
.GetWidth() <= 1))
755 // Implement LAST_NOT for MAC at least for
756 // orthogonal lines. RR.
777 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
779 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
780 wxMacFastPortSetter
helper(this) ;
781 if (m_pen
.GetStyle() != wxTRANSPARENT
)
786 wxCoord xx
= XLOG2DEVMAC(x
);
787 wxCoord yy
= YLOG2DEVMAC(y
);
789 ::MoveTo( XLOG2DEVMAC(0), yy
);
790 ::LineTo( XLOG2DEVMAC(w
), yy
);
791 ::MoveTo( xx
, YLOG2DEVMAC(0) );
792 ::LineTo( xx
, YLOG2DEVMAC(h
) );
793 CalcBoundingBox(x
, y
);
794 CalcBoundingBox(x
+w
, y
+h
);
799 * To draw arcs properly the angles need to be converted from the WX style:
800 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
801 * a normal axis on paper).
804 * Angles start on the +ve y axis and go clockwise.
807 static double wxConvertWXangleToMACangle(double angle
)
809 double newAngle
= 90 - angle
;
815 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
816 wxCoord x2
, wxCoord y2
,
817 wxCoord xc
, wxCoord yc
)
819 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
820 wxMacFastPortSetter
helper(this) ;
821 wxCoord xx1
= XLOG2DEVMAC(x1
);
822 wxCoord yy1
= YLOG2DEVMAC(y1
);
823 wxCoord xx2
= XLOG2DEVMAC(x2
);
824 wxCoord yy2
= YLOG2DEVMAC(y2
);
825 wxCoord xxc
= XLOG2DEVMAC(xc
);
826 wxCoord yyc
= YLOG2DEVMAC(yc
);
827 double dx
= xx1
- xxc
;
828 double dy
= yy1
- yyc
;
829 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
830 wxCoord rad
= (wxCoord
)radius
;
831 double radius1
, radius2
;
832 if (xx1
== xx2
&& yy1
== yy2
)
837 else if (radius
== 0.0)
839 radius1
= radius2
= 0.0;
843 radius1
= (xx1
- xxc
== 0) ?
844 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
845 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
846 radius2
= (xx2
- xxc
== 0) ?
847 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
848 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
850 wxCoord alpha2
= wxCoord(radius2
- radius1
);
851 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
852 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
855 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
856 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
858 PaintArc(&r
, alpha1
, alpha2
);
860 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
862 FrameArc(&r
, alpha1
, alpha2
);
866 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
867 double sa
, double ea
)
869 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
870 wxMacFastPortSetter
helper(this) ;
872 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
873 // we have to make sure that the filling is always counter-clockwise
876 wxCoord xx
= XLOG2DEVMAC(x
);
877 wxCoord yy
= YLOG2DEVMAC(y
);
878 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
879 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
880 // handle -ve width and/or height
881 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
882 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
883 sa
= wxConvertWXangleToMACangle(sa
);
888 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
890 PaintArc(&r
, (short)sa
, (short)angle
);
892 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
894 FrameArc(&r
, (short)sa
, (short)angle
);
898 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
900 wxCHECK_RET(Ok(), wxT("Invalid DC"));
901 wxMacFastPortSetter
helper(this) ;
902 if (m_pen
.GetStyle() != wxTRANSPARENT
)
904 wxCoord xx1
= XLOG2DEVMAC(x
);
905 wxCoord yy1
= YLOG2DEVMAC(y
);
906 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
907 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
908 CalcBoundingBox(x
, y
);
912 void wxDC::DoDrawLines(int n
, wxPoint points
[],
913 wxCoord xoffset
, wxCoord yoffset
)
915 wxCHECK_RET(Ok(), wxT("Invalid DC"));
916 wxMacFastPortSetter
helper(this) ;
917 if (m_pen
.GetStyle() == wxTRANSPARENT
)
920 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
921 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
922 wxCoord x1
, x2
, y1
, y2
;
923 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
924 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
925 ::MoveTo(x1
- offset
, y1
- offset
);
926 for (int i
= 0; i
< n
-1; i
++)
928 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
929 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
930 ::LineTo( x2
- offset
, y2
- offset
);
934 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
935 wxCoord xoffset
, wxCoord yoffset
,
938 wxCHECK_RET(Ok(), wxT("Invalid DC"));
939 wxMacFastPortSetter
helper(this) ;
940 wxCoord x1
, x2
, y1
, y2
;
941 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
943 PolyHandle polygon
= OpenPoly();
944 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
945 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
947 for (int i
= 1; i
< n
; i
++)
949 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
950 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
953 // close the polyline if necessary
954 if ( x1
!= x2
|| y1
!= y2
)
959 if (m_brush
.GetStyle() != wxTRANSPARENT
)
962 ::PaintPoly( polygon
);
964 if (m_pen
.GetStyle() != wxTRANSPARENT
)
967 ::FramePoly( polygon
) ;
972 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
974 wxCHECK_RET(Ok(), wxT("Invalid DC"));
975 wxMacFastPortSetter
helper(this) ;
976 wxCoord xx
= XLOG2DEVMAC(x
);
977 wxCoord yy
= YLOG2DEVMAC(y
);
978 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
979 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
980 // CMB: draw nothing if transformed w or h is 0
981 if (ww
== 0 || hh
== 0)
983 // CMB: handle -ve width and/or height
994 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
995 if (m_brush
.GetStyle() != wxTRANSPARENT
)
998 ::PaintRect( &rect
) ;
1000 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1003 ::FrameRect( &rect
) ;
1007 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1008 wxCoord width
, wxCoord height
,
1011 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1012 wxMacFastPortSetter
helper(this) ;
1014 radius
= - radius
* ((width
< height
) ? width
: height
);
1015 wxCoord xx
= XLOG2DEVMAC(x
);
1016 wxCoord yy
= YLOG2DEVMAC(y
);
1017 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1018 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1019 // CMB: draw nothing if transformed w or h is 0
1020 if (ww
== 0 || hh
== 0)
1022 // CMB: handle -ve width and/or height
1033 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1034 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1037 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1039 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1042 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1046 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1048 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1049 wxMacFastPortSetter
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
);
1054 // CMB: draw nothing if transformed w or h is 0
1055 if (ww
== 0 || hh
== 0)
1057 // CMB: handle -ve width and/or height
1068 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1069 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1072 ::PaintOval( &rect
) ;
1074 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1077 ::FrameOval( &rect
) ;
1081 bool wxDC::CanDrawBitmap(void) const
1086 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1087 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1088 wxCoord xsrcMask
, wxCoord ysrcMask
)
1090 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1091 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1092 if ( logical_func
== wxNO_OP
)
1094 if (xsrcMask
== -1 && ysrcMask
== -1)
1096 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1098 // correct the parameter in case this dc does not have a mask at all
1099 if ( useMask
&& !source
->m_macMask
)
1101 Rect srcrect
, dstrect
;
1102 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1103 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1104 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1105 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1106 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1107 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1108 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1109 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1110 short mode
= kUnsupportedMode
;
1111 bool invertDestinationFirst
= false ;
1112 switch ( logical_func
)
1114 case wxAND
: // src AND dst
1115 mode
= adMin
; // ok
1117 case wxAND_INVERT
: // (NOT src) AND dst
1118 mode
= notSrcOr
; // ok
1120 case wxAND_REVERSE
:// src AND (NOT dst)
1121 invertDestinationFirst
= true ;
1125 mode
= kEmulatedMode
;
1128 mode
= srcCopy
; // ok
1130 case wxEQUIV
: // (NOT src) XOR dst
1131 mode
= srcXor
; // ok
1133 case wxINVERT
: // NOT dst
1134 mode
= kEmulatedMode
; //or hilite ;
1136 case wxNAND
: // (NOT src) OR (NOT dst)
1137 invertDestinationFirst
= true ;
1140 case wxNOR
: // (NOT src) AND (NOT dst)
1141 invertDestinationFirst
= true ;
1144 case wxNO_OP
: // dst
1145 mode
= kEmulatedMode
; // this has already been handled upon entry
1147 case wxOR
: // src OR dst
1150 case wxOR_INVERT
: // (NOT src) OR dst
1153 case wxOR_REVERSE
: // src OR (NOT dst)
1154 invertDestinationFirst
= true ;
1158 mode
= kEmulatedMode
;
1160 case wxSRC_INVERT
: // (NOT src)
1161 mode
= notSrcCopy
; // ok
1163 case wxXOR
: // src XOR dst
1164 mode
= notSrcXor
; // ok
1169 if ( mode
== kUnsupportedMode
)
1171 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1174 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1175 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1176 if ( LockPixels(bmappixels
) )
1178 wxMacFastPortSetter
helper(this) ;
1179 if ( source
->GetDepth() == 1 )
1181 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1182 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1186 // the modes need this, otherwise we'll end up having really nice colors...
1187 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1188 RGBColor black
= { 0,0,0} ;
1189 RGBForeColor( &black
) ;
1190 RGBBackColor( &white
) ;
1192 if ( useMask
&& source
->m_macMask
)
1194 if ( mode
== srcCopy
)
1196 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1198 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1199 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1200 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1201 &srcrect
, &srcrect
, &dstrect
) ;
1202 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1207 RgnHandle clipRgn
= NewRgn() ;
1208 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1209 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1210 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1211 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1212 if ( mode
== kEmulatedMode
)
1215 ::PenPat(GetQDGlobalsBlack(&pat
));
1216 if ( logical_func
== wxSET
)
1218 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1219 ::RGBForeColor( &col
) ;
1220 ::PaintRgn( clipRgn
) ;
1222 else if ( logical_func
== wxCLEAR
)
1224 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1225 ::RGBForeColor( &col
) ;
1226 ::PaintRgn( clipRgn
) ;
1228 else if ( logical_func
== wxINVERT
)
1230 MacInvertRgn( clipRgn
) ;
1234 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1236 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1238 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1239 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1240 if ( PtInRgn( dstPoint
, clipRgn
) )
1244 SetPort( (GrafPtr
) sourcePort
) ;
1245 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1246 SetPort( (GrafPtr
) m_macPort
) ;
1247 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1248 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1249 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1257 if ( invertDestinationFirst
)
1259 MacInvertRgn( clipRgn
) ;
1261 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1262 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1263 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1265 DisposeRgn( clipRgn
) ;
1270 RgnHandle clipRgn
= NewRgn() ;
1271 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1272 if ( mode
== kEmulatedMode
)
1275 ::PenPat(GetQDGlobalsBlack(&pat
));
1276 if ( logical_func
== wxSET
)
1278 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1279 ::RGBForeColor( &col
) ;
1280 ::PaintRgn( clipRgn
) ;
1282 else if ( logical_func
== wxCLEAR
)
1284 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1285 ::RGBForeColor( &col
) ;
1286 ::PaintRgn( clipRgn
) ;
1288 else if ( logical_func
== wxINVERT
)
1290 MacInvertRgn( clipRgn
) ;
1294 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1296 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1298 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1299 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1303 SetPort( (GrafPtr
) sourcePort
) ;
1304 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1305 SetPort( (GrafPtr
) m_macPort
) ;
1306 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1307 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1308 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1316 if ( invertDestinationFirst
)
1318 MacInvertRgn( clipRgn
) ;
1320 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1321 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1322 &srcrect
, &dstrect
, mode
, NULL
) ;
1324 DisposeRgn( clipRgn
) ;
1326 UnlockPixels( bmappixels
) ;
1328 m_macPenInstalled
= false ;
1329 m_macBrushInstalled
= false ;
1330 m_macFontInstalled
= false ;
1335 // as macro in FixMath.h for 10.3
1336 inline Fixed
IntToFixed( int inInt
)
1338 return (((SInt32
) inInt
) << 16);
1341 inline int FixedToInt( Fixed inFixed
)
1343 return (((SInt32
) inFixed
) >> 16);
1347 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1350 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1354 DrawText(str
, x
, y
);
1358 if ( str
.length() == 0 )
1361 wxMacFastPortSetter
helper(this) ;
1366 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1367 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.GetMacFontSize()));
1368 m_macAliasWasEnabled
= true ;
1370 OSStatus status
= noErr
;
1371 ATSUTextLayout atsuLayout
;
1372 UniCharCount chars
= str
.length() ;
1374 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.length() , str
.length() , 1 ,
1375 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1377 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1378 int wlen
= wxWcslen( wchar
.data() ) ;
1379 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1380 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1382 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1383 int iAngle
= int( angle
);
1384 int drawX
= XLOG2DEVMAC(x
) ;
1385 int drawY
= YLOG2DEVMAC(y
) ;
1387 ATSUTextMeasurement textBefore
;
1388 ATSUTextMeasurement textAfter
;
1389 ATSUTextMeasurement ascent
;
1390 ATSUTextMeasurement descent
;
1393 if ( abs(iAngle
) > 0 )
1395 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1396 ATSUAttributeTag atsuTags
[] =
1398 kATSULineRotationTag
,
1400 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1404 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1408 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1409 atsuTags
, atsuSizes
, atsuValues
) ;
1411 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1412 &textBefore
, &textAfter
, &ascent
, &descent
);
1414 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1415 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1416 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1417 IntToFixed(drawX
) , IntToFixed(drawY
) );
1418 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1420 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1421 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1422 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1423 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1424 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1425 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1426 ::ATSUDisposeTextLayout(atsuLayout
);
1429 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1431 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1433 wxMacFastPortSetter
helper(this) ;
1434 long xx
= XLOG2DEVMAC(x
);
1435 long yy
= YLOG2DEVMAC(y
);
1437 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1438 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1439 useDrawThemeText
= false ;
1444 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1445 SetAntiAliasedTextEnabled(true, 8);
1446 m_macAliasWasEnabled
= true ;
1449 ::GetFontInfo( &fi
) ;
1451 if ( !useDrawThemeText
)
1454 ::MoveTo( xx
, yy
);
1455 if ( m_backgroundMode
== wxTRANSPARENT
)
1457 ::TextMode( srcOr
) ;
1461 ::TextMode( srcCopy
) ;
1463 int length
= strtext
.length() ;
1469 #if 0 // we don't have to do all that here
1472 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1474 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1476 if ( useDrawThemeText
)
1478 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1479 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1480 if ( m_backgroundMode
!= wxTRANSPARENT
)
1482 Point bounds
={0,0} ;
1483 Rect background
= frame
;
1485 ::GetThemeTextDimensions( mString
,
1486 kThemeCurrentPortFont
,
1491 background
.right
= background
.left
+ bounds
.h
;
1492 background
.bottom
= background
.top
+ bounds
.v
;
1493 ::EraseRect( &background
) ;
1495 ::DrawThemeTextBox( mString
,
1496 kThemeCurrentPortFont
,
1507 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1508 ::DrawText( text
, 0 , strlen(text
) ) ;
1509 if ( m_backgroundMode
!= wxTRANSPARENT
)
1511 Point bounds
={0,0} ;
1512 Rect background
= frame
;
1514 ::GetThemeTextDimensions( mString
,
1515 kThemeCurrentPortFont
,
1520 background
.right
= background
.left
+ bounds
.h
;
1521 background
.bottom
= background
.top
+ bounds
.v
;
1522 ::EraseRect( &background
) ;
1525 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1531 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1533 wxString linetext
= strtext
;
1535 if ( useDrawThemeText
)
1537 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1538 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1540 if ( m_backgroundMode
!= wxTRANSPARENT
)
1542 Point bounds
={0,0} ;
1543 Rect background
= frame
;
1545 ::GetThemeTextDimensions( mString
,
1546 kThemeCurrentPortFont
,
1551 background
.right
= background
.left
+ bounds
.h
;
1552 background
.bottom
= background
.top
+ bounds
.v
;
1553 ::EraseRect( &background
) ;
1555 ::DrawThemeTextBox( mString
,
1556 kThemeCurrentPortFont
,
1566 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1567 if ( m_backgroundMode
!= wxTRANSPARENT
)
1569 Rect frame
= { yy
- fi
.ascent
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
- fi
.ascent
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1570 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1571 frame
.right
= frame
.left
+ width
;
1573 ::EraseRect( &frame
) ;
1575 ::DrawText( text
, 0 , strlen(text
) ) ;
1578 ::TextMode( srcOr
) ;
1581 bool wxDC::CanGetTextExtent() const
1583 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1587 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1588 wxCoord
*descent
, wxCoord
*externalLeading
,
1589 wxFont
*theFont
) const
1591 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1592 wxMacFastPortSetter
helper(this) ;
1593 wxFont formerFont
= m_font
;
1596 // work around the constness
1597 *((wxFont
*)(&m_font
)) = *theFont
;
1601 ::GetFontInfo( &fi
) ;
1603 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1604 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1605 useGetThemeText
= false ;
1608 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1610 *descent
=YDEV2LOGREL( fi
.descent
);
1611 if ( externalLeading
)
1612 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1613 int length
= strtext
.length() ;
1621 #if 0 // apparently we don't have to do all that
1624 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1626 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1628 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1630 if ( useGetThemeText
)
1632 Point bounds
={0,0} ;
1634 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1635 ::GetThemeTextDimensions( mString
,
1636 kThemeCurrentPortFont
,
1641 curwidth
= bounds
.h
;
1646 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1647 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1649 if ( curwidth
> *width
)
1650 *width
= XDEV2LOGREL( curwidth
) ;
1656 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1658 wxString linetext
= strtext
;
1660 if ( useGetThemeText
)
1662 Point bounds
={0,0} ;
1664 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1665 ::GetThemeTextDimensions( mString
,
1666 kThemeCurrentPortFont
,
1671 curwidth
= bounds
.h
;
1676 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1677 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1679 if ( curwidth
> *width
)
1680 *width
= XDEV2LOGREL( curwidth
) ;
1684 // work around the constness
1685 *((wxFont
*)(&m_font
)) = formerFont
;
1686 m_macFontInstalled
= false ;
1691 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1693 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1696 widths
.Add(0, text
.length());
1698 if (text
.length() == 0)
1701 wxMacFastPortSetter
helper(this) ;
1704 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1705 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1706 useGetThemeText
= false ;
1708 if ( useGetThemeText
)
1710 // If anybody knows how to do this more efficiently yet still handle
1711 // the fractional glyph widths that may be present when using AA
1712 // fonts, please change it. Currently it is measuring from the
1713 // begining of the string for each succeding substring, which is much
1714 // slower than this should be.
1715 for (size_t i
=0; i
<text
.length(); i
++)
1717 wxString
str(text
.Left(i
+1));
1718 Point bounds
= {0,0};
1720 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1721 ::GetThemeTextDimensions( mString
,
1722 kThemeCurrentPortFont
,
1727 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1733 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1734 size_t len
= strlen(buff
);
1735 short* measurements
= new short[len
+1];
1736 MeasureText(len
, buff
.data(), measurements
);
1738 // Copy to widths, starting at measurements[1]
1739 // NOTE: this doesn't take into account any multi-byte characters
1740 // in buff, it probabkly should...
1741 for (size_t i
=0; i
<text
.length(); i
++)
1742 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1744 delete [] measurements
;
1752 wxCoord
wxDC::GetCharWidth(void) const
1754 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1755 wxMacFastPortSetter
helper(this) ;
1759 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1760 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1761 useGetThemeText
= false ;
1765 if ( useGetThemeText
)
1767 Point bounds
={0,0} ;
1769 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1770 ::GetThemeTextDimensions( mString
,
1771 kThemeCurrentPortFont
,
1776 CFRelease( mString
) ;
1782 width
= ::TextWidth( text
, 0 , 1 ) ;
1784 return YDEV2LOGREL(width
) ;
1787 wxCoord
wxDC::GetCharHeight(void) const
1789 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1790 wxMacFastPortSetter
helper(this) ;
1793 ::GetFontInfo( &fi
) ;
1794 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1797 void wxDC::Clear(void)
1799 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1800 wxMacFastPortSetter
helper(this) ;
1801 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1802 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1805 //MacInstallBrush() ;
1806 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1807 ::EraseRect( &rect
) ;
1811 void wxDC::MacInstallFont() const
1813 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1814 // if ( m_macFontInstalled )
1816 Pattern blackColor
;
1817 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1820 ::TextFont( m_font
.GetMacFontNum() ) ;
1821 ::TextSize( (short)(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1822 ::TextFace( m_font
.GetMacFontStyle() ) ;
1823 m_macFontInstalled
= true ;
1824 m_macBrushInstalled
= false ;
1825 m_macPenInstalled
= false ;
1826 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1827 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1828 ::RGBForeColor( &forecolor
);
1829 ::RGBBackColor( &backcolor
);
1833 FontFamilyID fontId
;
1837 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1838 GetFNum( fontName
, &fontId
);
1839 ::TextFont( fontId
) ;
1840 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1841 ::TextFace( fontStyle
) ;
1842 // todo reset after spacing changes - or store the current spacing somewhere
1843 m_macFontInstalled
= true ;
1844 m_macBrushInstalled
= false ;
1845 m_macPenInstalled
= false ;
1846 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1847 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1848 ::RGBForeColor( &forecolor
);
1849 ::RGBBackColor( &backcolor
);
1851 short mode
= patCopy
;
1853 switch( m_logicalFunction
)
1858 case wxINVERT
: // NOT dst
1859 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1862 case wxXOR
: // src XOR dst
1865 case wxOR_REVERSE
: // src OR (NOT dst)
1868 case wxSRC_INVERT
: // (NOT src)
1871 case wxAND
: // src AND dst
1876 case wxAND_REVERSE
:// src AND (NOT dst)
1877 case wxAND_INVERT
: // (NOT src) AND dst
1878 case wxNO_OP
: // dst
1879 case wxNOR
: // (NOT src) AND (NOT dst)
1880 case wxEQUIV
: // (NOT src) XOR dst
1881 case wxOR_INVERT
: // (NOT src) OR dst
1882 case wxNAND
: // (NOT src) OR (NOT dst)
1883 case wxOR
: // src OR dst
1885 // case wxSRC_OR: // source _bitmap_ OR destination
1886 // case wxSRC_AND: // source _bitmap_ AND destination
1890 OSStatus status
= noErr
;
1891 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1892 Style qdStyle
= m_font
.GetMacFontStyle() ;
1893 ATSUFontID atsuFont
= m_font
.GetMacATSUFontID() ;
1894 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1895 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1896 ATSUAttributeTag atsuTags
[] =
1901 // kATSUBaselineClassTag ,
1902 kATSUVerticalCharacterTag
,
1903 kATSUQDBoldfaceTag
,
1905 kATSUQDUnderlineTag
,
1906 kATSUQDCondensedTag
,
1907 kATSUQDExtendedTag
,
1909 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1911 sizeof( ATSUFontID
) ,
1913 // sizeof( RGBColor ) ,
1914 // sizeof( BslnBaselineClass ) ,
1915 sizeof( ATSUVerticalCharacterType
),
1922 Boolean kTrue
= true ;
1923 Boolean kFalse
= false ;
1924 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1925 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1926 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1930 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1931 // &kBaselineDefault ,
1933 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1934 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1935 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1936 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1937 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1939 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1940 atsuTags
, atsuSizes
, atsuValues
);
1941 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1944 Pattern gPatterns
[] =
1946 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1947 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1948 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1949 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1950 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1951 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1952 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1954 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1955 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1956 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1957 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1960 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1962 int index
= 0; // solid pattern by default
1966 case wxBDIAGONAL_HATCH
: index
= 1; break;
1967 case wxFDIAGONAL_HATCH
: index
= 2; break;
1968 case wxCROSS_HATCH
: index
= 3; break;
1969 case wxHORIZONTAL_HATCH
: index
= 4; break;
1970 case wxVERTICAL_HATCH
: index
= 5; break;
1971 case wxCROSSDIAG_HATCH
: index
= 6; break;
1973 case wxDOT
: index
= 7; break;
1974 case wxLONG_DASH
: index
= 8; break;
1975 case wxSHORT_DASH
: index
= 9; break;
1976 case wxDOT_DASH
: index
= 10; break;
1978 *pattern
= gPatterns
[index
];
1981 void wxDC::MacInstallPen() const
1983 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1984 //Pattern blackColor;
1985 // if ( m_macPenInstalled )
1987 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1988 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1989 ::RGBForeColor( &forecolor
);
1990 ::RGBBackColor( &backcolor
);
1992 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1993 // null means only one pixel, at whatever resolution
1994 if ( penWidth
== 0 )
1996 ::PenSize(penWidth
, penWidth
);
1998 int penStyle
= m_pen
.GetStyle();
2000 if (penStyle
== wxUSER_DASH
)
2002 // FIXME: there should be exactly 8 items in the dash
2004 int number
= m_pen
.GetDashes(&dash
) ;
2006 for ( int i
= 0 ; i
< 8 ; ++i
)
2008 pat
.pat
[i
] = dash
[index
] ;
2009 if (index
< number
- 1)
2015 wxMacGetPattern(penStyle
, &pat
);
2019 short mode
= patCopy
;
2021 switch( m_logicalFunction
)
2023 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2026 case wxINVERT
: // NOT dst
2027 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2030 case wxXOR
: // src XOR dst
2033 case wxOR_REVERSE
: // src OR (NOT dst)
2036 case wxSRC_INVERT
: // (NOT src)
2039 case wxAND
: // src AND dst
2044 case wxAND_REVERSE
:// src AND (NOT dst)
2045 case wxAND_INVERT
: // (NOT src) AND dst
2046 case wxNO_OP
: // dst
2047 case wxNOR
: // (NOT src) AND (NOT dst)
2048 case wxEQUIV
: // (NOT src) XOR dst
2049 case wxOR_INVERT
: // (NOT src) OR dst
2050 case wxNAND
: // (NOT src) OR (NOT dst)
2051 case wxOR
: // src OR dst
2053 // case wxSRC_OR: // source _bitmap_ OR destination
2054 // case wxSRC_AND: // source _bitmap_ AND destination
2058 m_macPenInstalled
= true ;
2059 m_macBrushInstalled
= false ;
2060 m_macFontInstalled
= false ;
2063 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2065 Pattern whiteColor
;
2066 switch( background
.MacGetBrushKind() )
2068 case kwxMacBrushTheme
:
2070 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2073 case kwxMacBrushThemeBackground
:
2076 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2077 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2080 case kwxMacBrushColour
:
2082 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2083 int brushStyle
= background
.GetStyle();
2084 if (brushStyle
== wxSOLID
)
2085 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2086 else if (background
.IsHatch())
2089 wxMacGetPattern(brushStyle
, &pat
);
2094 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2101 void wxDC::MacInstallBrush() const
2103 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2104 Pattern blackColor
;
2105 // if ( m_macBrushInstalled )
2108 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2109 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2110 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2111 int brushStyle
= m_brush
.GetStyle();
2112 if (brushStyle
== wxSOLID
)
2114 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2116 else if (m_brush
.IsHatch())
2119 wxMacGetPattern(brushStyle
, &pat
);
2122 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2124 // we force this in order to be compliant with wxMSW
2125 backgroundTransparent
= false ;
2126 // for these the text fore (and back for MASK_OPAQUE) colors are used
2127 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2128 int width
= bitmap
->GetWidth() ;
2129 int height
= bitmap
->GetHeight() ;
2130 GWorldPtr gw
= NULL
;
2131 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2132 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2134 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2135 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2136 LockPixels( gwpixmaphandle
) ;
2137 bool isMonochrome
= !IsPortColor( gw
) ;
2138 if ( !isMonochrome
)
2140 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2141 isMonochrome
= true ;
2143 if ( isMonochrome
&& width
== 8 && height
== 8 )
2145 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2146 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2147 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2148 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2149 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2151 for ( int i
= 0 ; i
< 8 ; ++i
)
2153 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2155 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2160 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2161 // caching scheme before putting this into production
2164 PixPatHandle pixpat
= NewPixPat() ;
2165 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2166 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2167 ((**(**pixpat
).patMap
).bounds
.bottom
-
2168 (**(**pixpat
).patMap
).bounds
.top
);
2169 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2170 (**pixpat
).patData
= image
;
2173 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2174 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2175 if ( ctspec
[0].rgb
.red
== 0x0000 )
2177 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2178 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2182 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2183 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2185 ::CTabChanged( ctable
) ;
2187 ::PenPixPat(pixpat
);
2188 m_macForegroundPixMap
= pixpat
;
2190 UnlockPixels( gwpixmaphandle
) ;
2194 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2196 short mode
= patCopy
;
2197 switch( m_logicalFunction
)
2200 if ( backgroundTransparent
)
2205 case wxINVERT
: // NOT dst
2206 if ( !backgroundTransparent
)
2208 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2212 case wxXOR
: // src XOR dst
2215 case wxOR_REVERSE
: // src OR (NOT dst)
2218 case wxSRC_INVERT
: // (NOT src)
2221 case wxAND
: // src AND dst
2226 case wxAND_REVERSE
:// src AND (NOT dst)
2227 case wxAND_INVERT
: // (NOT src) AND dst
2228 case wxNO_OP
: // dst
2229 case wxNOR
: // (NOT src) AND (NOT dst)
2230 case wxEQUIV
: // (NOT src) XOR dst
2231 case wxOR_INVERT
: // (NOT src) OR dst
2232 case wxNAND
: // (NOT src) OR (NOT dst)
2233 case wxOR
: // src OR dst
2235 // case wxSRC_OR: // source _bitmap_ OR destination
2236 // case wxSRC_AND: // source _bitmap_ AND destination
2240 m_macBrushInstalled
= true ;
2241 m_macPenInstalled
= false ;
2242 m_macFontInstalled
= false ;
2245 // ---------------------------------------------------------------------------
2246 // coordinates transformations
2247 // ---------------------------------------------------------------------------
2249 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2251 return ((wxDC
*)this)->XDEV2LOG(x
);
2254 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2256 return ((wxDC
*)this)->YDEV2LOG(y
);
2259 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2261 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2264 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2266 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2269 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2271 return ((wxDC
*)this)->XLOG2DEV(x
);
2274 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2276 return ((wxDC
*)this)->YLOG2DEV(y
);
2279 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2281 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2284 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2286 return ((wxDC
*)this)->YLOG2DEVREL(y
);