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 extern TECObjectRef s_TECNativeCToUnicode
;
60 // set to 0 if problems arise
61 #define wxMAC_EXPERIMENTAL_DC 1
63 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
64 m_ph( (GrafPtr
) dc
->m_macPort
)
66 wxASSERT( dc
->Ok() ) ;
68 dc
->MacSetupPort(&m_ph
) ;
70 wxMacPortSetter::~wxMacPortSetter()
72 m_dc
->MacCleanupPort(&m_ph
) ;
75 #if wxMAC_EXPERIMENTAL_DC
76 class wxMacFastPortSetter
79 wxMacFastPortSetter( const wxDC
*dc
)
81 wxASSERT( dc
->Ok() ) ;
82 GetPort( &m_oldPort
) ;
83 SetPort( (GrafPtr
) dc
->m_macPort
) ;
84 m_clipRgn
= NewRgn() ;
85 GetClip( m_clipRgn
) ;
87 dc
->MacSetupPort( NULL
) ;
89 ~wxMacFastPortSetter()
91 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
92 SetClip( m_clipRgn
) ;
93 SetPort( m_oldPort
) ;
94 m_dc
->MacCleanupPort( NULL
) ;
95 DisposeRgn( m_clipRgn
) ;
104 typedef wxMacPortSetter wxMacFastPortSetter
;
107 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
108 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
110 m_formerClip
= NewRgn() ;
111 m_newClip
= NewRgn() ;
112 GetClip( m_formerClip
) ;
117 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
) ;
123 SetClip( m_newClip
) ;
127 wxMacWindowClipper::~wxMacWindowClipper()
129 SetClip( m_formerClip
) ;
130 DisposeRgn( m_newClip
) ;
131 DisposeRgn( m_formerClip
) ;
134 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
137 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
138 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
139 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
141 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 // this function emulates all wx colour manipulations, used to verify the implementation
145 // by setting the mode in the blitting functions to kEmulatedMode
146 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
148 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
150 switch ( logical_func
)
152 case wxAND
: // src AND dst
153 dstColor
.red
= dstColor
.red
& srcColor
.red
;
154 dstColor
.green
= dstColor
.green
& srcColor
.green
;
155 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
157 case wxAND_INVERT
: // (NOT src) AND dst
158 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
159 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
160 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
162 case wxAND_REVERSE
:// src AND (NOT dst)
163 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
164 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
165 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
173 dstColor
.red
= srcColor
.red
;
174 dstColor
.green
= srcColor
.green
;
175 dstColor
.blue
= srcColor
.blue
;
177 case wxEQUIV
: // (NOT src) XOR dst
178 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
179 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
180 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
182 case wxINVERT
: // NOT dst
183 dstColor
.red
= ~dstColor
.red
;
184 dstColor
.green
= ~dstColor
.green
;
185 dstColor
.blue
= ~dstColor
.blue
;
187 case wxNAND
: // (NOT src) OR (NOT dst)
188 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
189 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
190 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
192 case wxNOR
: // (NOT src) AND (NOT dst)
193 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
194 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
195 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
199 case wxOR
: // src OR dst
200 dstColor
.red
= dstColor
.red
| srcColor
.red
;
201 dstColor
.green
= dstColor
.green
| srcColor
.green
;
202 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
204 case wxOR_INVERT
: // (NOT src) OR dst
205 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
206 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
207 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
209 case wxOR_REVERSE
: // src OR (NOT dst)
210 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
211 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
212 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
215 dstColor
.red
= 0xFFFF ;
216 dstColor
.green
= 0xFFFF ;
217 dstColor
.blue
= 0xFFFF ;
219 case wxSRC_INVERT
: // (NOT src)
220 dstColor
.red
= ~srcColor
.red
;
221 dstColor
.green
= ~srcColor
.green
;
222 dstColor
.blue
= ~srcColor
.blue
;
224 case wxXOR
: // src XOR dst
225 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
226 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
227 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
236 m_mm_to_pix_x
= mm2pt
;
237 m_mm_to_pix_y
= mm2pt
;
238 m_internalDeviceOriginX
= 0;
239 m_internalDeviceOriginY
= 0;
240 m_externalDeviceOriginX
= 0;
241 m_externalDeviceOriginY
= 0;
242 m_logicalScaleX
= 1.0;
243 m_logicalScaleY
= 1.0;
248 m_needComputeScaleX
= FALSE
;
249 m_needComputeScaleY
= FALSE
;
253 m_macFontInstalled
= false ;
254 m_macBrushInstalled
= false ;
255 m_macPenInstalled
= false ;
256 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
257 m_macBoundaryClipRgn
= NewRgn() ;
258 m_macCurrentClipRgn
= NewRgn() ;
259 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
260 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
261 m_pen
= *wxBLACK_PEN
;
262 m_font
= *wxNORMAL_FONT
;
263 m_brush
= *wxWHITE_BRUSH
;
265 // needed to debug possible errors with two active drawing methods at the same time on
267 m_macCurrentPortStateHelper
= NULL
;
269 m_macATSUIStyle
= NULL
;
270 m_macAliasWasEnabled
= false;
271 m_macForegroundPixMap
= NULL
;
272 m_macBackgroundPixMap
= NULL
;
277 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
278 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
281 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
284 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
285 m_macCurrentPortStateHelper
= help
;
287 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
288 #if ! wxMAC_EXPERIMENTAL_DC
289 m_macFontInstalled
= false ;
290 m_macBrushInstalled
= false ;
291 m_macPenInstalled
= false ;
294 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
297 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
298 m_macCurrentPortStateHelper
= NULL
;
300 if( m_macATSUIStyle
)
302 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
303 m_macATSUIStyle
= NULL
;
305 if ( m_macAliasWasEnabled
)
307 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
308 m_macAliasWasEnabled
= false ;
310 if ( m_macForegroundPixMap
)
313 ::PenPat(GetQDGlobalsBlack(&blackColor
));
314 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
315 m_macForegroundPixMap
= NULL
;
317 if ( m_macBackgroundPixMap
)
320 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
321 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
322 m_macBackgroundPixMap
= NULL
;
326 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
328 wxCHECK_RET( Ok(), wxT("invalid window dc") );
329 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
330 wxMacFastPortSetter
helper(this) ;
331 wxCoord xx
= XLOG2DEVMAC(x
);
332 wxCoord yy
= YLOG2DEVMAC(y
);
333 wxCoord w
= bmp
.GetWidth();
334 wxCoord h
= bmp
.GetHeight();
335 wxCoord ww
= XLOG2DEVREL(w
);
336 wxCoord hh
= YLOG2DEVREL(h
);
337 // Set up drawing mode
338 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
339 //m_logicalFunction == wxCLEAR ? WHITENESS :
340 //m_logicalFunction == wxSET ? BLACKNESS :
341 m_logicalFunction
== wxINVERT
? hilite
:
342 //m_logicalFunction == wxAND ? MERGECOPY :
343 m_logicalFunction
== wxOR
? srcOr
:
344 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
345 m_logicalFunction
== wxXOR
? srcXor
:
346 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
347 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
348 //m_logicalFunction == wxSRC_OR ? srcOr :
349 //m_logicalFunction == wxSRC_AND ? SRCAND :
351 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
352 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
353 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
354 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
356 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
358 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
359 PixMapHandle bmappixels
;
360 // Set foreground and background colours (for bitmaps depth = 1)
361 if(bmp
.GetDepth() == 1)
363 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
364 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
370 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
371 RGBColor black
= { 0,0,0} ;
372 RGBForeColor( &black
) ;
373 RGBBackColor( &white
) ;
375 bmappixels
= GetGWorldPixMap( bmapworld
) ;
376 wxCHECK_RET(LockPixels(bmappixels
),
377 wxT("DoDrawBitmap: Unable to lock pixels"));
378 Rect source
= { 0, 0, h
, w
};
379 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
380 if ( useMask
&& bmp
.GetMask() )
382 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
386 GetPortBitMapForCopyBits(bmapworld
),
387 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
388 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
389 &source
, &source
, &dest
, mode
, NULL
391 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
395 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
396 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
397 &source
, &dest
, mode
, NULL
) ;
399 UnlockPixels( bmappixels
) ;
401 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
403 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
404 OffsetRect( &bitmaprect
, xx
, yy
) ;
405 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
407 m_macPenInstalled
= false ;
408 m_macBrushInstalled
= false ;
409 m_macFontInstalled
= false ;
412 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
414 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
415 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
416 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
419 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
421 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
422 wxCoord xx
, yy
, ww
, hh
;
425 ww
= XLOG2DEVREL(width
);
426 hh
= YLOG2DEVREL(height
);
427 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
428 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
431 m_clipX1
= wxMax( m_clipX1
, xx
);
432 m_clipY1
= wxMax( m_clipY1
, yy
);
433 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
434 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
446 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
448 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
451 DestroyClippingRegion();
454 wxMacFastPortSetter
helper(this) ;
456 region
.GetBox( x
, y
, w
, h
);
457 wxCoord xx
, yy
, ww
, hh
;
462 // if we have a scaling that we cannot map onto native regions
463 // we must use the box
464 if ( ww
!= w
|| hh
!= h
)
466 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
470 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
471 if ( xx
!= x
|| yy
!= y
)
473 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
475 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
478 m_clipX1
= wxMax( m_clipX1
, xx
);
479 m_clipY1
= wxMax( m_clipY1
, yy
);
480 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
481 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
494 void wxDC::DestroyClippingRegion()
496 wxMacFastPortSetter
helper(this) ;
497 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
501 void wxDC::DoGetSizeMM( int* width
, int* height
) const
506 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
507 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
510 void wxDC::SetTextForeground( const wxColour
&col
)
512 wxCHECK_RET(Ok(), wxT("Invalid DC"));
513 m_textForegroundColour
= col
;
514 m_macFontInstalled
= false ;
517 void wxDC::SetTextBackground( const wxColour
&col
)
519 wxCHECK_RET(Ok(), wxT("Invalid DC"));
520 m_textBackgroundColour
= col
;
521 m_macFontInstalled
= false ;
524 void wxDC::SetMapMode( int mode
)
529 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
532 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
535 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
538 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
542 SetLogicalScale( 1.0, 1.0 );
545 if (mode
!= wxMM_TEXT
)
547 m_needComputeScaleX
= TRUE
;
548 m_needComputeScaleY
= TRUE
;
552 void wxDC::SetUserScale( double x
, double y
)
554 // allow negative ? -> no
557 ComputeScaleAndOrigin();
560 void wxDC::SetLogicalScale( double x
, double y
)
565 ComputeScaleAndOrigin();
568 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
570 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
571 m_logicalOriginY
= y
* m_signY
;
572 ComputeScaleAndOrigin();
575 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
577 m_externalDeviceOriginX
= x
;
578 m_externalDeviceOriginY
= y
;
579 ComputeScaleAndOrigin();
582 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
584 m_signX
= (xLeftRight
? 1 : -1);
585 m_signY
= (yBottomUp
? -1 : 1);
586 ComputeScaleAndOrigin();
589 wxSize
wxDC::GetPPI() const
591 return wxSize(72, 72);
594 int wxDC::GetDepth() const
596 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
598 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
603 void wxDC::ComputeScaleAndOrigin()
605 // CMB: copy scale to see if it changes
606 double origScaleX
= m_scaleX
;
607 double origScaleY
= m_scaleY
;
608 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
609 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
610 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
611 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
612 // CMB: if scale has changed call SetPen to recalulate the line width
613 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
615 // this is a bit artificial, but we need to force wxDC to think
616 // the pen has changed
617 wxPen
* pen
= & GetPen();
624 void wxDC::SetPalette( const wxPalette
& palette
)
628 void wxDC::SetBackgroundMode( int mode
)
630 m_backgroundMode
= mode
;
633 void wxDC::SetFont( const wxFont
&font
)
636 m_macFontInstalled
= false ;
639 void wxDC::SetPen( const wxPen
&pen
)
644 m_macPenInstalled
= false ;
647 void wxDC::SetBrush( const wxBrush
&brush
)
649 if (m_brush
== brush
)
652 m_macBrushInstalled
= false ;
655 void wxDC::SetBackground( const wxBrush
&brush
)
657 if (m_backgroundBrush
== brush
)
659 m_backgroundBrush
= brush
;
660 if (!m_backgroundBrush
.Ok())
662 m_macBrushInstalled
= false ;
665 void wxDC::SetLogicalFunction( int function
)
667 if (m_logicalFunction
== function
)
669 m_logicalFunction
= function
;
670 m_macFontInstalled
= false ;
671 m_macBrushInstalled
= false ;
672 m_macPenInstalled
= false ;
675 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
676 const wxColour
& col
, int style
);
678 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
679 const wxColour
& col
, int style
)
681 return wxDoFloodFill(this, x
, y
, col
, style
);
684 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
686 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
687 wxMacFastPortSetter
helper(this) ;
689 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
690 // Convert from Mac colour to wx
691 col
->Set( colour
.red
>> 8,
697 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
699 wxCHECK_RET(Ok(), wxT("Invalid DC"));
700 wxMacFastPortSetter
helper(this) ;
701 if (m_pen
.GetStyle() != wxTRANSPARENT
)
704 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
705 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
706 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
707 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
708 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
709 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
710 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
711 (m_pen
.GetWidth() <= 1))
713 // Implement LAST_NOT for MAC at least for
714 // orthogonal lines. RR.
735 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
737 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
738 wxMacFastPortSetter
helper(this) ;
739 if (m_pen
.GetStyle() != wxTRANSPARENT
)
744 wxCoord xx
= XLOG2DEVMAC(x
);
745 wxCoord yy
= YLOG2DEVMAC(y
);
747 ::MoveTo( XLOG2DEVMAC(0), yy
);
748 ::LineTo( XLOG2DEVMAC(w
), yy
);
749 ::MoveTo( xx
, YLOG2DEVMAC(0) );
750 ::LineTo( xx
, YLOG2DEVMAC(h
) );
751 CalcBoundingBox(x
, y
);
752 CalcBoundingBox(x
+w
, y
+h
);
757 * To draw arcs properly the angles need to be converted from the WX style:
758 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
759 * a normal axis on paper).
762 * Angles start on the +ve y axis and go clockwise.
765 static double wxConvertWXangleToMACangle(double angle
)
767 double newAngle
= 90 - angle
;
773 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
774 wxCoord x2
, wxCoord y2
,
775 wxCoord xc
, wxCoord yc
)
777 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
778 wxMacFastPortSetter
helper(this) ;
779 wxCoord xx1
= XLOG2DEVMAC(x1
);
780 wxCoord yy1
= YLOG2DEVMAC(y1
);
781 wxCoord xx2
= XLOG2DEVMAC(x2
);
782 wxCoord yy2
= YLOG2DEVMAC(y2
);
783 wxCoord xxc
= XLOG2DEVMAC(xc
);
784 wxCoord yyc
= YLOG2DEVMAC(yc
);
785 double dx
= xx1
- xxc
;
786 double dy
= yy1
- yyc
;
787 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
788 wxCoord rad
= (wxCoord
)radius
;
789 double radius1
, radius2
;
790 if (xx1
== xx2
&& yy1
== yy2
)
795 else if (radius
== 0.0)
797 radius1
= radius2
= 0.0;
801 radius1
= (xx1
- xxc
== 0) ?
802 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
803 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
804 radius2
= (xx2
- xxc
== 0) ?
805 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
806 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
808 wxCoord alpha2
= wxCoord(radius2
- radius1
);
809 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
810 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
813 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
814 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
816 PaintArc(&r
, alpha1
, alpha2
);
818 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
820 FrameArc(&r
, alpha1
, alpha2
);
824 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
825 double sa
, double ea
)
827 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
828 wxMacFastPortSetter
helper(this) ;
830 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
831 // we have to make sure that the filling is always counter-clockwise
834 wxCoord xx
= XLOG2DEVMAC(x
);
835 wxCoord yy
= YLOG2DEVMAC(y
);
836 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
837 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
838 // handle -ve width and/or height
839 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
840 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
841 sa
= wxConvertWXangleToMACangle(sa
);
846 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
848 PaintArc(&r
, (short)sa
, (short)angle
);
850 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
852 FrameArc(&r
, (short)sa
, (short)angle
);
856 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
858 wxCHECK_RET(Ok(), wxT("Invalid DC"));
859 wxMacFastPortSetter
helper(this) ;
860 if (m_pen
.GetStyle() != wxTRANSPARENT
)
862 wxCoord xx1
= XLOG2DEVMAC(x
);
863 wxCoord yy1
= YLOG2DEVMAC(y
);
864 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
865 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
866 CalcBoundingBox(x
, y
);
870 void wxDC::DoDrawLines(int n
, wxPoint points
[],
871 wxCoord xoffset
, wxCoord yoffset
)
873 wxCHECK_RET(Ok(), wxT("Invalid DC"));
874 wxMacFastPortSetter
helper(this) ;
875 if (m_pen
.GetStyle() == wxTRANSPARENT
)
878 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
879 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
880 wxCoord x1
, x2
, y1
, y2
;
881 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
882 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
883 ::MoveTo(x1
- offset
, y1
- offset
);
884 for (int i
= 0; i
< n
-1; i
++)
886 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
887 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
888 ::LineTo( x2
- offset
, y2
- offset
);
892 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
893 wxCoord xoffset
, wxCoord yoffset
,
896 wxCHECK_RET(Ok(), wxT("Invalid DC"));
897 wxMacFastPortSetter
helper(this) ;
898 wxCoord x1
, x2
, y1
, y2
;
899 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
901 PolyHandle polygon
= OpenPoly();
902 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
903 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
905 for (int i
= 1; i
< n
; i
++)
907 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
908 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
911 // close the polyline if necessary
912 if ( x1
!= x2
|| y1
!= y2
)
917 if (m_brush
.GetStyle() != wxTRANSPARENT
)
920 ::PaintPoly( polygon
);
922 if (m_pen
.GetStyle() != wxTRANSPARENT
)
925 ::FramePoly( polygon
) ;
930 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
932 wxCHECK_RET(Ok(), wxT("Invalid DC"));
933 wxMacFastPortSetter
helper(this) ;
934 wxCoord xx
= XLOG2DEVMAC(x
);
935 wxCoord yy
= YLOG2DEVMAC(y
);
936 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
937 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
938 // CMB: draw nothing if transformed w or h is 0
939 if (ww
== 0 || hh
== 0)
941 // CMB: handle -ve width and/or height
952 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
953 if (m_brush
.GetStyle() != wxTRANSPARENT
)
956 ::PaintRect( &rect
) ;
958 if (m_pen
.GetStyle() != wxTRANSPARENT
)
961 ::FrameRect( &rect
) ;
965 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
966 wxCoord width
, wxCoord height
,
969 wxCHECK_RET(Ok(), wxT("Invalid DC"));
970 wxMacFastPortSetter
helper(this) ;
972 radius
= - radius
* ((width
< height
) ? width
: height
);
973 wxCoord xx
= XLOG2DEVMAC(x
);
974 wxCoord yy
= YLOG2DEVMAC(y
);
975 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
976 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
977 // CMB: draw nothing if transformed w or h is 0
978 if (ww
== 0 || hh
== 0)
980 // CMB: handle -ve width and/or height
991 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
992 if (m_brush
.GetStyle() != wxTRANSPARENT
)
995 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
997 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1000 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1004 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1006 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1007 wxMacFastPortSetter
helper(this) ;
1008 wxCoord xx
= XLOG2DEVMAC(x
);
1009 wxCoord yy
= YLOG2DEVMAC(y
);
1010 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1011 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1012 // CMB: draw nothing if transformed w or h is 0
1013 if (ww
== 0 || hh
== 0)
1015 // CMB: handle -ve width and/or height
1026 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1027 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1030 ::PaintOval( &rect
) ;
1032 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1035 ::FrameOval( &rect
) ;
1039 bool wxDC::CanDrawBitmap(void) const
1044 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1045 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1046 wxCoord xsrcMask
, wxCoord ysrcMask
)
1048 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1049 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1050 if ( logical_func
== wxNO_OP
)
1052 if (xsrcMask
== -1 && ysrcMask
== -1)
1054 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1056 // correct the parameter in case this dc does not have a mask at all
1057 if ( useMask
&& !source
->m_macMask
)
1059 Rect srcrect
, dstrect
;
1060 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1061 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1062 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1063 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1064 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1065 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1066 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1067 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1068 short mode
= kUnsupportedMode
;
1069 bool invertDestinationFirst
= false ;
1070 switch ( logical_func
)
1072 case wxAND
: // src AND dst
1073 mode
= adMin
; // ok
1075 case wxAND_INVERT
: // (NOT src) AND dst
1076 mode
= notSrcOr
; // ok
1078 case wxAND_REVERSE
:// src AND (NOT dst)
1079 invertDestinationFirst
= true ;
1083 mode
= kEmulatedMode
;
1086 mode
= srcCopy
; // ok
1088 case wxEQUIV
: // (NOT src) XOR dst
1089 mode
= srcXor
; // ok
1091 case wxINVERT
: // NOT dst
1092 mode
= kEmulatedMode
; //or hilite ;
1094 case wxNAND
: // (NOT src) OR (NOT dst)
1095 invertDestinationFirst
= true ;
1098 case wxNOR
: // (NOT src) AND (NOT dst)
1099 invertDestinationFirst
= true ;
1102 case wxNO_OP
: // dst
1103 mode
= kEmulatedMode
; // this has already been handled upon entry
1105 case wxOR
: // src OR dst
1108 case wxOR_INVERT
: // (NOT src) OR dst
1111 case wxOR_REVERSE
: // src OR (NOT dst)
1112 invertDestinationFirst
= true ;
1116 mode
= kEmulatedMode
;
1118 case wxSRC_INVERT
: // (NOT src)
1119 mode
= notSrcCopy
; // ok
1121 case wxXOR
: // src XOR dst
1122 mode
= notSrcXor
; // ok
1127 if ( mode
== kUnsupportedMode
)
1129 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1132 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1133 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1134 if ( LockPixels(bmappixels
) )
1136 wxMacFastPortSetter
helper(this) ;
1137 if ( source
->GetDepth() == 1 )
1139 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1140 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1144 // the modes need this, otherwise we'll end up having really nice colors...
1145 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1146 RGBColor black
= { 0,0,0} ;
1147 RGBForeColor( &black
) ;
1148 RGBBackColor( &white
) ;
1150 if ( useMask
&& source
->m_macMask
)
1152 if ( mode
== srcCopy
)
1154 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1156 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1157 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1158 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1159 &srcrect
, &srcrect
, &dstrect
) ;
1160 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1165 RgnHandle clipRgn
= NewRgn() ;
1166 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1167 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1168 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1169 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1170 if ( mode
== kEmulatedMode
)
1173 ::PenPat(GetQDGlobalsBlack(&pat
));
1174 if ( logical_func
== wxSET
)
1176 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1177 ::RGBForeColor( &col
) ;
1178 ::PaintRgn( clipRgn
) ;
1180 else if ( logical_func
== wxCLEAR
)
1182 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1183 ::RGBForeColor( &col
) ;
1184 ::PaintRgn( clipRgn
) ;
1186 else if ( logical_func
== wxINVERT
)
1188 MacInvertRgn( clipRgn
) ;
1192 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1194 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1196 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1197 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1198 if ( PtInRgn( dstPoint
, clipRgn
) )
1202 SetPort( (GrafPtr
) sourcePort
) ;
1203 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1204 SetPort( (GrafPtr
) m_macPort
) ;
1205 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1206 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1207 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1215 if ( invertDestinationFirst
)
1217 MacInvertRgn( clipRgn
) ;
1219 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1220 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1221 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1223 DisposeRgn( clipRgn
) ;
1228 RgnHandle clipRgn
= NewRgn() ;
1229 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1230 if ( mode
== kEmulatedMode
)
1233 ::PenPat(GetQDGlobalsBlack(&pat
));
1234 if ( logical_func
== wxSET
)
1236 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1237 ::RGBForeColor( &col
) ;
1238 ::PaintRgn( clipRgn
) ;
1240 else if ( logical_func
== wxCLEAR
)
1242 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1243 ::RGBForeColor( &col
) ;
1244 ::PaintRgn( clipRgn
) ;
1246 else if ( logical_func
== wxINVERT
)
1248 MacInvertRgn( clipRgn
) ;
1252 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1254 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1256 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1257 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1261 SetPort( (GrafPtr
) sourcePort
) ;
1262 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1263 SetPort( (GrafPtr
) m_macPort
) ;
1264 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1265 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1266 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1274 if ( invertDestinationFirst
)
1276 MacInvertRgn( clipRgn
) ;
1278 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1279 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1280 &srcrect
, &dstrect
, mode
, NULL
) ;
1282 DisposeRgn( clipRgn
) ;
1284 UnlockPixels( bmappixels
) ;
1286 m_macPenInstalled
= false ;
1287 m_macBrushInstalled
= false ;
1288 m_macFontInstalled
= false ;
1293 // as macro in FixMath.h for 10.3
1294 inline Fixed
IntToFixed( int inInt
)
1296 return (((SInt32
) inInt
) << 16);
1299 inline int FixedToInt( Fixed inFixed
)
1301 return (((SInt32
) inFixed
) >> 16);
1305 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1308 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1312 DrawText(str, x, y);
1316 if ( str.Length() == 0 )
1319 wxMacFastPortSetter
helper(this) ;
1324 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1325 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1326 m_macAliasWasEnabled
= true ;
1328 OSStatus status
= noErr
;
1329 ATSUTextLayout atsuLayout
;
1330 UniCharCount chars
= str
.Length() ;
1332 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1333 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1335 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1336 int wlen
= wxWcslen( wchar
.data() ) ;
1337 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1338 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1340 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1341 int iAngle
= int( angle
);
1342 int drawX
= XLOG2DEVMAC(x
) ;
1343 int drawY
= YLOG2DEVMAC(y
) ;
1345 ATSUTextMeasurement textBefore
;
1346 ATSUTextMeasurement textAfter
;
1347 ATSUTextMeasurement ascent
;
1348 ATSUTextMeasurement descent
;
1351 if ( abs(iAngle
) > 0 )
1353 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1354 ATSUAttributeTag atsuTags
[] =
1356 kATSULineRotationTag
,
1358 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1362 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1366 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1367 atsuTags
, atsuSizes
, atsuValues
) ;
1369 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1370 &textBefore
, &textAfter
, &ascent
, &descent
);
1372 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1373 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1374 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1375 IntToFixed(drawX
) , IntToFixed(drawY
) );
1376 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1378 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1379 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1380 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1381 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1382 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1383 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1384 ::ATSUDisposeTextLayout(atsuLayout
);
1387 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1389 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1391 wxMacFastPortSetter
helper(this) ;
1392 long xx
= XLOG2DEVMAC(x
);
1393 long yy
= YLOG2DEVMAC(y
);
1395 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1396 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1397 useDrawThemeText
= false ;
1402 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1403 SetAntiAliasedTextEnabled(true, 8);
1404 m_macAliasWasEnabled
= true ;
1407 ::GetFontInfo( &fi
) ;
1409 if ( !useDrawThemeText
)
1412 ::MoveTo( xx
, yy
);
1413 if ( m_backgroundMode
== wxTRANSPARENT
)
1415 ::TextMode( srcOr
) ;
1419 ::TextMode( srcCopy
) ;
1423 wxString linetext
= strtext
;
1425 if ( useDrawThemeText
)
1427 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1428 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1430 if ( m_backgroundMode
!= wxTRANSPARENT
)
1432 Point bounds
={0,0} ;
1433 Rect background
= frame
;
1435 ::GetThemeTextDimensions( mString
,
1436 m_font
.MacGetThemeFontID() ,
1441 background
.right
= background
.left
+ bounds
.h
;
1442 background
.bottom
= background
.top
+ bounds
.v
;
1443 ::EraseRect( &background
) ;
1445 ::DrawThemeTextBox( mString
,
1446 m_font
.MacGetThemeFontID() ,
1456 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1457 if ( m_backgroundMode
!= wxTRANSPARENT
)
1459 Rect frame
= { yy
- fi
.ascent
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
- fi
.ascent
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1460 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1461 frame
.right
= frame
.left
+ width
;
1463 ::EraseRect( &frame
) ;
1465 ::DrawText( text
, 0 , strlen(text
) ) ;
1468 ::TextMode( srcOr
) ;
1471 bool wxDC::CanGetTextExtent() const
1473 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1477 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1478 wxCoord
*descent
, wxCoord
*externalLeading
,
1479 wxFont
*theFont
) const
1481 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1482 wxMacFastPortSetter
helper(this) ;
1483 wxFont formerFont
= m_font
;
1486 // work around the constness
1487 *((wxFont
*)(&m_font
)) = *theFont
;
1491 ::GetFontInfo( &fi
) ;
1493 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1494 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1495 useGetThemeText
= false ;
1498 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1500 *descent
=YDEV2LOGREL( fi
.descent
);
1501 if ( externalLeading
)
1502 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1508 wxString linetext
= strtext
;
1510 if ( useGetThemeText
)
1512 Point bounds
={0,0} ;
1514 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1515 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1516 ::GetThemeTextDimensions( mString
,
1522 curwidth
= bounds
.h
;
1526 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1527 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1529 if ( curwidth
> *width
)
1530 *width
= XDEV2LOGREL( curwidth
) ;
1534 // work around the constness
1535 *((wxFont
*)(&m_font
)) = formerFont
;
1536 m_macFontInstalled
= false ;
1541 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1543 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1546 widths
.Add(0, text
.Length());
1548 if (text
.Length() == 0)
1551 wxMacFastPortSetter
helper(this) ;
1554 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1555 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1556 useGetThemeText
= false ;
1558 if ( useGetThemeText
)
1560 // If anybody knows how to do this more efficiently yet still handle
1561 // the fractional glyph widths that may be present when using AA
1562 // fonts, please change it. Currently it is measuring from the
1563 // begining of the string for each succeding substring, which is much
1564 // slower than this should be.
1565 for (size_t i
=0; i
<text
.Length(); i
++)
1567 wxString
str(text
.Left(i
+1));
1568 Point bounds
= {0,0};
1570 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1571 ::GetThemeTextDimensions( mString
,
1572 m_font
.MacGetThemeFontID(),
1577 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1583 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1584 size_t len
= strlen(buff
);
1585 short* measurements
= new short[len
+1];
1586 MeasureText(len
, buff
.data(), measurements
);
1588 // Copy to widths, starting at measurements[1]
1589 // NOTE: this doesn't take into account any multi-byte characters
1590 // in buff, it probabkly should...
1591 for (size_t i
=0; i
<text
.Length(); i
++)
1592 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1594 delete [] measurements
;
1602 wxCoord
wxDC::GetCharWidth(void) const
1604 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1605 wxMacFastPortSetter
helper(this) ;
1609 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1610 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1611 useGetThemeText
= false ;
1615 if ( useGetThemeText
)
1617 Point bounds
={0,0} ;
1619 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1620 ::GetThemeTextDimensions( mString
,
1621 m_font
.MacGetThemeFontID(),
1626 CFRelease( mString
) ;
1632 width
= ::TextWidth( text
, 0 , 1 ) ;
1634 return YDEV2LOGREL(width
) ;
1637 wxCoord
wxDC::GetCharHeight(void) const
1639 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1640 wxMacFastPortSetter
helper(this) ;
1643 ::GetFontInfo( &fi
) ;
1644 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1647 void wxDC::Clear(void)
1649 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1650 wxMacFastPortSetter
helper(this) ;
1651 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1652 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1655 //MacInstallBrush() ;
1656 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1657 ::EraseRect( &rect
) ;
1661 void wxDC::MacInstallFont() const
1663 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1664 // if ( m_macFontInstalled )
1666 Pattern blackColor
;
1667 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1670 ::TextFont( m_font
.MacGetFontNum() ) ;
1671 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1672 ::TextFace( m_font
.MacGetFontStyle() ) ;
1673 m_macFontInstalled
= true ;
1674 m_macBrushInstalled
= false ;
1675 m_macPenInstalled
= false ;
1676 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1677 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1678 ::RGBForeColor( &forecolor
);
1679 ::RGBBackColor( &backcolor
);
1683 FontFamilyID fontId
;
1687 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1688 GetFNum( fontName
, &fontId
);
1689 ::TextFont( fontId
) ;
1690 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1691 ::TextFace( fontStyle
) ;
1692 // todo reset after spacing changes - or store the current spacing somewhere
1693 m_macFontInstalled
= true ;
1694 m_macBrushInstalled
= false ;
1695 m_macPenInstalled
= false ;
1696 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1697 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1698 ::RGBForeColor( &forecolor
);
1699 ::RGBBackColor( &backcolor
);
1701 short mode
= patCopy
;
1703 switch( m_logicalFunction
)
1708 case wxINVERT
: // NOT dst
1709 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1712 case wxXOR
: // src XOR dst
1715 case wxOR_REVERSE
: // src OR (NOT dst)
1718 case wxSRC_INVERT
: // (NOT src)
1721 case wxAND
: // src AND dst
1726 case wxAND_REVERSE
:// src AND (NOT dst)
1727 case wxAND_INVERT
: // (NOT src) AND dst
1728 case wxNO_OP
: // dst
1729 case wxNOR
: // (NOT src) AND (NOT dst)
1730 case wxEQUIV
: // (NOT src) XOR dst
1731 case wxOR_INVERT
: // (NOT src) OR dst
1732 case wxNAND
: // (NOT src) OR (NOT dst)
1733 case wxOR
: // src OR dst
1735 // case wxSRC_OR: // source _bitmap_ OR destination
1736 // case wxSRC_AND: // source _bitmap_ AND destination
1740 OSStatus status
= noErr
;
1741 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1742 Style qdStyle
= m_font
.MacGetATSUAdditionalQDStyles() ;
1743 ATSUFontID atsuFont
= m_font
.MacGetATSUFontID() ;
1744 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1745 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1746 ATSUAttributeTag atsuTags
[] =
1751 // kATSUBaselineClassTag ,
1752 kATSUVerticalCharacterTag
,
1753 kATSUQDBoldfaceTag
,
1755 kATSUQDUnderlineTag
,
1756 kATSUQDCondensedTag
,
1757 kATSUQDExtendedTag
,
1759 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1761 sizeof( ATSUFontID
) ,
1763 // sizeof( RGBColor ) ,
1764 // sizeof( BslnBaselineClass ) ,
1765 sizeof( ATSUVerticalCharacterType
),
1772 Boolean kTrue
= true ;
1773 Boolean kFalse
= false ;
1774 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1775 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1776 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1780 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1781 // &kBaselineDefault ,
1783 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1784 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1785 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1786 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1787 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1789 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1790 atsuTags
, atsuSizes
, atsuValues
);
1791 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1794 Pattern gPatterns
[] =
1796 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1797 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1798 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1799 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1800 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1801 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1802 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1804 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1805 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1806 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1807 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1810 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1812 int index
= 0; // solid pattern by default
1816 case wxBDIAGONAL_HATCH
: index
= 1; break;
1817 case wxFDIAGONAL_HATCH
: index
= 2; break;
1818 case wxCROSS_HATCH
: index
= 3; break;
1819 case wxHORIZONTAL_HATCH
: index
= 4; break;
1820 case wxVERTICAL_HATCH
: index
= 5; break;
1821 case wxCROSSDIAG_HATCH
: index
= 6; break;
1823 case wxDOT
: index
= 7; break;
1824 case wxLONG_DASH
: index
= 8; break;
1825 case wxSHORT_DASH
: index
= 9; break;
1826 case wxDOT_DASH
: index
= 10; break;
1828 *pattern
= gPatterns
[index
];
1831 void wxDC::MacInstallPen() const
1833 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1834 //Pattern blackColor;
1835 // if ( m_macPenInstalled )
1837 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1838 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1839 ::RGBForeColor( &forecolor
);
1840 ::RGBBackColor( &backcolor
);
1842 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1843 // null means only one pixel, at whatever resolution
1844 if ( penWidth
== 0 )
1846 ::PenSize(penWidth
, penWidth
);
1848 int penStyle
= m_pen
.GetStyle();
1850 if (penStyle
== wxUSER_DASH
)
1852 // FIXME: there should be exactly 8 items in the dash
1854 int number
= m_pen
.GetDashes(&dash
) ;
1856 for ( int i
= 0 ; i
< 8 ; ++i
)
1858 pat
.pat
[i
] = dash
[index
] ;
1859 if (index
< number
- 1)
1865 wxMacGetPattern(penStyle
, &pat
);
1869 short mode
= patCopy
;
1871 switch( m_logicalFunction
)
1873 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1876 case wxINVERT
: // NOT dst
1877 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1880 case wxXOR
: // src XOR dst
1883 case wxOR_REVERSE
: // src OR (NOT dst)
1886 case wxSRC_INVERT
: // (NOT src)
1889 case wxAND
: // src AND dst
1894 case wxAND_REVERSE
:// src AND (NOT dst)
1895 case wxAND_INVERT
: // (NOT src) AND dst
1896 case wxNO_OP
: // dst
1897 case wxNOR
: // (NOT src) AND (NOT dst)
1898 case wxEQUIV
: // (NOT src) XOR dst
1899 case wxOR_INVERT
: // (NOT src) OR dst
1900 case wxNAND
: // (NOT src) OR (NOT dst)
1901 case wxOR
: // src OR dst
1903 // case wxSRC_OR: // source _bitmap_ OR destination
1904 // case wxSRC_AND: // source _bitmap_ AND destination
1908 m_macPenInstalled
= true ;
1909 m_macBrushInstalled
= false ;
1910 m_macFontInstalled
= false ;
1913 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1915 Pattern whiteColor
;
1916 switch( background
.MacGetBrushKind() )
1918 case kwxMacBrushTheme
:
1920 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
1923 case kwxMacBrushThemeBackground
:
1926 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
1927 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1930 case kwxMacBrushColour
:
1932 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1933 int brushStyle
= background
.GetStyle();
1934 if (brushStyle
== wxSOLID
)
1935 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1936 else if (IS_HATCH(brushStyle
))
1939 wxMacGetPattern(brushStyle
, &pat
);
1944 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1951 void wxDC::MacInstallBrush() const
1953 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1954 Pattern blackColor
;
1955 // if ( m_macBrushInstalled )
1958 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1959 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1960 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1961 int brushStyle
= m_brush
.GetStyle();
1962 if (brushStyle
== wxSOLID
)
1964 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1966 else if (IS_HATCH(brushStyle
))
1969 wxMacGetPattern(brushStyle
, &pat
);
1972 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1974 // we force this in order to be compliant with wxMSW
1975 backgroundTransparent
= false ;
1976 // for these the text fore (and back for MASK_OPAQUE) colors are used
1977 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1978 int width
= bitmap
->GetWidth() ;
1979 int height
= bitmap
->GetHeight() ;
1980 GWorldPtr gw
= NULL
;
1981 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1982 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1984 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1985 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
1986 LockPixels( gwpixmaphandle
) ;
1987 bool isMonochrome
= !IsPortColor( gw
) ;
1988 if ( !isMonochrome
)
1990 if ( (**gwpixmaphandle
).pixelSize
== 1 )
1991 isMonochrome
= true ;
1993 if ( isMonochrome
&& width
== 8 && height
== 8 )
1995 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
1996 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
1997 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
1998 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
1999 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2001 for ( int i
= 0 ; i
< 8 ; ++i
)
2003 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2005 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2010 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2011 // caching scheme before putting this into production
2014 PixPatHandle pixpat
= NewPixPat() ;
2015 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2016 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2017 ((**(**pixpat
).patMap
).bounds
.bottom
-
2018 (**(**pixpat
).patMap
).bounds
.top
);
2019 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2020 (**pixpat
).patData
= image
;
2023 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2024 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2025 if ( ctspec
[0].rgb
.red
== 0x0000 )
2027 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2028 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2032 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2033 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2035 ::CTabChanged( ctable
) ;
2037 ::PenPixPat(pixpat
);
2038 m_macForegroundPixMap
= pixpat
;
2040 UnlockPixels( gwpixmaphandle
) ;
2044 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2046 short mode
= patCopy
;
2047 switch( m_logicalFunction
)
2050 if ( backgroundTransparent
)
2055 case wxINVERT
: // NOT dst
2056 if ( !backgroundTransparent
)
2058 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2062 case wxXOR
: // src XOR dst
2065 case wxOR_REVERSE
: // src OR (NOT dst)
2068 case wxSRC_INVERT
: // (NOT src)
2071 case wxAND
: // src AND dst
2076 case wxAND_REVERSE
:// src AND (NOT dst)
2077 case wxAND_INVERT
: // (NOT src) AND dst
2078 case wxNO_OP
: // dst
2079 case wxNOR
: // (NOT src) AND (NOT dst)
2080 case wxEQUIV
: // (NOT src) XOR dst
2081 case wxOR_INVERT
: // (NOT src) OR dst
2082 case wxNAND
: // (NOT src) OR (NOT dst)
2083 case wxOR
: // src OR dst
2085 // case wxSRC_OR: // source _bitmap_ OR destination
2086 // case wxSRC_AND: // source _bitmap_ AND destination
2090 m_macBrushInstalled
= true ;
2091 m_macPenInstalled
= false ;
2092 m_macFontInstalled
= false ;
2095 // ---------------------------------------------------------------------------
2096 // coordinates transformations
2097 // ---------------------------------------------------------------------------
2099 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2101 return ((wxDC
*)this)->XDEV2LOG(x
);
2104 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2106 return ((wxDC
*)this)->YDEV2LOG(y
);
2109 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2111 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2114 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2116 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2119 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2121 return ((wxDC
*)this)->XLOG2DEV(x
);
2124 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2126 return ((wxDC
*)this)->YLOG2DEV(y
);
2129 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2131 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2134 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2136 return ((wxDC
*)this)->YLOG2DEVREL(y
);