1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/mac/uma.h"
15 #include "wx/dcmemory.h"
16 #include "wx/dcprint.h"
17 #include "wx/region.h"
26 #include "wx/mac/private.h"
27 #include <ATSUnicode.h>
28 #include <TextCommon.h>
29 #include <TextEncodingConverter.h>
32 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 const double RAD2DEG
= 180.0 / M_PI
;
39 const short kEmulatedMode
= -1 ;
40 const short kUnsupportedMode
= -2 ;
42 extern TECObjectRef s_TECNativeCToUnicode
;
44 // set to 0 if problems arise
45 #define wxMAC_EXPERIMENTAL_DC 1
47 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
48 m_ph( (GrafPtr
) dc
->m_macPort
)
50 wxASSERT( dc
->Ok() ) ;
52 dc
->MacSetupPort(&m_ph
) ;
54 wxMacPortSetter::~wxMacPortSetter()
56 m_dc
->MacCleanupPort(&m_ph
) ;
59 #if wxMAC_EXPERIMENTAL_DC
60 class wxMacFastPortSetter
63 wxMacFastPortSetter( const wxDC
*dc
)
65 wxASSERT( dc
->Ok() ) ;
66 GetPort( &m_oldPort
) ;
67 SetPort( (GrafPtr
) dc
->m_macPort
) ;
68 m_clipRgn
= NewRgn() ;
69 GetClip( m_clipRgn
) ;
71 dc
->MacSetupPort( NULL
) ;
73 ~wxMacFastPortSetter()
75 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
76 SetClip( m_clipRgn
) ;
77 SetPort( m_oldPort
) ;
78 m_dc
->MacCleanupPort( NULL
) ;
79 DisposeRgn( m_clipRgn
) ;
88 typedef wxMacPortSetter wxMacFastPortSetter
;
93 // start moving to a dual implementation for QD and CGContextRef
95 class wxMacGraphicsContext
98 void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
) = 0 ;
99 void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0 ;
100 void SetClippingRegion( const wxRegion
®ion
) = 0 ;
101 void DestroyClippingRegion() = 0 ;
102 void SetTextForeground( const wxColour
&col
) = 0 ;
103 void SetTextBackground( const wxColour
&col
) = 0 ;
104 void SetLogicalScale( double x
, double y
) = 0 ;
105 void SetUserScale( double x
, double y
) = 0;
108 class wxMacQuickDrawContext
: public wxMacGraphicsContext
115 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
117 m_formerClip
= NewRgn() ;
118 m_newClip
= NewRgn() ;
119 GetClip( m_formerClip
) ;
124 // this clipping area was set to the parent window's drawing area, lead to problems
125 // with MacOSX controls drawing outside their wx' rectangle
126 RgnHandle insidergn
= NewRgn() ;
128 wxWindow
*parent
= win
->GetParent() ;
129 parent
->MacWindowToRootWindow( &x
,&y
) ;
130 wxSize size
= parent
->GetSize() ;
131 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
132 size
.x
- parent
->MacGetRightBorderSize(),
133 size
.y
- parent
->MacGetBottomBorderSize()) ;
134 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
135 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
136 OffsetRgn( m_newClip
, x
, y
) ;
137 SetClip( m_newClip
) ;
138 DisposeRgn( insidergn
) ;
141 win
->MacWindowToRootWindow( &x
,&y
) ;
142 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
143 OffsetRgn( m_newClip
, x
, y
) ;
144 SetClip( m_newClip
) ;
149 wxMacWindowClipper::~wxMacWindowClipper()
151 SetClip( m_formerClip
) ;
152 DisposeRgn( m_newClip
) ;
153 DisposeRgn( m_formerClip
) ;
156 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
160 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
161 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
166 // this function emulates all wx colour manipulations, used to verify the implementation
167 // by setting the mode in the blitting functions to kEmulatedMode
168 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
170 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
172 switch ( logical_func
)
174 case wxAND
: // src AND dst
175 dstColor
.red
= dstColor
.red
& srcColor
.red
;
176 dstColor
.green
= dstColor
.green
& srcColor
.green
;
177 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
179 case wxAND_INVERT
: // (NOT src) AND dst
180 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
181 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
182 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
184 case wxAND_REVERSE
:// src AND (NOT dst)
185 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
186 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
187 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
195 dstColor
.red
= srcColor
.red
;
196 dstColor
.green
= srcColor
.green
;
197 dstColor
.blue
= srcColor
.blue
;
199 case wxEQUIV
: // (NOT src) XOR dst
200 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
201 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
202 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
204 case wxINVERT
: // NOT dst
205 dstColor
.red
= ~dstColor
.red
;
206 dstColor
.green
= ~dstColor
.green
;
207 dstColor
.blue
= ~dstColor
.blue
;
209 case wxNAND
: // (NOT src) OR (NOT dst)
210 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
211 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
212 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
214 case wxNOR
: // (NOT src) AND (NOT dst)
215 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
216 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
217 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
221 case wxOR
: // src OR dst
222 dstColor
.red
= dstColor
.red
| srcColor
.red
;
223 dstColor
.green
= dstColor
.green
| srcColor
.green
;
224 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
226 case wxOR_INVERT
: // (NOT src) OR dst
227 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
228 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
229 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
231 case wxOR_REVERSE
: // src OR (NOT dst)
232 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
233 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
234 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
237 dstColor
.red
= 0xFFFF ;
238 dstColor
.green
= 0xFFFF ;
239 dstColor
.blue
= 0xFFFF ;
241 case wxSRC_INVERT
: // (NOT src)
242 dstColor
.red
= ~srcColor
.red
;
243 dstColor
.green
= ~srcColor
.green
;
244 dstColor
.blue
= ~srcColor
.blue
;
246 case wxXOR
: // src XOR dst
247 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
248 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
249 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
258 m_mm_to_pix_x
= mm2pt
;
259 m_mm_to_pix_y
= mm2pt
;
260 m_internalDeviceOriginX
= 0;
261 m_internalDeviceOriginY
= 0;
262 m_externalDeviceOriginX
= 0;
263 m_externalDeviceOriginY
= 0;
264 m_logicalScaleX
= 1.0;
265 m_logicalScaleY
= 1.0;
270 m_needComputeScaleX
= false;
271 m_needComputeScaleY
= false;
275 m_macFontInstalled
= false ;
276 m_macBrushInstalled
= false ;
277 m_macPenInstalled
= false ;
278 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
279 m_macBoundaryClipRgn
= NewRgn() ;
280 m_macCurrentClipRgn
= NewRgn() ;
281 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
282 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
283 m_pen
= *wxBLACK_PEN
;
284 m_font
= *wxNORMAL_FONT
;
285 m_brush
= *wxWHITE_BRUSH
;
287 // needed to debug possible errors with two active drawing methods at the same time on
289 m_macCurrentPortStateHelper
= NULL
;
291 m_macATSUIStyle
= NULL
;
292 m_macAliasWasEnabled
= false;
293 m_macForegroundPixMap
= NULL
;
294 m_macBackgroundPixMap
= NULL
;
299 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
300 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
303 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
306 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
307 m_macCurrentPortStateHelper
= help
;
309 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
310 #if ! wxMAC_EXPERIMENTAL_DC
311 m_macFontInstalled
= false ;
312 m_macBrushInstalled
= false ;
313 m_macPenInstalled
= false ;
316 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
319 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
320 m_macCurrentPortStateHelper
= NULL
;
322 if( m_macATSUIStyle
)
324 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
325 m_macATSUIStyle
= NULL
;
327 if ( m_macAliasWasEnabled
)
329 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
330 m_macAliasWasEnabled
= false ;
332 if ( m_macForegroundPixMap
)
335 ::PenPat(GetQDGlobalsBlack(&blackColor
));
336 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
337 m_macForegroundPixMap
= NULL
;
339 if ( m_macBackgroundPixMap
)
342 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
343 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
344 m_macBackgroundPixMap
= NULL
;
348 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
350 wxCHECK_RET( Ok(), wxT("invalid window dc") );
351 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
352 wxMacFastPortSetter
helper(this) ;
353 wxCoord xx
= XLOG2DEVMAC(x
);
354 wxCoord yy
= YLOG2DEVMAC(y
);
355 wxCoord w
= bmp
.GetWidth();
356 wxCoord h
= bmp
.GetHeight();
357 wxCoord ww
= XLOG2DEVREL(w
);
358 wxCoord hh
= YLOG2DEVREL(h
);
359 // Set up drawing mode
360 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
361 //m_logicalFunction == wxCLEAR ? WHITENESS :
362 //m_logicalFunction == wxSET ? BLACKNESS :
363 m_logicalFunction
== wxINVERT
? hilite
:
364 //m_logicalFunction == wxAND ? MERGECOPY :
365 m_logicalFunction
== wxOR
? srcOr
:
366 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
367 m_logicalFunction
== wxXOR
? srcXor
:
368 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
369 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
370 //m_logicalFunction == wxSRC_OR ? srcOr :
371 //m_logicalFunction == wxSRC_AND ? SRCAND :
373 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
374 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
375 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
376 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
378 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
380 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
381 PixMapHandle bmappixels
;
382 // Set foreground and background colours (for bitmaps depth = 1)
383 if(bmp
.GetDepth() == 1)
385 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
386 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
392 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
393 RGBColor black
= { 0,0,0} ;
394 RGBForeColor( &black
) ;
395 RGBBackColor( &white
) ;
397 bmappixels
= GetGWorldPixMap( bmapworld
) ;
398 wxCHECK_RET(LockPixels(bmappixels
),
399 wxT("DoDrawBitmap: Unable to lock pixels"));
400 Rect source
= { 0, 0, h
, w
};
401 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
402 if ( useMask
&& bmp
.GetMask() )
404 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
408 GetPortBitMapForCopyBits(bmapworld
),
409 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
410 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
411 &source
, &source
, &dest
, mode
, NULL
413 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
417 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
418 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
419 &source
, &dest
, mode
, NULL
) ;
421 UnlockPixels( bmappixels
) ;
423 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
425 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
426 OffsetRect( &bitmaprect
, xx
, yy
) ;
427 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
429 m_macPenInstalled
= false ;
430 m_macBrushInstalled
= false ;
431 m_macFontInstalled
= false ;
434 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
436 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
437 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
438 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
441 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
443 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
444 wxCoord xx
, yy
, ww
, hh
;
447 ww
= XLOG2DEVREL(width
);
448 hh
= YLOG2DEVREL(height
);
449 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
450 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
453 m_clipX1
= wxMax( m_clipX1
, xx
);
454 m_clipY1
= wxMax( m_clipY1
, yy
);
455 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
456 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
468 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
470 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
473 DestroyClippingRegion();
476 wxMacFastPortSetter
helper(this) ;
478 region
.GetBox( x
, y
, w
, h
);
479 wxCoord xx
, yy
, ww
, hh
;
484 // if we have a scaling that we cannot map onto native regions
485 // we must use the box
486 if ( ww
!= w
|| hh
!= h
)
488 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
492 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
493 if ( xx
!= x
|| yy
!= y
)
495 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
497 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
500 m_clipX1
= wxMax( m_clipX1
, xx
);
501 m_clipY1
= wxMax( m_clipY1
, yy
);
502 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
503 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
516 void wxDC::DestroyClippingRegion()
518 wxMacFastPortSetter
helper(this) ;
519 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
523 void wxDC::DoGetSizeMM( int* width
, int* height
) const
528 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
529 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
532 void wxDC::SetTextForeground( const wxColour
&col
)
534 wxCHECK_RET(Ok(), wxT("Invalid DC"));
535 m_textForegroundColour
= col
;
536 m_macFontInstalled
= false ;
539 void wxDC::SetTextBackground( const wxColour
&col
)
541 wxCHECK_RET(Ok(), wxT("Invalid DC"));
542 m_textBackgroundColour
= col
;
543 m_macFontInstalled
= false ;
546 void wxDC::SetMapMode( int mode
)
551 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
554 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
557 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
560 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
564 SetLogicalScale( 1.0, 1.0 );
567 if (mode
!= wxMM_TEXT
)
569 m_needComputeScaleX
= true;
570 m_needComputeScaleY
= true;
574 void wxDC::SetUserScale( double x
, double y
)
576 // allow negative ? -> no
579 ComputeScaleAndOrigin();
582 void wxDC::SetLogicalScale( double x
, double y
)
587 ComputeScaleAndOrigin();
590 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
592 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
593 m_logicalOriginY
= y
* m_signY
;
594 ComputeScaleAndOrigin();
597 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
599 m_externalDeviceOriginX
= x
;
600 m_externalDeviceOriginY
= y
;
601 ComputeScaleAndOrigin();
605 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
607 m_internalDeviceOriginX
= x
;
608 m_internalDeviceOriginY
= y
;
609 ComputeScaleAndOrigin();
611 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
613 if (x
) *x
= m_internalDeviceOriginX
;
614 if (y
) *y
= m_internalDeviceOriginY
;
618 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
620 m_signX
= (xLeftRight
? 1 : -1);
621 m_signY
= (yBottomUp
? -1 : 1);
622 ComputeScaleAndOrigin();
625 wxSize
wxDC::GetPPI() const
627 return wxSize(72, 72);
630 int wxDC::GetDepth() const
632 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
634 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
639 void wxDC::ComputeScaleAndOrigin()
641 // CMB: copy scale to see if it changes
642 double origScaleX
= m_scaleX
;
643 double origScaleY
= m_scaleY
;
644 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
645 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
646 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
647 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
648 // CMB: if scale has changed call SetPen to recalulate the line width
649 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
651 // this is a bit artificial, but we need to force wxDC to think
652 // the pen has changed
653 wxPen
* pen
= & GetPen();
660 void wxDC::SetPalette( const wxPalette
& palette
)
664 void wxDC::SetBackgroundMode( int mode
)
666 m_backgroundMode
= mode
;
669 void wxDC::SetFont( const wxFont
&font
)
672 m_macFontInstalled
= false ;
675 void wxDC::SetPen( const wxPen
&pen
)
680 m_macPenInstalled
= false ;
683 void wxDC::SetBrush( const wxBrush
&brush
)
685 if (m_brush
== brush
)
688 m_macBrushInstalled
= false ;
691 void wxDC::SetBackground( const wxBrush
&brush
)
693 if (m_backgroundBrush
== brush
)
695 m_backgroundBrush
= brush
;
696 if (!m_backgroundBrush
.Ok())
698 m_macBrushInstalled
= false ;
701 void wxDC::SetLogicalFunction( int function
)
703 if (m_logicalFunction
== function
)
705 m_logicalFunction
= function
;
706 m_macFontInstalled
= false ;
707 m_macBrushInstalled
= false ;
708 m_macPenInstalled
= false ;
711 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
712 const wxColour
& col
, int style
);
714 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
715 const wxColour
& col
, int style
)
717 return wxDoFloodFill(this, x
, y
, col
, style
);
720 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
722 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
723 wxMacFastPortSetter
helper(this) ;
725 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
726 // Convert from Mac colour to wx
727 col
->Set( colour
.red
>> 8,
733 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
735 wxCHECK_RET(Ok(), wxT("Invalid DC"));
736 wxMacFastPortSetter
helper(this) ;
737 if (m_pen
.GetStyle() != wxTRANSPARENT
)
740 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
741 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
742 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
743 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
744 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
745 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
746 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
747 (m_pen
.GetWidth() <= 1))
749 // Implement LAST_NOT for MAC at least for
750 // orthogonal lines. RR.
771 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
773 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
774 wxMacFastPortSetter
helper(this) ;
775 if (m_pen
.GetStyle() != wxTRANSPARENT
)
780 wxCoord xx
= XLOG2DEVMAC(x
);
781 wxCoord yy
= YLOG2DEVMAC(y
);
783 ::MoveTo( XLOG2DEVMAC(0), yy
);
784 ::LineTo( XLOG2DEVMAC(w
), yy
);
785 ::MoveTo( xx
, YLOG2DEVMAC(0) );
786 ::LineTo( xx
, YLOG2DEVMAC(h
) );
787 CalcBoundingBox(x
, y
);
788 CalcBoundingBox(x
+w
, y
+h
);
793 * To draw arcs properly the angles need to be converted from the WX style:
794 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
795 * a normal axis on paper).
798 * Angles start on the +ve y axis and go clockwise.
801 static double wxConvertWXangleToMACangle(double angle
)
803 double newAngle
= 90 - angle
;
809 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
810 wxCoord x2
, wxCoord y2
,
811 wxCoord xc
, wxCoord yc
)
813 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
814 wxMacFastPortSetter
helper(this) ;
815 wxCoord xx1
= XLOG2DEVMAC(x1
);
816 wxCoord yy1
= YLOG2DEVMAC(y1
);
817 wxCoord xx2
= XLOG2DEVMAC(x2
);
818 wxCoord yy2
= YLOG2DEVMAC(y2
);
819 wxCoord xxc
= XLOG2DEVMAC(xc
);
820 wxCoord yyc
= YLOG2DEVMAC(yc
);
821 double dx
= xx1
- xxc
;
822 double dy
= yy1
- yyc
;
823 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
824 wxCoord rad
= (wxCoord
)radius
;
825 double radius1
, radius2
;
826 if (xx1
== xx2
&& yy1
== yy2
)
831 else if (radius
== 0.0)
833 radius1
= radius2
= 0.0;
837 radius1
= (xx1
- xxc
== 0) ?
838 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
839 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
840 radius2
= (xx2
- xxc
== 0) ?
841 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
842 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
844 wxCoord alpha2
= wxCoord(radius2
- radius1
);
845 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
846 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
849 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
850 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
852 PaintArc(&r
, alpha1
, alpha2
);
854 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
856 FrameArc(&r
, alpha1
, alpha2
);
860 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
861 double sa
, double ea
)
863 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
864 wxMacFastPortSetter
helper(this) ;
866 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
867 // we have to make sure that the filling is always counter-clockwise
870 wxCoord xx
= XLOG2DEVMAC(x
);
871 wxCoord yy
= YLOG2DEVMAC(y
);
872 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
873 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
874 // handle -ve width and/or height
875 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
876 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
877 sa
= wxConvertWXangleToMACangle(sa
);
882 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
884 PaintArc(&r
, (short)sa
, (short)angle
);
886 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
888 FrameArc(&r
, (short)sa
, (short)angle
);
892 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
894 wxCHECK_RET(Ok(), wxT("Invalid DC"));
895 wxMacFastPortSetter
helper(this) ;
896 if (m_pen
.GetStyle() != wxTRANSPARENT
)
898 wxCoord xx1
= XLOG2DEVMAC(x
);
899 wxCoord yy1
= YLOG2DEVMAC(y
);
900 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
901 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
902 CalcBoundingBox(x
, y
);
906 void wxDC::DoDrawLines(int n
, wxPoint points
[],
907 wxCoord xoffset
, wxCoord yoffset
)
909 wxCHECK_RET(Ok(), wxT("Invalid DC"));
910 wxMacFastPortSetter
helper(this) ;
911 if (m_pen
.GetStyle() == wxTRANSPARENT
)
914 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
915 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
916 wxCoord x1
, x2
, y1
, y2
;
917 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
918 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
919 ::MoveTo(x1
- offset
, y1
- offset
);
920 for (int i
= 0; i
< n
-1; i
++)
922 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
923 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
924 ::LineTo( x2
- offset
, y2
- offset
);
928 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
929 wxCoord xoffset
, wxCoord yoffset
,
932 wxCHECK_RET(Ok(), wxT("Invalid DC"));
933 wxMacFastPortSetter
helper(this) ;
934 wxCoord x1
, x2
, y1
, y2
;
935 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
937 PolyHandle polygon
= OpenPoly();
938 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
939 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
941 for (int i
= 1; i
< n
; i
++)
943 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
944 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
947 // close the polyline if necessary
948 if ( x1
!= x2
|| y1
!= y2
)
953 if (m_brush
.GetStyle() != wxTRANSPARENT
)
956 ::PaintPoly( polygon
);
958 if (m_pen
.GetStyle() != wxTRANSPARENT
)
961 ::FramePoly( polygon
) ;
966 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
968 wxCHECK_RET(Ok(), wxT("Invalid DC"));
969 wxMacFastPortSetter
helper(this) ;
970 wxCoord xx
= XLOG2DEVMAC(x
);
971 wxCoord yy
= YLOG2DEVMAC(y
);
972 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
973 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
974 // CMB: draw nothing if transformed w or h is 0
975 if (ww
== 0 || hh
== 0)
977 // CMB: handle -ve width and/or height
988 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
989 if (m_brush
.GetStyle() != wxTRANSPARENT
)
992 ::PaintRect( &rect
) ;
994 if (m_pen
.GetStyle() != wxTRANSPARENT
)
997 ::FrameRect( &rect
) ;
1001 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1002 wxCoord width
, wxCoord height
,
1005 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1006 wxMacFastPortSetter
helper(this) ;
1008 radius
= - radius
* ((width
< height
) ? width
: height
);
1009 wxCoord xx
= XLOG2DEVMAC(x
);
1010 wxCoord yy
= YLOG2DEVMAC(y
);
1011 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1012 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1013 // CMB: draw nothing if transformed w or h is 0
1014 if (ww
== 0 || hh
== 0)
1016 // CMB: handle -ve width and/or height
1027 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1028 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1031 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1033 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1036 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1040 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1042 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1043 wxMacFastPortSetter
helper(this) ;
1044 wxCoord xx
= XLOG2DEVMAC(x
);
1045 wxCoord yy
= YLOG2DEVMAC(y
);
1046 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1047 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1048 // CMB: draw nothing if transformed w or h is 0
1049 if (ww
== 0 || hh
== 0)
1051 // CMB: handle -ve width and/or height
1062 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1063 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1066 ::PaintOval( &rect
) ;
1068 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1071 ::FrameOval( &rect
) ;
1075 bool wxDC::CanDrawBitmap(void) const
1080 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1081 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1082 wxCoord xsrcMask
, wxCoord ysrcMask
)
1084 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1085 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1086 if ( logical_func
== wxNO_OP
)
1088 if (xsrcMask
== -1 && ysrcMask
== -1)
1090 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1092 // correct the parameter in case this dc does not have a mask at all
1093 if ( useMask
&& !source
->m_macMask
)
1095 Rect srcrect
, dstrect
;
1096 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1097 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1098 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1099 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1100 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1101 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1102 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1103 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1104 short mode
= kUnsupportedMode
;
1105 bool invertDestinationFirst
= false ;
1106 switch ( logical_func
)
1108 case wxAND
: // src AND dst
1109 mode
= adMin
; // ok
1111 case wxAND_INVERT
: // (NOT src) AND dst
1112 mode
= notSrcOr
; // ok
1114 case wxAND_REVERSE
:// src AND (NOT dst)
1115 invertDestinationFirst
= true ;
1119 mode
= kEmulatedMode
;
1122 mode
= srcCopy
; // ok
1124 case wxEQUIV
: // (NOT src) XOR dst
1125 mode
= srcXor
; // ok
1127 case wxINVERT
: // NOT dst
1128 mode
= kEmulatedMode
; //or hilite ;
1130 case wxNAND
: // (NOT src) OR (NOT dst)
1131 invertDestinationFirst
= true ;
1134 case wxNOR
: // (NOT src) AND (NOT dst)
1135 invertDestinationFirst
= true ;
1138 case wxNO_OP
: // dst
1139 mode
= kEmulatedMode
; // this has already been handled upon entry
1141 case wxOR
: // src OR dst
1144 case wxOR_INVERT
: // (NOT src) OR dst
1147 case wxOR_REVERSE
: // src OR (NOT dst)
1148 invertDestinationFirst
= true ;
1152 mode
= kEmulatedMode
;
1154 case wxSRC_INVERT
: // (NOT src)
1155 mode
= notSrcCopy
; // ok
1157 case wxXOR
: // src XOR dst
1158 mode
= notSrcXor
; // ok
1163 if ( mode
== kUnsupportedMode
)
1165 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1168 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1169 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1170 if ( LockPixels(bmappixels
) )
1172 wxMacFastPortSetter
helper(this) ;
1173 if ( source
->GetDepth() == 1 )
1175 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1176 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1180 // the modes need this, otherwise we'll end up having really nice colors...
1181 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1182 RGBColor black
= { 0,0,0} ;
1183 RGBForeColor( &black
) ;
1184 RGBBackColor( &white
) ;
1186 if ( useMask
&& source
->m_macMask
)
1188 if ( mode
== srcCopy
)
1190 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1192 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1193 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1194 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1195 &srcrect
, &srcrect
, &dstrect
) ;
1196 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1201 RgnHandle clipRgn
= NewRgn() ;
1202 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1203 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1204 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1205 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1206 if ( mode
== kEmulatedMode
)
1209 ::PenPat(GetQDGlobalsBlack(&pat
));
1210 if ( logical_func
== wxSET
)
1212 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1213 ::RGBForeColor( &col
) ;
1214 ::PaintRgn( clipRgn
) ;
1216 else if ( logical_func
== wxCLEAR
)
1218 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1219 ::RGBForeColor( &col
) ;
1220 ::PaintRgn( clipRgn
) ;
1222 else if ( logical_func
== wxINVERT
)
1224 MacInvertRgn( clipRgn
) ;
1228 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1230 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1232 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1233 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1234 if ( PtInRgn( dstPoint
, clipRgn
) )
1238 SetPort( (GrafPtr
) sourcePort
) ;
1239 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1240 SetPort( (GrafPtr
) m_macPort
) ;
1241 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1242 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1243 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1251 if ( invertDestinationFirst
)
1253 MacInvertRgn( clipRgn
) ;
1255 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1256 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1257 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1259 DisposeRgn( clipRgn
) ;
1264 RgnHandle clipRgn
= NewRgn() ;
1265 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1266 if ( mode
== kEmulatedMode
)
1269 ::PenPat(GetQDGlobalsBlack(&pat
));
1270 if ( logical_func
== wxSET
)
1272 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1273 ::RGBForeColor( &col
) ;
1274 ::PaintRgn( clipRgn
) ;
1276 else if ( logical_func
== wxCLEAR
)
1278 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1279 ::RGBForeColor( &col
) ;
1280 ::PaintRgn( clipRgn
) ;
1282 else if ( logical_func
== wxINVERT
)
1284 MacInvertRgn( clipRgn
) ;
1288 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1290 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1292 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1293 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1297 SetPort( (GrafPtr
) sourcePort
) ;
1298 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1299 SetPort( (GrafPtr
) m_macPort
) ;
1300 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1301 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1302 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1310 if ( invertDestinationFirst
)
1312 MacInvertRgn( clipRgn
) ;
1314 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1315 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1316 &srcrect
, &dstrect
, mode
, NULL
) ;
1318 DisposeRgn( clipRgn
) ;
1320 UnlockPixels( bmappixels
) ;
1322 m_macPenInstalled
= false ;
1323 m_macBrushInstalled
= false ;
1324 m_macFontInstalled
= false ;
1329 // as macro in FixMath.h for 10.3
1330 inline Fixed
IntToFixed( int inInt
)
1332 return (((SInt32
) inInt
) << 16);
1335 inline int FixedToInt( Fixed inFixed
)
1337 return (((SInt32
) inFixed
) >> 16);
1341 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1344 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1348 DrawText(str
, x
, y
);
1352 if ( str
.Length() == 0 )
1355 wxMacFastPortSetter
helper(this) ;
1360 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1361 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.GetMacFontSize()));
1362 m_macAliasWasEnabled
= true ;
1364 OSStatus status
= noErr
;
1365 ATSUTextLayout atsuLayout
;
1366 UniCharCount chars
= str
.Length() ;
1368 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1369 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1371 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1372 int wlen
= wxWcslen( wchar
.data() ) ;
1373 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1374 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1376 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1377 int iAngle
= int( angle
);
1378 int drawX
= XLOG2DEVMAC(x
) ;
1379 int drawY
= YLOG2DEVMAC(y
) ;
1381 ATSUTextMeasurement textBefore
;
1382 ATSUTextMeasurement textAfter
;
1383 ATSUTextMeasurement ascent
;
1384 ATSUTextMeasurement descent
;
1387 if ( abs(iAngle
) > 0 )
1389 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1390 ATSUAttributeTag atsuTags
[] =
1392 kATSULineRotationTag
,
1394 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1398 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1402 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1403 atsuTags
, atsuSizes
, atsuValues
) ;
1405 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1406 &textBefore
, &textAfter
, &ascent
, &descent
);
1408 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1409 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1410 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1411 IntToFixed(drawX
) , IntToFixed(drawY
) );
1412 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1414 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1415 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1416 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1417 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1418 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1419 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1420 ::ATSUDisposeTextLayout(atsuLayout
);
1423 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1425 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1427 wxMacFastPortSetter
helper(this) ;
1428 long xx
= XLOG2DEVMAC(x
);
1429 long yy
= YLOG2DEVMAC(y
);
1431 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1432 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1433 useDrawThemeText
= false ;
1438 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1439 SetAntiAliasedTextEnabled(true, 8);
1440 m_macAliasWasEnabled
= true ;
1443 ::GetFontInfo( &fi
) ;
1445 if ( !useDrawThemeText
)
1448 ::MoveTo( xx
, yy
);
1449 if ( m_backgroundMode
== wxTRANSPARENT
)
1451 ::TextMode( srcOr
) ;
1455 ::TextMode( srcCopy
) ;
1457 int length
= strtext
.Length() ;
1463 #if 0 // we don't have to do all that here
1466 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1468 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1470 if ( useDrawThemeText
)
1472 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1473 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1474 if ( m_backgroundMode
!= wxTRANSPARENT
)
1476 Point bounds
={0,0} ;
1477 Rect background
= frame
;
1479 ::GetThemeTextDimensions( mString
,
1480 kThemeCurrentPortFont
,
1485 background
.right
= background
.left
+ bounds
.h
;
1486 background
.bottom
= background
.top
+ bounds
.v
;
1487 ::EraseRect( &background
) ;
1489 ::DrawThemeTextBox( mString
,
1490 kThemeCurrentPortFont
,
1501 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1502 ::DrawText( text
, 0 , strlen(text
) ) ;
1503 if ( m_backgroundMode
!= wxTRANSPARENT
)
1505 Point bounds
={0,0} ;
1506 Rect background
= frame
;
1508 ::GetThemeTextDimensions( mString
,
1509 kThemeCurrentPortFont
,
1514 background
.right
= background
.left
+ bounds
.h
;
1515 background
.bottom
= background
.top
+ bounds
.v
;
1516 ::EraseRect( &background
) ;
1519 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1525 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1527 wxString linetext
= strtext
;
1529 if ( useDrawThemeText
)
1531 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1532 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1534 if ( m_backgroundMode
!= wxTRANSPARENT
)
1536 Point bounds
={0,0} ;
1537 Rect background
= frame
;
1539 ::GetThemeTextDimensions( mString
,
1540 kThemeCurrentPortFont
,
1545 background
.right
= background
.left
+ bounds
.h
;
1546 background
.bottom
= background
.top
+ bounds
.v
;
1547 ::EraseRect( &background
) ;
1549 ::DrawThemeTextBox( mString
,
1550 kThemeCurrentPortFont
,
1560 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1561 if ( m_backgroundMode
!= wxTRANSPARENT
)
1563 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 } ;
1564 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1565 frame
.right
= frame
.left
+ width
;
1567 ::EraseRect( &frame
) ;
1569 ::DrawText( text
, 0 , strlen(text
) ) ;
1572 ::TextMode( srcOr
) ;
1575 bool wxDC::CanGetTextExtent() const
1577 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1581 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1582 wxCoord
*descent
, wxCoord
*externalLeading
,
1583 wxFont
*theFont
) const
1585 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1586 wxMacFastPortSetter
helper(this) ;
1587 wxFont formerFont
= m_font
;
1590 // work around the constness
1591 *((wxFont
*)(&m_font
)) = *theFont
;
1595 ::GetFontInfo( &fi
) ;
1597 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1598 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1599 useGetThemeText
= false ;
1602 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1604 *descent
=YDEV2LOGREL( fi
.descent
);
1605 if ( externalLeading
)
1606 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1607 int length
= strtext
.Length() ;
1615 #if 0 // apparently we don't have to do all that
1618 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1620 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1622 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1624 if ( useGetThemeText
)
1626 Point bounds
={0,0} ;
1628 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1629 ::GetThemeTextDimensions( mString
,
1630 kThemeCurrentPortFont
,
1635 curwidth
= bounds
.h
;
1640 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1641 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1643 if ( curwidth
> *width
)
1644 *width
= XDEV2LOGREL( curwidth
) ;
1650 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1652 wxString linetext
= strtext
;
1654 if ( useGetThemeText
)
1656 Point bounds
={0,0} ;
1658 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1659 ::GetThemeTextDimensions( mString
,
1660 kThemeCurrentPortFont
,
1665 curwidth
= bounds
.h
;
1670 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1671 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1673 if ( curwidth
> *width
)
1674 *width
= XDEV2LOGREL( curwidth
) ;
1678 // work around the constness
1679 *((wxFont
*)(&m_font
)) = formerFont
;
1680 m_macFontInstalled
= false ;
1685 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1687 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1690 widths
.Add(0, text
.Length());
1692 if (text
.Length() == 0)
1695 wxMacFastPortSetter
helper(this) ;
1698 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1699 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1700 useGetThemeText
= false ;
1702 if ( useGetThemeText
)
1704 // If anybody knows how to do this more efficiently yet still handle
1705 // the fractional glyph widths that may be present when using AA
1706 // fonts, please change it. Currently it is measuring from the
1707 // begining of the string for each succeding substring, which is much
1708 // slower than this should be.
1709 for (size_t i
=0; i
<text
.Length(); i
++)
1711 wxString
str(text
.Left(i
+1));
1712 Point bounds
= {0,0};
1714 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1715 ::GetThemeTextDimensions( mString
,
1716 kThemeCurrentPortFont
,
1721 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1727 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1728 size_t len
= strlen(buff
);
1729 short* measurements
= new short[len
+1];
1730 MeasureText(len
, buff
.data(), measurements
);
1732 // Copy to widths, starting at measurements[1]
1733 // NOTE: this doesn't take into account any multi-byte characters
1734 // in buff, it probabkly should...
1735 for (size_t i
=0; i
<text
.Length(); i
++)
1736 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1738 delete [] measurements
;
1746 wxCoord
wxDC::GetCharWidth(void) const
1748 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1749 wxMacFastPortSetter
helper(this) ;
1753 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1754 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1755 useGetThemeText
= false ;
1759 if ( useGetThemeText
)
1761 Point bounds
={0,0} ;
1763 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1764 ::GetThemeTextDimensions( mString
,
1765 kThemeCurrentPortFont
,
1770 CFRelease( mString
) ;
1776 width
= ::TextWidth( text
, 0 , 1 ) ;
1778 return YDEV2LOGREL(width
) ;
1781 wxCoord
wxDC::GetCharHeight(void) const
1783 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1784 wxMacFastPortSetter
helper(this) ;
1787 ::GetFontInfo( &fi
) ;
1788 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1791 void wxDC::Clear(void)
1793 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1794 wxMacFastPortSetter
helper(this) ;
1795 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1796 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1799 //MacInstallBrush() ;
1800 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1801 ::EraseRect( &rect
) ;
1805 void wxDC::MacInstallFont() const
1807 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1808 // if ( m_macFontInstalled )
1810 Pattern blackColor
;
1811 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1814 ::TextFont( m_font
.GetMacFontNum() ) ;
1815 ::TextSize( (short)(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1816 ::TextFace( m_font
.GetMacFontStyle() ) ;
1817 m_macFontInstalled
= true ;
1818 m_macBrushInstalled
= false ;
1819 m_macPenInstalled
= false ;
1820 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1821 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1822 ::RGBForeColor( &forecolor
);
1823 ::RGBBackColor( &backcolor
);
1827 FontFamilyID fontId
;
1831 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1832 GetFNum( fontName
, &fontId
);
1833 ::TextFont( fontId
) ;
1834 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1835 ::TextFace( fontStyle
) ;
1836 // todo reset after spacing changes - or store the current spacing somewhere
1837 m_macFontInstalled
= true ;
1838 m_macBrushInstalled
= false ;
1839 m_macPenInstalled
= false ;
1840 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1841 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1842 ::RGBForeColor( &forecolor
);
1843 ::RGBBackColor( &backcolor
);
1845 short mode
= patCopy
;
1847 switch( m_logicalFunction
)
1852 case wxINVERT
: // NOT dst
1853 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1856 case wxXOR
: // src XOR dst
1859 case wxOR_REVERSE
: // src OR (NOT dst)
1862 case wxSRC_INVERT
: // (NOT src)
1865 case wxAND
: // src AND dst
1870 case wxAND_REVERSE
:// src AND (NOT dst)
1871 case wxAND_INVERT
: // (NOT src) AND dst
1872 case wxNO_OP
: // dst
1873 case wxNOR
: // (NOT src) AND (NOT dst)
1874 case wxEQUIV
: // (NOT src) XOR dst
1875 case wxOR_INVERT
: // (NOT src) OR dst
1876 case wxNAND
: // (NOT src) OR (NOT dst)
1877 case wxOR
: // src OR dst
1879 // case wxSRC_OR: // source _bitmap_ OR destination
1880 // case wxSRC_AND: // source _bitmap_ AND destination
1884 OSStatus status
= noErr
;
1885 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1886 Style qdStyle
= m_font
.GetMacFontStyle() ;
1887 ATSUFontID atsuFont
= m_font
.GetMacATSUFontID() ;
1888 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1889 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1890 ATSUAttributeTag atsuTags
[] =
1895 // kATSUBaselineClassTag ,
1896 kATSUVerticalCharacterTag
,
1897 kATSUQDBoldfaceTag
,
1899 kATSUQDUnderlineTag
,
1900 kATSUQDCondensedTag
,
1901 kATSUQDExtendedTag
,
1903 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1905 sizeof( ATSUFontID
) ,
1907 // sizeof( RGBColor ) ,
1908 // sizeof( BslnBaselineClass ) ,
1909 sizeof( ATSUVerticalCharacterType
),
1916 Boolean kTrue
= true ;
1917 Boolean kFalse
= false ;
1918 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1919 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1920 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1924 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1925 // &kBaselineDefault ,
1927 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1928 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1929 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1930 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1931 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1933 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1934 atsuTags
, atsuSizes
, atsuValues
);
1935 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1938 Pattern gPatterns
[] =
1940 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1941 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1942 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1943 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1944 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1945 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1946 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1948 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1949 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1950 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1951 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1954 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1956 int index
= 0; // solid pattern by default
1960 case wxBDIAGONAL_HATCH
: index
= 1; break;
1961 case wxFDIAGONAL_HATCH
: index
= 2; break;
1962 case wxCROSS_HATCH
: index
= 3; break;
1963 case wxHORIZONTAL_HATCH
: index
= 4; break;
1964 case wxVERTICAL_HATCH
: index
= 5; break;
1965 case wxCROSSDIAG_HATCH
: index
= 6; break;
1967 case wxDOT
: index
= 7; break;
1968 case wxLONG_DASH
: index
= 8; break;
1969 case wxSHORT_DASH
: index
= 9; break;
1970 case wxDOT_DASH
: index
= 10; break;
1972 *pattern
= gPatterns
[index
];
1975 void wxDC::MacInstallPen() const
1977 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1978 //Pattern blackColor;
1979 // if ( m_macPenInstalled )
1981 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1982 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1983 ::RGBForeColor( &forecolor
);
1984 ::RGBBackColor( &backcolor
);
1986 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1987 // null means only one pixel, at whatever resolution
1988 if ( penWidth
== 0 )
1990 ::PenSize(penWidth
, penWidth
);
1992 int penStyle
= m_pen
.GetStyle();
1994 if (penStyle
== wxUSER_DASH
)
1996 // FIXME: there should be exactly 8 items in the dash
1998 int number
= m_pen
.GetDashes(&dash
) ;
2000 for ( int i
= 0 ; i
< 8 ; ++i
)
2002 pat
.pat
[i
] = dash
[index
] ;
2003 if (index
< number
- 1)
2009 wxMacGetPattern(penStyle
, &pat
);
2013 short mode
= patCopy
;
2015 switch( m_logicalFunction
)
2017 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2020 case wxINVERT
: // NOT dst
2021 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2024 case wxXOR
: // src XOR dst
2027 case wxOR_REVERSE
: // src OR (NOT dst)
2030 case wxSRC_INVERT
: // (NOT src)
2033 case wxAND
: // src AND dst
2038 case wxAND_REVERSE
:// src AND (NOT dst)
2039 case wxAND_INVERT
: // (NOT src) AND dst
2040 case wxNO_OP
: // dst
2041 case wxNOR
: // (NOT src) AND (NOT dst)
2042 case wxEQUIV
: // (NOT src) XOR dst
2043 case wxOR_INVERT
: // (NOT src) OR dst
2044 case wxNAND
: // (NOT src) OR (NOT dst)
2045 case wxOR
: // src OR dst
2047 // case wxSRC_OR: // source _bitmap_ OR destination
2048 // case wxSRC_AND: // source _bitmap_ AND destination
2052 m_macPenInstalled
= true ;
2053 m_macBrushInstalled
= false ;
2054 m_macFontInstalled
= false ;
2057 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2059 Pattern whiteColor
;
2060 switch( background
.MacGetBrushKind() )
2062 case kwxMacBrushTheme
:
2064 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2067 case kwxMacBrushThemeBackground
:
2070 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2071 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2074 case kwxMacBrushColour
:
2076 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2077 int brushStyle
= background
.GetStyle();
2078 if (brushStyle
== wxSOLID
)
2079 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2080 else if (background
.IsHatch())
2083 wxMacGetPattern(brushStyle
, &pat
);
2088 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2095 void wxDC::MacInstallBrush() const
2097 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2098 Pattern blackColor
;
2099 // if ( m_macBrushInstalled )
2102 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2103 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2104 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2105 int brushStyle
= m_brush
.GetStyle();
2106 if (brushStyle
== wxSOLID
)
2108 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2110 else if (m_brush
.IsHatch())
2113 wxMacGetPattern(brushStyle
, &pat
);
2116 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2118 // we force this in order to be compliant with wxMSW
2119 backgroundTransparent
= false ;
2120 // for these the text fore (and back for MASK_OPAQUE) colors are used
2121 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2122 int width
= bitmap
->GetWidth() ;
2123 int height
= bitmap
->GetHeight() ;
2124 GWorldPtr gw
= NULL
;
2125 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2126 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2128 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2129 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2130 LockPixels( gwpixmaphandle
) ;
2131 bool isMonochrome
= !IsPortColor( gw
) ;
2132 if ( !isMonochrome
)
2134 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2135 isMonochrome
= true ;
2137 if ( isMonochrome
&& width
== 8 && height
== 8 )
2139 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2140 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2141 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2142 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2143 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2145 for ( int i
= 0 ; i
< 8 ; ++i
)
2147 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2149 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2154 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2155 // caching scheme before putting this into production
2158 PixPatHandle pixpat
= NewPixPat() ;
2159 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2160 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2161 ((**(**pixpat
).patMap
).bounds
.bottom
-
2162 (**(**pixpat
).patMap
).bounds
.top
);
2163 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2164 (**pixpat
).patData
= image
;
2167 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2168 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2169 if ( ctspec
[0].rgb
.red
== 0x0000 )
2171 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2172 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2176 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2177 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2179 ::CTabChanged( ctable
) ;
2181 ::PenPixPat(pixpat
);
2182 m_macForegroundPixMap
= pixpat
;
2184 UnlockPixels( gwpixmaphandle
) ;
2188 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2190 short mode
= patCopy
;
2191 switch( m_logicalFunction
)
2194 if ( backgroundTransparent
)
2199 case wxINVERT
: // NOT dst
2200 if ( !backgroundTransparent
)
2202 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2206 case wxXOR
: // src XOR dst
2209 case wxOR_REVERSE
: // src OR (NOT dst)
2212 case wxSRC_INVERT
: // (NOT src)
2215 case wxAND
: // src AND dst
2220 case wxAND_REVERSE
:// src AND (NOT dst)
2221 case wxAND_INVERT
: // (NOT src) AND dst
2222 case wxNO_OP
: // dst
2223 case wxNOR
: // (NOT src) AND (NOT dst)
2224 case wxEQUIV
: // (NOT src) XOR dst
2225 case wxOR_INVERT
: // (NOT src) OR dst
2226 case wxNAND
: // (NOT src) OR (NOT dst)
2227 case wxOR
: // src OR dst
2229 // case wxSRC_OR: // source _bitmap_ OR destination
2230 // case wxSRC_AND: // source _bitmap_ AND destination
2234 m_macBrushInstalled
= true ;
2235 m_macPenInstalled
= false ;
2236 m_macFontInstalled
= false ;
2239 // ---------------------------------------------------------------------------
2240 // coordinates transformations
2241 // ---------------------------------------------------------------------------
2243 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2245 return ((wxDC
*)this)->XDEV2LOG(x
);
2248 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2250 return ((wxDC
*)this)->YDEV2LOG(y
);
2253 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2255 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2258 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2260 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2263 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2265 return ((wxDC
*)this)->XLOG2DEV(x
);
2268 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2270 return ((wxDC
*)this)->YLOG2DEV(y
);
2273 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2275 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2278 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2280 return ((wxDC
*)this)->YLOG2DEVREL(y
);