1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
21 #include "wx/region.h"
30 #include "wx/mac/private.h"
31 #include "ATSUnicode.h"
32 #include "TextCommon.h"
33 #include "TextEncodingConverter.h"
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 #define mm2inches 0.0393700787402
44 #define inches2mm 25.4
45 #define mm2twips 56.6929133859
46 #define twips2mm 0.0176388888889
47 #define mm2pt 2.83464566929
48 #define pt2mm 0.352777777778
49 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
51 const double M_PI
= 3.14159265358979 ;
54 const double RAD2DEG
= 180.0 / M_PI
;
55 const short kEmulatedMode
= -1 ;
56 const short kUnsupportedMode
= -2 ;
58 // set to 0 if problems arise
59 #define wxMAC_EXPERIMENTAL_DC 1
61 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
62 m_ph( (GrafPtr
) dc
->m_macPort
)
64 wxASSERT( dc
->Ok() ) ;
66 dc
->MacSetupPort(&m_ph
) ;
68 wxMacPortSetter::~wxMacPortSetter()
70 m_dc
->MacCleanupPort(&m_ph
) ;
73 #if wxMAC_EXPERIMENTAL_DC
74 class wxMacFastPortSetter
77 wxMacFastPortSetter( const wxDC
*dc
)
79 wxASSERT( dc
->Ok() ) ;
80 GetPort( &m_oldPort
) ;
81 SetPort( (GrafPtr
) dc
->m_macPort
) ;
83 dc
->MacSetupPort( NULL
) ;
85 ~wxMacFastPortSetter()
87 SetPort( m_oldPort
) ;
88 m_dc
->MacCleanupPort( NULL
) ;
96 typedef wxMacPortSetter wxMacFastPortSetter
;
99 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
101 m_formerClip
= NewRgn() ;
102 m_newClip
= NewRgn() ;
103 GetClip( m_formerClip
) ;
108 // this clipping area was set to the parent window's drawing area, lead to problems
109 // with MacOSX controls drawing outside their wx' rectangle
110 RgnHandle insidergn
= NewRgn() ;
112 wxWindow
*parent
= win
->GetParent() ;
113 parent
->MacWindowToRootWindow( &x
,&y
) ;
114 wxSize size
= parent
->GetSize() ;
115 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
116 size
.x
- parent
->MacGetRightBorderSize(),
117 size
.y
- parent
->MacGetBottomBorderSize()) ;
118 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
119 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
120 OffsetRgn( m_newClip
, x
, y
) ;
121 SetClip( m_newClip
) ;
122 DisposeRgn( insidergn
) ;
125 win
->MacWindowToRootWindow( &x
,&y
) ;
126 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
127 OffsetRgn( m_newClip
, x
, y
) ;
128 SetClip( m_newClip
) ;
133 wxMacWindowClipper::~wxMacWindowClipper()
135 SetClip( m_formerClip
) ;
136 DisposeRgn( m_newClip
) ;
137 DisposeRgn( m_formerClip
) ;
140 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
144 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
145 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
147 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
150 // this function emulates all wx colour manipulations, used to verify the implementation
151 // by setting the mode in the blitting functions to kEmulatedMode
152 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
154 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
156 switch ( logical_func
)
158 case wxAND
: // src AND dst
159 dstColor
.red
= dstColor
.red
& srcColor
.red
;
160 dstColor
.green
= dstColor
.green
& srcColor
.green
;
161 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
163 case wxAND_INVERT
: // (NOT src) AND dst
164 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
165 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
166 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
168 case wxAND_REVERSE
:// src AND (NOT dst)
169 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
170 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
171 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
179 dstColor
.red
= srcColor
.red
;
180 dstColor
.green
= srcColor
.green
;
181 dstColor
.blue
= srcColor
.blue
;
183 case wxEQUIV
: // (NOT src) XOR dst
184 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
185 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
186 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
188 case wxINVERT
: // NOT dst
189 dstColor
.red
= ~dstColor
.red
;
190 dstColor
.green
= ~dstColor
.green
;
191 dstColor
.blue
= ~dstColor
.blue
;
193 case wxNAND
: // (NOT src) OR (NOT dst)
194 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
195 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
196 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
198 case wxNOR
: // (NOT src) AND (NOT dst)
199 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
200 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
201 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
205 case wxOR
: // src OR dst
206 dstColor
.red
= dstColor
.red
| srcColor
.red
;
207 dstColor
.green
= dstColor
.green
| srcColor
.green
;
208 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
210 case wxOR_INVERT
: // (NOT src) OR dst
211 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
212 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
213 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
215 case wxOR_REVERSE
: // src OR (NOT dst)
216 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
217 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
218 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
221 dstColor
.red
= 0xFFFF ;
222 dstColor
.green
= 0xFFFF ;
223 dstColor
.blue
= 0xFFFF ;
225 case wxSRC_INVERT
: // (NOT src)
226 dstColor
.red
= ~srcColor
.red
;
227 dstColor
.green
= ~srcColor
.green
;
228 dstColor
.blue
= ~srcColor
.blue
;
230 case wxXOR
: // src XOR dst
231 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
232 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
233 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
242 m_mm_to_pix_x
= mm2pt
;
243 m_mm_to_pix_y
= mm2pt
;
244 m_internalDeviceOriginX
= 0;
245 m_internalDeviceOriginY
= 0;
246 m_externalDeviceOriginX
= 0;
247 m_externalDeviceOriginY
= 0;
248 m_logicalScaleX
= 1.0;
249 m_logicalScaleY
= 1.0;
254 m_needComputeScaleX
= FALSE
;
255 m_needComputeScaleY
= FALSE
;
259 m_macFontInstalled
= false ;
260 m_macBrushInstalled
= false ;
261 m_macPenInstalled
= false ;
262 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
263 m_macBoundaryClipRgn
= NewRgn() ;
264 m_macCurrentClipRgn
= NewRgn() ;
265 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
266 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
267 m_pen
= *wxBLACK_PEN
;
268 m_font
= *wxNORMAL_FONT
;
269 m_brush
= *wxWHITE_BRUSH
;
271 // needed to debug possible errors with two active drawing methods at the same time on
273 m_macCurrentPortStateHelper
= NULL
;
275 m_macATSUIStyle
= NULL
;
276 m_macAliasWasEnabled
= false;
277 m_macForegroundPixMap
= NULL
;
278 m_macBackgroundPixMap
= NULL
;
283 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
284 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
287 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
290 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
291 m_macCurrentPortStateHelper
= help
;
293 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
294 #if ! wxMAC_EXPERIMENTAL_DC
295 m_macFontInstalled
= false ;
296 m_macBrushInstalled
= false ;
297 m_macPenInstalled
= false ;
300 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
303 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
304 m_macCurrentPortStateHelper
= NULL
;
306 if( m_macATSUIStyle
)
308 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
309 m_macATSUIStyle
= NULL
;
311 if ( m_macAliasWasEnabled
)
313 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
314 m_macAliasWasEnabled
= false ;
316 if ( m_macForegroundPixMap
)
319 ::PenPat(GetQDGlobalsBlack(&blackColor
));
320 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
321 m_macForegroundPixMap
= NULL
;
323 if ( m_macBackgroundPixMap
)
326 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
327 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
328 m_macBackgroundPixMap
= NULL
;
332 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
334 wxCHECK_RET( Ok(), wxT("invalid window dc") );
335 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
336 wxMacFastPortSetter
helper(this) ;
337 wxCoord xx
= XLOG2DEVMAC(x
);
338 wxCoord yy
= YLOG2DEVMAC(y
);
339 wxCoord w
= bmp
.GetWidth();
340 wxCoord h
= bmp
.GetHeight();
341 wxCoord ww
= XLOG2DEVREL(w
);
342 wxCoord hh
= YLOG2DEVREL(h
);
343 // Set up drawing mode
344 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
345 //m_logicalFunction == wxCLEAR ? WHITENESS :
346 //m_logicalFunction == wxSET ? BLACKNESS :
347 m_logicalFunction
== wxINVERT
? hilite
:
348 //m_logicalFunction == wxAND ? MERGECOPY :
349 m_logicalFunction
== wxOR
? srcOr
:
350 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
351 m_logicalFunction
== wxXOR
? srcXor
:
352 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
353 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
354 //m_logicalFunction == wxSRC_OR ? srcOr :
355 //m_logicalFunction == wxSRC_AND ? SRCAND :
357 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
358 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
359 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
360 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
362 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
364 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
365 PixMapHandle bmappixels
;
366 // Set foreground and background colours (for bitmaps depth = 1)
367 if(bmp
.GetDepth() == 1)
369 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
370 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
376 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
377 RGBColor black
= { 0,0,0} ;
378 RGBForeColor( &black
) ;
379 RGBBackColor( &white
) ;
381 bmappixels
= GetGWorldPixMap( bmapworld
) ;
382 wxCHECK_RET(LockPixels(bmappixels
),
383 wxT("DoDrawBitmap: Unable to lock pixels"));
384 Rect source
= { 0, 0, h
, w
};
385 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
386 if ( useMask
&& bmp
.GetMask() )
388 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
392 GetPortBitMapForCopyBits(bmapworld
),
393 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
394 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
395 &source
, &source
, &dest
, mode
, NULL
397 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
401 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
402 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
403 &source
, &dest
, mode
, NULL
) ;
405 UnlockPixels( bmappixels
) ;
407 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
409 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
410 OffsetRect( &bitmaprect
, xx
, yy
) ;
411 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
413 m_macPenInstalled
= false ;
414 m_macBrushInstalled
= false ;
415 m_macFontInstalled
= false ;
418 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
420 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
421 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
422 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
425 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
427 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
428 wxCoord xx
, yy
, ww
, hh
;
431 ww
= XLOG2DEVREL(width
);
432 hh
= YLOG2DEVREL(height
);
433 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
434 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
437 m_clipX1
= wxMax( m_clipX1
, xx
);
438 m_clipY1
= wxMax( m_clipY1
, yy
);
439 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
440 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
452 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
454 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
457 DestroyClippingRegion();
460 wxMacFastPortSetter
helper(this) ;
462 region
.GetBox( x
, y
, w
, h
);
463 wxCoord xx
, yy
, ww
, hh
;
468 // if we have a scaling that we cannot map onto native regions
469 // we must use the box
470 if ( ww
!= w
|| hh
!= h
)
472 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
476 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
477 if ( xx
!= x
|| yy
!= y
)
479 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
481 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
484 m_clipX1
= wxMax( m_clipX1
, xx
);
485 m_clipY1
= wxMax( m_clipY1
, yy
);
486 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
487 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
500 void wxDC::DestroyClippingRegion()
502 wxMacFastPortSetter
helper(this) ;
503 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
507 void wxDC::DoGetSizeMM( int* width
, int* height
) const
512 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
513 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
516 void wxDC::SetTextForeground( const wxColour
&col
)
518 wxCHECK_RET(Ok(), wxT("Invalid DC"));
519 m_textForegroundColour
= col
;
520 m_macFontInstalled
= false ;
523 void wxDC::SetTextBackground( const wxColour
&col
)
525 wxCHECK_RET(Ok(), wxT("Invalid DC"));
526 m_textBackgroundColour
= col
;
527 m_macFontInstalled
= false ;
530 void wxDC::SetMapMode( int mode
)
535 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
538 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
541 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
544 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
548 SetLogicalScale( 1.0, 1.0 );
551 if (mode
!= wxMM_TEXT
)
553 m_needComputeScaleX
= TRUE
;
554 m_needComputeScaleY
= TRUE
;
558 void wxDC::SetUserScale( double x
, double y
)
560 // allow negative ? -> no
563 ComputeScaleAndOrigin();
566 void wxDC::SetLogicalScale( double x
, double y
)
571 ComputeScaleAndOrigin();
574 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
576 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
577 m_logicalOriginY
= y
* m_signY
;
578 ComputeScaleAndOrigin();
581 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
583 m_externalDeviceOriginX
= x
;
584 m_externalDeviceOriginY
= y
;
585 ComputeScaleAndOrigin();
589 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
591 m_internalDeviceOriginX
= x
;
592 m_internalDeviceOriginY
= y
;
593 ComputeScaleAndOrigin();
595 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
597 if (x
) *x
= m_internalDeviceOriginX
;
598 if (y
) *y
= m_internalDeviceOriginY
;
602 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
604 m_signX
= (xLeftRight
? 1 : -1);
605 m_signY
= (yBottomUp
? -1 : 1);
606 ComputeScaleAndOrigin();
609 wxSize
wxDC::GetPPI() const
611 return wxSize(72, 72);
614 int wxDC::GetDepth() const
616 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
618 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
623 void wxDC::ComputeScaleAndOrigin()
625 // CMB: copy scale to see if it changes
626 double origScaleX
= m_scaleX
;
627 double origScaleY
= m_scaleY
;
628 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
629 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
630 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
631 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
632 // CMB: if scale has changed call SetPen to recalulate the line width
633 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
635 // this is a bit artificial, but we need to force wxDC to think
636 // the pen has changed
637 wxPen
* pen
= & GetPen();
644 void wxDC::SetPalette( const wxPalette
& palette
)
648 void wxDC::SetBackgroundMode( int mode
)
650 m_backgroundMode
= mode
;
653 void wxDC::SetFont( const wxFont
&font
)
656 m_macFontInstalled
= false ;
659 void wxDC::SetPen( const wxPen
&pen
)
664 m_macPenInstalled
= false ;
667 void wxDC::SetBrush( const wxBrush
&brush
)
669 if (m_brush
== brush
)
672 m_macBrushInstalled
= false ;
675 void wxDC::SetBackground( const wxBrush
&brush
)
677 if (m_backgroundBrush
== brush
)
679 m_backgroundBrush
= brush
;
680 if (!m_backgroundBrush
.Ok())
682 m_macBrushInstalled
= false ;
685 void wxDC::SetLogicalFunction( int function
)
687 if (m_logicalFunction
== function
)
689 m_logicalFunction
= function
;
690 m_macFontInstalled
= false ;
691 m_macBrushInstalled
= false ;
692 m_macPenInstalled
= false ;
695 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
696 const wxColour
& col
, int style
);
698 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
699 const wxColour
& col
, int style
)
701 return wxDoFloodFill(this, x
, y
, col
, style
);
704 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
706 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
707 wxMacFastPortSetter
helper(this) ;
709 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
710 // Convert from Mac colour to wx
711 col
->Set( colour
.red
>> 8,
717 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
719 wxCHECK_RET(Ok(), wxT("Invalid DC"));
720 wxMacFastPortSetter
helper(this) ;
721 if (m_pen
.GetStyle() != wxTRANSPARENT
)
724 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
725 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
726 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
727 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
728 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
729 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
730 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
731 (m_pen
.GetWidth() <= 1))
733 // Implement LAST_NOT for MAC at least for
734 // orthogonal lines. RR.
755 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
757 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
758 wxMacFastPortSetter
helper(this) ;
759 if (m_pen
.GetStyle() != wxTRANSPARENT
)
764 wxCoord xx
= XLOG2DEVMAC(x
);
765 wxCoord yy
= YLOG2DEVMAC(y
);
767 ::MoveTo( XLOG2DEVMAC(0), yy
);
768 ::LineTo( XLOG2DEVMAC(w
), yy
);
769 ::MoveTo( xx
, YLOG2DEVMAC(0) );
770 ::LineTo( xx
, YLOG2DEVMAC(h
) );
771 CalcBoundingBox(x
, y
);
772 CalcBoundingBox(x
+w
, y
+h
);
777 * To draw arcs properly the angles need to be converted from the WX style:
778 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
779 * a normal axis on paper).
782 * Angles start on the +ve y axis and go clockwise.
785 static double wxConvertWXangleToMACangle(double angle
)
787 double newAngle
= 90 - angle
;
793 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
794 wxCoord x2
, wxCoord y2
,
795 wxCoord xc
, wxCoord yc
)
797 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
798 wxMacFastPortSetter
helper(this) ;
799 wxCoord xx1
= XLOG2DEVMAC(x1
);
800 wxCoord yy1
= YLOG2DEVMAC(y1
);
801 wxCoord xx2
= XLOG2DEVMAC(x2
);
802 wxCoord yy2
= YLOG2DEVMAC(y2
);
803 wxCoord xxc
= XLOG2DEVMAC(xc
);
804 wxCoord yyc
= YLOG2DEVMAC(yc
);
805 double dx
= xx1
- xxc
;
806 double dy
= yy1
- yyc
;
807 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
808 wxCoord rad
= (wxCoord
)radius
;
809 double radius1
, radius2
;
810 if (xx1
== xx2
&& yy1
== yy2
)
815 else if (radius
== 0.0)
817 radius1
= radius2
= 0.0;
821 radius1
= (xx1
- xxc
== 0) ?
822 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
823 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
824 radius2
= (xx2
- xxc
== 0) ?
825 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
826 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
828 wxCoord alpha2
= wxCoord(radius2
- radius1
);
829 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
830 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
833 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
834 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
836 PaintArc(&r
, alpha1
, alpha2
);
838 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
840 FrameArc(&r
, alpha1
, alpha2
);
844 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
845 double sa
, double ea
)
847 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
848 wxMacFastPortSetter
helper(this) ;
850 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
851 // we have to make sure that the filling is always counter-clockwise
854 wxCoord xx
= XLOG2DEVMAC(x
);
855 wxCoord yy
= YLOG2DEVMAC(y
);
856 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
857 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
858 // handle -ve width and/or height
859 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
860 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
861 sa
= wxConvertWXangleToMACangle(sa
);
866 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
868 PaintArc(&r
, (short)sa
, (short)angle
);
870 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
872 FrameArc(&r
, (short)sa
, (short)angle
);
876 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
878 wxCHECK_RET(Ok(), wxT("Invalid DC"));
879 wxMacFastPortSetter
helper(this) ;
880 if (m_pen
.GetStyle() != wxTRANSPARENT
)
882 wxCoord xx1
= XLOG2DEVMAC(x
);
883 wxCoord yy1
= YLOG2DEVMAC(y
);
884 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
885 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
886 CalcBoundingBox(x
, y
);
890 void wxDC::DoDrawLines(int n
, wxPoint points
[],
891 wxCoord xoffset
, wxCoord yoffset
)
893 wxCHECK_RET(Ok(), wxT("Invalid DC"));
894 wxMacFastPortSetter
helper(this) ;
895 if (m_pen
.GetStyle() == wxTRANSPARENT
)
898 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
899 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
900 wxCoord x1
, x2
, y1
, y2
;
901 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
902 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
903 ::MoveTo(x1
- offset
, y1
- offset
);
904 for (int i
= 0; i
< n
-1; i
++)
906 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
907 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
908 ::LineTo( x2
- offset
, y2
- offset
);
912 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
913 wxCoord xoffset
, wxCoord yoffset
,
916 wxCHECK_RET(Ok(), wxT("Invalid DC"));
917 wxMacFastPortSetter
helper(this) ;
918 wxCoord x1
, x2
, y1
, y2
;
919 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
921 PolyHandle polygon
= OpenPoly();
922 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
923 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
925 for (int i
= 1; i
< n
; i
++)
927 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
928 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
931 // close the polyline if necessary
932 if ( x1
!= x2
|| y1
!= y2
)
937 if (m_brush
.GetStyle() != wxTRANSPARENT
)
940 ::PaintPoly( polygon
);
942 if (m_pen
.GetStyle() != wxTRANSPARENT
)
945 ::FramePoly( polygon
) ;
950 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
952 wxCHECK_RET(Ok(), wxT("Invalid DC"));
953 wxMacFastPortSetter
helper(this) ;
954 wxCoord xx
= XLOG2DEVMAC(x
);
955 wxCoord yy
= YLOG2DEVMAC(y
);
956 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
957 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
958 // CMB: draw nothing if transformed w or h is 0
959 if (ww
== 0 || hh
== 0)
961 // CMB: handle -ve width and/or height
972 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
973 if (m_brush
.GetStyle() != wxTRANSPARENT
)
976 ::PaintRect( &rect
) ;
978 if (m_pen
.GetStyle() != wxTRANSPARENT
)
981 ::FrameRect( &rect
) ;
985 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
986 wxCoord width
, wxCoord height
,
989 wxCHECK_RET(Ok(), wxT("Invalid DC"));
990 wxMacFastPortSetter
helper(this) ;
992 radius
= - radius
* ((width
< height
) ? width
: height
);
993 wxCoord xx
= XLOG2DEVMAC(x
);
994 wxCoord yy
= YLOG2DEVMAC(y
);
995 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
996 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
997 // CMB: draw nothing if transformed w or h is 0
998 if (ww
== 0 || hh
== 0)
1000 // CMB: handle -ve width and/or height
1011 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1012 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1015 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1017 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1020 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1024 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1026 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1027 wxMacFastPortSetter
helper(this) ;
1028 wxCoord xx
= XLOG2DEVMAC(x
);
1029 wxCoord yy
= YLOG2DEVMAC(y
);
1030 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1031 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1032 // CMB: draw nothing if transformed w or h is 0
1033 if (ww
== 0 || hh
== 0)
1035 // CMB: handle -ve width and/or height
1046 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1047 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1050 ::PaintOval( &rect
) ;
1052 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1055 ::FrameOval( &rect
) ;
1059 bool wxDC::CanDrawBitmap(void) const
1064 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1065 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1066 wxCoord xsrcMask
, wxCoord ysrcMask
)
1068 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1069 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1070 if ( logical_func
== wxNO_OP
)
1072 if (xsrcMask
== -1 && ysrcMask
== -1)
1074 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1076 // correct the parameter in case this dc does not have a mask at all
1077 if ( useMask
&& !source
->m_macMask
)
1079 Rect srcrect
, dstrect
;
1080 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1081 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1082 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1083 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1084 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1085 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1086 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1087 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1088 short mode
= kUnsupportedMode
;
1089 bool invertDestinationFirst
= false ;
1090 switch ( logical_func
)
1092 case wxAND
: // src AND dst
1093 mode
= adMin
; // ok
1095 case wxAND_INVERT
: // (NOT src) AND dst
1096 mode
= notSrcOr
; // ok
1098 case wxAND_REVERSE
:// src AND (NOT dst)
1099 invertDestinationFirst
= true ;
1103 mode
= kEmulatedMode
;
1106 mode
= srcCopy
; // ok
1108 case wxEQUIV
: // (NOT src) XOR dst
1109 mode
= srcXor
; // ok
1111 case wxINVERT
: // NOT dst
1112 mode
= kEmulatedMode
; //or hilite ;
1114 case wxNAND
: // (NOT src) OR (NOT dst)
1115 invertDestinationFirst
= true ;
1118 case wxNOR
: // (NOT src) AND (NOT dst)
1119 invertDestinationFirst
= true ;
1122 case wxNO_OP
: // dst
1123 mode
= kEmulatedMode
; // this has already been handled upon entry
1125 case wxOR
: // src OR dst
1128 case wxOR_INVERT
: // (NOT src) OR dst
1131 case wxOR_REVERSE
: // src OR (NOT dst)
1132 invertDestinationFirst
= true ;
1136 mode
= kEmulatedMode
;
1138 case wxSRC_INVERT
: // (NOT src)
1139 mode
= notSrcCopy
; // ok
1141 case wxXOR
: // src XOR dst
1142 mode
= notSrcXor
; // ok
1147 if ( mode
== kUnsupportedMode
)
1149 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1152 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1153 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1154 if ( LockPixels(bmappixels
) )
1156 wxMacFastPortSetter
helper(this) ;
1157 if ( source
->GetDepth() == 1 )
1159 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1160 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1164 // the modes need this, otherwise we'll end up having really nice colors...
1165 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1166 RGBColor black
= { 0,0,0} ;
1167 RGBForeColor( &black
) ;
1168 RGBBackColor( &white
) ;
1170 if ( useMask
&& source
->m_macMask
)
1172 if ( mode
== srcCopy
)
1174 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1176 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1177 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1178 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1179 &srcrect
, &srcrect
, &dstrect
) ;
1180 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1185 RgnHandle clipRgn
= NewRgn() ;
1186 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1187 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1188 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1189 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1190 if ( mode
== kEmulatedMode
)
1193 ::PenPat(GetQDGlobalsBlack(&pat
));
1194 if ( logical_func
== wxSET
)
1196 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1197 ::RGBForeColor( &col
) ;
1198 ::PaintRgn( clipRgn
) ;
1200 else if ( logical_func
== wxCLEAR
)
1202 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1203 ::RGBForeColor( &col
) ;
1204 ::PaintRgn( clipRgn
) ;
1206 else if ( logical_func
== wxINVERT
)
1208 MacInvertRgn( clipRgn
) ;
1212 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1214 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1216 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1217 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1218 if ( PtInRgn( dstPoint
, clipRgn
) )
1222 SetPort( (GrafPtr
) sourcePort
) ;
1223 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1224 SetPort( (GrafPtr
) m_macPort
) ;
1225 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1226 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1227 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1235 if ( invertDestinationFirst
)
1237 MacInvertRgn( clipRgn
) ;
1239 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1240 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1241 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1243 DisposeRgn( clipRgn
) ;
1248 RgnHandle clipRgn
= NewRgn() ;
1249 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1250 if ( mode
== kEmulatedMode
)
1253 ::PenPat(GetQDGlobalsBlack(&pat
));
1254 if ( logical_func
== wxSET
)
1256 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1257 ::RGBForeColor( &col
) ;
1258 ::PaintRgn( clipRgn
) ;
1260 else if ( logical_func
== wxCLEAR
)
1262 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1263 ::RGBForeColor( &col
) ;
1264 ::PaintRgn( clipRgn
) ;
1266 else if ( logical_func
== wxINVERT
)
1268 MacInvertRgn( clipRgn
) ;
1272 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1274 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1276 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1277 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1281 SetPort( (GrafPtr
) sourcePort
) ;
1282 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1283 SetPort( (GrafPtr
) m_macPort
) ;
1284 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1285 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1286 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1294 if ( invertDestinationFirst
)
1296 MacInvertRgn( clipRgn
) ;
1298 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1299 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1300 &srcrect
, &dstrect
, mode
, NULL
) ;
1302 DisposeRgn( clipRgn
) ;
1304 UnlockPixels( bmappixels
) ;
1306 m_macPenInstalled
= false ;
1307 m_macBrushInstalled
= false ;
1308 m_macFontInstalled
= false ;
1313 // as macro in FixMath.h for 10.3
1314 inline Fixed
IntToFixed( int inInt
)
1316 return (((SInt32
) inInt
) << 16);
1319 inline int FixedToInt( Fixed inFixed
)
1321 return (((SInt32
) inFixed
) >> 16);
1325 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1328 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1332 DrawText(str
, x
, y
);
1336 if ( str
.Length() == 0 )
1339 wxMacFastPortSetter
helper(this) ;
1342 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1345 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1346 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1347 m_macAliasWasEnabled
= true ;
1349 OSStatus status
= noErr
;
1350 ATSUTextLayout atsuLayout
;
1351 UniCharCount chars
= str
.Length() ;
1353 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1354 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1357 status
= TECCreateConverter(&ec
,
1358 wxApp::s_macDefaultEncodingIsPC
1359 ? (int)kTextEncodingWindowsLatin1
1360 : (int)kTextEncodingMacRoman
,
1361 kTextEncodingUnicodeDefault
);
1363 wxASSERT_MSG( status
== noErr
, wxT("couldn't start converter") ) ;
1364 ByteCount byteOutLen
;
1365 ByteCount byteInLen
= str
.Length() ;
1366 ByteCount byteBufferLen
= byteInLen
*2 ;
1367 char* buf
= new char[byteBufferLen
] ;
1368 status
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
,
1369 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1370 wxASSERT_MSG( status
== noErr
, wxT("couldn't convert text") ) ;
1371 status
= TECDisposeConverter(ec
);
1372 wxASSERT_MSG( status
== noErr
, wxT("couldn't dispose converter") ) ;
1373 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1374 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1376 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1377 int iAngle
= int( angle
);
1378 int drawX
= XLOG2DEVMAC(x
) ;
1379 int drawY
= YLOG2DEVMAC(y
) ;
1381 ATSUTextMeasurement textBefore
;
1382 ATSUTextMeasurement textAfter
;
1383 ATSUTextMeasurement ascent
;
1384 ATSUTextMeasurement descent
;
1387 if ( abs(iAngle
) > 0 )
1389 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1390 ATSUAttributeTag atsuTags
[] =
1392 kATSULineRotationTag
,
1394 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1398 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1402 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1403 atsuTags
, atsuSizes
, atsuValues
) ;
1405 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1406 &textBefore
, &textAfter
, &ascent
, &descent
);
1408 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1409 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1410 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1411 IntToFixed(drawX
) , IntToFixed(drawY
) );
1412 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1414 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1415 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1416 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1417 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1418 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1419 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1420 ::ATSUDisposeTextLayout(atsuLayout
);
1427 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1429 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1431 wxMacFastPortSetter
helper(this) ;
1432 long xx
= XLOG2DEVMAC(x
);
1433 long yy
= YLOG2DEVMAC(y
);
1435 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1436 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1437 useDrawThemeText
= false ;
1442 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1443 SetAntiAliasedTextEnabled(true, 8);
1444 m_macAliasWasEnabled
= true ;
1447 ::GetFontInfo( &fi
) ;
1449 if ( !useDrawThemeText
)
1452 ::MoveTo( xx
, yy
);
1453 if ( m_backgroundMode
== wxTRANSPARENT
)
1455 ::TextMode( srcOr
) ;
1459 ::TextMode( srcCopy
) ;
1461 int length
= strtext
.Length() ;
1469 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1471 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1473 if ( useDrawThemeText
)
1475 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1476 wxMacCFStringHolder
mString( linetext
) ;
1477 if ( m_backgroundMode
!= wxTRANSPARENT
)
1479 Point bounds
={0,0} ;
1480 Rect background
= frame
;
1482 ::GetThemeTextDimensions( mString
,
1483 kThemeCurrentPortFont
,
1488 background
.right
= background
.left
+ bounds
.h
;
1489 background
.bottom
= background
.top
+ bounds
.v
;
1490 ::EraseRect( &background
) ;
1492 ::DrawThemeTextBox( mString
,
1493 kThemeCurrentPortFont
,
1504 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1505 ::DrawText( text
, 0 , strlen(text
) ) ;
1507 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1513 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1515 if ( useDrawThemeText
)
1517 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1518 wxMacCFStringHolder
mString( linetext
) ;
1520 if ( m_backgroundMode
!= wxTRANSPARENT
)
1522 Point bounds
={0,0} ;
1523 Rect background
= frame
;
1525 ::GetThemeTextDimensions( mString
,
1526 kThemeCurrentPortFont
,
1531 background
.right
= background
.left
+ bounds
.h
;
1532 background
.bottom
= background
.top
+ bounds
.v
;
1533 ::EraseRect( &background
) ;
1535 ::DrawThemeTextBox( mString
,
1536 kThemeCurrentPortFont
,
1546 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1547 ::DrawText( text
, 0 , strlen(text
) ) ;
1550 ::TextMode( srcOr
) ;
1553 bool wxDC::CanGetTextExtent() const
1555 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1559 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1560 wxCoord
*descent
, wxCoord
*externalLeading
,
1561 wxFont
*theFont
) const
1563 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1564 wxMacFastPortSetter
helper(this) ;
1565 wxFont formerFont
= m_font
;
1568 // work around the constness
1569 *((wxFont
*)(&m_font
)) = *theFont
;
1573 ::GetFontInfo( &fi
) ;
1575 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1576 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1577 useGetThemeText
= false ;
1580 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1582 *descent
=YDEV2LOGREL( fi
.descent
);
1583 if ( externalLeading
)
1584 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1585 int length
= strtext
.Length() ;
1587 const char *text = NULL ;
1589 if ( wxApp::s_macDefaultEncodingIsPC )
1591 macText = wxMacMakeMacStringFromPC( string ) ;
1593 length = macText.Length() ;
1598 length = string.Length() ;
1609 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1611 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1613 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1615 if ( useGetThemeText
)
1617 Point bounds
={0,0} ;
1619 wxMacCFStringHolder
mString( linetext
) ;
1620 ::GetThemeTextDimensions( mString
,
1621 kThemeCurrentPortFont
,
1626 curwidth
= bounds
.h
;
1631 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1632 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1634 if ( curwidth
> *width
)
1635 *width
= XDEV2LOGREL( curwidth
) ;
1641 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1643 if ( useGetThemeText
)
1645 Point bounds
={0,0} ;
1647 wxMacCFStringHolder
mString( linetext
) ;
1648 ::GetThemeTextDimensions( mString
,
1649 kThemeCurrentPortFont
,
1654 curwidth
= bounds
.h
;
1659 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1660 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1662 if ( curwidth
> *width
)
1663 *width
= XDEV2LOGREL( curwidth
) ;
1667 // work around the constness
1668 *((wxFont
*)(&m_font
)) = formerFont
;
1669 m_macFontInstalled
= false ;
1673 wxCoord
wxDC::GetCharWidth(void) const
1675 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1676 wxMacFastPortSetter
helper(this) ;
1680 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1681 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1682 useGetThemeText
= false ;
1686 if ( useGetThemeText
)
1688 Point bounds
={0,0} ;
1690 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1691 ::GetThemeTextDimensions( mString
,
1692 kThemeCurrentPortFont
,
1697 CFRelease( mString
) ;
1703 width
= ::TextWidth( text
, 0 , 1 ) ;
1705 return YDEV2LOGREL(width
) ;
1708 wxCoord
wxDC::GetCharHeight(void) const
1710 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1711 wxMacFastPortSetter
helper(this) ;
1714 ::GetFontInfo( &fi
) ;
1715 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1718 void wxDC::Clear(void)
1720 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1721 wxMacFastPortSetter
helper(this) ;
1722 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1723 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1726 //MacInstallBrush() ;
1727 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1728 ::EraseRect( &rect
) ;
1732 void wxDC::MacInstallFont() const
1734 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1735 // if ( m_macFontInstalled )
1737 Pattern blackColor
;
1738 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1739 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1742 ::TextFont( font
->m_macFontNum
) ;
1743 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1744 ::TextFace( font
->m_macFontStyle
) ;
1745 m_macFontInstalled
= true ;
1746 m_macBrushInstalled
= false ;
1747 m_macPenInstalled
= false ;
1748 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1749 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1750 ::RGBForeColor( &forecolor
);
1751 ::RGBBackColor( &backcolor
);
1755 FontFamilyID fontId
;
1759 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1760 GetFNum( fontName
, &fontId
);
1761 ::TextFont( fontId
) ;
1762 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1763 ::TextFace( fontStyle
) ;
1764 // todo reset after spacing changes - or store the current spacing somewhere
1765 m_macFontInstalled
= true ;
1766 m_macBrushInstalled
= false ;
1767 m_macPenInstalled
= false ;
1768 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1769 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1770 ::RGBForeColor( &forecolor
);
1771 ::RGBBackColor( &backcolor
);
1773 short mode
= patCopy
;
1775 switch( m_logicalFunction
)
1780 case wxINVERT
: // NOT dst
1781 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1784 case wxXOR
: // src XOR dst
1787 case wxOR_REVERSE
: // src OR (NOT dst)
1790 case wxSRC_INVERT
: // (NOT src)
1793 case wxAND
: // src AND dst
1798 case wxAND_REVERSE
:// src AND (NOT dst)
1799 case wxAND_INVERT
: // (NOT src) AND dst
1800 case wxNO_OP
: // dst
1801 case wxNOR
: // (NOT src) AND (NOT dst)
1802 case wxEQUIV
: // (NOT src) XOR dst
1803 case wxOR_INVERT
: // (NOT src) OR dst
1804 case wxNAND
: // (NOT src) OR (NOT dst)
1805 case wxOR
: // src OR dst
1807 // case wxSRC_OR: // source _bitmap_ OR destination
1808 // case wxSRC_AND: // source _bitmap_ AND destination
1812 OSStatus status
= noErr
;
1813 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1814 Style qdStyle
= font
->m_macFontStyle
;
1815 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1816 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1817 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1818 ATSUAttributeTag atsuTags
[] =
1823 // kATSUBaselineClassTag ,
1824 kATSUVerticalCharacterTag
,
1825 kATSUQDBoldfaceTag
,
1827 kATSUQDUnderlineTag
,
1828 kATSUQDCondensedTag
,
1829 kATSUQDExtendedTag
,
1831 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1833 sizeof( ATSUFontID
) ,
1835 // sizeof( RGBColor ) ,
1836 // sizeof( BslnBaselineClass ) ,
1837 sizeof( ATSUVerticalCharacterType
),
1844 Boolean kTrue
= true ;
1845 Boolean kFalse
= false ;
1846 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1847 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1848 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1852 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1853 // &kBaselineDefault ,
1855 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1856 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1857 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1858 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1859 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1861 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1862 atsuTags
, atsuSizes
, atsuValues
);
1863 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1866 Pattern gPatterns
[] =
1868 { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ,
1869 { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } ,
1870 { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } ,
1871 { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } ,
1872 { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } ,
1873 { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } ,
1874 { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } ,
1876 { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } , // DOT
1877 { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } , // LONG_DASH
1878 { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } , // SHORT_DASH
1879 { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } , // DOT_DASH
1882 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1884 int index
= 0; // solid pattern by default
1888 case wxBDIAGONAL_HATCH
: index
= 1; break;
1889 case wxFDIAGONAL_HATCH
: index
= 2; break;
1890 case wxCROSS_HATCH
: index
= 3; break;
1891 case wxHORIZONTAL_HATCH
: index
= 4; break;
1892 case wxVERTICAL_HATCH
: index
= 5; break;
1893 case wxCROSSDIAG_HATCH
: index
= 6; break;
1895 case wxDOT
: index
= 7; break;
1896 case wxLONG_DASH
: index
= 8; break;
1897 case wxSHORT_DASH
: index
= 9; break;
1898 case wxDOT_DASH
: index
= 10; break;
1900 *pattern
= gPatterns
[index
];
1903 void wxDC::MacInstallPen() const
1905 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1907 // if ( m_macPenInstalled )
1909 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1910 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1911 ::RGBForeColor( &forecolor
);
1912 ::RGBBackColor( &backcolor
);
1914 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1915 // null means only one pixel, at whatever resolution
1916 if ( penWidth
== 0 )
1918 ::PenSize(penWidth
, penWidth
);
1920 int penStyle
= m_pen
.GetStyle();
1922 if (penStyle
== wxUSER_DASH
)
1924 // FIXME: there should be exactly 8 items in the dash
1926 int number
= m_pen
.GetDashes(&dash
) ;
1928 for ( int i
= 0 ; i
< 8 ; ++i
)
1930 pat
.pat
[i
] = dash
[index
] ;
1931 if (index
< number
- 1)
1937 wxMacGetPattern(penStyle
, &pat
);
1941 short mode
= patCopy
;
1943 switch( m_logicalFunction
)
1945 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1948 case wxINVERT
: // NOT dst
1949 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1952 case wxXOR
: // src XOR dst
1955 case wxOR_REVERSE
: // src OR (NOT dst)
1958 case wxSRC_INVERT
: // (NOT src)
1961 case wxAND
: // src AND dst
1966 case wxAND_REVERSE
:// src AND (NOT dst)
1967 case wxAND_INVERT
: // (NOT src) AND dst
1968 case wxNO_OP
: // dst
1969 case wxNOR
: // (NOT src) AND (NOT dst)
1970 case wxEQUIV
: // (NOT src) XOR dst
1971 case wxOR_INVERT
: // (NOT src) OR dst
1972 case wxNAND
: // (NOT src) OR (NOT dst)
1973 case wxOR
: // src OR dst
1975 // case wxSRC_OR: // source _bitmap_ OR destination
1976 // case wxSRC_AND: // source _bitmap_ AND destination
1980 m_macPenInstalled
= true ;
1981 m_macBrushInstalled
= false ;
1982 m_macFontInstalled
= false ;
1985 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1987 Pattern whiteColor
;
1988 switch( background
.MacGetBrushKind() )
1990 case kwxMacBrushTheme
:
1992 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1995 case kwxMacBrushThemeBackground
:
1998 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1999 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2002 case kwxMacBrushColour
:
2004 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2005 int brushStyle
= background
.GetStyle();
2006 if (brushStyle
== wxSOLID
)
2007 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2008 else if (IS_HATCH(brushStyle
))
2011 wxMacGetPattern(brushStyle
, &pat
);
2016 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2023 void wxDC::MacInstallBrush() const
2025 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2026 Pattern blackColor
;
2027 // if ( m_macBrushInstalled )
2030 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2031 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2032 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2033 int brushStyle
= m_brush
.GetStyle();
2034 if (brushStyle
== wxSOLID
)
2036 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2038 else if (IS_HATCH(brushStyle
))
2041 wxMacGetPattern(brushStyle
, &pat
);
2044 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2046 // we force this in order to be compliant with wxMSW
2047 backgroundTransparent
= false ;
2048 // for these the text fore (and back for MASK_OPAQUE) colors are used
2049 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2050 int width
= bitmap
->GetWidth() ;
2051 int height
= bitmap
->GetHeight() ;
2052 GWorldPtr gw
= NULL
;
2053 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2054 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2056 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2057 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2058 LockPixels( gwpixmaphandle
) ;
2059 bool isMonochrome
= !IsPortColor( gw
) ;
2060 if ( !isMonochrome
)
2062 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2063 isMonochrome
= true ;
2065 if ( isMonochrome
&& width
== 8 && height
== 8 )
2067 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2068 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2069 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2070 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2071 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2073 for ( int i
= 0 ; i
< 8 ; ++i
)
2075 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2077 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2082 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2083 // caching scheme before putting this into production
2086 PixPatHandle pixpat
= NewPixPat() ;
2087 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2088 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2089 ((**(**pixpat
).patMap
).bounds
.bottom
-
2090 (**(**pixpat
).patMap
).bounds
.top
);
2091 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2092 (**pixpat
).patData
= image
;
2095 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2096 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2097 if ( ctspec
[0].rgb
.red
== 0x0000 )
2099 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2100 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2104 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2105 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2107 ::CTabChanged( ctable
) ;
2109 ::PenPixPat(pixpat
);
2110 m_macForegroundPixMap
= pixpat
;
2112 UnlockPixels( gwpixmaphandle
) ;
2116 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2118 short mode
= patCopy
;
2119 switch( m_logicalFunction
)
2122 if ( backgroundTransparent
)
2127 case wxINVERT
: // NOT dst
2128 if ( !backgroundTransparent
)
2130 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2134 case wxXOR
: // src XOR dst
2137 case wxOR_REVERSE
: // src OR (NOT dst)
2140 case wxSRC_INVERT
: // (NOT src)
2143 case wxAND
: // src AND dst
2148 case wxAND_REVERSE
:// src AND (NOT dst)
2149 case wxAND_INVERT
: // (NOT src) AND dst
2150 case wxNO_OP
: // dst
2151 case wxNOR
: // (NOT src) AND (NOT dst)
2152 case wxEQUIV
: // (NOT src) XOR dst
2153 case wxOR_INVERT
: // (NOT src) OR dst
2154 case wxNAND
: // (NOT src) OR (NOT dst)
2155 case wxOR
: // src OR dst
2157 // case wxSRC_OR: // source _bitmap_ OR destination
2158 // case wxSRC_AND: // source _bitmap_ AND destination
2162 m_macBrushInstalled
= true ;
2163 m_macPenInstalled
= false ;
2164 m_macFontInstalled
= false ;
2167 // ---------------------------------------------------------------------------
2168 // coordinates transformations
2169 // ---------------------------------------------------------------------------
2171 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2173 return ((wxDC
*)this)->XDEV2LOG(x
);
2176 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2178 return ((wxDC
*)this)->YDEV2LOG(y
);
2181 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2183 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2186 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2188 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2191 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2193 return ((wxDC
*)this)->XLOG2DEV(x
);
2196 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2198 return ((wxDC
*)this)->YLOG2DEV(y
);
2201 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2203 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2206 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2208 return ((wxDC
*)this)->YLOG2DEVREL(y
);