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/region.h"
28 #include "wx/mac/private.h"
29 #include "ATSUnicode.h"
30 #include "TextCommon.h"
31 #include "TextEncodingConverter.h"
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #define mm2inches 0.0393700787402
41 #define inches2mm 25.4
42 #define mm2twips 56.6929133859
43 #define twips2mm 0.0176388888889
44 #define mm2pt 2.83464566929
45 #define pt2mm 0.352777777778
47 const double M_PI
= 3.14159265358979 ;
49 const double RAD2DEG
= 180.0 / M_PI
;
50 const short kEmulatedMode
= -1 ;
51 const short kUnsupportedMode
= -2 ;
53 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
54 m_ph( (GrafPtr
) dc
->m_macPort
)
56 wxASSERT( dc
->Ok() ) ;
58 dc
->MacSetupPort(&m_ph
) ;
61 wxMacPortSetter::~wxMacPortSetter()
63 m_dc
->MacCleanupPort(&m_ph
) ;
66 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
68 m_formerClip
= NewRgn() ;
69 m_newClip
= NewRgn() ;
70 GetClip( m_formerClip
) ;
75 // this clipping area was set to the parent window's drawing area, lead to problems
76 // with MacOSX controls drawing outside their wx' rectangle
77 RgnHandle insidergn
= NewRgn() ;
79 wxWindow
*parent
= win
->GetParent() ;
80 parent
->MacWindowToRootWindow( &x
,&y
) ;
81 wxSize size
= parent
->GetSize() ;
82 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
83 size
.x
- parent
->MacGetRightBorderSize(),
84 size
.y
- parent
->MacGetBottomBorderSize()) ;
85 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
86 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
87 OffsetRgn( m_newClip
, x
, y
) ;
88 SetClip( m_newClip
) ;
89 DisposeRgn( insidergn
) ;
91 RgnHandle insidergn
= NewRgn() ;
93 win
->MacWindowToRootWindow( &x
,&y
) ;
94 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
95 OffsetRgn( m_newClip
, x
, y
) ;
96 SetClip( m_newClip
) ;
100 wxMacWindowClipper::~wxMacWindowClipper()
102 SetClip( m_formerClip
) ;
103 DisposeRgn( m_newClip
) ;
104 DisposeRgn( m_formerClip
) ;
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
110 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
111 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
112 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
114 //-----------------------------------------------------------------------------
116 //-----------------------------------------------------------------------------
117 // this function emulates all wx colour manipulations, used to verify the implementation
118 // by setting the mode in the blitting functions to kEmulatedMode
119 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
121 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
123 switch ( logical_func
)
125 case wxAND
: // src AND dst
126 dstColor
.red
= dstColor
.red
& srcColor
.red
;
127 dstColor
.green
= dstColor
.green
& srcColor
.green
;
128 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
130 case wxAND_INVERT
: // (NOT src) AND dst
131 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
132 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
133 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
135 case wxAND_REVERSE
:// src AND (NOT dst)
136 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
137 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
138 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
146 dstColor
.red
= srcColor
.red
;
147 dstColor
.green
= srcColor
.green
;
148 dstColor
.blue
= srcColor
.blue
;
150 case wxEQUIV
: // (NOT src) XOR dst
151 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
152 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
153 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
155 case wxINVERT
: // NOT dst
156 dstColor
.red
= ~dstColor
.red
;
157 dstColor
.green
= ~dstColor
.green
;
158 dstColor
.blue
= ~dstColor
.blue
;
160 case wxNAND
: // (NOT src) OR (NOT dst)
161 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
162 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
163 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
165 case wxNOR
: // (NOT src) AND (NOT dst)
166 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
167 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
168 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
172 case wxOR
: // src OR dst
173 dstColor
.red
= dstColor
.red
| srcColor
.red
;
174 dstColor
.green
= dstColor
.green
| srcColor
.green
;
175 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
177 case wxOR_INVERT
: // (NOT src) OR dst
178 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
179 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
180 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
182 case wxOR_REVERSE
: // src OR (NOT dst)
183 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
184 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
185 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
188 dstColor
.red
= 0xFFFF ;
189 dstColor
.green
= 0xFFFF ;
190 dstColor
.blue
= 0xFFFF ;
192 case wxSRC_INVERT
: // (NOT src)
193 dstColor
.red
= ~srcColor
.red
;
194 dstColor
.green
= ~srcColor
.green
;
195 dstColor
.blue
= ~srcColor
.blue
;
197 case wxXOR
: // src XOR dst
198 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
199 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
200 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
209 m_mm_to_pix_x
= mm2pt
;
210 m_mm_to_pix_y
= mm2pt
;
211 m_internalDeviceOriginX
= 0;
212 m_internalDeviceOriginY
= 0;
213 m_externalDeviceOriginX
= 0;
214 m_externalDeviceOriginY
= 0;
215 m_logicalScaleX
= 1.0;
216 m_logicalScaleY
= 1.0;
221 m_needComputeScaleX
= FALSE
;
222 m_needComputeScaleY
= FALSE
;
226 m_macFontInstalled
= false ;
227 m_macBrushInstalled
= false ;
228 m_macPenInstalled
= false ;
229 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
230 m_macBoundaryClipRgn
= NewRgn() ;
231 m_macCurrentClipRgn
= NewRgn() ;
232 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
233 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
234 m_pen
= *wxBLACK_PEN
;
235 m_font
= *wxNORMAL_FONT
;
236 m_brush
= *wxWHITE_BRUSH
;
237 m_macCurrentPortStateHelper
= NULL
;
238 m_macATSUIStyle
= NULL
;
239 m_macAliasWasEnabled
= false;
240 m_macForegroundPixMap
= NULL
;
241 m_macBackgroundPixMap
= NULL
;
246 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
247 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
250 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
252 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
253 m_macCurrentPortStateHelper
= help
;
254 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
255 m_macFontInstalled
= false ;
256 m_macBrushInstalled
= false ;
257 m_macPenInstalled
= false ;
260 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
262 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
263 m_macCurrentPortStateHelper
= NULL
;
264 if( m_macATSUIStyle
)
266 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
267 m_macATSUIStyle
= NULL
;
269 if ( m_macAliasWasEnabled
)
271 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
272 m_macAliasWasEnabled
= false ;
274 if ( m_macForegroundPixMap
)
277 ::PenPat(GetQDGlobalsBlack(&blackColor
));
278 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
279 m_macForegroundPixMap
= NULL
;
281 if ( m_macBackgroundPixMap
)
284 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
285 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
286 m_macBackgroundPixMap
= NULL
;
290 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
292 wxCHECK_RET( Ok(), wxT("invalid window dc") );
293 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
294 wxMacPortSetter
helper(this) ;
295 wxCoord xx
= XLOG2DEVMAC(x
);
296 wxCoord yy
= YLOG2DEVMAC(y
);
297 wxCoord w
= bmp
.GetWidth();
298 wxCoord h
= bmp
.GetHeight();
299 wxCoord ww
= XLOG2DEVREL(w
);
300 wxCoord hh
= YLOG2DEVREL(h
);
301 // Set up drawing mode
302 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
303 //m_logicalFunction == wxCLEAR ? WHITENESS :
304 //m_logicalFunction == wxSET ? BLACKNESS :
305 m_logicalFunction
== wxINVERT
? hilite
:
306 //m_logicalFunction == wxAND ? MERGECOPY :
307 m_logicalFunction
== wxOR
? srcOr
:
308 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
309 m_logicalFunction
== wxXOR
? srcXor
:
310 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
311 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
312 //m_logicalFunction == wxSRC_OR ? srcOr :
313 //m_logicalFunction == wxSRC_AND ? SRCAND :
315 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
316 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
317 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
318 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
320 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
322 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
323 PixMapHandle bmappixels
;
324 // Set foreground and background colours (for bitmaps depth = 1)
325 if(bmp
.GetDepth() == 1)
327 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
328 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
334 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
335 RGBColor black
= { 0,0,0} ;
336 RGBForeColor( &black
) ;
337 RGBBackColor( &white
) ;
339 bmappixels
= GetGWorldPixMap( bmapworld
) ;
340 wxCHECK_RET(LockPixels(bmappixels
),
341 wxT("DoDrawBitmap: Unable to lock pixels"));
342 Rect source
= { 0, 0, h
, w
};
343 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
344 if ( useMask
&& bmp
.GetMask() )
346 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
350 GetPortBitMapForCopyBits(bmapworld
),
351 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
352 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
353 &source
, &source
, &dest
, mode
, NULL
355 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
359 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
360 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
361 &source
, &dest
, mode
, NULL
) ;
363 UnlockPixels( bmappixels
) ;
365 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
367 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
368 OffsetRect( &bitmaprect
, xx
, yy
) ;
369 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
371 m_macPenInstalled
= false ;
372 m_macBrushInstalled
= false ;
373 m_macFontInstalled
= false ;
376 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
378 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
379 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
380 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
383 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
385 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
386 wxCoord xx
, yy
, ww
, hh
;
389 ww
= XLOG2DEVREL(width
);
390 hh
= YLOG2DEVREL(height
);
391 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
392 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
395 m_clipX1
= wxMax( m_clipX1
, xx
);
396 m_clipY1
= wxMax( m_clipY1
, yy
);
397 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
398 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
410 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
412 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
413 wxMacPortSetter
helper(this) ;
416 DestroyClippingRegion();
420 region
.GetBox( x
, y
, w
, h
);
421 wxCoord xx
, yy
, ww
, hh
;
426 // if we have a scaling that we cannot map onto native regions
427 // we must use the box
428 if ( ww
!= w
|| hh
!= h
)
430 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
434 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
435 if ( xx
!= x
|| yy
!= y
)
437 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
439 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
442 m_clipX1
= wxMax( m_clipX1
, xx
);
443 m_clipY1
= wxMax( m_clipY1
, yy
);
444 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
445 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
458 void wxDC::DestroyClippingRegion()
460 wxMacPortSetter
helper(this) ;
461 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
465 void wxDC::DoGetSize( int* width
, int* height
) const
467 *width
= m_maxX
-m_minX
;
468 *height
= m_maxY
-m_minY
;
471 void wxDC::DoGetSizeMM( int* width
, int* height
) const
476 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
477 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
480 void wxDC::SetTextForeground( const wxColour
&col
)
482 wxCHECK_RET(Ok(), wxT("Invalid DC"));
483 m_textForegroundColour
= col
;
484 m_macFontInstalled
= false ;
487 void wxDC::SetTextBackground( const wxColour
&col
)
489 wxCHECK_RET(Ok(), wxT("Invalid DC"));
490 m_textBackgroundColour
= col
;
491 m_macFontInstalled
= false ;
494 void wxDC::SetMapMode( int mode
)
499 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
502 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
505 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
508 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
512 SetLogicalScale( 1.0, 1.0 );
515 if (mode
!= wxMM_TEXT
)
517 m_needComputeScaleX
= TRUE
;
518 m_needComputeScaleY
= TRUE
;
522 void wxDC::SetUserScale( double x
, double y
)
524 // allow negative ? -> no
527 ComputeScaleAndOrigin();
530 void wxDC::SetLogicalScale( double x
, double y
)
535 ComputeScaleAndOrigin();
538 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
540 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
541 m_logicalOriginY
= y
* m_signY
;
542 ComputeScaleAndOrigin();
545 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
547 m_externalDeviceOriginX
= x
;
548 m_externalDeviceOriginY
= y
;
549 ComputeScaleAndOrigin();
553 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
555 m_internalDeviceOriginX
= x
;
556 m_internalDeviceOriginY
= y
;
557 ComputeScaleAndOrigin();
559 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
561 if (x
) *x
= m_internalDeviceOriginX
;
562 if (y
) *y
= m_internalDeviceOriginY
;
566 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
568 m_signX
= (xLeftRight
? 1 : -1);
569 m_signY
= (yBottomUp
? -1 : 1);
570 ComputeScaleAndOrigin();
573 wxSize
wxDC::GetPPI() const
575 return wxSize(72, 72);
578 int wxDC::GetDepth() const
580 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
582 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
587 void wxDC::ComputeScaleAndOrigin()
589 // CMB: copy scale to see if it changes
590 double origScaleX
= m_scaleX
;
591 double origScaleY
= m_scaleY
;
592 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
593 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
594 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
595 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
596 // CMB: if scale has changed call SetPen to recalulate the line width
597 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
599 // this is a bit artificial, but we need to force wxDC to think
600 // the pen has changed
601 wxPen
* pen
= & GetPen();
608 void wxDC::SetPalette( const wxPalette
& palette
)
612 void wxDC::SetBackgroundMode( int mode
)
614 m_backgroundMode
= mode
;
617 void wxDC::SetFont( const wxFont
&font
)
620 m_macFontInstalled
= false ;
623 void wxDC::SetPen( const wxPen
&pen
)
628 m_macPenInstalled
= false ;
631 void wxDC::SetBrush( const wxBrush
&brush
)
633 if (m_brush
== brush
)
636 m_macBrushInstalled
= false ;
639 void wxDC::SetBackground( const wxBrush
&brush
)
641 if (m_backgroundBrush
== brush
)
643 m_backgroundBrush
= brush
;
644 if (!m_backgroundBrush
.Ok())
646 m_macBrushInstalled
= false ;
649 void wxDC::SetLogicalFunction( int function
)
651 if (m_logicalFunction
== function
)
653 m_logicalFunction
= function
;
654 m_macFontInstalled
= false ;
655 m_macBrushInstalled
= false ;
656 m_macPenInstalled
= false ;
659 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
660 const wxColour
& col
, int style
);
662 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
663 const wxColour
& col
, int style
)
665 return wxDoFloodFill(this, x
, y
, col
, style
);
668 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
670 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
671 wxMacPortSetter
helper(this) ;
673 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
674 // Convert from Mac colour to wx
675 col
->Set( colour
.red
>> 8,
681 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
683 wxCHECK_RET(Ok(), wxT("Invalid DC"));
684 wxMacPortSetter
helper(this) ;
685 if (m_pen
.GetStyle() != wxTRANSPARENT
)
688 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
689 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
690 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
691 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
692 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
693 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
694 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
695 (m_pen
.GetWidth() <= 1))
697 // Implement LAST_NOT for MAC at least for
698 // orthogonal lines. RR.
719 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
721 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
722 wxMacPortSetter
helper(this) ;
723 if (m_pen
.GetStyle() != wxTRANSPARENT
)
728 wxCoord xx
= XLOG2DEVMAC(x
);
729 wxCoord yy
= YLOG2DEVMAC(y
);
731 ::MoveTo( XLOG2DEVMAC(0), yy
);
732 ::LineTo( XLOG2DEVMAC(w
), yy
);
733 ::MoveTo( xx
, YLOG2DEVMAC(0) );
734 ::LineTo( xx
, YLOG2DEVMAC(h
) );
735 CalcBoundingBox(x
, y
);
736 CalcBoundingBox(x
+w
, y
+h
);
741 * To draw arcs properly the angles need to be converted from the WX style:
742 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
743 * a normal axis on paper).
746 * Angles start on the +ve y axis and go clockwise.
749 static double wxConvertWXangleToMACangle(double angle
)
751 double newAngle
= 90 - angle
;
757 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
758 wxCoord x2
, wxCoord y2
,
759 wxCoord xc
, wxCoord yc
)
761 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
762 wxMacPortSetter
helper(this) ;
763 wxCoord xx1
= XLOG2DEVMAC(x1
);
764 wxCoord yy1
= YLOG2DEVMAC(y1
);
765 wxCoord xx2
= XLOG2DEVMAC(x2
);
766 wxCoord yy2
= YLOG2DEVMAC(y2
);
767 wxCoord xxc
= XLOG2DEVMAC(xc
);
768 wxCoord yyc
= YLOG2DEVMAC(yc
);
769 double dx
= xx1
- xxc
;
770 double dy
= yy1
- yyc
;
771 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
772 wxCoord rad
= (wxCoord
)radius
;
773 double radius1
, radius2
;
774 if (xx1
== xx2
&& yy1
== yy2
)
779 else if (radius
== 0.0)
781 radius1
= radius2
= 0.0;
785 radius1
= (xx1
- xxc
== 0) ?
786 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
787 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
788 radius2
= (xx2
- xxc
== 0) ?
789 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
790 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
792 wxCoord alpha2
= wxCoord(radius2
- radius1
);
793 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
794 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
797 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
798 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
800 PaintArc(&r
, alpha1
, alpha2
);
802 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
804 FrameArc(&r
, alpha1
, alpha2
);
808 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
809 double sa
, double ea
)
811 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
812 wxMacPortSetter
helper(this) ;
814 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
815 // we have to make sure that the filling is always counter-clockwise
818 wxCoord xx
= XLOG2DEVMAC(x
);
819 wxCoord yy
= YLOG2DEVMAC(y
);
820 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
821 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
822 // handle -ve width and/or height
823 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
824 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
825 sa
= wxConvertWXangleToMACangle(sa
);
830 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
832 PaintArc(&r
, (short)sa
, (short)angle
);
834 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
836 FrameArc(&r
, (short)sa
, (short)angle
);
840 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
842 wxCHECK_RET(Ok(), wxT("Invalid DC"));
843 wxMacPortSetter
helper(this) ;
844 if (m_pen
.GetStyle() != wxTRANSPARENT
)
846 wxCoord xx1
= XLOG2DEVMAC(x
);
847 wxCoord yy1
= YLOG2DEVMAC(y
);
848 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
849 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
850 CalcBoundingBox(x
, y
);
854 void wxDC::DoDrawLines(int n
, wxPoint points
[],
855 wxCoord xoffset
, wxCoord yoffset
)
857 wxCHECK_RET(Ok(), wxT("Invalid DC"));
858 wxMacPortSetter
helper(this) ;
859 if (m_pen
.GetStyle() == wxTRANSPARENT
)
862 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
863 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
864 wxCoord x1
, x2
, y1
, y2
;
865 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
866 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
867 ::MoveTo(x1
- offset
, y1
- offset
);
868 for (int i
= 0; i
< n
-1; i
++)
870 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
871 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
872 ::LineTo( x2
- offset
, y2
- offset
);
876 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
877 wxCoord xoffset
, wxCoord yoffset
,
880 wxCHECK_RET(Ok(), wxT("Invalid DC"));
881 wxMacPortSetter
helper(this) ;
882 wxCoord x1
, x2
, y1
, y2
;
883 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
885 PolyHandle polygon
= OpenPoly();
886 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
887 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
889 for (int i
= 1; i
< n
; i
++)
891 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
892 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
895 // close the polyline if necessary
896 if ( x1
!= x2
|| y1
!= y2
)
901 if (m_brush
.GetStyle() != wxTRANSPARENT
)
904 ::PaintPoly( polygon
);
906 if (m_pen
.GetStyle() != wxTRANSPARENT
)
909 ::FramePoly( polygon
) ;
914 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
916 wxCHECK_RET(Ok(), wxT("Invalid DC"));
917 wxMacPortSetter
helper(this) ;
918 wxCoord xx
= XLOG2DEVMAC(x
);
919 wxCoord yy
= YLOG2DEVMAC(y
);
920 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
921 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
922 // CMB: draw nothing if transformed w or h is 0
923 if (ww
== 0 || hh
== 0)
925 // CMB: handle -ve width and/or height
936 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
937 if (m_brush
.GetStyle() != wxTRANSPARENT
)
940 ::PaintRect( &rect
) ;
942 if (m_pen
.GetStyle() != wxTRANSPARENT
)
945 ::FrameRect( &rect
) ;
949 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
950 wxCoord width
, wxCoord height
,
953 wxCHECK_RET(Ok(), wxT("Invalid DC"));
954 wxMacPortSetter
helper(this) ;
956 radius
= - radius
* ((width
< height
) ? width
: height
);
957 wxCoord xx
= XLOG2DEVMAC(x
);
958 wxCoord yy
= YLOG2DEVMAC(y
);
959 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
960 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
961 // CMB: draw nothing if transformed w or h is 0
962 if (ww
== 0 || hh
== 0)
964 // CMB: handle -ve width and/or height
975 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
976 if (m_brush
.GetStyle() != wxTRANSPARENT
)
979 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
981 if (m_pen
.GetStyle() != wxTRANSPARENT
)
984 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
988 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
990 wxCHECK_RET(Ok(), wxT("Invalid DC"));
991 wxMacPortSetter
helper(this) ;
992 wxCoord xx
= XLOG2DEVMAC(x
);
993 wxCoord yy
= YLOG2DEVMAC(y
);
994 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
995 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
996 // CMB: draw nothing if transformed w or h is 0
997 if (ww
== 0 || hh
== 0)
999 // CMB: handle -ve width and/or height
1010 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1011 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1014 ::PaintOval( &rect
) ;
1016 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1019 ::FrameOval( &rect
) ;
1023 bool wxDC::CanDrawBitmap(void) const
1028 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1029 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1030 wxCoord xsrcMask
, wxCoord ysrcMask
)
1032 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1033 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1034 if ( logical_func
== wxNO_OP
)
1036 if (xsrcMask
== -1 && ysrcMask
== -1)
1038 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1040 // correct the parameter in case this dc does not have a mask at all
1041 if ( useMask
&& !source
->m_macMask
)
1043 Rect srcrect
, dstrect
;
1044 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1045 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1046 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1047 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1048 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1049 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1050 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1051 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1052 short mode
= kUnsupportedMode
;
1053 bool invertDestinationFirst
= false ;
1054 switch ( logical_func
)
1056 case wxAND
: // src AND dst
1057 mode
= srcOr
; // ok
1059 case wxAND_INVERT
: // (NOT src) AND dst
1060 mode
= notSrcOr
; // ok
1062 case wxAND_REVERSE
:// src AND (NOT dst)
1063 invertDestinationFirst
= true ;
1067 mode
= kEmulatedMode
;
1070 mode
= srcCopy
; // ok
1072 case wxEQUIV
: // (NOT src) XOR dst
1073 mode
= srcXor
; // ok
1075 case wxINVERT
: // NOT dst
1076 mode
= kEmulatedMode
; //or hilite ;
1078 case wxNAND
: // (NOT src) OR (NOT dst)
1079 invertDestinationFirst
= true ;
1082 case wxNOR
: // (NOT src) AND (NOT dst)
1083 invertDestinationFirst
= true ;
1086 case wxNO_OP
: // dst
1087 mode
= kEmulatedMode
; // this has already been handled upon entry
1089 case wxOR
: // src OR dst
1092 case wxOR_INVERT
: // (NOT src) OR dst
1095 case wxOR_REVERSE
: // src OR (NOT dst)
1096 invertDestinationFirst
= true ;
1100 mode
= kEmulatedMode
;
1102 case wxSRC_INVERT
: // (NOT src)
1103 mode
= notSrcCopy
; // ok
1105 case wxXOR
: // src XOR dst
1106 mode
= notSrcXor
; // ok
1111 if ( mode
== kUnsupportedMode
)
1113 wxFAIL_MSG("unsupported blitting mode" );
1116 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1117 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1118 if ( LockPixels(bmappixels
) )
1120 wxMacPortSetter
helper(this) ;
1121 if ( source
->GetDepth() == 1 )
1123 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1124 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1128 // the modes need this, otherwise we'll end up having really nice colors...
1129 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1130 RGBColor black
= { 0,0,0} ;
1131 RGBForeColor( &black
) ;
1132 RGBBackColor( &white
) ;
1134 if ( useMask
&& source
->m_macMask
)
1136 if ( mode
== srcCopy
)
1138 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1140 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1141 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1142 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1143 &srcrect
, &srcrect
, &dstrect
) ;
1144 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1149 RgnHandle clipRgn
= NewRgn() ;
1150 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1151 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1152 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1153 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1154 if ( mode
== kEmulatedMode
)
1157 ::PenPat(GetQDGlobalsBlack(&pat
));
1158 if ( logical_func
== wxSET
)
1160 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1161 ::RGBForeColor( &col
) ;
1162 ::PaintRgn( clipRgn
) ;
1164 else if ( logical_func
== wxCLEAR
)
1166 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1167 ::RGBForeColor( &col
) ;
1168 ::PaintRgn( clipRgn
) ;
1170 else if ( logical_func
== wxINVERT
)
1172 MacInvertRgn( clipRgn
) ;
1176 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1178 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1180 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1181 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1182 if ( PtInRgn( dstPoint
, clipRgn
) )
1186 SetPort( (GrafPtr
) sourcePort
) ;
1187 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1188 SetPort( (GrafPtr
) m_macPort
) ;
1189 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1190 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1191 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1199 if ( invertDestinationFirst
)
1201 MacInvertRgn( clipRgn
) ;
1203 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1204 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1205 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1207 DisposeRgn( clipRgn
) ;
1212 RgnHandle clipRgn
= NewRgn() ;
1213 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1214 if ( mode
== kEmulatedMode
)
1217 ::PenPat(GetQDGlobalsBlack(&pat
));
1218 if ( logical_func
== wxSET
)
1220 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1221 ::RGBForeColor( &col
) ;
1222 ::PaintRgn( clipRgn
) ;
1224 else if ( logical_func
== wxCLEAR
)
1226 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1227 ::RGBForeColor( &col
) ;
1228 ::PaintRgn( clipRgn
) ;
1230 else if ( logical_func
== wxINVERT
)
1232 MacInvertRgn( clipRgn
) ;
1236 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1238 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1240 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1241 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1245 SetPort( (GrafPtr
) sourcePort
) ;
1246 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1247 SetPort( (GrafPtr
) m_macPort
) ;
1248 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1249 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1250 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1258 if ( invertDestinationFirst
)
1260 MacInvertRgn( clipRgn
) ;
1262 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1263 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1264 &srcrect
, &dstrect
, mode
, NULL
) ;
1266 DisposeRgn( clipRgn
) ;
1268 UnlockPixels( bmappixels
) ;
1270 m_macPenInstalled
= false ;
1271 m_macBrushInstalled
= false ;
1272 m_macFontInstalled
= false ;
1276 inline Fixed
IntToFixed( int inInt
)
1278 return (((SInt32
) inInt
) << 16);
1281 inline int FixedToInt( Fixed inFixed
)
1283 return (((SInt32
) inFixed
) >> 16);
1286 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1289 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1292 DrawText(str
, x
, y
);
1295 if ( str
.Length() == 0 )
1297 wxMacPortSetter
helper(this) ;
1300 if ( wxApp::s_macDefaultEncodingIsPC
)
1302 text
= wxMacMakeMacStringFromPC( str
) ;
1308 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1311 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1312 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1313 m_macAliasWasEnabled
= true ;
1315 OSStatus status
= noErr
;
1317 status
= TECCreateConverter(&ec
, kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1318 wxASSERT_MSG( status
== noErr
, "couldn't start converter" ) ;
1319 ByteCount byteOutLen
;
1320 ByteCount byteInLen
= text
.Length() ;
1321 ByteCount byteBufferLen
= byteInLen
*2 ;
1322 char* buf
= new char[byteBufferLen
] ;
1323 status
= TECConvertText(ec
, (ConstTextPtr
)text
.c_str() , byteInLen
, &byteInLen
,
1324 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1325 wxASSERT_MSG( status
== noErr
, "couldn't convert text" ) ;
1326 status
= TECDisposeConverter(ec
);
1327 wxASSERT_MSG( status
== noErr
, "couldn't dispose converter" ) ;
1328 ATSUTextLayout atsuLayout
;
1329 UniCharCount chars
= byteOutLen
/ 2 ;
1330 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1331 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1332 wxASSERT_MSG( status
== noErr
, "couldn't create the layout of the rotated text" );
1333 int iAngle
= int( angle
);
1334 int drawX
= XLOG2DEVMAC(x
) ;
1335 int drawY
= YLOG2DEVMAC(y
) ;
1337 ATSUTextMeasurement textBefore
;
1338 ATSUTextMeasurement textAfter
;
1339 ATSUTextMeasurement ascent
;
1340 ATSUTextMeasurement descent
;
1343 if ( abs(iAngle
) > 0 )
1345 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1346 ATSUAttributeTag atsuTags
[] =
1348 kATSULineRotationTag
,
1350 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1354 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1358 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1359 atsuTags
, atsuSizes
, atsuValues
) ;
1361 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1362 &textBefore
, &textAfter
, &ascent
, &descent
);
1364 drawX
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1365 drawY
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1366 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1367 IntToFixed(drawX
) , IntToFixed(drawY
) );
1368 wxASSERT_MSG( status
== noErr
, "couldn't draw the rotated text" );
1370 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1371 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1372 wxASSERT_MSG( status
== noErr
, "couldn't measure the rotated text" );
1373 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1374 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1375 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1376 ::ATSUDisposeTextLayout(atsuLayout
);
1380 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1382 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1383 wxMacPortSetter
helper(this) ;
1384 long xx
= XLOG2DEVMAC(x
);
1385 long yy
= YLOG2DEVMAC(y
);
1387 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1388 if ( m_font
.GetNoAntiAliasing() )
1389 useDrawThemeText
= false ;
1394 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1395 SetAntiAliasedTextEnabled(true, 8);
1396 m_macAliasWasEnabled
= true ;
1399 ::GetFontInfo( &fi
) ;
1401 if ( !useDrawThemeText
)
1404 ::MoveTo( xx
, yy
);
1405 if ( m_backgroundMode
== wxTRANSPARENT
)
1407 ::TextMode( srcOr
) ;
1411 ::TextMode( srcCopy
) ;
1413 const char *text
= NULL
;
1416 if ( wxApp::s_macDefaultEncodingIsPC
)
1418 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1420 length
= macText
.Length() ;
1425 length
= strtext
.Length() ;
1433 if( text
[i
] == 13 || text
[i
] == 10)
1436 if ( useDrawThemeText
)
1438 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1439 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1440 if ( m_backgroundMode
!= wxTRANSPARENT
)
1442 Point bounds
={0,0} ;
1443 Rect background
= frame
;
1445 ::GetThemeTextDimensions( mString
,
1446 kThemeCurrentPortFont
,
1451 background
.right
= background
.left
+ bounds
.h
;
1452 background
.bottom
= background
.top
+ bounds
.v
;
1453 ::EraseRect( &background
) ;
1455 ::DrawThemeTextBox( mString
,
1456 kThemeCurrentPortFont
,
1462 CFRelease( mString
) ;
1468 ::DrawText( text
, laststop
, i
- laststop
) ;
1470 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1477 if ( useDrawThemeText
)
1479 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1480 CFStringRef mString
= CFStringCreateWithCString( NULL
, text
+ laststop
, kCFStringEncodingMacRoman
) ;
1481 if ( m_backgroundMode
!= wxTRANSPARENT
)
1483 Point bounds
={0,0} ;
1484 Rect background
= frame
;
1486 ::GetThemeTextDimensions( mString
,
1487 kThemeCurrentPortFont
,
1492 background
.right
= background
.left
+ bounds
.h
;
1493 background
.bottom
= background
.top
+ bounds
.v
;
1494 ::EraseRect( &background
) ;
1496 ::DrawThemeTextBox( mString
,
1497 kThemeCurrentPortFont
,
1503 CFRelease( mString
) ;
1508 ::DrawText( text
, laststop
, i
- laststop
) ;
1511 ::TextMode( srcOr
) ;
1514 bool wxDC::CanGetTextExtent() const
1516 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1520 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1521 wxCoord
*descent
, wxCoord
*externalLeading
,
1522 wxFont
*theFont
) const
1524 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1525 wxMacPortSetter
helper(this) ;
1526 wxFont formerFont
= m_font
;
1529 // work around the constness
1530 *((wxFont
*)(&m_font
)) = *theFont
;
1534 ::GetFontInfo( &fi
) ;
1536 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1537 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1538 useGetThemeText
= false ;
1541 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1543 *descent
=YDEV2LOGREL( fi
.descent
);
1544 if ( externalLeading
)
1545 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1546 const char *text
= NULL
;
1549 if ( wxApp::s_macDefaultEncodingIsPC
)
1551 macText
= wxMacMakeMacStringFromPC( string
) ;
1553 length
= macText
.Length() ;
1558 length
= string
.Length() ;
1568 if( text
[i
] == 13 || text
[i
] == 10)
1571 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1573 if ( useGetThemeText
)
1575 Point bounds
={0,0} ;
1577 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1578 ::GetThemeTextDimensions( mString
,
1579 kThemeCurrentPortFont
,
1584 CFRelease( mString
) ;
1585 curwidth
= bounds
.h
;
1590 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1592 if ( curwidth
> *width
)
1593 *width
= XDEV2LOGREL( curwidth
) ;
1600 if ( useGetThemeText
)
1602 Point bounds
={0,0} ;
1604 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1605 ::GetThemeTextDimensions( mString
,
1606 kThemeCurrentPortFont
,
1611 CFRelease( mString
) ;
1612 curwidth
= bounds
.h
;
1617 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1619 if ( curwidth
> *width
)
1620 *width
= XDEV2LOGREL( curwidth
) ;
1624 // work around the constness
1625 *((wxFont
*)(&m_font
)) = formerFont
;
1626 m_macFontInstalled
= false ;
1630 wxCoord
wxDC::GetCharWidth(void) const
1632 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1633 wxMacPortSetter
helper(this) ;
1637 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1638 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1639 useGetThemeText
= false ;
1643 if ( useGetThemeText
)
1645 Point bounds
={0,0} ;
1647 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1648 ::GetThemeTextDimensions( mString
,
1649 kThemeCurrentPortFont
,
1654 CFRelease( mString
) ;
1660 width
= ::TextWidth( text
, 0 , 1 ) ;
1662 return YDEV2LOGREL(width
) ;
1665 wxCoord
wxDC::GetCharHeight(void) const
1667 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1668 wxMacPortSetter
helper(this) ;
1671 ::GetFontInfo( &fi
) ;
1672 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1675 void wxDC::Clear(void)
1677 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1678 wxMacPortSetter
helper(this) ;
1679 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1680 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1683 //MacInstallBrush() ;
1684 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1685 ::EraseRect( &rect
) ;
1689 void wxDC::MacInstallFont() const
1691 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1692 // if ( m_macFontInstalled )
1694 Pattern blackColor
;
1695 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1696 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1699 ::TextFont( font
->m_macFontNum
) ;
1700 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1701 ::TextFace( font
->m_macFontStyle
) ;
1702 m_macFontInstalled
= true ;
1703 m_macBrushInstalled
= false ;
1704 m_macPenInstalled
= false ;
1705 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1706 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1707 ::RGBForeColor( &forecolor
);
1708 ::RGBBackColor( &backcolor
);
1712 FontFamilyID fontId
;
1716 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1717 GetFNum( fontName
, &fontId
);
1718 ::TextFont( fontId
) ;
1719 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1720 ::TextFace( fontStyle
) ;
1721 // todo reset after spacing changes - or store the current spacing somewhere
1722 m_macFontInstalled
= true ;
1723 m_macBrushInstalled
= false ;
1724 m_macPenInstalled
= false ;
1725 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1726 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1727 ::RGBForeColor( &forecolor
);
1728 ::RGBBackColor( &backcolor
);
1730 short mode
= patCopy
;
1732 switch( m_logicalFunction
)
1737 case wxINVERT
: // NOT dst
1738 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1741 case wxXOR
: // src XOR dst
1744 case wxOR_REVERSE
: // src OR (NOT dst)
1747 case wxSRC_INVERT
: // (NOT src)
1752 case wxAND_REVERSE
:// src AND (NOT dst)
1753 case wxAND
: // src AND dst
1754 case wxAND_INVERT
: // (NOT src) AND dst
1755 case wxNO_OP
: // dst
1756 case wxNOR
: // (NOT src) AND (NOT dst)
1757 case wxEQUIV
: // (NOT src) XOR dst
1758 case wxOR_INVERT
: // (NOT src) OR dst
1759 case wxNAND
: // (NOT src) OR (NOT dst)
1760 case wxOR
: // src OR dst
1762 // case wxSRC_OR: // source _bitmap_ OR destination
1763 // case wxSRC_AND: // source _bitmap_ AND destination
1767 OSStatus status
= noErr
;
1768 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1769 Style qdStyle
= font
->m_macFontStyle
;
1770 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1771 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1772 wxASSERT_MSG( status
== noErr
, "couldn't create ATSU style" ) ;
1773 ATSUAttributeTag atsuTags
[] =
1778 // kATSUBaselineClassTag ,
1779 kATSUVerticalCharacterTag
,
1780 kATSUQDBoldfaceTag
,
1782 kATSUQDUnderlineTag
,
1783 kATSUQDCondensedTag
,
1784 kATSUQDExtendedTag
,
1786 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1788 sizeof( ATSUFontID
) ,
1790 // sizeof( RGBColor ) ,
1791 // sizeof( BslnBaselineClass ) ,
1792 sizeof( ATSUVerticalCharacterType
),
1799 Boolean kTrue
= true ;
1800 Boolean kFalse
= false ;
1801 BslnBaselineClass kBaselineDefault
= kBSLNHangingBaseline
;
1802 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1803 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1807 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1808 // &kBaselineDefault ,
1810 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1811 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1812 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1813 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1814 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1816 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1817 atsuTags
, atsuSizes
, atsuValues
);
1818 wxASSERT_MSG( status
== noErr
, "couldn't set create ATSU style" ) ;
1821 Pattern gHatchPatterns
[] =
1823 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1824 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1825 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1826 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1827 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1828 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1829 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1832 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1837 case wxBDIAGONAL_HATCH
:
1840 case wxFDIAGONAL_HATCH
:
1846 case wxHORIZONTAL_HATCH
:
1849 case wxVERTICAL_HATCH
:
1852 case wxCROSSDIAG_HATCH
:
1856 theIndex
= 1; // solid pattern
1859 *pattern
= gHatchPatterns
[theIndex
-1] ;
1862 void wxDC::MacInstallPen() const
1864 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1866 // if ( m_macPenInstalled )
1868 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1869 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1870 ::RGBForeColor( &forecolor
);
1871 ::RGBBackColor( &backcolor
);
1873 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1874 // null means only one pixel, at whatever resolution
1875 if ( penWidth
== 0 )
1877 ::PenSize(penWidth
, penWidth
);
1878 int penStyle
= m_pen
.GetStyle();
1879 if (penStyle
== wxSOLID
)
1881 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1883 else if (IS_HATCH(penStyle
))
1886 wxMacGetHatchPattern(penStyle
, &pat
);
1891 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1895 for ( int i
= 0 ; i
< 8 ; ++i
)
1901 for ( int i
= 0 ; i
< 8 ; ++i
)
1907 for ( int i
= 0 ; i
< 8 ; ++i
)
1913 for ( int i
= 0 ; i
< 8 ; ++i
)
1921 m_pen
.GetDashes(&dash
) ;
1922 // right now we don't allocate larger pixmaps
1924 m_pen
.GetDashes(&dash
) ;
1925 for ( int i
= 0 ; i
< 8 ; ++i
)
1927 pat
.pat
[i
] = dash
[0] ;
1934 short mode
= patCopy
;
1936 switch( m_logicalFunction
)
1938 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1941 case wxINVERT
: // NOT dst
1942 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1945 case wxXOR
: // src XOR dst
1948 case wxOR_REVERSE
: // src OR (NOT dst)
1951 case wxSRC_INVERT
: // (NOT src)
1956 case wxAND_REVERSE
:// src AND (NOT dst)
1957 case wxAND
: // src AND dst
1958 case wxAND_INVERT
: // (NOT src) AND dst
1959 case wxNO_OP
: // dst
1960 case wxNOR
: // (NOT src) AND (NOT dst)
1961 case wxEQUIV
: // (NOT src) XOR dst
1962 case wxOR_INVERT
: // (NOT src) OR dst
1963 case wxNAND
: // (NOT src) OR (NOT dst)
1964 case wxOR
: // src OR dst
1966 // case wxSRC_OR: // source _bitmap_ OR destination
1967 // case wxSRC_AND: // source _bitmap_ AND destination
1971 m_macPenInstalled
= true ;
1972 m_macBrushInstalled
= false ;
1973 m_macFontInstalled
= false ;
1976 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1978 Pattern whiteColor
;
1979 switch( background
.MacGetBrushKind() )
1981 case kwxMacBrushTheme
:
1983 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1986 case kwxMacBrushThemeBackground
:
1989 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1990 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1993 case kwxMacBrushColour
:
1995 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1996 int brushStyle
= background
.GetStyle();
1997 if (brushStyle
== wxSOLID
)
1998 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1999 else if (IS_HATCH(brushStyle
))
2002 wxMacGetHatchPattern(brushStyle
, &pat
);
2007 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2014 void wxDC::MacInstallBrush() const
2016 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2017 Pattern blackColor
;
2018 // if ( m_macBrushInstalled )
2021 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2022 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2023 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2024 int brushStyle
= m_brush
.GetStyle();
2025 if (brushStyle
== wxSOLID
)
2027 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2029 else if (IS_HATCH(brushStyle
))
2032 wxMacGetHatchPattern(brushStyle
, &pat
);
2035 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2037 // we force this in order to be compliant with wxMSW
2038 backgroundTransparent
= false ;
2039 // for these the text fore (and back for MASK_OPAQUE) colors are used
2040 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2041 int width
= bitmap
->GetWidth() ;
2042 int height
= bitmap
->GetHeight() ;
2043 GWorldPtr gw
= NULL
;
2044 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2045 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2047 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2048 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2049 LockPixels( gwpixmaphandle
) ;
2050 bool isMonochrome
= !IsPortColor( gw
) ;
2051 if ( !isMonochrome
)
2053 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2054 isMonochrome
= true ;
2056 if ( isMonochrome
&& width
== 8 && height
== 8 )
2058 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2059 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2060 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2061 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2062 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2064 for ( int i
= 0 ; i
< 8 ; ++i
)
2066 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2068 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2073 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2074 // caching scheme before putting this into production
2077 PixPatHandle pixpat
= NewPixPat() ;
2078 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2079 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2080 ((**(**pixpat
).patMap
).bounds
.bottom
-
2081 (**(**pixpat
).patMap
).bounds
.top
);
2082 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2083 (**pixpat
).patData
= image
;
2086 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2087 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2088 if ( ctspec
[0].rgb
.red
== 0x0000 )
2090 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2091 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2095 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2096 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2098 ::CTabChanged( ctable
) ;
2100 ::PenPixPat(pixpat
);
2101 m_macForegroundPixMap
= pixpat
;
2103 UnlockPixels( gwpixmaphandle
) ;
2107 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2109 short mode
= patCopy
;
2110 switch( m_logicalFunction
)
2113 if ( backgroundTransparent
)
2118 case wxINVERT
: // NOT dst
2119 if ( !backgroundTransparent
)
2121 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2125 case wxXOR
: // src XOR dst
2128 case wxOR_REVERSE
: // src OR (NOT dst)
2131 case wxSRC_INVERT
: // (NOT src)
2136 case wxAND_REVERSE
:// src AND (NOT dst)
2137 case wxAND
: // src AND dst
2138 case wxAND_INVERT
: // (NOT src) AND dst
2139 case wxNO_OP
: // dst
2140 case wxNOR
: // (NOT src) AND (NOT dst)
2141 case wxEQUIV
: // (NOT src) XOR dst
2142 case wxOR_INVERT
: // (NOT src) OR dst
2143 case wxNAND
: // (NOT src) OR (NOT dst)
2144 case wxOR
: // src OR dst
2146 // case wxSRC_OR: // source _bitmap_ OR destination
2147 // case wxSRC_AND: // source _bitmap_ AND destination
2151 m_macBrushInstalled
= true ;
2152 m_macPenInstalled
= false ;
2153 m_macFontInstalled
= false ;
2156 // ---------------------------------------------------------------------------
2157 // coordinates transformations
2158 // ---------------------------------------------------------------------------
2160 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2162 return ((wxDC
*)this)->XDEV2LOG(x
);
2165 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2167 return ((wxDC
*)this)->YDEV2LOG(y
);
2170 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2172 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2175 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2177 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2180 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2182 return ((wxDC
*)this)->XLOG2DEV(x
);
2185 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2187 return ((wxDC
*)this)->YLOG2DEV(y
);
2190 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2192 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2195 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2197 return ((wxDC
*)this)->YLOG2DEVREL(y
);