1 /////////////////////////////////////////////////////////////////////////////
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
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
21 #include "wx/region.h"
32 #include "wx/mac/private.h"
34 #include <ATSUnicode.h>
35 #include <TextCommon.h>
36 #include <TextEncodingConverter.h>
39 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 const double RAD2DEG
= 180.0 / M_PI
;
46 const short kEmulatedMode
= -1 ;
47 const short kUnsupportedMode
= -2 ;
49 extern TECObjectRef s_TECNativeCToUnicode
;
51 // set to 0 if problems arise
52 #define wxMAC_EXPERIMENTAL_DC 1
54 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
55 m_ph( (GrafPtr
) dc
->m_macPort
)
57 wxASSERT( dc
->Ok() ) ;
59 dc
->MacSetupPort(&m_ph
) ;
62 wxMacPortSetter::~wxMacPortSetter()
64 m_dc
->MacCleanupPort(&m_ph
) ;
67 #if wxMAC_EXPERIMENTAL_DC
68 class wxMacFastPortSetter
71 wxMacFastPortSetter( const wxDC
*dc
)
73 wxASSERT( dc
->Ok() ) ;
74 m_swapped
= QDSwapPort( (GrafPtr
) dc
->m_macPort
, &m_oldPort
) ;
75 m_clipRgn
= NewRgn() ;
76 GetClip( m_clipRgn
) ;
78 dc
->MacSetupPort( NULL
) ;
81 ~wxMacFastPortSetter()
83 // SetPort( (GrafPtr) m_dc->m_macPort ) ;
84 SetClip( m_clipRgn
) ;
86 SetPort( m_oldPort
) ;
87 m_dc
->MacCleanupPort( NULL
) ;
88 DisposeRgn( m_clipRgn
) ;
99 typedef wxMacPortSetter wxMacFastPortSetter
;
102 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
103 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
105 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
106 m_formerClip
= NewRgn() ;
107 m_newClip
= NewRgn() ;
108 GetClip( m_formerClip
) ;
112 // guard against half constructed objects, this just leads to a empty clip
113 if ( win
->GetPeer() )
116 win
->MacWindowToRootWindow( &x
,&y
) ;
118 // get area including focus rect
119 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
120 if ( !EmptyRgn( m_newClip
) )
121 OffsetRgn( m_newClip
, x
, y
) ;
124 SetClip( m_newClip
) ;
128 wxMacWindowClipper::~wxMacWindowClipper()
130 SetPort( m_newPort
) ;
131 SetClip( m_formerClip
) ;
132 DisposeRgn( m_newClip
) ;
133 DisposeRgn( m_formerClip
) ;
136 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
137 wxMacWindowClipper( win
)
139 // the port is already set at this point
140 m_newPort
= (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
141 GetThemeDrawingState( &m_themeDrawingState
) ;
144 wxMacWindowStateSaver::~wxMacWindowStateSaver()
146 SetPort( m_newPort
) ;
147 SetThemeDrawingState( m_themeDrawingState
, true ) ;
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
153 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
154 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
155 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 // this function emulates all wx colour manipulations, used to verify the implementation
161 // by setting the mode in the blitting functions to kEmulatedMode
162 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
164 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
166 switch ( logical_func
)
168 case wxAND
: // src AND dst
169 dstColor
.red
= dstColor
.red
& srcColor
.red
;
170 dstColor
.green
= dstColor
.green
& srcColor
.green
;
171 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
174 case wxAND_INVERT
: // (NOT src) AND dst
175 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
176 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
177 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
180 case wxAND_REVERSE
:// src AND (NOT dst)
181 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
182 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
183 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
193 dstColor
.red
= srcColor
.red
;
194 dstColor
.green
= srcColor
.green
;
195 dstColor
.blue
= srcColor
.blue
;
198 case wxEQUIV
: // (NOT src) XOR dst
199 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
200 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
201 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
;
210 case wxNAND
: // (NOT src) OR (NOT dst)
211 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
212 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
213 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
216 case wxNOR
: // (NOT src) AND (NOT dst)
217 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
218 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
219 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
222 case wxOR
: // src OR dst
223 dstColor
.red
= dstColor
.red
| srcColor
.red
;
224 dstColor
.green
= dstColor
.green
| srcColor
.green
;
225 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
228 case wxOR_INVERT
: // (NOT src) OR dst
229 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
230 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
231 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
234 case wxOR_REVERSE
: // src OR (NOT dst)
235 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
236 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
237 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
241 dstColor
.red
= 0xFFFF ;
242 dstColor
.green
= 0xFFFF ;
243 dstColor
.blue
= 0xFFFF ;
246 case wxSRC_INVERT
: // (NOT src)
247 dstColor
.red
= ~srcColor
.red
;
248 dstColor
.green
= ~srcColor
.green
;
249 dstColor
.blue
= ~srcColor
.blue
;
252 case wxXOR
: // src XOR dst
253 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
254 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
255 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
268 m_mm_to_pix_x
= mm2pt
;
269 m_mm_to_pix_y
= mm2pt
;
270 m_internalDeviceOriginX
= 0;
271 m_internalDeviceOriginY
= 0;
272 m_externalDeviceOriginX
= 0;
273 m_externalDeviceOriginY
= 0;
274 m_logicalScaleX
= 1.0;
275 m_logicalScaleY
= 1.0;
280 m_needComputeScaleX
= false;
281 m_needComputeScaleY
= false;
284 m_macFontInstalled
= false ;
285 m_macBrushInstalled
= false ;
286 m_macPenInstalled
= false ;
287 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
288 m_macBoundaryClipRgn
= NewRgn() ;
289 m_macCurrentClipRgn
= NewRgn() ;
290 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
291 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
292 m_pen
= *wxBLACK_PEN
;
293 m_font
= *wxNORMAL_FONT
;
294 m_brush
= *wxWHITE_BRUSH
;
297 // needed to debug possible errors with two active drawing methods at the same time on
299 m_macCurrentPortStateHelper
= NULL
;
302 m_macATSUIStyle
= NULL
;
303 m_macAliasWasEnabled
= false;
304 m_macForegroundPixMap
= NULL
;
305 m_macBackgroundPixMap
= NULL
;
310 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
311 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
314 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
317 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
318 m_macCurrentPortStateHelper
= help
;
321 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
323 #if ! wxMAC_EXPERIMENTAL_DC
324 m_macFontInstalled
= false ;
325 m_macBrushInstalled
= false ;
326 m_macPenInstalled
= false ;
330 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
333 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
334 m_macCurrentPortStateHelper
= NULL
;
337 if ( m_macATSUIStyle
)
339 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
340 m_macATSUIStyle
= NULL
;
343 if ( m_macAliasWasEnabled
)
345 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
346 m_macAliasWasEnabled
= false ;
349 if ( m_macForegroundPixMap
)
352 ::PenPat(GetQDGlobalsBlack(&blackColor
));
353 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
354 m_macForegroundPixMap
= NULL
;
357 if ( m_macBackgroundPixMap
)
360 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
361 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
362 m_macBackgroundPixMap
= NULL
;
366 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
368 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawBitmap - invalid DC") );
369 wxCHECK_RET( bmp
.Ok(), wxT("wxDC::DoDrawBitmap - invalid bitmap") );
371 wxMacFastPortSetter
helper(this) ;
372 wxCoord xx
= XLOG2DEVMAC(x
);
373 wxCoord yy
= YLOG2DEVMAC(y
);
374 wxCoord w
= bmp
.GetWidth();
375 wxCoord h
= bmp
.GetHeight();
376 wxCoord ww
= XLOG2DEVREL(w
);
377 wxCoord hh
= YLOG2DEVREL(h
);
379 // Set up drawing mode
380 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
381 //m_logicalFunction == wxCLEAR ? WHITENESS :
382 //m_logicalFunction == wxSET ? BLACKNESS :
383 m_logicalFunction
== wxINVERT
? hilite
:
384 //m_logicalFunction == wxAND ? MERGECOPY :
385 m_logicalFunction
== wxOR
? srcOr
:
386 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
387 m_logicalFunction
== wxXOR
? srcXor
:
388 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
389 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
390 //m_logicalFunction == wxSRC_OR ? srcOr :
391 //m_logicalFunction == wxSRC_AND ? SRCAND :
394 GWorldPtr maskworld
= NULL
;
395 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP((WXHBITMAP
*)&maskworld
) );
396 PixMapHandle bmappixels
;
398 // Set foreground and background colours (for bitmaps depth = 1)
399 if (bmp
.GetDepth() == 1)
401 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
402 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
408 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF} ;
409 RGBColor black
= { 0, 0, 0} ;
410 RGBForeColor( &black
) ;
411 RGBBackColor( &white
) ;
413 bmappixels
= GetGWorldPixMap( bmapworld
) ;
415 wxCHECK_RET(LockPixels(bmappixels
),
416 wxT("wxDC::DoDrawBitmap - failed to lock pixels"));
418 Rect source
= { 0, 0, h
, w
};
419 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
420 if ( useMask
&& maskworld
)
422 if ( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
))))
426 GetPortBitMapForCopyBits(bmapworld
),
427 GetPortBitMapForCopyBits(MAC_WXHBITMAP(maskworld
)),
428 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
429 &source
, &source
, &dest
, mode
, NULL
431 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
)));
436 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
437 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
438 &source
, &dest
, mode
, NULL
) ;
440 UnlockPixels( bmappixels
) ;
442 m_macPenInstalled
= false ;
443 m_macBrushInstalled
= false ;
444 m_macFontInstalled
= false ;
447 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
449 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawIcon - invalid DC"));
450 wxCHECK_RET(icon
.Ok(), wxT("wxDC::DoDrawIcon - invalid icon"));
452 wxMacFastPortSetter
helper(this) ;
454 wxCoord xx
= XLOG2DEVMAC(x
);
455 wxCoord yy
= YLOG2DEVMAC(y
);
456 wxCoord w
= icon
.GetWidth();
457 wxCoord h
= icon
.GetHeight();
458 wxCoord ww
= XLOG2DEVREL(w
);
459 wxCoord hh
= YLOG2DEVREL(h
);
461 Rect r
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
462 PlotIconRef( &r
, kAlignNone
, kTransformNone
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
465 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
467 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion - invalid DC"));
469 wxCoord xx
, yy
, ww
, hh
;
472 ww
= XLOG2DEVREL(width
);
473 hh
= YLOG2DEVREL(height
);
475 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
476 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
479 m_clipX1
= wxMax( m_clipX1
, xx
);
480 m_clipY1
= wxMax( m_clipY1
, yy
);
481 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
482 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
494 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
496 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegionAsRegion - invalid DC"));
498 wxMacFastPortSetter
helper(this) ;
500 region
.GetBox( x
, y
, w
, h
);
501 wxCoord xx
, yy
, ww
, hh
;
507 // if we have a scaling that we cannot map onto native regions
508 // we must use the box
509 if ( ww
!= w
|| hh
!= h
)
511 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
515 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
516 if ( xx
!= x
|| yy
!= y
)
517 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
519 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
522 m_clipX1
= wxMax( m_clipX1
, xx
);
523 m_clipY1
= wxMax( m_clipY1
, yy
);
524 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
525 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
538 void wxDC::DestroyClippingRegion()
540 wxMacFastPortSetter
helper(this) ;
542 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
546 void wxDC::DoGetSizeMM( int* width
, int* height
) const
552 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
554 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
557 void wxDC::SetTextForeground( const wxColour
&col
)
559 wxCHECK_RET(Ok(), wxT("wxDC::SetTextForeground - invalid DC"));
561 m_textForegroundColour
= col
;
562 m_macFontInstalled
= false ;
565 void wxDC::SetTextBackground( const wxColour
&col
)
567 wxCHECK_RET(Ok(), wxT("wxDC::SetTextBackground - invalid DC"));
569 m_textBackgroundColour
= col
;
570 m_macFontInstalled
= false ;
573 void wxDC::SetMapMode( int mode
)
578 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
582 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
586 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
590 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
595 SetLogicalScale( 1.0, 1.0 );
599 if (mode
!= wxMM_TEXT
)
601 m_needComputeScaleX
= true;
602 m_needComputeScaleY
= true;
606 void wxDC::SetUserScale( double x
, double y
)
608 // allow negative ? -> no
611 ComputeScaleAndOrigin();
614 void wxDC::SetLogicalScale( double x
, double y
)
619 ComputeScaleAndOrigin();
622 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
624 // is this still correct ?
625 m_logicalOriginX
= x
* m_signX
;
626 m_logicalOriginY
= y
* m_signY
;
627 ComputeScaleAndOrigin();
630 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
632 m_externalDeviceOriginX
= x
;
633 m_externalDeviceOriginY
= y
;
634 ComputeScaleAndOrigin();
637 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
639 m_signX
= (xLeftRight
? 1 : -1);
640 m_signY
= (yBottomUp
? -1 : 1);
641 ComputeScaleAndOrigin();
644 wxSize
wxDC::GetPPI() const
646 return wxSize(72, 72);
649 int wxDC::GetDepth() const
651 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
652 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
657 void wxDC::ComputeScaleAndOrigin()
659 // CMB: copy scale to see if it changes
660 double origScaleX
= m_scaleX
;
661 double origScaleY
= m_scaleY
;
662 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
663 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
664 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
665 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
667 // CMB: if scale has changed call SetPen to recalulate the line width
668 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
670 // this is a bit artificial, but we need to force wxDC to think
671 // the pen has changed
678 void wxDC::SetPalette( const wxPalette
& palette
)
682 void wxDC::SetBackgroundMode( int mode
)
684 m_backgroundMode
= mode
;
687 void wxDC::SetFont( const wxFont
&font
)
690 m_macFontInstalled
= false ;
693 void wxDC::SetPen( const wxPen
&pen
)
699 m_macPenInstalled
= false ;
702 void wxDC::SetBrush( const wxBrush
&brush
)
704 if (m_brush
== brush
)
708 m_macBrushInstalled
= false ;
711 void wxDC::SetBackground( const wxBrush
&brush
)
713 if (m_backgroundBrush
== brush
)
716 m_backgroundBrush
= brush
;
717 if (m_backgroundBrush
.Ok())
718 m_macBrushInstalled
= false ;
721 void wxDC::SetLogicalFunction( int function
)
723 if (m_logicalFunction
== function
)
726 m_logicalFunction
= function
;
727 m_macFontInstalled
= false ;
728 m_macBrushInstalled
= false ;
729 m_macPenInstalled
= false ;
732 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
733 const wxColour
& col
, int style
);
735 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
736 const wxColour
& col
, int style
)
738 return wxDoFloodFill(this, x
, y
, col
, style
);
741 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
743 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel - invalid DC") );
745 wxMacFastPortSetter
helper(this) ;
747 // NOTE: Get/SetCPixel are slow!
749 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
751 // convert from Mac colour to wx
752 col
->Set( colour
.red
>> 8,
759 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
761 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLine - invalid DC"));
763 wxMacFastPortSetter
helper(this) ;
765 if (m_pen
.GetStyle() != wxTRANSPARENT
)
768 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
769 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
770 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
771 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
772 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
773 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
775 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
776 (m_pen
.GetWidth() <= 1))
778 // Implement LAST_NOT for MAC at least for
779 // orthogonal lines. RR.
802 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
804 wxCHECK_RET(Ok(), wxT("wxDC::DoCrossHair - invalid DC"));
806 wxMacFastPortSetter
helper(this) ;
808 if (m_pen
.GetStyle() != wxTRANSPARENT
)
813 wxCoord xx
= XLOG2DEVMAC(x
);
814 wxCoord yy
= YLOG2DEVMAC(y
);
817 ::MoveTo( XLOG2DEVMAC(0), yy
);
818 ::LineTo( XLOG2DEVMAC(w
), yy
);
819 ::MoveTo( xx
, YLOG2DEVMAC(0) );
820 ::LineTo( xx
, YLOG2DEVMAC(h
) );
821 CalcBoundingBox(x
, y
);
822 CalcBoundingBox(x
+ w
, y
+ h
);
827 * To draw arcs properly the angles need to be converted from the WX style:
828 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
829 * a normal axis on paper).
832 * Angles start on the +ve y axis and go clockwise.
835 static double wxConvertWXangleToMACangle(double angle
)
837 double newAngle
= 90 - angle
;
839 while ( newAngle
> 360 )
841 while ( newAngle
< 0 )
847 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
848 wxCoord x2
, wxCoord y2
,
849 wxCoord xc
, wxCoord yc
)
851 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc - invalid DC"));
853 wxMacFastPortSetter
helper(this) ;
855 wxCoord xx1
= XLOG2DEVMAC(x1
);
856 wxCoord yy1
= YLOG2DEVMAC(y1
);
857 wxCoord xx2
= XLOG2DEVMAC(x2
);
858 wxCoord yy2
= YLOG2DEVMAC(y2
);
859 wxCoord xxc
= XLOG2DEVMAC(xc
);
860 wxCoord yyc
= YLOG2DEVMAC(yc
);
862 double dx
= xx1
- xxc
;
863 double dy
= yy1
- yyc
;
864 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
865 wxCoord rad
= (wxCoord
)radius
;
866 double radius1
, radius2
;
868 if (xx1
== xx2
&& yy1
== yy2
)
873 else if (radius
== 0.0)
875 radius1
= radius2
= 0.0;
879 radius1
= (xx1
- xxc
== 0) ?
880 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
881 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
882 radius2
= (xx2
- xxc
== 0) ?
883 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
884 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
887 wxCoord alpha2
= wxCoord(radius2
- radius1
);
888 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
892 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
894 if (m_brush
.GetStyle() != wxTRANSPARENT
)
897 PaintArc(&r
, alpha1
, alpha2
);
900 if (m_pen
.GetStyle() != wxTRANSPARENT
)
903 FrameArc(&r
, alpha1
, alpha2
);
907 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
908 double sa
, double ea
)
910 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc - invalid DC"));
911 wxMacFastPortSetter
helper(this) ;
914 // Order important Mac in opposite direction to wx
915 // we have to make sure that the filling is always counter-clockwise
916 double angle
= sa
- ea
;
920 wxCoord xx
= XLOG2DEVMAC(x
);
921 wxCoord yy
= YLOG2DEVMAC(y
);
922 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
923 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
925 // handle -ve width and/or height
938 sa
= wxConvertWXangleToMACangle(sa
);
944 if (m_brush
.GetStyle() != wxTRANSPARENT
)
947 PaintArc(&r
, (short)sa
, (short)angle
);
950 if (m_pen
.GetStyle() != wxTRANSPARENT
)
953 FrameArc(&r
, (short)sa
, (short)angle
);
957 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
959 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPoint - invalid DC"));
961 wxMacFastPortSetter
helper(this) ;
963 if (m_pen
.GetStyle() != wxTRANSPARENT
)
965 wxCoord xx1
= XLOG2DEVMAC(x
);
966 wxCoord yy1
= YLOG2DEVMAC(y
);
967 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
969 // NOTE: Get/SetCPixel are slow!
970 ::SetCPixel( xx1
, yy1
, &pencolor
) ;
971 CalcBoundingBox(x
, y
);
975 void wxDC::DoDrawLines(int n
, wxPoint points
[],
976 wxCoord xoffset
, wxCoord yoffset
)
978 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLines - invalid DC"));
980 if (m_pen
.GetStyle() == wxTRANSPARENT
)
983 wxMacFastPortSetter
helper(this) ;
986 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
987 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
988 wxCoord x1
, x2
, y1
, y2
;
989 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
990 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
992 ::MoveTo(x1
- offset
, y1
- offset
);
993 for (int i
= 0; i
< n
-1; i
++)
995 x2
= XLOG2DEVMAC(points
[i
+ 1].x
+ xoffset
);
996 y2
= YLOG2DEVMAC(points
[i
+ 1].y
+ yoffset
);
997 ::LineTo( x2
- offset
, y2
- offset
);
1001 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1002 wxCoord xoffset
, wxCoord yoffset
,
1005 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPolygon - invalid DC"));
1007 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
1010 wxMacFastPortSetter
helper(this) ;
1012 wxCoord x1
, x2
, y1
, y2
;
1013 PolyHandle polygon
= OpenPoly();
1014 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1015 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1018 for (int i
= 1; i
< n
; i
++)
1020 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1021 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1025 // close the polyline if necessary
1026 if ( x1
!= x2
|| y1
!= y2
)
1030 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1033 ::PaintPoly( polygon
);
1036 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1039 ::FramePoly( polygon
) ;
1042 KillPoly( polygon
);
1045 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1047 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRectangle - invalid DC"));
1049 wxMacFastPortSetter
helper(this) ;
1051 wxCoord xx
= XLOG2DEVMAC(x
);
1052 wxCoord yy
= YLOG2DEVMAC(y
);
1053 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1054 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1056 // CMB: draw nothing if transformed w or h is 0
1057 if (ww
== 0 || hh
== 0)
1060 // CMB: handle -ve width and/or height
1073 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1075 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1078 ::PaintRect( &rect
) ;
1081 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1084 ::FrameRect( &rect
) ;
1088 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1089 wxCoord width
, wxCoord height
,
1092 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRoundedRectangle - invalid DC"));
1094 wxMacFastPortSetter
helper(this) ;
1096 radius
= - radius
* ((width
< height
) ? width
: height
);
1097 wxCoord xx
= XLOG2DEVMAC(x
);
1098 wxCoord yy
= YLOG2DEVMAC(y
);
1099 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1100 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1102 // CMB: draw nothing if transformed w or h is 0
1103 if (ww
== 0 || hh
== 0)
1106 // CMB: handle -ve width and/or height
1119 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1121 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1124 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1127 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1130 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1134 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1136 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllipse - invalid DC"));
1138 wxMacFastPortSetter
helper(this) ;
1140 wxCoord xx
= XLOG2DEVMAC(x
);
1141 wxCoord yy
= YLOG2DEVMAC(y
);
1142 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1143 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1145 // CMB: draw nothing if transformed w or h is 0
1146 if (ww
== 0 || hh
== 0)
1149 // CMB: handle -ve width and/or height
1162 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1164 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1167 ::PaintOval( &rect
) ;
1170 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1173 ::FrameOval( &rect
) ;
1177 bool wxDC::CanDrawBitmap(void) const
1182 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1183 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1184 wxCoord xsrcMask
, wxCoord ysrcMask
)
1186 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit - invalid DC"));
1187 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit - invalid source DC"));
1189 if ( logical_func
== wxNO_OP
)
1192 if (xsrcMask
== -1 && ysrcMask
== -1)
1198 // correct the parameter in case this dc does not have a mask at all
1199 if ( useMask
&& !source
->m_macMask
)
1202 Rect srcrect
, dstrect
;
1203 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1204 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1205 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1206 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1207 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1208 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1209 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1210 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1211 short mode
= kUnsupportedMode
;
1212 bool invertDestinationFirst
= false ;
1214 switch ( logical_func
)
1216 case wxAND
: // src AND dst
1217 mode
= adMin
; // ok
1220 case wxAND_INVERT
: // (NOT src) AND dst
1221 mode
= notSrcOr
; // ok
1224 case wxAND_REVERSE
:// src AND (NOT dst)
1225 invertDestinationFirst
= true ;
1230 mode
= kEmulatedMode
;
1234 mode
= srcCopy
; // ok
1237 case wxEQUIV
: // (NOT src) XOR dst
1238 mode
= srcXor
; // ok
1241 case wxINVERT
: // NOT dst
1242 mode
= kEmulatedMode
; //or hilite ;
1245 case wxNAND
: // (NOT src) OR (NOT dst)
1246 invertDestinationFirst
= true ;
1250 case wxNOR
: // (NOT src) AND (NOT dst)
1251 invertDestinationFirst
= true ;
1255 case wxNO_OP
: // dst
1256 mode
= kEmulatedMode
; // this has already been handled upon entry
1259 case wxOR
: // src OR dst
1263 case wxOR_INVERT
: // (NOT src) OR dst
1267 case wxOR_REVERSE
: // src OR (NOT dst)
1268 invertDestinationFirst
= true ;
1273 mode
= kEmulatedMode
;
1276 case wxSRC_INVERT
: // (NOT src)
1277 mode
= notSrcCopy
; // ok
1280 case wxXOR
: // src XOR dst
1281 mode
= notSrcXor
; // ok
1288 if ( mode
== kUnsupportedMode
)
1290 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1295 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1296 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1297 if ( LockPixels(bmappixels
) )
1299 wxMacFastPortSetter
helper(this) ;
1301 if ( source
->GetDepth() == 1 )
1303 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1304 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1308 // the modes need this, otherwise we'll end up having really nice colors...
1309 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF} ;
1310 RGBColor black
= { 0, 0, 0} ;
1312 RGBForeColor( &black
) ;
1313 RGBBackColor( &white
) ;
1316 if ( useMask
&& source
->m_macMask
)
1318 if ( mode
== srcCopy
)
1320 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1322 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1323 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1324 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1325 &srcrect
, &srcrect
, &dstrect
) ;
1326 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1331 RgnHandle clipRgn
= NewRgn() ;
1332 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1333 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1334 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1335 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1337 if ( mode
== kEmulatedMode
)
1341 ::PenPat(GetQDGlobalsBlack(&pat
));
1342 if ( logical_func
== wxSET
)
1344 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1345 ::RGBForeColor( &col
) ;
1346 ::PaintRgn( clipRgn
) ;
1348 else if ( logical_func
== wxCLEAR
)
1350 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1351 ::RGBForeColor( &col
) ;
1352 ::PaintRgn( clipRgn
) ;
1354 else if ( logical_func
== wxINVERT
)
1356 MacInvertRgn( clipRgn
) ;
1360 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1362 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1364 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1365 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1366 if ( PtInRgn( dstPoint
, clipRgn
) )
1368 RGBColor srcColor
, dstColor
;
1370 // NOTE: Get/SetCPixel are slow!
1371 SetPort( (GrafPtr
) sourcePort
) ;
1372 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1373 SetPort( (GrafPtr
) m_macPort
) ;
1374 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1375 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1376 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1384 if ( invertDestinationFirst
)
1385 MacInvertRgn( clipRgn
) ;
1387 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1388 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1389 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1392 DisposeRgn( clipRgn
) ;
1397 RgnHandle clipRgn
= NewRgn() ;
1398 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1400 if ( mode
== kEmulatedMode
)
1404 ::PenPat(GetQDGlobalsBlack(&pat
));
1405 if ( logical_func
== wxSET
)
1407 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1408 ::RGBForeColor( &col
) ;
1409 ::PaintRgn( clipRgn
) ;
1411 else if ( logical_func
== wxCLEAR
)
1413 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1415 ::RGBForeColor( &col
) ;
1416 ::PaintRgn( clipRgn
) ;
1418 else if ( logical_func
== wxINVERT
)
1420 MacInvertRgn( clipRgn
) ;
1424 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1426 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1428 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1429 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1431 RGBColor srcColor
, dstColor
;
1433 // NOTE: Get/SetCPixel are slow!
1434 SetPort( (GrafPtr
) sourcePort
) ;
1435 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1436 SetPort( (GrafPtr
) m_macPort
) ;
1437 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1438 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1439 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1447 if ( invertDestinationFirst
)
1448 MacInvertRgn( clipRgn
) ;
1450 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1451 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1452 &srcrect
, &dstrect
, mode
, NULL
) ;
1455 DisposeRgn( clipRgn
) ;
1458 UnlockPixels( bmappixels
) ;
1461 m_macPenInstalled
= false ;
1462 m_macBrushInstalled
= false ;
1463 m_macFontInstalled
= false ;
1468 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1471 // TODO: support text background color (only possible by hand, ATSUI does not support it)
1472 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText - invalid DC") );
1474 if ( str
.Length() == 0 )
1477 wxMacFastPortSetter
helper(this) ;
1483 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1484 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1485 m_macAliasWasEnabled
= true ;
1489 OSStatus status
= noErr
;
1490 ATSUTextLayout atsuLayout
;
1491 UniCharCount chars
= str
.Length() ;
1492 UniChar
* ubuf
= NULL
;
1494 #if SIZEOF_WCHAR_T == 4
1495 wxMBConvUTF16 converter
;
1497 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1498 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1499 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1501 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1502 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1503 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1504 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1506 chars
= unicharlen
/ 2 ;
1509 ubuf
= (UniChar
*) str
.wc_str() ;
1511 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1512 chars
= wxWcslen( wchar
.data() ) ;
1513 ubuf
= (UniChar
*) wchar
.data() ;
1517 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1518 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1520 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1522 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1523 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1525 int iAngle
= int( angle
);
1526 int drawX
= XLOG2DEVMAC(x
) ;
1527 int drawY
= YLOG2DEVMAC(y
) ;
1529 ATSUTextMeasurement textBefore
, textAfter
;
1530 ATSUTextMeasurement ascent
, descent
;
1532 if ( abs(iAngle
) > 0 )
1534 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1536 ATSUAttributeTag atsuTags
[] =
1538 kATSULineRotationTag
,
1540 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1544 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1549 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1550 atsuTags
, atsuSizes
, atsuValues
) ;
1553 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1554 &textBefore
, &textAfter
, &ascent
, &descent
);
1556 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1557 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1558 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1559 IntToFixed(drawX
) , IntToFixed(drawY
) );
1561 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1564 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1565 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1566 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1567 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1568 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1569 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1570 ::ATSUDisposeTextLayout(atsuLayout
);
1572 #if SIZEOF_WCHAR_T == 4
1577 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1579 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText - invalid DC"));
1581 wxMacFastPortSetter
helper(this) ;
1582 long xx
= XLOG2DEVMAC(x
);
1583 long yy
= YLOG2DEVMAC(y
);
1586 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1587 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1588 useDrawThemeText
= false ;
1594 ::GetFontInfo( &fi
) ;
1597 if ( !useDrawThemeText
)
1603 ::TextMode( (m_backgroundMode
== wxTRANSPARENT
) ? srcOr
: srcCopy
) ;
1604 ::MoveTo( xx
, yy
);
1608 wxString linetext
= strtext
;
1611 if ( useDrawThemeText
)
1614 yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
), xx
,
1615 yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1616 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1618 if ( m_backgroundMode
!= wxTRANSPARENT
)
1620 Point bounds
= {0, 0} ;
1621 Rect background
= frame
;
1623 ::GetThemeTextDimensions( mString
,
1624 m_font
.MacGetThemeFontID() ,
1629 background
.right
= background
.left
+ bounds
.h
;
1630 background
.bottom
= background
.top
+ bounds
.v
;
1631 ::EraseRect( &background
) ;
1634 ::DrawThemeTextBox( mString
,
1635 m_font
.MacGetThemeFontID() ,
1645 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1646 ::DrawText( text
, 0 , strlen(text
) ) ;
1650 ::TextMode( srcOr
) ;
1653 bool wxDC::CanGetTextExtent() const
1655 wxCHECK_MSG(Ok(), false, wxT("wxDC::CanGetTextExtent - invalid DC"));
1660 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1661 wxCoord
*descent
, wxCoord
*externalLeading
,
1662 wxFont
*theFont
) const
1664 wxCHECK_RET(Ok(), wxT("wxDC::DoGetTextExtent - invalid DC"));
1666 wxMacFastPortSetter
helper(this) ;
1667 wxFont formerFont
= m_font
;
1670 // work around the constness
1671 *((wxFont
*)(&m_font
)) = *theFont
;
1676 ::GetFontInfo( &fi
) ;
1679 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1680 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1681 useGetThemeText
= false ;
1685 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1687 *descent
=YDEV2LOGREL( fi
.descent
);
1688 if ( externalLeading
)
1689 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1695 wxString linetext
= strtext
;
1697 if ( useGetThemeText
)
1699 Point bounds
= {0, 0} ;
1701 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1702 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1703 ::GetThemeTextDimensions( mString
,
1709 curwidth
= bounds
.h
;
1713 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1714 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1717 if ( curwidth
> *width
)
1718 *width
= XDEV2LOGREL( curwidth
) ;
1723 // work around the constness
1724 *((wxFont
*)(&m_font
)) = formerFont
;
1725 m_macFontInstalled
= false ;
1729 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1731 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoGetPartialTextExtents - invalid DC"));
1734 widths
.Add(0, text
.Length());
1736 if (text
.Length() == 0)
1739 wxMacFastPortSetter
helper(this) ;
1743 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1744 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1745 useGetThemeText
= false ;
1747 if ( useGetThemeText
)
1749 // If anybody knows how to do this more efficiently yet still handle
1750 // the fractional glyph widths that may be present when using AA
1751 // fonts, please change it. Currently it is measuring from the
1752 // begining of the string for each succeding substring, which is much
1753 // slower than this should be.
1754 for (size_t i
=0; i
<text
.Length(); i
++)
1756 wxString
str(text
.Left(i
+ 1));
1757 Point bounds
= {0, 0};
1759 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1761 ::GetThemeTextDimensions( mString
,
1762 m_font
.MacGetThemeFontID(),
1767 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1773 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1774 size_t len
= strlen(buff
);
1775 short* measurements
= new short[len
+1];
1776 MeasureText(len
, buff
.data(), measurements
);
1778 // Copy to widths, starting at measurements[1]
1779 // NOTE: this doesn't take into account any multi-byte characters
1780 // in buff, it probabkly should...
1781 for (size_t i
=0; i
<text
.Length(); i
++)
1782 widths
[i
] = XDEV2LOGREL(measurements
[i
+ 1]);
1784 delete [] measurements
;
1790 wxCoord
wxDC::GetCharWidth(void) const
1792 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharWidth - invalid DC"));
1794 wxMacFastPortSetter
helper(this) ;
1796 const char text
[] = "g" ;
1801 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1802 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1803 useGetThemeText
= false ;
1805 if ( useGetThemeText
)
1807 Point bounds
= {0, 0} ;
1809 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1810 ::GetThemeTextDimensions( mString
,
1811 m_font
.MacGetThemeFontID(),
1816 CFRelease( mString
) ;
1822 width
= ::TextWidth( text
, 0 , 1 ) ;
1825 return YDEV2LOGREL(width
) ;
1828 wxCoord
wxDC::GetCharHeight(void) const
1830 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharHeight - invalid DC"));
1832 wxMacFastPortSetter
helper(this) ;
1835 ::GetFontInfo( &fi
) ;
1837 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1840 void wxDC::Clear(void)
1842 wxCHECK_RET(Ok(), wxT("wxDC::Clear - invalid DC"));
1844 wxMacFastPortSetter
helper(this) ;
1845 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1847 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1850 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1851 ::EraseRect( &rect
) ;
1855 void wxDC::MacInstallFont() const
1857 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1859 // if ( m_macFontInstalled )
1861 Pattern blackColor
;
1862 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1863 if ( m_backgroundMode
!= wxTRANSPARENT
)
1865 Pattern whiteColor
;
1866 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1869 wxASSERT( m_font
.Ok() ) ;
1871 ::TextFont( m_font
.MacGetFontNum() ) ;
1872 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1873 ::TextFace( m_font
.MacGetFontStyle() ) ;
1874 m_macFontInstalled
= true ;
1875 m_macBrushInstalled
= false ;
1876 m_macPenInstalled
= false ;
1877 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1878 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1879 ::RGBForeColor( &forecolor
);
1880 ::RGBBackColor( &backcolor
);
1883 short mode
= patCopy
;
1884 switch ( m_logicalFunction
)
1890 case wxINVERT
: // NOT dst
1891 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1895 case wxXOR
: // src XOR dst
1899 case wxOR_REVERSE
: // src OR (NOT dst)
1903 case wxSRC_INVERT
: // (NOT src)
1907 case wxAND
: // src AND dst
1911 // TODO: unsupported
1913 case wxAND_REVERSE
:// src AND (NOT dst)
1914 case wxAND_INVERT
: // (NOT src) AND dst
1915 case wxNO_OP
: // dst
1916 case wxNOR
: // (NOT src) AND (NOT dst)
1917 case wxEQUIV
: // (NOT src) XOR dst
1918 case wxOR_INVERT
: // (NOT src) OR dst
1919 case wxNAND
: // (NOT src) OR (NOT dst)
1920 case wxOR
: // src OR dst
1922 // case wxSRC_OR: // source _bitmap_ OR destination
1923 // case wxSRC_AND: // source _bitmap_ AND destination
1931 OSStatus status
= noErr
;
1932 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1933 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1935 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1936 ATSUAttributeTag atsuTags
[] =
1940 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1944 // Boolean kTrue = true ;
1945 // Boolean kFalse = false ;
1947 // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
1948 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1952 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1953 atsuTags
, atsuSizes
, atsuValues
);
1955 wxASSERT_MSG( status
== noErr
, wxT("couldn't Modify ATSU style") ) ;
1958 Pattern gPatterns
[] =
1961 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1962 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1963 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1964 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1965 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1966 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1967 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1970 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1971 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1972 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1973 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1976 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1978 int index
= 0; // solid pattern by default
1982 case wxBDIAGONAL_HATCH
: index
= 1; break;
1983 case wxFDIAGONAL_HATCH
: index
= 2; break;
1984 case wxCROSS_HATCH
: index
= 3; break;
1985 case wxHORIZONTAL_HATCH
: index
= 4; break;
1986 case wxVERTICAL_HATCH
: index
= 5; break;
1987 case wxCROSSDIAG_HATCH
: index
= 6; break;
1990 case wxDOT
: index
= 7; break;
1991 case wxLONG_DASH
: index
= 8; break;
1992 case wxSHORT_DASH
: index
= 9; break;
1993 case wxDOT_DASH
: index
= 10; break;
1999 *pattern
= gPatterns
[index
];
2002 void wxDC::MacInstallPen() const
2004 wxCHECK_RET(Ok(), wxT("wxDC::MacInstallPen - invalid DC"));
2006 //Pattern blackColor;
2007 // if ( m_macPenInstalled )
2009 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
2010 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
2011 ::RGBForeColor( &forecolor
);
2012 ::RGBBackColor( &backcolor
);
2014 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
2015 // null means only one pixel, at whatever resolution
2016 if ( penWidth
== 0 )
2018 ::PenSize(penWidth
, penWidth
);
2020 int penStyle
= m_pen
.GetStyle();
2022 if (penStyle
== wxUSER_DASH
)
2024 // FIXME: there should be exactly 8 items in the dash
2026 int number
= m_pen
.GetDashes(&dash
) ;
2028 for ( int i
= 0 ; i
< 8 ; ++i
)
2030 pat
.pat
[i
] = dash
[index
] ;
2031 if (index
< number
- 1)
2037 wxMacGetPattern(penStyle
, &pat
);
2042 short mode
= patCopy
;
2043 switch ( m_logicalFunction
)
2045 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2049 case wxINVERT
: // NOT dst
2050 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2054 case wxXOR
: // src XOR dst
2058 case wxOR_REVERSE
: // src OR (NOT dst)
2062 case wxSRC_INVERT
: // (NOT src)
2066 case wxAND
: // src AND dst
2070 // TODO: unsupported
2072 case wxAND_REVERSE
:// src AND (NOT dst)
2073 case wxAND_INVERT
: // (NOT src) AND dst
2074 case wxNO_OP
: // dst
2075 case wxNOR
: // (NOT src) AND (NOT dst)
2076 case wxEQUIV
: // (NOT src) XOR dst
2077 case wxOR_INVERT
: // (NOT src) OR dst
2078 case wxNAND
: // (NOT src) OR (NOT dst)
2079 case wxOR
: // src OR dst
2081 // case wxSRC_OR: // source _bitmap_ OR destination
2082 // case wxSRC_AND: // source _bitmap_ AND destination
2090 m_macPenInstalled
= true ;
2091 m_macBrushInstalled
= false ;
2092 m_macFontInstalled
= false ;
2095 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2097 Pattern whiteColor
;
2098 if ( background
.Ok() )
2100 switch ( background
.MacGetBrushKind() )
2102 case kwxMacBrushTheme
:
2103 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
2106 case kwxMacBrushThemeBackground
:
2109 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
2110 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2114 case kwxMacBrushColour
:
2116 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2117 int brushStyle
= background
.GetStyle();
2118 if (brushStyle
== wxSOLID
)
2119 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2120 else if (background
.IsHatch())
2123 wxMacGetPattern(brushStyle
, &pat
);
2128 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2139 void wxDC::MacInstallBrush() const
2141 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2142 Pattern blackColor
;
2143 // if ( m_macBrushInstalled )
2146 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2147 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2148 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2150 int brushStyle
= m_brush
.GetStyle();
2151 if (brushStyle
== wxSOLID
)
2153 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2155 else if (m_brush
.IsHatch())
2159 wxMacGetPattern(brushStyle
, &pat
);
2162 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2164 // we force this in order to be compliant with wxMSW
2165 backgroundTransparent
= false ;
2167 // for these the text fore (and back for MASK_OPAQUE) colors are used
2168 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2169 int width
= bitmap
->GetWidth() ;
2170 int height
= bitmap
->GetHeight() ;
2171 GWorldPtr gw
= NULL
;
2173 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2174 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP(NULL
)) ;
2176 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetHBITMAP()) ;
2178 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2179 LockPixels( gwpixmaphandle
) ;
2180 bool isMonochrome
= !IsPortColor( gw
) ;
2181 if ( !isMonochrome
)
2183 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2184 isMonochrome
= true ;
2187 if ( isMonochrome
&& width
== 8 && height
== 8 )
2189 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2190 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2191 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2192 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2193 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2196 for ( int i
= 0 ; i
< 8 ; ++i
)
2198 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2201 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2206 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2207 // caching scheme before putting this into production
2211 PixPatHandle pixpat
= NewPixPat() ;
2212 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2213 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2214 ((**(**pixpat
).patMap
).bounds
.bottom
-
2215 (**(**pixpat
).patMap
).bounds
.top
);
2216 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2217 (**pixpat
).patData
= image
;
2221 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2222 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2223 if ( ctspec
[0].rgb
.red
== 0x0000 )
2225 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2226 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2230 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2231 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2233 ::CTabChanged( ctable
) ;
2236 ::PenPixPat(pixpat
);
2237 m_macForegroundPixMap
= pixpat
;
2240 UnlockPixels( gwpixmaphandle
) ;
2244 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2247 short mode
= patCopy
;
2248 switch ( m_logicalFunction
)
2251 if ( backgroundTransparent
)
2257 case wxINVERT
: // NOT dst
2258 if ( !backgroundTransparent
)
2259 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2263 case wxXOR
: // src XOR dst
2267 case wxOR_REVERSE
: // src OR (NOT dst)
2271 case wxSRC_INVERT
: // (NOT src)
2275 case wxAND
: // src AND dst
2279 // TODO: unsupported
2281 case wxAND_REVERSE
:// src AND (NOT dst)
2282 case wxAND_INVERT
: // (NOT src) AND dst
2283 case wxNO_OP
: // dst
2284 case wxNOR
: // (NOT src) AND (NOT dst)
2285 case wxEQUIV
: // (NOT src) XOR dst
2286 case wxOR_INVERT
: // (NOT src) OR dst
2287 case wxNAND
: // (NOT src) OR (NOT dst)
2288 case wxOR
: // src OR dst
2290 // case wxSRC_OR: // source _bitmap_ OR destination
2291 // case wxSRC_AND: // source _bitmap_ AND destination
2299 m_macBrushInstalled
= true ;
2300 m_macPenInstalled
= false ;
2301 m_macFontInstalled
= false ;
2304 // ---------------------------------------------------------------------------
2305 // coordinates transformations
2306 // ---------------------------------------------------------------------------
2308 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2310 return ((wxDC
*)this)->XDEV2LOG(x
);
2313 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2315 return ((wxDC
*)this)->YDEV2LOG(y
);
2318 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2320 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2323 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2325 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2328 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2330 return ((wxDC
*)this)->XLOG2DEV(x
);
2333 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2335 return ((wxDC
*)this)->YLOG2DEV(y
);
2338 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2340 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2343 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2345 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2348 #endif // !wxMAC_USE_CORE_GRAPHICS