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;
285 m_macFontInstalled
= false ;
286 m_macBrushInstalled
= false ;
287 m_macPenInstalled
= false ;
288 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
289 m_macBoundaryClipRgn
= NewRgn() ;
290 m_macCurrentClipRgn
= NewRgn() ;
291 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
292 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
293 m_pen
= *wxBLACK_PEN
;
294 m_font
= *wxNORMAL_FONT
;
295 m_brush
= *wxWHITE_BRUSH
;
298 // needed to debug possible errors with two active drawing methods at the same time on
300 m_macCurrentPortStateHelper
= NULL
;
303 m_macATSUIStyle
= NULL
;
304 m_macAliasWasEnabled
= false;
305 m_macForegroundPixMap
= NULL
;
306 m_macBackgroundPixMap
= NULL
;
311 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
312 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
315 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
318 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
319 m_macCurrentPortStateHelper
= help
;
322 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
324 #if ! wxMAC_EXPERIMENTAL_DC
325 m_macFontInstalled
= false ;
326 m_macBrushInstalled
= false ;
327 m_macPenInstalled
= false ;
331 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
334 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
335 m_macCurrentPortStateHelper
= NULL
;
338 if ( m_macATSUIStyle
)
340 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
341 m_macATSUIStyle
= NULL
;
344 if ( m_macAliasWasEnabled
)
346 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
347 m_macAliasWasEnabled
= false ;
350 if ( m_macForegroundPixMap
)
353 ::PenPat(GetQDGlobalsBlack(&blackColor
));
354 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
355 m_macForegroundPixMap
= NULL
;
358 if ( m_macBackgroundPixMap
)
361 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
362 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
363 m_macBackgroundPixMap
= NULL
;
367 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
369 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawBitmap - invalid DC") );
370 wxCHECK_RET( bmp
.Ok(), wxT("wxDC::DoDrawBitmap - invalid bitmap") );
372 wxMacFastPortSetter
helper(this) ;
373 wxCoord xx
= XLOG2DEVMAC(x
);
374 wxCoord yy
= YLOG2DEVMAC(y
);
375 wxCoord w
= bmp
.GetWidth();
376 wxCoord h
= bmp
.GetHeight();
377 wxCoord ww
= XLOG2DEVREL(w
);
378 wxCoord hh
= YLOG2DEVREL(h
);
380 // Set up drawing mode
381 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
382 //m_logicalFunction == wxCLEAR ? WHITENESS :
383 //m_logicalFunction == wxSET ? BLACKNESS :
384 m_logicalFunction
== wxINVERT
? hilite
:
385 //m_logicalFunction == wxAND ? MERGECOPY :
386 m_logicalFunction
== wxOR
? srcOr
:
387 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
388 m_logicalFunction
== wxXOR
? srcXor
:
389 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
390 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
391 //m_logicalFunction == wxSRC_OR ? srcOr :
392 //m_logicalFunction == wxSRC_AND ? SRCAND :
395 GWorldPtr maskworld
= NULL
;
396 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP((WXHBITMAP
*)&maskworld
) );
397 PixMapHandle bmappixels
;
399 // Set foreground and background colours (for bitmaps depth = 1)
400 if (bmp
.GetDepth() == 1)
402 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
403 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
409 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF} ;
410 RGBColor black
= { 0, 0, 0} ;
411 RGBForeColor( &black
) ;
412 RGBBackColor( &white
) ;
414 bmappixels
= GetGWorldPixMap( bmapworld
) ;
416 wxCHECK_RET(LockPixels(bmappixels
),
417 wxT("wxDC::DoDrawBitmap - failed to lock pixels"));
419 Rect source
= { 0, 0, h
, w
};
420 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
421 if ( useMask
&& maskworld
)
423 if ( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
))))
427 GetPortBitMapForCopyBits(bmapworld
),
428 GetPortBitMapForCopyBits(MAC_WXHBITMAP(maskworld
)),
429 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
430 &source
, &source
, &dest
, mode
, NULL
432 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld
)));
437 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
438 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
439 &source
, &dest
, mode
, NULL
) ;
441 UnlockPixels( bmappixels
) ;
443 m_macPenInstalled
= false ;
444 m_macBrushInstalled
= false ;
445 m_macFontInstalled
= false ;
448 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
450 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawIcon - invalid DC"));
451 wxCHECK_RET(icon
.Ok(), wxT("wxDC::DoDrawIcon - invalid icon"));
453 wxMacFastPortSetter
helper(this) ;
455 wxCoord xx
= XLOG2DEVMAC(x
);
456 wxCoord yy
= YLOG2DEVMAC(y
);
457 wxCoord w
= icon
.GetWidth();
458 wxCoord h
= icon
.GetHeight();
459 wxCoord ww
= XLOG2DEVREL(w
);
460 wxCoord hh
= YLOG2DEVREL(h
);
462 Rect r
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
463 PlotIconRef( &r
, kAlignNone
, kTransformNone
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) ) ;
466 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
468 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion - invalid DC"));
470 wxCoord xx
, yy
, ww
, hh
;
473 ww
= XLOG2DEVREL(width
);
474 hh
= YLOG2DEVREL(height
);
476 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
477 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
480 m_clipX1
= wxMax( m_clipX1
, xx
);
481 m_clipY1
= wxMax( m_clipY1
, yy
);
482 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
483 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
495 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
497 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegionAsRegion - invalid DC"));
499 wxMacFastPortSetter
helper(this) ;
501 region
.GetBox( x
, y
, w
, h
);
502 wxCoord xx
, yy
, ww
, hh
;
508 // if we have a scaling that we cannot map onto native regions
509 // we must use the box
510 if ( ww
!= w
|| hh
!= h
)
512 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
516 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
517 if ( xx
!= x
|| yy
!= y
)
518 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
520 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
523 m_clipX1
= wxMax( m_clipX1
, xx
);
524 m_clipY1
= wxMax( m_clipY1
, yy
);
525 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
526 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
539 void wxDC::DestroyClippingRegion()
541 wxMacFastPortSetter
helper(this) ;
543 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
547 void wxDC::DoGetSizeMM( int* width
, int* height
) const
553 *width
= long( double(w
) / (m_scaleX
* m_mm_to_pix_x
) );
555 *height
= long( double(h
) / (m_scaleY
* m_mm_to_pix_y
) );
558 void wxDC::SetTextForeground( const wxColour
&col
)
560 wxCHECK_RET(Ok(), wxT("wxDC::SetTextForeground - invalid DC"));
562 m_textForegroundColour
= col
;
563 m_macFontInstalled
= false ;
566 void wxDC::SetTextBackground( const wxColour
&col
)
568 wxCHECK_RET(Ok(), wxT("wxDC::SetTextBackground - invalid DC"));
570 m_textBackgroundColour
= col
;
571 m_macFontInstalled
= false ;
574 void wxDC::SetMapMode( int mode
)
579 SetLogicalScale( twips2mm
* m_mm_to_pix_x
, twips2mm
* m_mm_to_pix_y
);
583 SetLogicalScale( pt2mm
* m_mm_to_pix_x
, pt2mm
* m_mm_to_pix_y
);
587 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
591 SetLogicalScale( m_mm_to_pix_x
/ 10.0, m_mm_to_pix_y
/ 10.0 );
596 SetLogicalScale( 1.0, 1.0 );
600 if (mode
!= wxMM_TEXT
)
602 m_needComputeScaleX
= true;
603 m_needComputeScaleY
= true;
607 void wxDC::SetUserScale( double x
, double y
)
609 // allow negative ? -> no
612 ComputeScaleAndOrigin();
615 void wxDC::SetLogicalScale( double x
, double y
)
620 ComputeScaleAndOrigin();
623 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
625 // is this still correct ?
626 m_logicalOriginX
= x
* m_signX
;
627 m_logicalOriginY
= y
* m_signY
;
628 ComputeScaleAndOrigin();
631 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
633 m_externalDeviceOriginX
= x
;
634 m_externalDeviceOriginY
= y
;
635 ComputeScaleAndOrigin();
638 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
640 m_signX
= (xLeftRight
? 1 : -1);
641 m_signY
= (yBottomUp
? -1 : 1);
642 ComputeScaleAndOrigin();
645 wxSize
wxDC::GetPPI() const
647 return wxSize(72, 72);
650 int wxDC::GetDepth() const
652 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
653 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
658 void wxDC::ComputeScaleAndOrigin()
660 // CMB: copy scale to see if it changes
661 double origScaleX
= m_scaleX
;
662 double origScaleY
= m_scaleY
;
663 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
664 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
665 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
666 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
668 // CMB: if scale has changed call SetPen to recalulate the line width
669 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
671 // this is a bit artificial, but we need to force wxDC to think
672 // the pen has changed
679 void wxDC::SetPalette( const wxPalette
& palette
)
683 void wxDC::SetBackgroundMode( int mode
)
685 m_backgroundMode
= mode
;
688 void wxDC::SetFont( const wxFont
&font
)
691 m_macFontInstalled
= false ;
694 void wxDC::SetPen( const wxPen
&pen
)
700 m_macPenInstalled
= false ;
703 void wxDC::SetBrush( const wxBrush
&brush
)
705 if (m_brush
== brush
)
709 m_macBrushInstalled
= false ;
712 void wxDC::SetBackground( const wxBrush
&brush
)
714 if (m_backgroundBrush
== brush
)
717 m_backgroundBrush
= brush
;
718 if (m_backgroundBrush
.Ok())
719 m_macBrushInstalled
= false ;
722 void wxDC::SetLogicalFunction( int function
)
724 if (m_logicalFunction
== function
)
727 m_logicalFunction
= function
;
728 m_macFontInstalled
= false ;
729 m_macBrushInstalled
= false ;
730 m_macPenInstalled
= false ;
733 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
734 const wxColour
& col
, int style
);
736 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
737 const wxColour
& col
, int style
)
739 return wxDoFloodFill(this, x
, y
, col
, style
);
742 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
744 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel - invalid DC") );
746 wxMacFastPortSetter
helper(this) ;
748 // NOTE: Get/SetCPixel are slow!
750 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
752 // convert from Mac colour to wx
753 col
->Set( colour
.red
>> 8,
760 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
762 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLine - invalid DC"));
764 wxMacFastPortSetter
helper(this) ;
766 if (m_pen
.GetStyle() != wxTRANSPARENT
)
769 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
770 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
771 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
772 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
773 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
774 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
776 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
777 (m_pen
.GetWidth() <= 1))
779 // Implement LAST_NOT for MAC at least for
780 // orthogonal lines. RR.
803 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
805 wxCHECK_RET(Ok(), wxT("wxDC::DoCrossHair - invalid DC"));
807 wxMacFastPortSetter
helper(this) ;
809 if (m_pen
.GetStyle() != wxTRANSPARENT
)
814 wxCoord xx
= XLOG2DEVMAC(x
);
815 wxCoord yy
= YLOG2DEVMAC(y
);
818 ::MoveTo( XLOG2DEVMAC(0), yy
);
819 ::LineTo( XLOG2DEVMAC(w
), yy
);
820 ::MoveTo( xx
, YLOG2DEVMAC(0) );
821 ::LineTo( xx
, YLOG2DEVMAC(h
) );
822 CalcBoundingBox(x
, y
);
823 CalcBoundingBox(x
+ w
, y
+ h
);
828 * To draw arcs properly the angles need to be converted from the WX style:
829 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
830 * a normal axis on paper).
833 * Angles start on the +ve y axis and go clockwise.
836 static double wxConvertWXangleToMACangle(double angle
)
838 double newAngle
= 90 - angle
;
840 while ( newAngle
> 360 )
842 while ( newAngle
< 0 )
848 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
849 wxCoord x2
, wxCoord y2
,
850 wxCoord xc
, wxCoord yc
)
852 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc - invalid DC"));
854 wxMacFastPortSetter
helper(this) ;
856 wxCoord xx1
= XLOG2DEVMAC(x1
);
857 wxCoord yy1
= YLOG2DEVMAC(y1
);
858 wxCoord xx2
= XLOG2DEVMAC(x2
);
859 wxCoord yy2
= YLOG2DEVMAC(y2
);
860 wxCoord xxc
= XLOG2DEVMAC(xc
);
861 wxCoord yyc
= YLOG2DEVMAC(yc
);
863 double dx
= xx1
- xxc
;
864 double dy
= yy1
- yyc
;
865 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
866 wxCoord rad
= (wxCoord
)radius
;
867 double radius1
, radius2
;
869 if (xx1
== xx2
&& yy1
== yy2
)
874 else if (radius
== 0.0)
876 radius1
= radius2
= 0.0;
880 radius1
= (xx1
- xxc
== 0) ?
881 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
882 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
883 radius2
= (xx2
- xxc
== 0) ?
884 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
885 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
888 wxCoord alpha2
= wxCoord(radius2
- radius1
);
889 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
893 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
895 if (m_brush
.GetStyle() != wxTRANSPARENT
)
898 PaintArc(&r
, alpha1
, alpha2
);
901 if (m_pen
.GetStyle() != wxTRANSPARENT
)
904 FrameArc(&r
, alpha1
, alpha2
);
908 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
909 double sa
, double ea
)
911 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc - invalid DC"));
912 wxMacFastPortSetter
helper(this) ;
915 // Order important Mac in opposite direction to wx
916 // we have to make sure that the filling is always counter-clockwise
917 double angle
= sa
- ea
;
921 wxCoord xx
= XLOG2DEVMAC(x
);
922 wxCoord yy
= YLOG2DEVMAC(y
);
923 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
924 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
926 // handle -ve width and/or height
939 sa
= wxConvertWXangleToMACangle(sa
);
945 if (m_brush
.GetStyle() != wxTRANSPARENT
)
948 PaintArc(&r
, (short)sa
, (short)angle
);
951 if (m_pen
.GetStyle() != wxTRANSPARENT
)
954 FrameArc(&r
, (short)sa
, (short)angle
);
958 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
960 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPoint - invalid DC"));
962 wxMacFastPortSetter
helper(this) ;
964 if (m_pen
.GetStyle() != wxTRANSPARENT
)
966 wxCoord xx1
= XLOG2DEVMAC(x
);
967 wxCoord yy1
= YLOG2DEVMAC(y
);
968 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
970 // NOTE: Get/SetCPixel are slow!
971 ::SetCPixel( xx1
, yy1
, &pencolor
) ;
972 CalcBoundingBox(x
, y
);
976 void wxDC::DoDrawLines(int n
, wxPoint points
[],
977 wxCoord xoffset
, wxCoord yoffset
)
979 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLines - invalid DC"));
981 if (m_pen
.GetStyle() == wxTRANSPARENT
)
984 wxMacFastPortSetter
helper(this) ;
987 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
988 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
989 wxCoord x1
, x2
, y1
, y2
;
990 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
991 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
993 ::MoveTo(x1
- offset
, y1
- offset
);
994 for (int i
= 0; i
< n
-1; i
++)
996 x2
= XLOG2DEVMAC(points
[i
+ 1].x
+ xoffset
);
997 y2
= YLOG2DEVMAC(points
[i
+ 1].y
+ yoffset
);
998 ::LineTo( x2
- offset
, y2
- offset
);
1002 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
1003 wxCoord xoffset
, wxCoord yoffset
,
1006 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPolygon - invalid DC"));
1008 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
1011 wxMacFastPortSetter
helper(this) ;
1013 wxCoord x1
, x2
, y1
, y2
;
1014 PolyHandle polygon
= OpenPoly();
1015 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
1016 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
1019 for (int i
= 1; i
< n
; i
++)
1021 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
1022 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
1026 // close the polyline if necessary
1027 if ( x1
!= x2
|| y1
!= y2
)
1031 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1034 ::PaintPoly( polygon
);
1037 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1040 ::FramePoly( polygon
) ;
1043 KillPoly( polygon
);
1046 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1048 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRectangle - invalid DC"));
1050 wxMacFastPortSetter
helper(this) ;
1052 wxCoord xx
= XLOG2DEVMAC(x
);
1053 wxCoord yy
= YLOG2DEVMAC(y
);
1054 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1055 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1057 // CMB: draw nothing if transformed w or h is 0
1058 if (ww
== 0 || hh
== 0)
1061 // CMB: handle -ve width and/or height
1074 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1076 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1079 ::PaintRect( &rect
) ;
1082 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1085 ::FrameRect( &rect
) ;
1089 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1090 wxCoord width
, wxCoord height
,
1093 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRoundedRectangle - invalid DC"));
1095 wxMacFastPortSetter
helper(this) ;
1097 radius
= - radius
* ((width
< height
) ? width
: height
);
1098 wxCoord xx
= XLOG2DEVMAC(x
);
1099 wxCoord yy
= YLOG2DEVMAC(y
);
1100 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1101 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1103 // CMB: draw nothing if transformed w or h is 0
1104 if (ww
== 0 || hh
== 0)
1107 // CMB: handle -ve width and/or height
1120 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1122 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1125 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1128 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1131 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1135 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1137 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllipse - invalid DC"));
1139 wxMacFastPortSetter
helper(this) ;
1141 wxCoord xx
= XLOG2DEVMAC(x
);
1142 wxCoord yy
= YLOG2DEVMAC(y
);
1143 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1144 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1146 // CMB: draw nothing if transformed w or h is 0
1147 if (ww
== 0 || hh
== 0)
1150 // CMB: handle -ve width and/or height
1163 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1165 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1168 ::PaintOval( &rect
) ;
1171 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1174 ::FrameOval( &rect
) ;
1178 bool wxDC::CanDrawBitmap(void) const
1183 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1184 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1185 wxCoord xsrcMask
, wxCoord ysrcMask
)
1187 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit - invalid DC"));
1188 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit - invalid source DC"));
1190 if ( logical_func
== wxNO_OP
)
1193 if (xsrcMask
== -1 && ysrcMask
== -1)
1199 // correct the parameter in case this dc does not have a mask at all
1200 if ( useMask
&& !source
->m_macMask
)
1203 Rect srcrect
, dstrect
;
1204 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1205 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1206 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1207 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1208 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1209 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1210 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1211 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1212 short mode
= kUnsupportedMode
;
1213 bool invertDestinationFirst
= false ;
1215 switch ( logical_func
)
1217 case wxAND
: // src AND dst
1218 mode
= adMin
; // ok
1221 case wxAND_INVERT
: // (NOT src) AND dst
1222 mode
= notSrcOr
; // ok
1225 case wxAND_REVERSE
:// src AND (NOT dst)
1226 invertDestinationFirst
= true ;
1231 mode
= kEmulatedMode
;
1235 mode
= srcCopy
; // ok
1238 case wxEQUIV
: // (NOT src) XOR dst
1239 mode
= srcXor
; // ok
1242 case wxINVERT
: // NOT dst
1243 mode
= kEmulatedMode
; //or hilite ;
1246 case wxNAND
: // (NOT src) OR (NOT dst)
1247 invertDestinationFirst
= true ;
1251 case wxNOR
: // (NOT src) AND (NOT dst)
1252 invertDestinationFirst
= true ;
1256 case wxNO_OP
: // dst
1257 mode
= kEmulatedMode
; // this has already been handled upon entry
1260 case wxOR
: // src OR dst
1264 case wxOR_INVERT
: // (NOT src) OR dst
1268 case wxOR_REVERSE
: // src OR (NOT dst)
1269 invertDestinationFirst
= true ;
1274 mode
= kEmulatedMode
;
1277 case wxSRC_INVERT
: // (NOT src)
1278 mode
= notSrcCopy
; // ok
1281 case wxXOR
: // src XOR dst
1282 mode
= notSrcXor
; // ok
1289 if ( mode
== kUnsupportedMode
)
1291 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1296 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1297 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1298 if ( LockPixels(bmappixels
) )
1300 wxMacFastPortSetter
helper(this) ;
1302 if ( source
->GetDepth() == 1 )
1304 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1305 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1309 // the modes need this, otherwise we'll end up having really nice colors...
1310 RGBColor white
= { 0xFFFF, 0xFFFF, 0xFFFF} ;
1311 RGBColor black
= { 0, 0, 0} ;
1313 RGBForeColor( &black
) ;
1314 RGBBackColor( &white
) ;
1317 if ( useMask
&& source
->m_macMask
)
1319 if ( mode
== srcCopy
)
1321 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1323 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1324 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1325 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1326 &srcrect
, &srcrect
, &dstrect
) ;
1327 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1332 RgnHandle clipRgn
= NewRgn() ;
1333 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1334 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1335 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1336 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1338 if ( mode
== kEmulatedMode
)
1342 ::PenPat(GetQDGlobalsBlack(&pat
));
1343 if ( logical_func
== wxSET
)
1345 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1346 ::RGBForeColor( &col
) ;
1347 ::PaintRgn( clipRgn
) ;
1349 else if ( logical_func
== wxCLEAR
)
1351 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1352 ::RGBForeColor( &col
) ;
1353 ::PaintRgn( clipRgn
) ;
1355 else if ( logical_func
== wxINVERT
)
1357 MacInvertRgn( clipRgn
) ;
1361 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1363 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1365 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1366 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1367 if ( PtInRgn( dstPoint
, clipRgn
) )
1369 RGBColor srcColor
, dstColor
;
1371 // NOTE: Get/SetCPixel are slow!
1372 SetPort( (GrafPtr
) sourcePort
) ;
1373 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1374 SetPort( (GrafPtr
) m_macPort
) ;
1375 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1376 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1377 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1385 if ( invertDestinationFirst
)
1386 MacInvertRgn( clipRgn
) ;
1388 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1389 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1390 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1393 DisposeRgn( clipRgn
) ;
1398 RgnHandle clipRgn
= NewRgn() ;
1399 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1401 if ( mode
== kEmulatedMode
)
1405 ::PenPat(GetQDGlobalsBlack(&pat
));
1406 if ( logical_func
== wxSET
)
1408 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1409 ::RGBForeColor( &col
) ;
1410 ::PaintRgn( clipRgn
) ;
1412 else if ( logical_func
== wxCLEAR
)
1414 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1416 ::RGBForeColor( &col
) ;
1417 ::PaintRgn( clipRgn
) ;
1419 else if ( logical_func
== wxINVERT
)
1421 MacInvertRgn( clipRgn
) ;
1425 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1427 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1429 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1430 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1432 RGBColor srcColor
, dstColor
;
1434 // NOTE: Get/SetCPixel are slow!
1435 SetPort( (GrafPtr
) sourcePort
) ;
1436 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1437 SetPort( (GrafPtr
) m_macPort
) ;
1438 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1439 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1440 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1448 if ( invertDestinationFirst
)
1449 MacInvertRgn( clipRgn
) ;
1451 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1452 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1453 &srcrect
, &dstrect
, mode
, NULL
) ;
1456 DisposeRgn( clipRgn
) ;
1459 UnlockPixels( bmappixels
) ;
1462 m_macPenInstalled
= false ;
1463 m_macBrushInstalled
= false ;
1464 m_macFontInstalled
= false ;
1469 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1472 // TODO: support text background color (only possible by hand, ATSUI does not support it)
1473 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText - invalid DC") );
1475 if ( str
.Length() == 0 )
1478 wxMacFastPortSetter
helper(this) ;
1484 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1485 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1486 m_macAliasWasEnabled
= true ;
1490 OSStatus status
= noErr
;
1491 ATSUTextLayout atsuLayout
;
1492 UniCharCount chars
= str
.Length() ;
1493 UniChar
* ubuf
= NULL
;
1495 #if SIZEOF_WCHAR_T == 4
1496 wxMBConvUTF16 converter
;
1498 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1499 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1500 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1502 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1503 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1504 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1505 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1507 chars
= unicharlen
/ 2 ;
1510 ubuf
= (UniChar
*) str
.wc_str() ;
1512 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1513 chars
= wxWcslen( wchar
.data() ) ;
1514 ubuf
= (UniChar
*) wchar
.data() ;
1518 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1519 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1521 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1523 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true ) ;
1524 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1526 int iAngle
= int( angle
);
1527 int drawX
= XLOG2DEVMAC(x
) ;
1528 int drawY
= YLOG2DEVMAC(y
) ;
1530 ATSUTextMeasurement textBefore
, textAfter
;
1531 ATSUTextMeasurement ascent
, descent
;
1533 if ( abs(iAngle
) > 0 )
1535 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1537 ATSUAttributeTag atsuTags
[] =
1539 kATSULineRotationTag
,
1541 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1545 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1550 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1551 atsuTags
, atsuSizes
, atsuValues
) ;
1554 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1555 &textBefore
, &textAfter
, &ascent
, &descent
);
1557 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1558 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1559 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1560 IntToFixed(drawX
) , IntToFixed(drawY
) );
1562 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1565 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1566 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1567 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1568 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1569 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1570 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1571 ::ATSUDisposeTextLayout(atsuLayout
);
1573 #if SIZEOF_WCHAR_T == 4
1578 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1580 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText - invalid DC"));
1582 wxMacFastPortSetter
helper(this) ;
1583 long xx
= XLOG2DEVMAC(x
);
1584 long yy
= YLOG2DEVMAC(y
);
1587 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1588 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1589 useDrawThemeText
= false ;
1595 ::GetFontInfo( &fi
) ;
1598 if ( !useDrawThemeText
)
1604 ::TextMode( (m_backgroundMode
== wxTRANSPARENT
) ? srcOr
: srcCopy
) ;
1605 ::MoveTo( xx
, yy
);
1609 wxString linetext
= strtext
;
1612 if ( useDrawThemeText
)
1615 yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
), xx
,
1616 yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1617 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1619 if ( m_backgroundMode
!= wxTRANSPARENT
)
1621 Point bounds
= {0, 0} ;
1622 Rect background
= frame
;
1624 ::GetThemeTextDimensions( mString
,
1625 m_font
.MacGetThemeFontID() ,
1630 background
.right
= background
.left
+ bounds
.h
;
1631 background
.bottom
= background
.top
+ bounds
.v
;
1632 ::EraseRect( &background
) ;
1635 ::DrawThemeTextBox( mString
,
1636 m_font
.MacGetThemeFontID() ,
1646 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1647 ::DrawText( text
, 0 , strlen(text
) ) ;
1651 ::TextMode( srcOr
) ;
1654 bool wxDC::CanGetTextExtent() const
1656 wxCHECK_MSG(Ok(), false, wxT("wxDC::CanGetTextExtent - invalid DC"));
1661 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1662 wxCoord
*descent
, wxCoord
*externalLeading
,
1663 wxFont
*theFont
) const
1665 wxCHECK_RET(Ok(), wxT("wxDC::DoGetTextExtent - invalid DC"));
1667 wxMacFastPortSetter
helper(this) ;
1668 wxFont formerFont
= m_font
;
1671 // work around the constness
1672 *((wxFont
*)(&m_font
)) = *theFont
;
1677 ::GetFontInfo( &fi
) ;
1680 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1681 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1682 useGetThemeText
= false ;
1686 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1688 *descent
=YDEV2LOGREL( fi
.descent
);
1689 if ( externalLeading
)
1690 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1696 wxString linetext
= strtext
;
1698 if ( useGetThemeText
)
1700 Point bounds
= {0, 0} ;
1702 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1703 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1704 ::GetThemeTextDimensions( mString
,
1710 curwidth
= bounds
.h
;
1714 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1715 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1718 if ( curwidth
> *width
)
1719 *width
= XDEV2LOGREL( curwidth
) ;
1724 // work around the constness
1725 *((wxFont
*)(&m_font
)) = formerFont
;
1726 m_macFontInstalled
= false ;
1730 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1732 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoGetPartialTextExtents - invalid DC"));
1735 widths
.Add(0, text
.Length());
1737 if (text
.Length() == 0)
1740 wxMacFastPortSetter
helper(this) ;
1744 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1745 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1746 useGetThemeText
= false ;
1748 if ( useGetThemeText
)
1750 // If anybody knows how to do this more efficiently yet still handle
1751 // the fractional glyph widths that may be present when using AA
1752 // fonts, please change it. Currently it is measuring from the
1753 // begining of the string for each succeding substring, which is much
1754 // slower than this should be.
1755 for (size_t i
=0; i
<text
.Length(); i
++)
1757 wxString
str(text
.Left(i
+ 1));
1758 Point bounds
= {0, 0};
1760 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1762 ::GetThemeTextDimensions( mString
,
1763 m_font
.MacGetThemeFontID(),
1768 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1774 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1775 size_t len
= strlen(buff
);
1776 short* measurements
= new short[len
+1];
1777 MeasureText(len
, buff
.data(), measurements
);
1779 // Copy to widths, starting at measurements[1]
1780 // NOTE: this doesn't take into account any multi-byte characters
1781 // in buff, it probabkly should...
1782 for (size_t i
=0; i
<text
.Length(); i
++)
1783 widths
[i
] = XDEV2LOGREL(measurements
[i
+ 1]);
1785 delete [] measurements
;
1791 wxCoord
wxDC::GetCharWidth(void) const
1793 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharWidth - invalid DC"));
1795 wxMacFastPortSetter
helper(this) ;
1797 const char text
[] = "g" ;
1802 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1803 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1804 useGetThemeText
= false ;
1806 if ( useGetThemeText
)
1808 Point bounds
= {0, 0} ;
1810 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1811 ::GetThemeTextDimensions( mString
,
1812 m_font
.MacGetThemeFontID(),
1817 CFRelease( mString
) ;
1823 width
= ::TextWidth( text
, 0 , 1 ) ;
1826 return YDEV2LOGREL(width
) ;
1829 wxCoord
wxDC::GetCharHeight(void) const
1831 wxCHECK_MSG(Ok(), 1, wxT("wxDC::GetCharHeight - invalid DC"));
1833 wxMacFastPortSetter
helper(this) ;
1836 ::GetFontInfo( &fi
) ;
1838 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1841 void wxDC::Clear(void)
1843 wxCHECK_RET(Ok(), wxT("wxDC::Clear - invalid DC"));
1845 wxMacFastPortSetter
helper(this) ;
1846 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1848 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1851 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1852 ::EraseRect( &rect
) ;
1856 void wxDC::MacInstallFont() const
1858 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1860 // if ( m_macFontInstalled )
1862 Pattern blackColor
;
1863 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1864 if ( m_backgroundMode
!= wxTRANSPARENT
)
1866 Pattern whiteColor
;
1867 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1870 wxASSERT( m_font
.Ok() ) ;
1872 ::TextFont( m_font
.MacGetFontNum() ) ;
1873 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1874 ::TextFace( m_font
.MacGetFontStyle() ) ;
1875 m_macFontInstalled
= true ;
1876 m_macBrushInstalled
= false ;
1877 m_macPenInstalled
= false ;
1878 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1879 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1880 ::RGBForeColor( &forecolor
);
1881 ::RGBBackColor( &backcolor
);
1884 short mode
= patCopy
;
1885 switch ( m_logicalFunction
)
1891 case wxINVERT
: // NOT dst
1892 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1896 case wxXOR
: // src XOR dst
1900 case wxOR_REVERSE
: // src OR (NOT dst)
1904 case wxSRC_INVERT
: // (NOT src)
1908 case wxAND
: // src AND dst
1912 // TODO: unsupported
1914 case wxAND_REVERSE
:// src AND (NOT dst)
1915 case wxAND_INVERT
: // (NOT src) AND dst
1916 case wxNO_OP
: // dst
1917 case wxNOR
: // (NOT src) AND (NOT dst)
1918 case wxEQUIV
: // (NOT src) XOR dst
1919 case wxOR_INVERT
: // (NOT src) OR dst
1920 case wxNAND
: // (NOT src) OR (NOT dst)
1921 case wxOR
: // src OR dst
1923 // case wxSRC_OR: // source _bitmap_ OR destination
1924 // case wxSRC_AND: // source _bitmap_ AND destination
1932 OSStatus status
= noErr
;
1933 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) m_font
.MacGetATSUStyle() , (ATSUStyle
*) &m_macATSUIStyle
) ;
1934 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1936 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1937 ATSUAttributeTag atsuTags
[] =
1941 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1945 // Boolean kTrue = true ;
1946 // Boolean kFalse = false ;
1948 // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
1949 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1953 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1954 atsuTags
, atsuSizes
, atsuValues
);
1956 wxASSERT_MSG( status
== noErr
, wxT("couldn't Modify ATSU style") ) ;
1959 Pattern gPatterns
[] =
1962 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1963 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1964 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1965 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1966 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1967 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1968 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1971 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1972 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1973 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1974 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1977 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1979 int index
= 0; // solid pattern by default
1983 case wxBDIAGONAL_HATCH
: index
= 1; break;
1984 case wxFDIAGONAL_HATCH
: index
= 2; break;
1985 case wxCROSS_HATCH
: index
= 3; break;
1986 case wxHORIZONTAL_HATCH
: index
= 4; break;
1987 case wxVERTICAL_HATCH
: index
= 5; break;
1988 case wxCROSSDIAG_HATCH
: index
= 6; break;
1991 case wxDOT
: index
= 7; break;
1992 case wxLONG_DASH
: index
= 8; break;
1993 case wxSHORT_DASH
: index
= 9; break;
1994 case wxDOT_DASH
: index
= 10; break;
2000 *pattern
= gPatterns
[index
];
2003 void wxDC::MacInstallPen() const
2005 wxCHECK_RET(Ok(), wxT("wxDC::MacInstallPen - invalid DC"));
2007 //Pattern blackColor;
2008 // if ( m_macPenInstalled )
2010 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
2011 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
2012 ::RGBForeColor( &forecolor
);
2013 ::RGBBackColor( &backcolor
);
2015 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
2016 // null means only one pixel, at whatever resolution
2017 if ( penWidth
== 0 )
2019 ::PenSize(penWidth
, penWidth
);
2021 int penStyle
= m_pen
.GetStyle();
2023 if (penStyle
== wxUSER_DASH
)
2025 // FIXME: there should be exactly 8 items in the dash
2027 int number
= m_pen
.GetDashes(&dash
) ;
2029 for ( int i
= 0 ; i
< 8 ; ++i
)
2031 pat
.pat
[i
] = dash
[index
] ;
2032 if (index
< number
- 1)
2038 wxMacGetPattern(penStyle
, &pat
);
2043 short mode
= patCopy
;
2044 switch ( m_logicalFunction
)
2046 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2050 case wxINVERT
: // NOT dst
2051 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2055 case wxXOR
: // src XOR dst
2059 case wxOR_REVERSE
: // src OR (NOT dst)
2063 case wxSRC_INVERT
: // (NOT src)
2067 case wxAND
: // src AND dst
2071 // TODO: unsupported
2073 case wxAND_REVERSE
:// src AND (NOT dst)
2074 case wxAND_INVERT
: // (NOT src) AND dst
2075 case wxNO_OP
: // dst
2076 case wxNOR
: // (NOT src) AND (NOT dst)
2077 case wxEQUIV
: // (NOT src) XOR dst
2078 case wxOR_INVERT
: // (NOT src) OR dst
2079 case wxNAND
: // (NOT src) OR (NOT dst)
2080 case wxOR
: // src OR dst
2082 // case wxSRC_OR: // source _bitmap_ OR destination
2083 // case wxSRC_AND: // source _bitmap_ AND destination
2091 m_macPenInstalled
= true ;
2092 m_macBrushInstalled
= false ;
2093 m_macFontInstalled
= false ;
2096 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2098 Pattern whiteColor
;
2099 if ( background
.Ok() )
2101 switch ( background
.MacGetBrushKind() )
2103 case kwxMacBrushTheme
:
2104 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
2107 case kwxMacBrushThemeBackground
:
2110 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
2111 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2115 case kwxMacBrushColour
:
2117 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2118 int brushStyle
= background
.GetStyle();
2119 if (brushStyle
== wxSOLID
)
2120 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2121 else if (background
.IsHatch())
2124 wxMacGetPattern(brushStyle
, &pat
);
2129 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2140 void wxDC::MacInstallBrush() const
2142 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2143 Pattern blackColor
;
2144 // if ( m_macBrushInstalled )
2147 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2148 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2149 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2151 int brushStyle
= m_brush
.GetStyle();
2152 if (brushStyle
== wxSOLID
)
2154 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2156 else if (m_brush
.IsHatch())
2160 wxMacGetPattern(brushStyle
, &pat
);
2163 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2165 // we force this in order to be compliant with wxMSW
2166 backgroundTransparent
= false ;
2168 // for these the text fore (and back for MASK_OPAQUE) colors are used
2169 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2170 int width
= bitmap
->GetWidth() ;
2171 int height
= bitmap
->GetHeight() ;
2172 GWorldPtr gw
= NULL
;
2174 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2175 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP(NULL
)) ;
2177 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetHBITMAP()) ;
2179 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2180 LockPixels( gwpixmaphandle
) ;
2181 bool isMonochrome
= !IsPortColor( gw
) ;
2182 if ( !isMonochrome
)
2184 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2185 isMonochrome
= true ;
2188 if ( isMonochrome
&& width
== 8 && height
== 8 )
2190 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2191 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2192 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2193 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2194 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2197 for ( int i
= 0 ; i
< 8 ; ++i
)
2199 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2202 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2207 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2208 // caching scheme before putting this into production
2212 PixPatHandle pixpat
= NewPixPat() ;
2213 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2214 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2215 ((**(**pixpat
).patMap
).bounds
.bottom
-
2216 (**(**pixpat
).patMap
).bounds
.top
);
2217 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2218 (**pixpat
).patData
= image
;
2222 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2223 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2224 if ( ctspec
[0].rgb
.red
== 0x0000 )
2226 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2227 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2231 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2232 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2234 ::CTabChanged( ctable
) ;
2237 ::PenPixPat(pixpat
);
2238 m_macForegroundPixMap
= pixpat
;
2241 UnlockPixels( gwpixmaphandle
) ;
2245 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2248 short mode
= patCopy
;
2249 switch ( m_logicalFunction
)
2252 if ( backgroundTransparent
)
2258 case wxINVERT
: // NOT dst
2259 if ( !backgroundTransparent
)
2260 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2264 case wxXOR
: // src XOR dst
2268 case wxOR_REVERSE
: // src OR (NOT dst)
2272 case wxSRC_INVERT
: // (NOT src)
2276 case wxAND
: // src AND dst
2280 // TODO: unsupported
2282 case wxAND_REVERSE
:// src AND (NOT dst)
2283 case wxAND_INVERT
: // (NOT src) AND dst
2284 case wxNO_OP
: // dst
2285 case wxNOR
: // (NOT src) AND (NOT dst)
2286 case wxEQUIV
: // (NOT src) XOR dst
2287 case wxOR_INVERT
: // (NOT src) OR dst
2288 case wxNAND
: // (NOT src) OR (NOT dst)
2289 case wxOR
: // src OR dst
2291 // case wxSRC_OR: // source _bitmap_ OR destination
2292 // case wxSRC_AND: // source _bitmap_ AND destination
2300 m_macBrushInstalled
= true ;
2301 m_macPenInstalled
= false ;
2302 m_macFontInstalled
= false ;
2305 // ---------------------------------------------------------------------------
2306 // coordinates transformations
2307 // ---------------------------------------------------------------------------
2309 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2311 return ((wxDC
*)this)->XDEV2LOG(x
);
2314 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2316 return ((wxDC
*)this)->YDEV2LOG(y
);
2319 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2321 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2324 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2326 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2329 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2331 return ((wxDC
*)this)->XLOG2DEV(x
);
2334 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2336 return ((wxDC
*)this)->YLOG2DEV(y
);
2339 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2341 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2344 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2346 return ((wxDC
*)this)->YLOG2DEVREL(y
);
2349 #endif // !wxMAC_USE_CORE_GRAPHICS