1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dc.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #if !wxMAC_USE_CORE_GRAPHICS
21 #include "wx/dcmemory.h"
22 #include "wx/dcprint.h"
25 #include "wx/mac/uma.h"
26 #include "wx/region.h"
36 #include "wx/mac/private.h"
38 #include <ATSUnicode.h>
39 #include <TextCommon.h>
40 #include <TextEncodingConverter.h>
44 // set to 0 if problems arise
45 #define wxMAC_EXPERIMENTAL_DC 1
48 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 const double RAD2DEG
= 180.0 / M_PI
;
55 const short kEmulatedMode
= -1 ;
56 const short kUnsupportedMode
= -2 ;
58 extern TECObjectRef s_TECNativeCToUnicode
;
61 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
62 m_ph( (GrafPtr
) dc
->m_macPort
)
64 wxASSERT( dc
->Ok() ) ;
66 dc
->MacSetupPort(&m_ph
) ;
69 wxMacPortSetter::~wxMacPortSetter()
71 m_dc
->MacCleanupPort(&m_ph
) ;
74 #if wxMAC_EXPERIMENTAL_DC
75 class wxMacFastPortSetter
78 wxMacFastPortSetter( const wxDC
*dc
)
80 wxASSERT( dc
->Ok() ) ;
81 m_swapped
= QDSwapPort( (GrafPtr
) dc
->m_macPort
, &m_oldPort
) ;
82 m_clipRgn
= NewRgn() ;
83 GetClip( m_clipRgn
) ;
85 dc
->MacSetupPort( NULL
) ;
88 ~wxMacFastPortSetter()
90 // SetPort( (GrafPtr) m_dc->m_macPort ) ;
91 SetClip( m_clipRgn
) ;
93 SetPort( m_oldPort
) ;
94 m_dc
->MacCleanupPort( NULL
) ;
95 DisposeRgn( m_clipRgn
) ;
100 RgnHandle m_clipRgn
;
106 typedef wxMacPortSetter wxMacFastPortSetter
;
109 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
110 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
112 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
113 m_formerClip
= NewRgn() ;
114 m_newClip
= NewRgn() ;
115 GetClip( m_formerClip
) ;
119 // guard against half constructed objects, this just leads to a empty clip
120 if ( win
->GetPeer() )
123 win
->MacWindowToRootWindow( &x
, &y
) ;
125 // get area including focus rect
126 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
127 if ( !EmptyRgn( m_newClip
) )
128 OffsetRgn( m_newClip
, x
, y
) ;
131 SetClip( m_newClip
) ;
135 wxMacWindowClipper::~wxMacWindowClipper()
137 SetPort( m_newPort
) ;
138 SetClip( m_formerClip
) ;
139 DisposeRgn( m_newClip
) ;
140 DisposeRgn( m_formerClip
) ;
143 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
144 wxMacWindowClipper( win
)
146 // the port is already set at this point
147 m_newPort
= (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
148 GetThemeDrawingState( &m_themeDrawingState
) ;
151 wxMacWindowStateSaver::~wxMacWindowStateSaver()
153 SetPort( m_newPort
) ;
154 SetThemeDrawingState( m_themeDrawingState
, true ) ;
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
161 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
162 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
167 // this function emulates all wx colour manipulations, used to verify the implementation
168 // by setting the mode in the blitting functions to kEmulatedMode
169 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
171 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
173 switch ( logical_func
)
175 case wxAND
: // src AND dst
176 dstColor
.red
= dstColor
.red
& srcColor
.red
;
177 dstColor
.green
= dstColor
.green
& srcColor
.green
;
178 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
181 case wxAND_INVERT
: // (NOT src) AND dst
182 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
183 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
184 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
187 case wxAND_REVERSE
:// src AND (NOT dst)
188 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
189 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
190 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
200 dstColor
.red
= srcColor
.red
;
201 dstColor
.green
= srcColor
.green
;
202 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
;
211 case wxINVERT
: // NOT dst
212 dstColor
.red
= ~dstColor
.red
;
213 dstColor
.green
= ~dstColor
.green
;
214 dstColor
.blue
= ~dstColor
.blue
;
217 case wxNAND
: // (NOT src) OR (NOT dst)
218 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
219 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
220 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
223 case wxNOR
: // (NOT src) AND (NOT dst)
224 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
225 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
226 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
229 case wxOR
: // src OR dst
230 dstColor
.red
= dstColor
.red
| srcColor
.red
;
231 dstColor
.green
= dstColor
.green
| srcColor
.green
;
232 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
235 case wxOR_INVERT
: // (NOT src) OR dst
236 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
237 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
238 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
241 case wxOR_REVERSE
: // src OR (NOT dst)
242 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
243 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
244 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
248 dstColor
.red
= 0xFFFF ;
249 dstColor
.green
= 0xFFFF ;
250 dstColor
.blue
= 0xFFFF ;
253 case wxSRC_INVERT
: // (NOT src)
254 dstColor
.red
= ~srcColor
.red
;
255 dstColor
.green
= ~srcColor
.green
;
256 dstColor
.blue
= ~srcColor
.blue
;
259 case wxXOR
: // src XOR dst
260 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
261 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
262 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
275 m_mm_to_pix_x
= mm2pt
;
276 m_mm_to_pix_y
= mm2pt
;
277 m_internalDeviceOriginX
= 0;
278 m_internalDeviceOriginY
= 0;
279 m_externalDeviceOriginX
= 0;
280 m_externalDeviceOriginY
= 0;
281 m_logicalScaleX
= 1.0;
282 m_logicalScaleY
= 1.0;
287 m_needComputeScaleX
= false;
288 m_needComputeScaleY
= false;
291 m_macFontInstalled
= false ;
292 m_macBrushInstalled
= false ;
293 m_macPenInstalled
= false ;
294 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
295 m_macBoundaryClipRgn
= NewRgn() ;
296 m_macCurrentClipRgn
= NewRgn() ;
297 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
298 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
299 m_pen
= *wxBLACK_PEN
;
300 m_font
= *wxNORMAL_FONT
;
301 m_brush
= *wxWHITE_BRUSH
;
304 // needed to debug possible errors with two active drawing methods at the same time on
306 m_macCurrentPortStateHelper
= NULL
;
309 m_macATSUIStyle
= NULL
;
310 m_macAliasWasEnabled
= false;
311 m_macForegroundPixMap
= NULL
;
312 m_macBackgroundPixMap
= NULL
;
317 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
318 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
321 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
324 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
325 m_macCurrentPortStateHelper
= help
;
328 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
330 #if ! wxMAC_EXPERIMENTAL_DC
331 m_macFontInstalled
= false ;
332 m_macBrushInstalled
= false ;
333 m_macPenInstalled
= false ;
337 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
340 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
341 m_macCurrentPortStateHelper
= NULL
;
344 if ( m_macATSUIStyle
)
346 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
347 m_macATSUIStyle
= NULL
;
350 if ( m_macAliasWasEnabled
)
352 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
353 m_macAliasWasEnabled
= false ;
356 if ( m_macForegroundPixMap
)
359 ::PenPat(GetQDGlobalsBlack(&blackColor
));
360 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
361 m_macForegroundPixMap
= NULL
;
364 if ( m_macBackgroundPixMap
)
367 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
368 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
369 m_macBackgroundPixMap
= NULL
;
373 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
375 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawBitmap - invalid DC") );
376 wxCHECK_RET( bmp
.Ok(), wxT("wxDC::DoDrawBitmap - invalid bitmap") );
378 wxMacFastPortSetter
helper(this) ;
379 wxCoord xx
= XLOG2DEVMAC(x
);
380 wxCoord yy
= YLOG2DEVMAC(y
);
381 wxCoord w
= bmp
.GetWidth();
382 wxCoord h
= bmp
.GetHeight();
383 wxCoord ww
= XLOG2DEVREL(w
);
384 wxCoord hh
= YLOG2DEVREL(h
);
386 // Set up drawing mode
387 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
388 //m_logicalFunction == wxCLEAR ? WHITENESS :
389 //m_logicalFunction == wxSET ? BLACKNESS :
390 m_logicalFunction
== wxINVERT
? hilite
:
391 //m_logicalFunction == wxAND ? MERGECOPY :
392 m_logicalFunction
== wxOR
? srcOr
:
393 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
394 m_logicalFunction
== wxXOR
? srcXor
:
395 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
396 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
397 //m_logicalFunction == wxSRC_OR ? srcOr :
398 //m_logicalFunction == wxSRC_AND ? SRCAND :
401 GWorldPtr maskworld
= NULL
;
402 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP((WXHBITMAP
*)&maskworld
) );
403 PixMapHandle bmappixels
;
405 // Set foreground and background colours (for bitmaps depth = 1)
406 if (bmp
.GetDepth() == 1)
408 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
409 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
415 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
416 RGBColor black
= { 0, 0, 0 } ;
417 RGBForeColor( &black
) ;
418 RGBBackColor( &white
) ;
420 bmappixels
= GetGWorldPixMap( bmapworld
) ;
422 wxCHECK_RET(LockPixels(bmappixels
),
423 wxT("wxDC::DoDrawBitmap - failed to lock pixels"));
425 Rect source
= { 0, 0, h
, w
};
426 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
427 if ( useMask
&& maskworld
)
429 if ( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
))))
433 GetPortBitMapForCopyBits(bmapworld
),
434 GetPortBitMapForCopyBits(MAC_WXHBITMAP(maskworld
)),
435 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
436 &source
, &source
, &dest
, mode
, NULL
438 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
)));
443 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
444 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
445 &source
, &dest
, mode
, NULL
) ;
447 UnlockPixels( bmappixels
) ;
449 m_macPenInstalled
= false ;
450 m_macBrushInstalled
= false ;
451 m_macFontInstalled
= false ;
454 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
456 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawIcon - invalid DC"));
457 wxCHECK_RET(icon
.Ok(), wxT("wxDC::DoDrawIcon - invalid icon"));
459 wxMacFastPortSetter
helper(this) ;
461 wxCoord xx
= XLOG2DEVMAC(x
);
462 wxCoord yy
= YLOG2DEVMAC(y
);
463 wxCoord w
= icon
.GetWidth();
464 wxCoord h
= icon
.GetHeight();
465 wxCoord ww
= XLOG2DEVREL(w
);
466 wxCoord hh
= YLOG2DEVREL(h
);
468 Rect r
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
469 PlotIconRef( &r
, kAlignNone
, kTransformNone
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
472 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
474 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion - invalid DC"));
476 wxCoord xx
, yy
, ww
, hh
;
479 ww
= XLOG2DEVREL(width
);
480 hh
= YLOG2DEVREL(height
);
482 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
483 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
486 m_clipX1
= wxMax( m_clipX1
, xx
);
487 m_clipY1
= wxMax( m_clipY1
, yy
);
488 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
489 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
501 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
503 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegionAsRegion - invalid DC"));
505 wxMacFastPortSetter
helper(this) ;
507 region
.GetBox( x
, y
, w
, h
);
508 wxCoord xx
, yy
, ww
, hh
;
514 // if we have a scaling that we cannot map onto native regions
515 // we must use the box
516 if ( ww
!= w
|| hh
!= h
)
518 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
522 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
523 if ( xx
!= x
|| yy
!= y
)
524 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
526 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
529 m_clipX1
= wxMax( m_clipX1
, xx
);
530 m_clipY1
= wxMax( m_clipY1
, yy
);
531 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
) );
532 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
) );
545 void wxDC::DestroyClippingRegion()
547 wxMacFastPortSetter
helper(this) ;
549 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
553 void wxDC::DoGetSizeMM( int* width
, int* height
) const
559 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
561 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
564 void wxDC::SetTextForeground( const wxColour
&col
)
566 wxCHECK_RET(Ok(), wxT("wxDC::SetTextForeground - invalid DC"));
568 m_textForegroundColour
= col
;
569 m_macFontInstalled
= false ;
572 void wxDC::SetTextBackground( const wxColour
&col
)
574 wxCHECK_RET(Ok(), wxT("wxDC::SetTextBackground - invalid DC"));
576 m_textBackgroundColour
= col
;
577 m_macFontInstalled
= false ;
580 void wxDC::SetMapMode( int mode
)
585 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
589 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
593 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
597 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
602 SetLogicalScale( 1.0, 1.0 );
606 if (mode
!= wxMM_TEXT
)
608 m_needComputeScaleX
= true;
609 m_needComputeScaleY
= true;
613 void wxDC::SetUserScale( double x
, double y
)
615 // allow negative ? -> no
618 ComputeScaleAndOrigin();
621 void wxDC::SetLogicalScale( double x
, double y
)
626 ComputeScaleAndOrigin();
629 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
631 // is this still correct ?
632 m_logicalOriginX
= x
* m_signX
;
633 m_logicalOriginY
= y
* m_signY
;
634 ComputeScaleAndOrigin();
637 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
639 m_externalDeviceOriginX
= x
;
640 m_externalDeviceOriginY
= y
;
641 ComputeScaleAndOrigin();
644 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
646 m_signX
= (xLeftRight
? 1 : -1);
647 m_signY
= (yBottomUp
? -1 : 1);
648 ComputeScaleAndOrigin();
651 wxSize
wxDC::GetPPI() const
653 return wxSize(72, 72);
656 int wxDC::GetDepth() const
658 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
659 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
664 void wxDC::ComputeScaleAndOrigin()
666 // CMB: copy scale to see if it changes
667 double origScaleX
= m_scaleX
;
668 double origScaleY
= m_scaleY
;
669 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
670 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
671 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
672 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
674 // CMB: if scale has changed call SetPen to recalulate the line width
675 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
677 // this is a bit artificial, but we need to force wxDC to think
678 // the pen has changed
685 void wxDC::SetPalette( const wxPalette
& palette
)
689 void wxDC::SetBackgroundMode( int mode
)
691 m_backgroundMode
= mode
;
694 void wxDC::SetFont( const wxFont
&font
)
697 m_macFontInstalled
= false ;
700 void wxDC::SetPen( const wxPen
&pen
)
706 m_macPenInstalled
= false ;
709 void wxDC::SetBrush( const wxBrush
&brush
)
711 if (m_brush
== brush
)
715 m_macBrushInstalled
= false ;
718 void wxDC::SetBackground( const wxBrush
&brush
)
720 if (m_backgroundBrush
== brush
)
723 m_backgroundBrush
= brush
;
724 if (m_backgroundBrush
.Ok())
725 m_macBrushInstalled
= false ;
728 void wxDC::SetLogicalFunction( int function
)
730 if (m_logicalFunction
== function
)
733 m_logicalFunction
= function
;
734 m_macFontInstalled
= false ;
735 m_macBrushInstalled
= false ;
736 m_macPenInstalled
= false ;
739 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
740 const wxColour
& col
, int style
);
742 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
743 const wxColour
& col
, int style
)
745 return wxDoFloodFill(this, x
, y
, col
, style
);
748 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
750 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel - invalid DC") );
752 wxMacFastPortSetter
helper(this) ;
754 // NOTE: Get/SetCPixel are slow!
756 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
758 // convert from Mac colour to wx
759 col
->Set( colour
.red
>> 8, colour
.green
>> 8, colour
.blue
>> 8);
764 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
766 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLine - invalid DC"));
768 wxMacFastPortSetter
helper(this) ;
770 if (m_pen
.GetStyle() != wxTRANSPARENT
)
773 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
774 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
775 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
776 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
777 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
778 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
780 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
781 (m_pen
.GetWidth() <= 1))
783 // Implement LAST_NOT for MAC at least for
784 // orthogonal lines. RR.
807 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
809 wxCHECK_RET(Ok(), wxT("wxDC::DoCrossHair - invalid DC"));
811 wxMacFastPortSetter
helper(this) ;
813 if (m_pen
.GetStyle() != wxTRANSPARENT
)
818 wxCoord xx
= XLOG2DEVMAC(x
);
819 wxCoord yy
= YLOG2DEVMAC(y
);
822 ::MoveTo( XLOG2DEVMAC(0), yy
);
823 ::LineTo( XLOG2DEVMAC(w
), yy
);
824 ::MoveTo( xx
, YLOG2DEVMAC(0) );
825 ::LineTo( xx
, YLOG2DEVMAC(h
) );
826 CalcBoundingBox(x
, y
);
827 CalcBoundingBox(x
+ w
, y
+ h
);
832 * To draw arcs properly the angles need to be converted from the WX style:
833 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
834 * a normal axis on paper).
837 * Angles start on the +ve y axis and go clockwise.
840 static double wxConvertWXangleToMACangle(double angle
)
842 double newAngle
= 90 - angle
;
844 while ( newAngle
> 360 )
846 while ( newAngle
< 0 )
852 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
853 wxCoord x2
, wxCoord y2
,
854 wxCoord xc
, wxCoord yc
)
856 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc - invalid DC"));
858 wxMacFastPortSetter
helper(this) ;
860 wxCoord xx1
= XLOG2DEVMAC(x1
);
861 wxCoord yy1
= YLOG2DEVMAC(y1
);
862 wxCoord xx2
= XLOG2DEVMAC(x2
);
863 wxCoord yy2
= YLOG2DEVMAC(y2
);
864 wxCoord xxc
= XLOG2DEVMAC(xc
);
865 wxCoord yyc
= YLOG2DEVMAC(yc
);
867 double dx
= xx1
- xxc
;
868 double dy
= yy1
- yyc
;
869 double radius
= sqrt((double)(dx
* dx
+ dy
* dy
));
870 wxCoord rad
= (wxCoord
)radius
;
871 double radius1
, radius2
;
873 if (xx1
== xx2
&& yy1
== yy2
)
878 else if (radius
== 0.0)
880 radius1
= radius2
= 0.0;
884 radius1
= (xx1
- xxc
== 0) ?
885 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
886 -atan2(double(yy1
- yyc
), double(xx1
- xxc
)) * RAD2DEG
;
887 radius2
= (xx2
- xxc
== 0) ?
888 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
889 -atan2(double(yy2
- yyc
), double(xx2
- xxc
)) * RAD2DEG
;
892 wxCoord alpha2
= wxCoord(radius2
- radius1
);
893 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
897 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
899 if (m_brush
.GetStyle() != wxTRANSPARENT
)
902 PaintArc(&r
, alpha1
, alpha2
);
905 if (m_pen
.GetStyle() != wxTRANSPARENT
)
908 FrameArc(&r
, alpha1
, alpha2
);
912 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
913 double sa
, double ea
)
915 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc - invalid DC"));
916 wxMacFastPortSetter
helper(this) ;
919 // Order important Mac in opposite direction to wx
920 // we have to make sure that the filling is always counter-clockwise
921 double angle
= sa
- ea
;
925 wxCoord xx
= XLOG2DEVMAC(x
);
926 wxCoord yy
= YLOG2DEVMAC(y
);
927 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
928 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
930 // handle -ve width and/or height
943 sa
= wxConvertWXangleToMACangle(sa
);
949 if (m_brush
.GetStyle() != wxTRANSPARENT
)
952 PaintArc(&r
, (short)sa
, (short)angle
);
955 if (m_pen
.GetStyle() != wxTRANSPARENT
)
958 FrameArc(&r
, (short)sa
, (short)angle
);
962 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
964 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPoint - invalid DC"));
966 wxMacFastPortSetter
helper(this) ;
968 if (m_pen
.GetStyle() != wxTRANSPARENT
)
970 wxCoord xx1
= XLOG2DEVMAC(x
);
971 wxCoord yy1
= YLOG2DEVMAC(y
);
972 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
974 // NOTE: Get/SetCPixel are slow!
975 ::SetCPixel( xx1
, yy1
, &pencolor
) ;
976 CalcBoundingBox(x
, y
);
980 void wxDC::DoDrawLines(int n
, wxPoint points
[],
981 wxCoord xoffset
, wxCoord yoffset
)
983 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLines - invalid DC"));
985 if (m_pen
.GetStyle() == wxTRANSPARENT
)
988 wxMacFastPortSetter
helper(this) ;
991 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
992 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
994 wxCoord x1
, x2
, y1
, y2
;
995 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
996 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
998 ::MoveTo( x1
- offset
, y1
- offset
);
999 for (int i
= 0; i
< n
-1; i
++)
1001 x2
= XLOG2DEVMAC(points
[i
+ 1].x
+ xoffset
);
1002 y2
= YLOG2DEVMAC(points
[i
+ 1].y
+ yoffset
);
1003 ::LineTo( x2
- offset
, y2
- offset
);
1007 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1008 wxCoord xoffset
, wxCoord yoffset
,
1011 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPolygon - invalid DC"));
1013 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
1016 wxMacFastPortSetter
helper(this) ;
1018 wxCoord x1
, x2
, y1
, y2
;
1019 PolyHandle polygon
= OpenPoly();
1020 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1021 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1024 for (int i
= 1; i
< n
; i
++)
1026 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1027 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1031 // close the polyline if necessary
1032 if ( x1
!= x2
|| y1
!= y2
)
1033 ::LineTo( x1
, y1
) ;
1036 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1039 ::PaintPoly( polygon
);
1042 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1045 ::FramePoly( polygon
) ;
1048 KillPoly( polygon
);
1051 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1053 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRectangle - invalid DC"));
1055 wxMacFastPortSetter
helper(this) ;
1057 wxCoord xx
= XLOG2DEVMAC(x
);
1058 wxCoord yy
= YLOG2DEVMAC(y
);
1059 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1060 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1062 // CMB: draw nothing if transformed w or h is 0
1063 if (ww
== 0 || hh
== 0)
1066 // CMB: handle -ve width and/or height
1079 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1081 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1084 ::PaintRect( &rect
) ;
1087 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1090 ::FrameRect( &rect
) ;
1094 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1095 wxCoord width
, wxCoord height
,
1098 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRoundedRectangle - invalid DC"));
1100 wxMacFastPortSetter
helper(this) ;
1102 radius
= - radius
* ((width
< height
) ? width
: height
);
1103 wxCoord xx
= XLOG2DEVMAC(x
);
1104 wxCoord yy
= YLOG2DEVMAC(y
);
1105 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1106 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1108 // CMB: draw nothing if transformed w or h is 0
1109 if (ww
== 0 || hh
== 0)
1112 // CMB: handle -ve width and/or height
1125 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1127 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1130 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1133 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1136 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1140 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1142 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllipse - invalid DC"));
1144 wxMacFastPortSetter
helper(this) ;
1146 wxCoord xx
= XLOG2DEVMAC(x
);
1147 wxCoord yy
= YLOG2DEVMAC(y
);
1148 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1149 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1151 // CMB: draw nothing if transformed w or h is 0
1152 if (ww
== 0 || hh
== 0)
1155 // CMB: handle -ve width and/or height
1168 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1170 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1173 ::PaintOval( &rect
) ;
1176 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1179 ::FrameOval( &rect
) ;
1183 bool wxDC::CanDrawBitmap(void) const
1188 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1189 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1190 wxCoord xsrcMask
, wxCoord ysrcMask
)
1192 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit - invalid DC"));
1193 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit - invalid source DC"));
1195 if ( logical_func
== wxNO_OP
)
1198 if (xsrcMask
== -1 && ysrcMask
== -1)
1204 // correct the parameter in case this dc does not have a mask at all
1205 if ( useMask
&& !source
->m_macMask
)
1208 Rect srcrect
, dstrect
;
1209 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1210 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1211 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1212 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1213 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1214 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1215 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1216 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1217 short mode
= kUnsupportedMode
;
1218 bool invertDestinationFirst
= false ;
1220 switch ( logical_func
)
1222 case wxAND
: // src AND dst
1223 mode
= adMin
; // ok
1226 case wxAND_INVERT
: // (NOT src) AND dst
1227 mode
= notSrcOr
; // ok
1230 case wxAND_REVERSE
:// src AND (NOT dst)
1231 invertDestinationFirst
= true ;
1236 mode
= kEmulatedMode
;
1240 mode
= srcCopy
; // ok
1243 case wxEQUIV
: // (NOT src) XOR dst
1244 mode
= srcXor
; // ok
1247 case wxINVERT
: // NOT dst
1248 mode
= kEmulatedMode
; //or hilite ;
1251 case wxNAND
: // (NOT src) OR (NOT dst)
1252 invertDestinationFirst
= true ;
1256 case wxNOR
: // (NOT src) AND (NOT dst)
1257 invertDestinationFirst
= true ;
1261 case wxNO_OP
: // dst
1262 mode
= kEmulatedMode
; // this has already been handled upon entry
1265 case wxOR
: // src OR dst
1269 case wxOR_INVERT
: // (NOT src) OR dst
1273 case wxOR_REVERSE
: // src OR (NOT dst)
1274 invertDestinationFirst
= true ;
1279 mode
= kEmulatedMode
;
1282 case wxSRC_INVERT
: // (NOT src)
1283 mode
= notSrcCopy
; // ok
1286 case wxXOR
: // src XOR dst
1287 mode
= notSrcXor
; // ok
1294 if ( mode
== kUnsupportedMode
)
1296 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1301 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1302 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1303 if ( LockPixels(bmappixels
) )
1305 wxMacFastPortSetter
helper(this) ;
1307 if ( source
->GetDepth() == 1 )
1309 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1310 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1314 // the modes need this, otherwise we'll end up having really nice colors...
1315 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1316 RGBColor black
= { 0, 0, 0 } ;
1318 RGBForeColor( &black
) ;
1319 RGBBackColor( &white
) ;
1322 if ( useMask
&& source
->m_macMask
)
1324 if ( mode
== srcCopy
)
1326 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1328 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1329 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1330 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1331 &srcrect
, &srcrect
, &dstrect
) ;
1332 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1337 RgnHandle clipRgn
= NewRgn() ;
1338 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1339 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1340 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1341 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1343 if ( mode
== kEmulatedMode
)
1347 ::PenPat(GetQDGlobalsBlack(&pat
));
1348 if ( logical_func
== wxSET
)
1350 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1351 ::RGBForeColor( &col
) ;
1352 ::PaintRgn( clipRgn
) ;
1354 else if ( logical_func
== wxCLEAR
)
1356 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1357 ::RGBForeColor( &col
) ;
1358 ::PaintRgn( clipRgn
) ;
1360 else if ( logical_func
== wxINVERT
)
1362 MacInvertRgn( clipRgn
) ;
1366 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1368 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1370 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1371 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1372 if ( PtInRgn( dstPoint
, clipRgn
) )
1374 RGBColor srcColor
, dstColor
;
1376 // NOTE: Get/SetCPixel are slow!
1377 SetPort( (GrafPtr
) sourcePort
) ;
1378 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1379 SetPort( (GrafPtr
) m_macPort
) ;
1380 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1381 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1382 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1390 if ( invertDestinationFirst
)
1391 MacInvertRgn( clipRgn
) ;
1393 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1394 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1395 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1398 DisposeRgn( clipRgn
) ;
1403 RgnHandle clipRgn
= NewRgn() ;
1404 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1406 if ( mode
== kEmulatedMode
)
1410 ::PenPat(GetQDGlobalsBlack(&pat
));
1411 if ( logical_func
== wxSET
)
1413 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1414 ::RGBForeColor( &col
) ;
1415 ::PaintRgn( clipRgn
) ;
1417 else if ( logical_func
== wxCLEAR
)
1419 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1421 ::RGBForeColor( &col
) ;
1422 ::PaintRgn( clipRgn
) ;
1424 else if ( logical_func
== wxINVERT
)
1426 MacInvertRgn( clipRgn
) ;
1430 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1432 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1434 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1435 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1437 RGBColor srcColor
, dstColor
;
1439 // NOTE: Get/SetCPixel are slow!
1440 SetPort( (GrafPtr
) sourcePort
) ;
1441 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1442 SetPort( (GrafPtr
) m_macPort
) ;
1443 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1444 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1445 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1453 if ( invertDestinationFirst
)
1454 MacInvertRgn( clipRgn
) ;
1456 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1457 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1458 &srcrect
, &dstrect
, mode
, NULL
) ;
1461 DisposeRgn( clipRgn
) ;
1464 UnlockPixels( bmappixels
) ;
1467 m_macPenInstalled
= false ;
1468 m_macBrushInstalled
= false ;
1469 m_macFontInstalled
= false ;
1474 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1477 // TODO: support text background color (only possible by hand, ATSUI does not support it)
1478 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText - invalid DC") );
1483 wxMacFastPortSetter
helper(this) ;
1489 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1490 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1491 m_macAliasWasEnabled
= true ;
1495 OSStatus status
= noErr
;
1496 ATSUTextLayout atsuLayout
;
1497 UniCharCount chars
= str
.length() ;
1498 UniChar
* ubuf
= NULL
;
1500 #if SIZEOF_WCHAR_T == 4
1501 wxMBConvUTF16 converter
;
1503 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1504 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1505 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1507 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1508 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1509 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1510 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1512 chars
= unicharlen
/ 2 ;
1515 ubuf
= (UniChar
*) str
.wc_str() ;
1517 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1518 chars
= wxWcslen( wchar
.data() ) ;
1519 ubuf
= (UniChar
*) wchar
.data() ;
1523 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1524 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1526 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1528 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1529 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1531 int iAngle
= int( angle
);
1532 int drawX
= XLOG2DEVMAC(x
) ;
1533 int drawY
= YLOG2DEVMAC(y
) ;
1535 ATSUTextMeasurement textBefore
, textAfter
;
1536 ATSUTextMeasurement ascent
, descent
;
1538 if ( abs(iAngle
) > 0 )
1540 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1542 ATSUAttributeTag atsuTags
[] =
1544 kATSULineRotationTag
,
1546 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1550 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1555 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1556 atsuTags
, atsuSizes
, atsuValues
) ;
1559 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1560 &textBefore
, &textAfter
, &ascent
, &descent
);
1562 drawX
+= (int)(sin(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1563 drawY
+= (int)(cos(angle
/ RAD2DEG
) * FixedToInt(ascent
));
1564 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1565 IntToFixed(drawX
) , IntToFixed(drawY
) );
1567 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1570 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1571 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1572 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1574 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1575 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1576 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1577 ::ATSUDisposeTextLayout(atsuLayout
);
1579 #if SIZEOF_WCHAR_T == 4
1584 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1586 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText - invalid DC"));
1588 wxMacFastPortSetter
helper(this) ;
1589 long xx
= XLOG2DEVMAC(x
);
1590 long yy
= YLOG2DEVMAC(y
);
1593 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1594 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1595 useDrawThemeText
= false ;
1601 ::GetFontInfo( &fi
) ;
1604 if ( !useDrawThemeText
)
1610 ::TextMode( (m_backgroundMode
== wxTRANSPARENT
) ? srcOr
: srcCopy
) ;
1611 ::MoveTo( xx
, yy
);
1615 wxString linetext
= strtext
;
1618 if ( useDrawThemeText
)
1621 yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
), xx
,
1622 yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1623 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1625 if ( m_backgroundMode
!= wxTRANSPARENT
)
1627 Point bounds
= {0, 0} ;
1628 Rect background
= frame
;
1630 ::GetThemeTextDimensions( mString
,
1631 m_font
.MacGetThemeFontID() ,
1636 background
.right
= background
.left
+ bounds
.h
;
1637 background
.bottom
= background
.top
+ bounds
.v
;
1638 ::EraseRect( &background
) ;
1641 ::DrawThemeTextBox( mString
,
1642 m_font
.MacGetThemeFontID() ,
1652 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1653 ::DrawText( text
, 0 , strlen(text
) ) ;
1657 ::TextMode( srcOr
) ;
1660 bool wxDC::CanGetTextExtent() const
1662 wxCHECK_MSG(Ok(), false, wxT("wxDC::CanGetTextExtent - invalid DC"));
1667 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1668 wxCoord
*descent
, wxCoord
*externalLeading
,
1669 wxFont
*theFont
) const
1671 wxCHECK_RET(Ok(), wxT("wxDC::DoGetTextExtent - invalid DC"));
1673 wxMacFastPortSetter
helper(this) ;
1674 wxFont formerFont
= m_font
;
1677 // work around the constness
1678 *((wxFont
*)(&m_font
)) = *theFont
;
1683 ::GetFontInfo( &fi
) ;
1686 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1687 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1688 useGetThemeText
= false ;
1692 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1694 *descent
=YDEV2LOGREL( fi
.descent
);
1695 if ( externalLeading
)
1696 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1702 wxString linetext
= strtext
;
1704 if ( useGetThemeText
)
1706 Point bounds
= {0, 0} ;
1708 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1709 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1710 ::GetThemeTextDimensions( mString
,
1716 curwidth
= bounds
.h
;
1720 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1721 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1724 if ( curwidth
> *width
)
1725 *width
= XDEV2LOGREL( curwidth
) ;
1730 // work around the constness
1731 *((wxFont
*)(&m_font
)) = formerFont
;
1732 m_macFontInstalled
= false ;
1736 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1738 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoGetPartialTextExtents - invalid DC"));
1741 widths
.Add(0, text
.length());
1743 if (text
.length() == 0)
1746 wxMacFastPortSetter
helper(this) ;
1750 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1751 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1752 useGetThemeText
= false ;
1754 if ( useGetThemeText
)
1756 // If anybody knows how to do this more efficiently yet still handle
1757 // the fractional glyph widths that may be present when using AA
1758 // fonts, please change it. Currently it is measuring from the
1759 // beginning of the string for each succeeding substring, which is much
1760 // slower than this should be.
1761 for (size_t i
=0; i
<text
.length(); i
++)
1763 wxString
str(text
.Left(i
+ 1));
1764 Point bounds
= {0, 0};
1766 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1768 ::GetThemeTextDimensions( mString
,
1769 m_font
.MacGetThemeFontID(),
1774 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1780 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1781 size_t len
= strlen(buff
);
1782 short* measurements
= new short[len
+1];
1783 MeasureText(len
, buff
.data(), measurements
);
1785 // Copy to widths, starting at measurements[1]
1786 // NOTE: this doesn't take into account any multi-byte characters
1787 // in buff, it probably should...
1788 for (size_t i
=0; i
<text
.length(); i
++)
1789 widths
[i
] = XDEV2LOGREL(measurements
[i
+ 1]);
1791 delete [] measurements
;
1797 wxCoord
wxDC::GetCharWidth(void) const
1799 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharWidth - invalid DC"));
1801 wxMacFastPortSetter
helper(this) ;
1803 const char text
[] = "g" ;
1808 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1809 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1810 useGetThemeText
= false ;
1812 if ( useGetThemeText
)
1814 Point bounds
= {0, 0} ;
1816 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1817 ::GetThemeTextDimensions( mString
,
1818 m_font
.MacGetThemeFontID(),
1823 CFRelease( mString
) ;
1829 width
= ::TextWidth( text
, 0 , 1 ) ;
1832 return YDEV2LOGREL(width
) ;
1835 wxCoord
wxDC::GetCharHeight(void) const
1837 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharHeight - invalid DC"));
1839 wxMacFastPortSetter
helper(this) ;
1842 ::GetFontInfo( &fi
) ;
1844 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1847 void wxDC::Clear(void)
1849 wxCHECK_RET(Ok(), wxT("wxDC::Clear - invalid DC"));
1851 wxMacFastPortSetter
helper(this) ;
1852 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1854 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1857 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1858 ::EraseRect( &rect
) ;
1862 void wxDC::MacInstallFont() const
1864 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1866 // if ( m_macFontInstalled )
1869 Pattern blackColor
;
1870 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1871 if ( m_backgroundMode
!= wxTRANSPARENT
)
1873 Pattern whiteColor
;
1874 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1877 wxASSERT( m_font
.Ok() ) ;
1879 ::TextFont( m_font
.MacGetFontNum() ) ;
1880 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1881 ::TextFace( m_font
.MacGetFontStyle() ) ;
1882 m_macFontInstalled
= true ;
1883 m_macBrushInstalled
= false ;
1884 m_macPenInstalled
= false ;
1885 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1886 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1887 ::RGBForeColor( &forecolor
);
1888 ::RGBBackColor( &backcolor
);
1891 short mode
= patCopy
;
1892 switch ( m_logicalFunction
)
1898 case wxINVERT
: // NOT dst
1899 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1903 case wxXOR
: // src XOR dst
1907 case wxOR_REVERSE
: // src OR (NOT dst)
1911 case wxSRC_INVERT
: // (NOT src)
1915 case wxAND
: // src AND dst
1919 // TODO: unsupported
1921 case wxAND_REVERSE
:// src AND (NOT dst)
1922 case wxAND_INVERT
: // (NOT src) AND dst
1923 case wxNO_OP
: // dst
1924 case wxNOR
: // (NOT src) AND (NOT dst)
1925 case wxEQUIV
: // (NOT src) XOR dst
1926 case wxOR_INVERT
: // (NOT src) OR dst
1927 case wxNAND
: // (NOT src) OR (NOT dst)
1928 case wxOR
: // src OR dst
1930 // case wxSRC_OR: // source _bitmap_ OR destination
1931 // case wxSRC_AND: // source _bitmap_ AND destination
1939 OSStatus status
= noErr
;
1940 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1941 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1943 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1944 ATSUAttributeTag atsuTags
[] =
1948 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1952 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1957 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1958 atsuTags
, atsuSizes
, atsuValues
);
1960 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") ) ;
1963 Pattern gPatterns
[] =
1966 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1967 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1968 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1969 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1970 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1971 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1972 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1975 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1976 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1977 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1978 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1981 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1983 int index
= 0; // solid pattern by default
1987 case wxBDIAGONAL_HATCH
: index
= 1; break;
1988 case wxFDIAGONAL_HATCH
: index
= 2; break;
1989 case wxCROSS_HATCH
: index
= 3; break;
1990 case wxHORIZONTAL_HATCH
: index
= 4; break;
1991 case wxVERTICAL_HATCH
: index
= 5; break;
1992 case wxCROSSDIAG_HATCH
: index
= 6; break;
1995 case wxDOT
: index
= 7; break;
1996 case wxLONG_DASH
: index
= 8; break;
1997 case wxSHORT_DASH
: index
= 9; break;
1998 case wxDOT_DASH
: index
= 10; break;
2004 *pattern
= gPatterns
[index
];
2007 void wxDC::MacInstallPen() const
2009 wxCHECK_RET(Ok(), wxT("wxDC::MacInstallPen - invalid DC"));
2011 //Pattern blackColor;
2012 // if ( m_macPenInstalled )
2015 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
2016 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
2017 ::RGBForeColor( &forecolor
);
2018 ::RGBBackColor( &backcolor
);
2021 // null means only one pixel, at whatever resolution
2022 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ;
2023 if ( penWidth
== 0 )
2025 ::PenSize(penWidth
, penWidth
);
2028 int penStyle
= m_pen
.GetStyle();
2029 if (penStyle
== wxUSER_DASH
)
2031 // FIXME: there should be exactly 8 items in the dash
2033 int number
= m_pen
.GetDashes(&dash
) ;
2035 for ( int i
= 0 ; i
< 8 ; ++i
)
2037 pat
.pat
[i
] = dash
[index
] ;
2038 if (index
< number
- 1)
2044 wxMacGetPattern(penStyle
, &pat
);
2049 short mode
= patCopy
;
2050 switch ( m_logicalFunction
)
2052 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2056 case wxINVERT
: // NOT dst
2057 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2061 case wxXOR
: // src XOR dst
2065 case wxOR_REVERSE
: // src OR (NOT dst)
2069 case wxSRC_INVERT
: // (NOT src)
2073 case wxAND
: // src AND dst
2077 // TODO: unsupported
2079 case wxAND_REVERSE
:// src AND (NOT dst)
2080 case wxAND_INVERT
: // (NOT src) AND dst
2081 case wxNO_OP
: // dst
2082 case wxNOR
: // (NOT src) AND (NOT dst)
2083 case wxEQUIV
: // (NOT src) XOR dst
2084 case wxOR_INVERT
: // (NOT src) OR dst
2085 case wxNAND
: // (NOT src) OR (NOT dst)
2086 case wxOR
: // src OR dst
2088 // case wxSRC_OR: // source _bitmap_ OR destination
2089 // case wxSRC_AND: // source _bitmap_ AND destination
2097 m_macPenInstalled
= true ;
2098 m_macBrushInstalled
= false ;
2099 m_macFontInstalled
= false ;
2102 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2104 Pattern whiteColor
;
2106 if ( background
.Ok() )
2108 switch ( background
.MacGetBrushKind() )
2110 case kwxMacBrushTheme
:
2111 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
2114 case kwxMacBrushThemeBackground
:
2117 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
2118 ::ApplyThemeBackground( bg
, &extent
, kThemeStateActive
, wxDisplayDepth() , true ) ;
2122 case kwxMacBrushColour
:
2124 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2125 int brushStyle
= background
.GetStyle();
2126 if (brushStyle
== wxSOLID
)
2127 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2128 else if (background
.IsHatch())
2131 wxMacGetPattern(brushStyle
, &pat
);
2136 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2147 void wxDC::MacInstallBrush() const
2149 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2151 // if ( m_macBrushInstalled )
2154 Pattern blackColor
;
2155 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2156 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2157 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2159 int brushStyle
= m_brush
.GetStyle();
2160 if (brushStyle
== wxSOLID
)
2162 switch ( m_brush
.MacGetBrushKind() )
2164 case kwxMacBrushTheme
:
2166 Pattern whiteColor
;
2167 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2168 ::SetThemePen( m_brush
.MacGetTheme() , wxDisplayDepth() , true ) ;
2173 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2178 else if (m_brush
.IsHatch())
2182 wxMacGetPattern(brushStyle
, &pat
);
2185 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2187 // we force this in order to be compliant with wxMSW
2188 backgroundTransparent
= false ;
2190 // for these the text fore (and back for MASK_OPAQUE) colors are used
2191 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2192 int width
= bitmap
->GetWidth() ;
2193 int height
= bitmap
->GetHeight() ;
2194 GWorldPtr gw
= NULL
;
2196 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2197 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP(NULL
)) ;
2199 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetHBITMAP()) ;
2201 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2202 LockPixels( gwpixmaphandle
) ;
2203 bool isMonochrome
= !IsPortColor( gw
) ;
2204 if ( !isMonochrome
)
2206 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2207 isMonochrome
= true ;
2210 if ( isMonochrome
&& width
== 8 && height
== 8 )
2212 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2213 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2214 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2215 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2216 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2219 for ( int i
= 0 ; i
< 8 ; ++i
)
2221 pat
.pat
[i
] = gwbits
[i
* alignment
+ 0] ;
2224 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2229 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2230 // caching scheme before putting this into production
2234 PixPatHandle pixpat
= NewPixPat() ;
2235 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2236 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2237 ((**(**pixpat
).patMap
).bounds
.bottom
-
2238 (**(**pixpat
).patMap
).bounds
.top
);
2239 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2240 (**pixpat
).patData
= image
;
2244 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2245 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2246 if ( ctspec
[0].rgb
.red
== 0x0000 )
2248 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2249 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2253 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2254 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2256 ::CTabChanged( ctable
) ;
2259 ::PenPixPat(pixpat
);
2260 m_macForegroundPixMap
= pixpat
;
2263 UnlockPixels( gwpixmaphandle
) ;
2267 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2270 short mode
= patCopy
;
2271 switch ( m_logicalFunction
)
2274 if ( backgroundTransparent
)
2280 case wxINVERT
: // NOT dst
2281 if ( !backgroundTransparent
)
2282 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2286 case wxXOR
: // src XOR dst
2290 case wxOR_REVERSE
: // src OR (NOT dst)
2294 case wxSRC_INVERT
: // (NOT src)
2298 case wxAND
: // src AND dst
2302 // TODO: unsupported
2304 case wxAND_REVERSE
:// src AND (NOT dst)
2305 case wxAND_INVERT
: // (NOT src) AND dst
2306 case wxNO_OP
: // dst
2307 case wxNOR
: // (NOT src) AND (NOT dst)
2308 case wxEQUIV
: // (NOT src) XOR dst
2309 case wxOR_INVERT
: // (NOT src) OR dst
2310 case wxNAND
: // (NOT src) OR (NOT dst)
2311 case wxOR
: // src OR dst
2313 // case wxSRC_OR: // source _bitmap_ OR destination
2314 // case wxSRC_AND: // source _bitmap_ AND destination
2322 m_macBrushInstalled
= true ;
2323 m_macPenInstalled
= false ;
2324 m_macFontInstalled
= false ;
2327 // ---------------------------------------------------------------------------
2328 // coordinates transformations
2329 // ---------------------------------------------------------------------------
2331 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2333 return ((wxDC
*)this)->XDEV2LOG(x
);
2336 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2338 return ((wxDC
*)this)->YDEV2LOG(y
);
2341 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2343 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2346 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2348 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2351 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2353 return ((wxDC
*)this)->XLOG2DEV(x
);
2356 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2358 return ((wxDC
*)this)->YLOG2DEV(y
);
2361 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2363 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2366 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2368 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2371 #endif // !wxMAC_USE_CORE_GRAPHICS