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
) ;
85 dc
->MacSetupPort( NULL
) ;
87 ~wxMacFastPortSetter()
89 SetPort( m_oldPort
) ;
90 m_dc
->MacCleanupPort( NULL
) ;
98 typedef wxMacPortSetter wxMacFastPortSetter
;
101 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
103 m_formerClip
= NewRgn() ;
104 m_newClip
= NewRgn() ;
105 GetClip( m_formerClip
) ;
110 // this clipping area was set to the parent window's drawing area, lead to problems
111 // with MacOSX controls drawing outside their wx' rectangle
112 RgnHandle insidergn
= NewRgn() ;
114 wxWindow
*parent
= win
->GetParent() ;
115 parent
->MacWindowToRootWindow( &x
,&y
) ;
116 wxSize size
= parent
->GetSize() ;
117 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
118 size
.x
- parent
->MacGetRightBorderSize(),
119 size
.y
- parent
->MacGetBottomBorderSize()) ;
120 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
121 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
122 OffsetRgn( m_newClip
, x
, y
) ;
123 SetClip( m_newClip
) ;
124 DisposeRgn( insidergn
) ;
127 win
->MacWindowToRootWindow( &x
,&y
) ;
128 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
129 OffsetRgn( m_newClip
, x
, y
) ;
130 SetClip( m_newClip
) ;
135 wxMacWindowClipper::~wxMacWindowClipper()
137 SetClip( m_formerClip
) ;
138 DisposeRgn( m_newClip
) ;
139 DisposeRgn( m_formerClip
) ;
142 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
145 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
146 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
147 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
149 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
152 // this function emulates all wx colour manipulations, used to verify the implementation
153 // by setting the mode in the blitting functions to kEmulatedMode
154 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
156 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
158 switch ( logical_func
)
160 case wxAND
: // src AND dst
161 dstColor
.red
= dstColor
.red
& srcColor
.red
;
162 dstColor
.green
= dstColor
.green
& srcColor
.green
;
163 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
165 case wxAND_INVERT
: // (NOT src) AND dst
166 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
167 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
168 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
170 case wxAND_REVERSE
:// src AND (NOT dst)
171 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
172 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
173 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
181 dstColor
.red
= srcColor
.red
;
182 dstColor
.green
= srcColor
.green
;
183 dstColor
.blue
= srcColor
.blue
;
185 case wxEQUIV
: // (NOT src) XOR dst
186 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
187 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
188 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
190 case wxINVERT
: // NOT dst
191 dstColor
.red
= ~dstColor
.red
;
192 dstColor
.green
= ~dstColor
.green
;
193 dstColor
.blue
= ~dstColor
.blue
;
195 case wxNAND
: // (NOT src) OR (NOT dst)
196 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
197 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
198 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
200 case wxNOR
: // (NOT src) AND (NOT dst)
201 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
202 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
203 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
207 case wxOR
: // src OR dst
208 dstColor
.red
= dstColor
.red
| srcColor
.red
;
209 dstColor
.green
= dstColor
.green
| srcColor
.green
;
210 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
212 case wxOR_INVERT
: // (NOT src) OR dst
213 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
214 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
215 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
217 case wxOR_REVERSE
: // src OR (NOT dst)
218 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
219 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
220 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
223 dstColor
.red
= 0xFFFF ;
224 dstColor
.green
= 0xFFFF ;
225 dstColor
.blue
= 0xFFFF ;
227 case wxSRC_INVERT
: // (NOT src)
228 dstColor
.red
= ~srcColor
.red
;
229 dstColor
.green
= ~srcColor
.green
;
230 dstColor
.blue
= ~srcColor
.blue
;
232 case wxXOR
: // src XOR dst
233 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
234 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
235 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
244 m_mm_to_pix_x
= mm2pt
;
245 m_mm_to_pix_y
= mm2pt
;
246 m_internalDeviceOriginX
= 0;
247 m_internalDeviceOriginY
= 0;
248 m_externalDeviceOriginX
= 0;
249 m_externalDeviceOriginY
= 0;
250 m_logicalScaleX
= 1.0;
251 m_logicalScaleY
= 1.0;
256 m_needComputeScaleX
= FALSE
;
257 m_needComputeScaleY
= FALSE
;
261 m_macFontInstalled
= false ;
262 m_macBrushInstalled
= false ;
263 m_macPenInstalled
= false ;
264 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
265 m_macBoundaryClipRgn
= NewRgn() ;
266 m_macCurrentClipRgn
= NewRgn() ;
267 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
268 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
269 m_pen
= *wxBLACK_PEN
;
270 m_font
= *wxNORMAL_FONT
;
271 m_brush
= *wxWHITE_BRUSH
;
273 // needed to debug possible errors with two active drawing methods at the same time on
275 m_macCurrentPortStateHelper
= NULL
;
277 m_macATSUIStyle
= NULL
;
278 m_macAliasWasEnabled
= false;
279 m_macForegroundPixMap
= NULL
;
280 m_macBackgroundPixMap
= NULL
;
285 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
286 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
289 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
292 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
293 m_macCurrentPortStateHelper
= help
;
295 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
296 #if ! wxMAC_EXPERIMENTAL_DC
297 m_macFontInstalled
= false ;
298 m_macBrushInstalled
= false ;
299 m_macPenInstalled
= false ;
302 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
305 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
306 m_macCurrentPortStateHelper
= NULL
;
308 if( m_macATSUIStyle
)
310 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
311 m_macATSUIStyle
= NULL
;
313 if ( m_macAliasWasEnabled
)
315 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
316 m_macAliasWasEnabled
= false ;
318 if ( m_macForegroundPixMap
)
321 ::PenPat(GetQDGlobalsBlack(&blackColor
));
322 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
323 m_macForegroundPixMap
= NULL
;
325 if ( m_macBackgroundPixMap
)
328 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
329 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
330 m_macBackgroundPixMap
= NULL
;
334 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
336 wxCHECK_RET( Ok(), wxT("invalid window dc") );
337 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
338 wxMacFastPortSetter
helper(this) ;
339 wxCoord xx
= XLOG2DEVMAC(x
);
340 wxCoord yy
= YLOG2DEVMAC(y
);
341 wxCoord w
= bmp
.GetWidth();
342 wxCoord h
= bmp
.GetHeight();
343 wxCoord ww
= XLOG2DEVREL(w
);
344 wxCoord hh
= YLOG2DEVREL(h
);
345 // Set up drawing mode
346 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
347 //m_logicalFunction == wxCLEAR ? WHITENESS :
348 //m_logicalFunction == wxSET ? BLACKNESS :
349 m_logicalFunction
== wxINVERT
? hilite
:
350 //m_logicalFunction == wxAND ? MERGECOPY :
351 m_logicalFunction
== wxOR
? srcOr
:
352 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
353 m_logicalFunction
== wxXOR
? srcXor
:
354 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
355 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
356 //m_logicalFunction == wxSRC_OR ? srcOr :
357 //m_logicalFunction == wxSRC_AND ? SRCAND :
359 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
360 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
361 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
362 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
364 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
366 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
367 PixMapHandle bmappixels
;
368 // Set foreground and background colours (for bitmaps depth = 1)
369 if(bmp
.GetDepth() == 1)
371 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
372 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
378 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
379 RGBColor black
= { 0,0,0} ;
380 RGBForeColor( &black
) ;
381 RGBBackColor( &white
) ;
383 bmappixels
= GetGWorldPixMap( bmapworld
) ;
384 wxCHECK_RET(LockPixels(bmappixels
),
385 wxT("DoDrawBitmap: Unable to lock pixels"));
386 Rect source
= { 0, 0, h
, w
};
387 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
388 if ( useMask
&& bmp
.GetMask() )
390 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
394 GetPortBitMapForCopyBits(bmapworld
),
395 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
396 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
397 &source
, &source
, &dest
, mode
, NULL
399 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
403 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
404 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
405 &source
, &dest
, mode
, NULL
) ;
407 UnlockPixels( bmappixels
) ;
409 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
411 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
412 OffsetRect( &bitmaprect
, xx
, yy
) ;
413 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
415 m_macPenInstalled
= false ;
416 m_macBrushInstalled
= false ;
417 m_macFontInstalled
= false ;
420 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
422 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
423 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
424 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
427 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
429 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
430 wxCoord xx
, yy
, ww
, hh
;
433 ww
= XLOG2DEVREL(width
);
434 hh
= YLOG2DEVREL(height
);
435 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
436 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
439 m_clipX1
= wxMax( m_clipX1
, xx
);
440 m_clipY1
= wxMax( m_clipY1
, yy
);
441 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
442 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
454 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
456 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
459 DestroyClippingRegion();
462 wxMacFastPortSetter
helper(this) ;
464 region
.GetBox( x
, y
, w
, h
);
465 wxCoord xx
, yy
, ww
, hh
;
470 // if we have a scaling that we cannot map onto native regions
471 // we must use the box
472 if ( ww
!= w
|| hh
!= h
)
474 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
478 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
479 if ( xx
!= x
|| yy
!= y
)
481 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
483 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
486 m_clipX1
= wxMax( m_clipX1
, xx
);
487 m_clipY1
= wxMax( m_clipY1
, yy
);
488 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
489 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
502 void wxDC::DestroyClippingRegion()
504 wxMacFastPortSetter
helper(this) ;
505 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
509 void wxDC::DoGetSizeMM( int* width
, int* height
) const
514 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
515 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
518 void wxDC::SetTextForeground( const wxColour
&col
)
520 wxCHECK_RET(Ok(), wxT("Invalid DC"));
521 m_textForegroundColour
= col
;
522 m_macFontInstalled
= false ;
525 void wxDC::SetTextBackground( const wxColour
&col
)
527 wxCHECK_RET(Ok(), wxT("Invalid DC"));
528 m_textBackgroundColour
= col
;
529 m_macFontInstalled
= false ;
532 void wxDC::SetMapMode( int mode
)
537 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
540 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
543 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
546 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
550 SetLogicalScale( 1.0, 1.0 );
553 if (mode
!= wxMM_TEXT
)
555 m_needComputeScaleX
= TRUE
;
556 m_needComputeScaleY
= TRUE
;
560 void wxDC::SetUserScale( double x
, double y
)
562 // allow negative ? -> no
565 ComputeScaleAndOrigin();
568 void wxDC::SetLogicalScale( double x
, double y
)
573 ComputeScaleAndOrigin();
576 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
578 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
579 m_logicalOriginY
= y
* m_signY
;
580 ComputeScaleAndOrigin();
583 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
585 m_externalDeviceOriginX
= x
;
586 m_externalDeviceOriginY
= y
;
587 ComputeScaleAndOrigin();
591 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
593 m_internalDeviceOriginX
= x
;
594 m_internalDeviceOriginY
= y
;
595 ComputeScaleAndOrigin();
597 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
599 if (x
) *x
= m_internalDeviceOriginX
;
600 if (y
) *y
= m_internalDeviceOriginY
;
604 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
606 m_signX
= (xLeftRight
? 1 : -1);
607 m_signY
= (yBottomUp
? -1 : 1);
608 ComputeScaleAndOrigin();
611 wxSize
wxDC::GetPPI() const
613 return wxSize(72, 72);
616 int wxDC::GetDepth() const
618 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
620 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
625 void wxDC::ComputeScaleAndOrigin()
627 // CMB: copy scale to see if it changes
628 double origScaleX
= m_scaleX
;
629 double origScaleY
= m_scaleY
;
630 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
631 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
632 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
633 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
634 // CMB: if scale has changed call SetPen to recalulate the line width
635 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
637 // this is a bit artificial, but we need to force wxDC to think
638 // the pen has changed
639 wxPen
* pen
= & GetPen();
646 void wxDC::SetPalette( const wxPalette
& palette
)
650 void wxDC::SetBackgroundMode( int mode
)
652 m_backgroundMode
= mode
;
655 void wxDC::SetFont( const wxFont
&font
)
658 m_macFontInstalled
= false ;
661 void wxDC::SetPen( const wxPen
&pen
)
666 m_macPenInstalled
= false ;
669 void wxDC::SetBrush( const wxBrush
&brush
)
671 if (m_brush
== brush
)
674 m_macBrushInstalled
= false ;
677 void wxDC::SetBackground( const wxBrush
&brush
)
679 if (m_backgroundBrush
== brush
)
681 m_backgroundBrush
= brush
;
682 if (!m_backgroundBrush
.Ok())
684 m_macBrushInstalled
= false ;
687 void wxDC::SetLogicalFunction( int function
)
689 if (m_logicalFunction
== function
)
691 m_logicalFunction
= function
;
692 m_macFontInstalled
= false ;
693 m_macBrushInstalled
= false ;
694 m_macPenInstalled
= false ;
697 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
698 const wxColour
& col
, int style
);
700 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
701 const wxColour
& col
, int style
)
703 return wxDoFloodFill(this, x
, y
, col
, style
);
706 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
708 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
709 wxMacFastPortSetter
helper(this) ;
711 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
712 // Convert from Mac colour to wx
713 col
->Set( colour
.red
>> 8,
719 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
721 wxCHECK_RET(Ok(), wxT("Invalid DC"));
722 wxMacFastPortSetter
helper(this) ;
723 if (m_pen
.GetStyle() != wxTRANSPARENT
)
726 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
727 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
728 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
729 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
730 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
731 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
732 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
733 (m_pen
.GetWidth() <= 1))
735 // Implement LAST_NOT for MAC at least for
736 // orthogonal lines. RR.
757 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
759 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
760 wxMacFastPortSetter
helper(this) ;
761 if (m_pen
.GetStyle() != wxTRANSPARENT
)
766 wxCoord xx
= XLOG2DEVMAC(x
);
767 wxCoord yy
= YLOG2DEVMAC(y
);
769 ::MoveTo( XLOG2DEVMAC(0), yy
);
770 ::LineTo( XLOG2DEVMAC(w
), yy
);
771 ::MoveTo( xx
, YLOG2DEVMAC(0) );
772 ::LineTo( xx
, YLOG2DEVMAC(h
) );
773 CalcBoundingBox(x
, y
);
774 CalcBoundingBox(x
+w
, y
+h
);
779 * To draw arcs properly the angles need to be converted from the WX style:
780 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
781 * a normal axis on paper).
784 * Angles start on the +ve y axis and go clockwise.
787 static double wxConvertWXangleToMACangle(double angle
)
789 double newAngle
= 90 - angle
;
795 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
796 wxCoord x2
, wxCoord y2
,
797 wxCoord xc
, wxCoord yc
)
799 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
800 wxMacFastPortSetter
helper(this) ;
801 wxCoord xx1
= XLOG2DEVMAC(x1
);
802 wxCoord yy1
= YLOG2DEVMAC(y1
);
803 wxCoord xx2
= XLOG2DEVMAC(x2
);
804 wxCoord yy2
= YLOG2DEVMAC(y2
);
805 wxCoord xxc
= XLOG2DEVMAC(xc
);
806 wxCoord yyc
= YLOG2DEVMAC(yc
);
807 double dx
= xx1
- xxc
;
808 double dy
= yy1
- yyc
;
809 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
810 wxCoord rad
= (wxCoord
)radius
;
811 double radius1
, radius2
;
812 if (xx1
== xx2
&& yy1
== yy2
)
817 else if (radius
== 0.0)
819 radius1
= radius2
= 0.0;
823 radius1
= (xx1
- xxc
== 0) ?
824 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
825 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
826 radius2
= (xx2
- xxc
== 0) ?
827 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
828 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
830 wxCoord alpha2
= wxCoord(radius2
- radius1
);
831 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
832 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
835 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
836 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
838 PaintArc(&r
, alpha1
, alpha2
);
840 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
842 FrameArc(&r
, alpha1
, alpha2
);
846 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
847 double sa
, double ea
)
849 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
850 wxMacFastPortSetter
helper(this) ;
852 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
853 // we have to make sure that the filling is always counter-clockwise
856 wxCoord xx
= XLOG2DEVMAC(x
);
857 wxCoord yy
= YLOG2DEVMAC(y
);
858 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
859 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
860 // handle -ve width and/or height
861 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
862 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
863 sa
= wxConvertWXangleToMACangle(sa
);
868 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
870 PaintArc(&r
, (short)sa
, (short)angle
);
872 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
874 FrameArc(&r
, (short)sa
, (short)angle
);
878 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
880 wxCHECK_RET(Ok(), wxT("Invalid DC"));
881 wxMacFastPortSetter
helper(this) ;
882 if (m_pen
.GetStyle() != wxTRANSPARENT
)
884 wxCoord xx1
= XLOG2DEVMAC(x
);
885 wxCoord yy1
= YLOG2DEVMAC(y
);
886 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
887 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
888 CalcBoundingBox(x
, y
);
892 void wxDC::DoDrawLines(int n
, wxPoint points
[],
893 wxCoord xoffset
, wxCoord yoffset
)
895 wxCHECK_RET(Ok(), wxT("Invalid DC"));
896 wxMacFastPortSetter
helper(this) ;
897 if (m_pen
.GetStyle() == wxTRANSPARENT
)
900 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
901 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
902 wxCoord x1
, x2
, y1
, y2
;
903 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
904 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
905 ::MoveTo(x1
- offset
, y1
- offset
);
906 for (int i
= 0; i
< n
-1; i
++)
908 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
909 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
910 ::LineTo( x2
- offset
, y2
- offset
);
914 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
915 wxCoord xoffset
, wxCoord yoffset
,
918 wxCHECK_RET(Ok(), wxT("Invalid DC"));
919 wxMacFastPortSetter
helper(this) ;
920 wxCoord x1
, x2
, y1
, y2
;
921 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
923 PolyHandle polygon
= OpenPoly();
924 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
925 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
927 for (int i
= 1; i
< n
; i
++)
929 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
930 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
933 // close the polyline if necessary
934 if ( x1
!= x2
|| y1
!= y2
)
939 if (m_brush
.GetStyle() != wxTRANSPARENT
)
942 ::PaintPoly( polygon
);
944 if (m_pen
.GetStyle() != wxTRANSPARENT
)
947 ::FramePoly( polygon
) ;
952 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
954 wxCHECK_RET(Ok(), wxT("Invalid DC"));
955 wxMacFastPortSetter
helper(this) ;
956 wxCoord xx
= XLOG2DEVMAC(x
);
957 wxCoord yy
= YLOG2DEVMAC(y
);
958 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
959 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
960 // CMB: draw nothing if transformed w or h is 0
961 if (ww
== 0 || hh
== 0)
963 // CMB: handle -ve width and/or height
974 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
975 if (m_brush
.GetStyle() != wxTRANSPARENT
)
978 ::PaintRect( &rect
) ;
980 if (m_pen
.GetStyle() != wxTRANSPARENT
)
983 ::FrameRect( &rect
) ;
987 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
988 wxCoord width
, wxCoord height
,
991 wxCHECK_RET(Ok(), wxT("Invalid DC"));
992 wxMacFastPortSetter
helper(this) ;
994 radius
= - radius
* ((width
< height
) ? width
: height
);
995 wxCoord xx
= XLOG2DEVMAC(x
);
996 wxCoord yy
= YLOG2DEVMAC(y
);
997 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
998 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
999 // CMB: draw nothing if transformed w or h is 0
1000 if (ww
== 0 || hh
== 0)
1002 // CMB: handle -ve width and/or height
1013 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1014 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1017 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1019 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1022 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1026 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1028 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1029 wxMacFastPortSetter
helper(this) ;
1030 wxCoord xx
= XLOG2DEVMAC(x
);
1031 wxCoord yy
= YLOG2DEVMAC(y
);
1032 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1033 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1034 // CMB: draw nothing if transformed w or h is 0
1035 if (ww
== 0 || hh
== 0)
1037 // CMB: handle -ve width and/or height
1048 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1049 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1052 ::PaintOval( &rect
) ;
1054 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1057 ::FrameOval( &rect
) ;
1061 bool wxDC::CanDrawBitmap(void) const
1066 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1067 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1068 wxCoord xsrcMask
, wxCoord ysrcMask
)
1070 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1071 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1072 if ( logical_func
== wxNO_OP
)
1074 if (xsrcMask
== -1 && ysrcMask
== -1)
1076 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1078 // correct the parameter in case this dc does not have a mask at all
1079 if ( useMask
&& !source
->m_macMask
)
1081 Rect srcrect
, dstrect
;
1082 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1083 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1084 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1085 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1086 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1087 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1088 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1089 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1090 short mode
= kUnsupportedMode
;
1091 bool invertDestinationFirst
= false ;
1092 switch ( logical_func
)
1094 case wxAND
: // src AND dst
1095 mode
= adMin
; // ok
1097 case wxAND_INVERT
: // (NOT src) AND dst
1098 mode
= notSrcOr
; // ok
1100 case wxAND_REVERSE
:// src AND (NOT dst)
1101 invertDestinationFirst
= true ;
1105 mode
= kEmulatedMode
;
1108 mode
= srcCopy
; // ok
1110 case wxEQUIV
: // (NOT src) XOR dst
1111 mode
= srcXor
; // ok
1113 case wxINVERT
: // NOT dst
1114 mode
= kEmulatedMode
; //or hilite ;
1116 case wxNAND
: // (NOT src) OR (NOT dst)
1117 invertDestinationFirst
= true ;
1120 case wxNOR
: // (NOT src) AND (NOT dst)
1121 invertDestinationFirst
= true ;
1124 case wxNO_OP
: // dst
1125 mode
= kEmulatedMode
; // this has already been handled upon entry
1127 case wxOR
: // src OR dst
1130 case wxOR_INVERT
: // (NOT src) OR dst
1133 case wxOR_REVERSE
: // src OR (NOT dst)
1134 invertDestinationFirst
= true ;
1138 mode
= kEmulatedMode
;
1140 case wxSRC_INVERT
: // (NOT src)
1141 mode
= notSrcCopy
; // ok
1143 case wxXOR
: // src XOR dst
1144 mode
= notSrcXor
; // ok
1149 if ( mode
== kUnsupportedMode
)
1151 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1154 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1155 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1156 if ( LockPixels(bmappixels
) )
1158 wxMacFastPortSetter
helper(this) ;
1159 if ( source
->GetDepth() == 1 )
1161 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1162 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1166 // the modes need this, otherwise we'll end up having really nice colors...
1167 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1168 RGBColor black
= { 0,0,0} ;
1169 RGBForeColor( &black
) ;
1170 RGBBackColor( &white
) ;
1172 if ( useMask
&& source
->m_macMask
)
1174 if ( mode
== srcCopy
)
1176 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1178 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1179 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1180 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1181 &srcrect
, &srcrect
, &dstrect
) ;
1182 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1187 RgnHandle clipRgn
= NewRgn() ;
1188 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1189 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1190 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1191 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1192 if ( mode
== kEmulatedMode
)
1195 ::PenPat(GetQDGlobalsBlack(&pat
));
1196 if ( logical_func
== wxSET
)
1198 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1199 ::RGBForeColor( &col
) ;
1200 ::PaintRgn( clipRgn
) ;
1202 else if ( logical_func
== wxCLEAR
)
1204 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1205 ::RGBForeColor( &col
) ;
1206 ::PaintRgn( clipRgn
) ;
1208 else if ( logical_func
== wxINVERT
)
1210 MacInvertRgn( clipRgn
) ;
1214 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1216 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1218 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1219 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1220 if ( PtInRgn( dstPoint
, clipRgn
) )
1224 SetPort( (GrafPtr
) sourcePort
) ;
1225 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1226 SetPort( (GrafPtr
) m_macPort
) ;
1227 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1228 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1229 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1237 if ( invertDestinationFirst
)
1239 MacInvertRgn( clipRgn
) ;
1241 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1242 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1243 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1245 DisposeRgn( clipRgn
) ;
1250 RgnHandle clipRgn
= NewRgn() ;
1251 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1252 if ( mode
== kEmulatedMode
)
1255 ::PenPat(GetQDGlobalsBlack(&pat
));
1256 if ( logical_func
== wxSET
)
1258 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1259 ::RGBForeColor( &col
) ;
1260 ::PaintRgn( clipRgn
) ;
1262 else if ( logical_func
== wxCLEAR
)
1264 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1265 ::RGBForeColor( &col
) ;
1266 ::PaintRgn( clipRgn
) ;
1268 else if ( logical_func
== wxINVERT
)
1270 MacInvertRgn( clipRgn
) ;
1274 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1276 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1278 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1279 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1283 SetPort( (GrafPtr
) sourcePort
) ;
1284 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1285 SetPort( (GrafPtr
) m_macPort
) ;
1286 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1287 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1288 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1296 if ( invertDestinationFirst
)
1298 MacInvertRgn( clipRgn
) ;
1300 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1301 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1302 &srcrect
, &dstrect
, mode
, NULL
) ;
1304 DisposeRgn( clipRgn
) ;
1306 UnlockPixels( bmappixels
) ;
1308 m_macPenInstalled
= false ;
1309 m_macBrushInstalled
= false ;
1310 m_macFontInstalled
= false ;
1315 // as macro in FixMath.h for 10.3
1316 inline Fixed
IntToFixed( int inInt
)
1318 return (((SInt32
) inInt
) << 16);
1321 inline int FixedToInt( Fixed inFixed
)
1323 return (((SInt32
) inFixed
) >> 16);
1327 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1330 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1334 DrawText(str
, x
, y
);
1338 if ( str
.Length() == 0 )
1341 wxMacFastPortSetter
helper(this) ;
1344 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1347 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1348 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1349 m_macAliasWasEnabled
= true ;
1351 OSStatus status
= noErr
;
1352 ATSUTextLayout atsuLayout
;
1353 UniCharCount chars
= str
.Length() ;
1355 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1356 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1358 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1359 int wlen
= wxWcslen( wchar
.data() ) ;
1360 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1361 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1363 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1364 int iAngle
= int( angle
);
1365 int drawX
= XLOG2DEVMAC(x
) ;
1366 int drawY
= YLOG2DEVMAC(y
) ;
1368 ATSUTextMeasurement textBefore
;
1369 ATSUTextMeasurement textAfter
;
1370 ATSUTextMeasurement ascent
;
1371 ATSUTextMeasurement descent
;
1374 if ( abs(iAngle
) > 0 )
1376 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1377 ATSUAttributeTag atsuTags
[] =
1379 kATSULineRotationTag
,
1381 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1385 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1389 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1390 atsuTags
, atsuSizes
, atsuValues
) ;
1392 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1393 &textBefore
, &textAfter
, &ascent
, &descent
);
1395 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1396 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1397 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1398 IntToFixed(drawX
) , IntToFixed(drawY
) );
1399 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1401 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1402 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1403 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1404 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1405 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1406 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1407 ::ATSUDisposeTextLayout(atsuLayout
);
1410 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1412 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1414 wxMacFastPortSetter
helper(this) ;
1415 long xx
= XLOG2DEVMAC(x
);
1416 long yy
= YLOG2DEVMAC(y
);
1418 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1419 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1420 useDrawThemeText
= false ;
1425 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1426 SetAntiAliasedTextEnabled(true, 8);
1427 m_macAliasWasEnabled
= true ;
1430 ::GetFontInfo( &fi
) ;
1432 if ( !useDrawThemeText
)
1435 ::MoveTo( xx
, yy
);
1436 if ( m_backgroundMode
== wxTRANSPARENT
)
1438 ::TextMode( srcOr
) ;
1442 ::TextMode( srcCopy
) ;
1444 int length
= strtext
.Length() ;
1452 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1454 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1456 if ( useDrawThemeText
)
1458 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1459 wxMacCFStringHolder
mString( linetext
) ;
1460 if ( m_backgroundMode
!= wxTRANSPARENT
)
1462 Point bounds
={0,0} ;
1463 Rect background
= frame
;
1465 ::GetThemeTextDimensions( mString
,
1466 kThemeCurrentPortFont
,
1471 background
.right
= background
.left
+ bounds
.h
;
1472 background
.bottom
= background
.top
+ bounds
.v
;
1473 ::EraseRect( &background
) ;
1475 ::DrawThemeTextBox( mString
,
1476 kThemeCurrentPortFont
,
1487 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1488 ::DrawText( text
, 0 , strlen(text
) ) ;
1490 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1496 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1498 if ( useDrawThemeText
)
1500 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1501 wxMacCFStringHolder
mString( linetext
) ;
1503 if ( m_backgroundMode
!= wxTRANSPARENT
)
1505 Point bounds
={0,0} ;
1506 Rect background
= frame
;
1508 ::GetThemeTextDimensions( mString
,
1509 kThemeCurrentPortFont
,
1514 background
.right
= background
.left
+ bounds
.h
;
1515 background
.bottom
= background
.top
+ bounds
.v
;
1516 ::EraseRect( &background
) ;
1518 ::DrawThemeTextBox( mString
,
1519 kThemeCurrentPortFont
,
1529 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1530 ::DrawText( text
, 0 , strlen(text
) ) ;
1533 ::TextMode( srcOr
) ;
1536 bool wxDC::CanGetTextExtent() const
1538 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1542 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1543 wxCoord
*descent
, wxCoord
*externalLeading
,
1544 wxFont
*theFont
) const
1546 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1547 wxMacFastPortSetter
helper(this) ;
1548 wxFont formerFont
= m_font
;
1551 // work around the constness
1552 *((wxFont
*)(&m_font
)) = *theFont
;
1556 ::GetFontInfo( &fi
) ;
1558 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1559 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1560 useGetThemeText
= false ;
1563 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1565 *descent
=YDEV2LOGREL( fi
.descent
);
1566 if ( externalLeading
)
1567 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1568 int length
= strtext
.Length() ;
1578 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1580 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1582 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1584 if ( useGetThemeText
)
1586 Point bounds
={0,0} ;
1588 wxMacCFStringHolder
mString( linetext
) ;
1589 ::GetThemeTextDimensions( mString
,
1590 kThemeCurrentPortFont
,
1595 curwidth
= bounds
.h
;
1600 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1601 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1603 if ( curwidth
> *width
)
1604 *width
= XDEV2LOGREL( curwidth
) ;
1610 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1612 if ( useGetThemeText
)
1614 Point bounds
={0,0} ;
1616 wxMacCFStringHolder
mString( linetext
) ;
1617 ::GetThemeTextDimensions( mString
,
1618 kThemeCurrentPortFont
,
1623 curwidth
= bounds
.h
;
1628 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1629 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1631 if ( curwidth
> *width
)
1632 *width
= XDEV2LOGREL( curwidth
) ;
1636 // work around the constness
1637 *((wxFont
*)(&m_font
)) = formerFont
;
1638 m_macFontInstalled
= false ;
1642 wxCoord
wxDC::GetCharWidth(void) const
1644 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1645 wxMacFastPortSetter
helper(this) ;
1649 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1650 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1651 useGetThemeText
= false ;
1655 if ( useGetThemeText
)
1657 Point bounds
={0,0} ;
1659 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1660 ::GetThemeTextDimensions( mString
,
1661 kThemeCurrentPortFont
,
1666 CFRelease( mString
) ;
1672 width
= ::TextWidth( text
, 0 , 1 ) ;
1674 return YDEV2LOGREL(width
) ;
1677 wxCoord
wxDC::GetCharHeight(void) const
1679 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1680 wxMacFastPortSetter
helper(this) ;
1683 ::GetFontInfo( &fi
) ;
1684 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1687 void wxDC::Clear(void)
1689 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1690 wxMacFastPortSetter
helper(this) ;
1691 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1692 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1695 //MacInstallBrush() ;
1696 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1697 ::EraseRect( &rect
) ;
1701 void wxDC::MacInstallFont() const
1703 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1704 // if ( m_macFontInstalled )
1706 Pattern blackColor
;
1707 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1708 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1711 ::TextFont( font
->m_macFontNum
) ;
1712 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1713 ::TextFace( font
->m_macFontStyle
) ;
1714 m_macFontInstalled
= true ;
1715 m_macBrushInstalled
= false ;
1716 m_macPenInstalled
= false ;
1717 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1718 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1719 ::RGBForeColor( &forecolor
);
1720 ::RGBBackColor( &backcolor
);
1724 FontFamilyID fontId
;
1728 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1729 GetFNum( fontName
, &fontId
);
1730 ::TextFont( fontId
) ;
1731 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1732 ::TextFace( fontStyle
) ;
1733 // todo reset after spacing changes - or store the current spacing somewhere
1734 m_macFontInstalled
= true ;
1735 m_macBrushInstalled
= false ;
1736 m_macPenInstalled
= false ;
1737 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1738 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1739 ::RGBForeColor( &forecolor
);
1740 ::RGBBackColor( &backcolor
);
1742 short mode
= patCopy
;
1744 switch( m_logicalFunction
)
1749 case wxINVERT
: // NOT dst
1750 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1753 case wxXOR
: // src XOR dst
1756 case wxOR_REVERSE
: // src OR (NOT dst)
1759 case wxSRC_INVERT
: // (NOT src)
1762 case wxAND
: // src AND dst
1767 case wxAND_REVERSE
:// src AND (NOT dst)
1768 case wxAND_INVERT
: // (NOT src) AND dst
1769 case wxNO_OP
: // dst
1770 case wxNOR
: // (NOT src) AND (NOT dst)
1771 case wxEQUIV
: // (NOT src) XOR dst
1772 case wxOR_INVERT
: // (NOT src) OR dst
1773 case wxNAND
: // (NOT src) OR (NOT dst)
1774 case wxOR
: // src OR dst
1776 // case wxSRC_OR: // source _bitmap_ OR destination
1777 // case wxSRC_AND: // source _bitmap_ AND destination
1781 OSStatus status
= noErr
;
1782 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1783 Style qdStyle
= font
->m_macFontStyle
;
1784 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1785 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1786 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1787 ATSUAttributeTag atsuTags
[] =
1792 // kATSUBaselineClassTag ,
1793 kATSUVerticalCharacterTag
,
1794 kATSUQDBoldfaceTag
,
1796 kATSUQDUnderlineTag
,
1797 kATSUQDCondensedTag
,
1798 kATSUQDExtendedTag
,
1800 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1802 sizeof( ATSUFontID
) ,
1804 // sizeof( RGBColor ) ,
1805 // sizeof( BslnBaselineClass ) ,
1806 sizeof( ATSUVerticalCharacterType
),
1813 Boolean kTrue
= true ;
1814 Boolean kFalse
= false ;
1815 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1816 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1817 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1821 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1822 // &kBaselineDefault ,
1824 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1825 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1826 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1827 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1828 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1830 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1831 atsuTags
, atsuSizes
, atsuValues
);
1832 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1835 Pattern gPatterns
[] =
1837 { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ,
1838 { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } ,
1839 { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } ,
1840 { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } ,
1841 { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } ,
1842 { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } ,
1843 { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } ,
1845 { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } , // DOT
1846 { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } , // LONG_DASH
1847 { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } , // SHORT_DASH
1848 { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } , // DOT_DASH
1851 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1853 int index
= 0; // solid pattern by default
1857 case wxBDIAGONAL_HATCH
: index
= 1; break;
1858 case wxFDIAGONAL_HATCH
: index
= 2; break;
1859 case wxCROSS_HATCH
: index
= 3; break;
1860 case wxHORIZONTAL_HATCH
: index
= 4; break;
1861 case wxVERTICAL_HATCH
: index
= 5; break;
1862 case wxCROSSDIAG_HATCH
: index
= 6; break;
1864 case wxDOT
: index
= 7; break;
1865 case wxLONG_DASH
: index
= 8; break;
1866 case wxSHORT_DASH
: index
= 9; break;
1867 case wxDOT_DASH
: index
= 10; break;
1869 *pattern
= gPatterns
[index
];
1872 void wxDC::MacInstallPen() const
1874 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1876 // if ( m_macPenInstalled )
1878 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1879 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1880 ::RGBForeColor( &forecolor
);
1881 ::RGBBackColor( &backcolor
);
1883 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1884 // null means only one pixel, at whatever resolution
1885 if ( penWidth
== 0 )
1887 ::PenSize(penWidth
, penWidth
);
1889 int penStyle
= m_pen
.GetStyle();
1891 if (penStyle
== wxUSER_DASH
)
1893 // FIXME: there should be exactly 8 items in the dash
1895 int number
= m_pen
.GetDashes(&dash
) ;
1897 for ( int i
= 0 ; i
< 8 ; ++i
)
1899 pat
.pat
[i
] = dash
[index
] ;
1900 if (index
< number
- 1)
1906 wxMacGetPattern(penStyle
, &pat
);
1910 short mode
= patCopy
;
1912 switch( m_logicalFunction
)
1914 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1917 case wxINVERT
: // NOT dst
1918 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1921 case wxXOR
: // src XOR dst
1924 case wxOR_REVERSE
: // src OR (NOT dst)
1927 case wxSRC_INVERT
: // (NOT src)
1930 case wxAND
: // src AND dst
1935 case wxAND_REVERSE
:// src AND (NOT dst)
1936 case wxAND_INVERT
: // (NOT src) AND dst
1937 case wxNO_OP
: // dst
1938 case wxNOR
: // (NOT src) AND (NOT dst)
1939 case wxEQUIV
: // (NOT src) XOR dst
1940 case wxOR_INVERT
: // (NOT src) OR dst
1941 case wxNAND
: // (NOT src) OR (NOT dst)
1942 case wxOR
: // src OR dst
1944 // case wxSRC_OR: // source _bitmap_ OR destination
1945 // case wxSRC_AND: // source _bitmap_ AND destination
1949 m_macPenInstalled
= true ;
1950 m_macBrushInstalled
= false ;
1951 m_macFontInstalled
= false ;
1954 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1956 Pattern whiteColor
;
1957 switch( background
.MacGetBrushKind() )
1959 case kwxMacBrushTheme
:
1961 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1964 case kwxMacBrushThemeBackground
:
1967 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1968 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1971 case kwxMacBrushColour
:
1973 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1974 int brushStyle
= background
.GetStyle();
1975 if (brushStyle
== wxSOLID
)
1976 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1977 else if (IS_HATCH(brushStyle
))
1980 wxMacGetPattern(brushStyle
, &pat
);
1985 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1992 void wxDC::MacInstallBrush() const
1994 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1995 Pattern blackColor
;
1996 // if ( m_macBrushInstalled )
1999 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2000 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2001 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2002 int brushStyle
= m_brush
.GetStyle();
2003 if (brushStyle
== wxSOLID
)
2005 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2007 else if (IS_HATCH(brushStyle
))
2010 wxMacGetPattern(brushStyle
, &pat
);
2013 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2015 // we force this in order to be compliant with wxMSW
2016 backgroundTransparent
= false ;
2017 // for these the text fore (and back for MASK_OPAQUE) colors are used
2018 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2019 int width
= bitmap
->GetWidth() ;
2020 int height
= bitmap
->GetHeight() ;
2021 GWorldPtr gw
= NULL
;
2022 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2023 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2025 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2026 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2027 LockPixels( gwpixmaphandle
) ;
2028 bool isMonochrome
= !IsPortColor( gw
) ;
2029 if ( !isMonochrome
)
2031 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2032 isMonochrome
= true ;
2034 if ( isMonochrome
&& width
== 8 && height
== 8 )
2036 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2037 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2038 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2039 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2040 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2042 for ( int i
= 0 ; i
< 8 ; ++i
)
2044 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2046 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2051 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2052 // caching scheme before putting this into production
2055 PixPatHandle pixpat
= NewPixPat() ;
2056 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2057 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2058 ((**(**pixpat
).patMap
).bounds
.bottom
-
2059 (**(**pixpat
).patMap
).bounds
.top
);
2060 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2061 (**pixpat
).patData
= image
;
2064 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2065 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2066 if ( ctspec
[0].rgb
.red
== 0x0000 )
2068 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2069 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2073 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2074 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2076 ::CTabChanged( ctable
) ;
2078 ::PenPixPat(pixpat
);
2079 m_macForegroundPixMap
= pixpat
;
2081 UnlockPixels( gwpixmaphandle
) ;
2085 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2087 short mode
= patCopy
;
2088 switch( m_logicalFunction
)
2091 if ( backgroundTransparent
)
2096 case wxINVERT
: // NOT dst
2097 if ( !backgroundTransparent
)
2099 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2103 case wxXOR
: // src XOR dst
2106 case wxOR_REVERSE
: // src OR (NOT dst)
2109 case wxSRC_INVERT
: // (NOT src)
2112 case wxAND
: // src AND dst
2117 case wxAND_REVERSE
:// src AND (NOT dst)
2118 case wxAND_INVERT
: // (NOT src) AND dst
2119 case wxNO_OP
: // dst
2120 case wxNOR
: // (NOT src) AND (NOT dst)
2121 case wxEQUIV
: // (NOT src) XOR dst
2122 case wxOR_INVERT
: // (NOT src) OR dst
2123 case wxNAND
: // (NOT src) OR (NOT dst)
2124 case wxOR
: // src OR dst
2126 // case wxSRC_OR: // source _bitmap_ OR destination
2127 // case wxSRC_AND: // source _bitmap_ AND destination
2131 m_macBrushInstalled
= true ;
2132 m_macPenInstalled
= false ;
2133 m_macFontInstalled
= false ;
2136 // ---------------------------------------------------------------------------
2137 // coordinates transformations
2138 // ---------------------------------------------------------------------------
2140 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2142 return ((wxDC
*)this)->XDEV2LOG(x
);
2145 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2147 return ((wxDC
*)this)->YDEV2LOG(y
);
2150 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2152 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2155 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2157 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2160 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2162 return ((wxDC
*)this)->XLOG2DEV(x
);
2165 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2167 return ((wxDC
*)this)->YLOG2DEV(y
);
2170 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2172 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2175 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2177 return ((wxDC
*)this)->YLOG2DEVREL(y
);