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"
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 #define mm2inches 0.0393700787402
43 #define inches2mm 25.4
44 #define mm2twips 56.6929133859
45 #define twips2mm 0.0176388888889
46 #define mm2pt 2.83464566929
47 #define pt2mm 0.352777777778
48 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
49 const double M_PI
= 3.14159265358979 ;
51 const double RAD2DEG
= 180.0 / M_PI
;
52 const short kEmulatedMode
= -1 ;
53 const short kUnsupportedMode
= -2 ;
55 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
56 m_ph( (GrafPtr
) dc
->m_macPort
)
58 wxASSERT( dc
->Ok() ) ;
60 dc
->MacSetupPort(&m_ph
) ;
63 wxMacPortSetter::~wxMacPortSetter()
65 m_dc
->MacCleanupPort(&m_ph
) ;
68 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
70 m_formerClip
= NewRgn() ;
71 m_newClip
= NewRgn() ;
72 GetClip( m_formerClip
) ;
77 // this clipping area was set to the parent window's drawing area, lead to problems
78 // with MacOSX controls drawing outside their wx' rectangle
79 RgnHandle insidergn
= NewRgn() ;
81 wxWindow
*parent
= win
->GetParent() ;
82 parent
->MacWindowToRootWindow( &x
,&y
) ;
83 wxSize size
= parent
->GetSize() ;
84 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
85 size
.x
- parent
->MacGetRightBorderSize(),
86 size
.y
- parent
->MacGetBottomBorderSize()) ;
87 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
88 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
89 OffsetRgn( m_newClip
, x
, y
) ;
90 SetClip( m_newClip
) ;
91 DisposeRgn( insidergn
) ;
94 win
->MacWindowToRootWindow( &x
,&y
) ;
95 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
96 OffsetRgn( m_newClip
, x
, y
) ;
97 SetClip( m_newClip
) ;
102 wxMacWindowClipper::~wxMacWindowClipper()
104 SetClip( m_formerClip
) ;
105 DisposeRgn( m_newClip
) ;
106 DisposeRgn( m_formerClip
) ;
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
112 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
113 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
114 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
116 //-----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
119 // this function emulates all wx colour manipulations, used to verify the implementation
120 // by setting the mode in the blitting functions to kEmulatedMode
121 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
123 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
125 switch ( logical_func
)
127 case wxAND
: // src AND dst
128 dstColor
.red
= dstColor
.red
& srcColor
.red
;
129 dstColor
.green
= dstColor
.green
& srcColor
.green
;
130 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
132 case wxAND_INVERT
: // (NOT src) AND dst
133 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
134 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
135 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
137 case wxAND_REVERSE
:// src AND (NOT dst)
138 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
139 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
140 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
148 dstColor
.red
= srcColor
.red
;
149 dstColor
.green
= srcColor
.green
;
150 dstColor
.blue
= srcColor
.blue
;
152 case wxEQUIV
: // (NOT src) XOR dst
153 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
154 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
155 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
157 case wxINVERT
: // NOT dst
158 dstColor
.red
= ~dstColor
.red
;
159 dstColor
.green
= ~dstColor
.green
;
160 dstColor
.blue
= ~dstColor
.blue
;
162 case wxNAND
: // (NOT src) OR (NOT dst)
163 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
164 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
165 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
167 case wxNOR
: // (NOT src) AND (NOT dst)
168 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
169 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
170 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
174 case wxOR
: // src OR dst
175 dstColor
.red
= dstColor
.red
| srcColor
.red
;
176 dstColor
.green
= dstColor
.green
| srcColor
.green
;
177 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
179 case wxOR_INVERT
: // (NOT src) OR dst
180 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
181 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
182 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
184 case wxOR_REVERSE
: // src OR (NOT dst)
185 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
186 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
187 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
190 dstColor
.red
= 0xFFFF ;
191 dstColor
.green
= 0xFFFF ;
192 dstColor
.blue
= 0xFFFF ;
194 case wxSRC_INVERT
: // (NOT src)
195 dstColor
.red
= ~srcColor
.red
;
196 dstColor
.green
= ~srcColor
.green
;
197 dstColor
.blue
= ~srcColor
.blue
;
199 case wxXOR
: // src XOR dst
200 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
201 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
202 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
211 m_mm_to_pix_x
= mm2pt
;
212 m_mm_to_pix_y
= mm2pt
;
213 m_internalDeviceOriginX
= 0;
214 m_internalDeviceOriginY
= 0;
215 m_externalDeviceOriginX
= 0;
216 m_externalDeviceOriginY
= 0;
217 m_logicalScaleX
= 1.0;
218 m_logicalScaleY
= 1.0;
223 m_needComputeScaleX
= FALSE
;
224 m_needComputeScaleY
= FALSE
;
228 m_macFontInstalled
= false ;
229 m_macBrushInstalled
= false ;
230 m_macPenInstalled
= false ;
231 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
232 m_macBoundaryClipRgn
= NewRgn() ;
233 m_macCurrentClipRgn
= NewRgn() ;
234 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
235 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
236 m_pen
= *wxBLACK_PEN
;
237 m_font
= *wxNORMAL_FONT
;
238 m_brush
= *wxWHITE_BRUSH
;
239 m_macCurrentPortStateHelper
= NULL
;
240 m_macATSUIStyle
= NULL
;
241 m_macAliasWasEnabled
= false;
242 m_macForegroundPixMap
= NULL
;
243 m_macBackgroundPixMap
= NULL
;
248 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
249 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
252 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
254 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
255 m_macCurrentPortStateHelper
= help
;
256 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
257 m_macFontInstalled
= false ;
258 m_macBrushInstalled
= false ;
259 m_macPenInstalled
= false ;
262 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
264 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
265 m_macCurrentPortStateHelper
= NULL
;
266 if( m_macATSUIStyle
)
268 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
269 m_macATSUIStyle
= NULL
;
271 if ( m_macAliasWasEnabled
)
273 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
274 m_macAliasWasEnabled
= false ;
276 if ( m_macForegroundPixMap
)
279 ::PenPat(GetQDGlobalsBlack(&blackColor
));
280 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
281 m_macForegroundPixMap
= NULL
;
283 if ( m_macBackgroundPixMap
)
286 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
287 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
288 m_macBackgroundPixMap
= NULL
;
292 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
294 wxCHECK_RET( Ok(), wxT("invalid window dc") );
295 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
296 wxMacPortSetter
helper(this) ;
297 wxCoord xx
= XLOG2DEVMAC(x
);
298 wxCoord yy
= YLOG2DEVMAC(y
);
299 wxCoord w
= bmp
.GetWidth();
300 wxCoord h
= bmp
.GetHeight();
301 wxCoord ww
= XLOG2DEVREL(w
);
302 wxCoord hh
= YLOG2DEVREL(h
);
303 // Set up drawing mode
304 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
305 //m_logicalFunction == wxCLEAR ? WHITENESS :
306 //m_logicalFunction == wxSET ? BLACKNESS :
307 m_logicalFunction
== wxINVERT
? hilite
:
308 //m_logicalFunction == wxAND ? MERGECOPY :
309 m_logicalFunction
== wxOR
? srcOr
:
310 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
311 m_logicalFunction
== wxXOR
? srcXor
:
312 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
313 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
314 //m_logicalFunction == wxSRC_OR ? srcOr :
315 //m_logicalFunction == wxSRC_AND ? SRCAND :
317 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
318 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
319 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
320 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
322 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
324 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
325 PixMapHandle bmappixels
;
326 // Set foreground and background colours (for bitmaps depth = 1)
327 if(bmp
.GetDepth() == 1)
329 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
330 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
336 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
337 RGBColor black
= { 0,0,0} ;
338 RGBForeColor( &black
) ;
339 RGBBackColor( &white
) ;
341 bmappixels
= GetGWorldPixMap( bmapworld
) ;
342 wxCHECK_RET(LockPixels(bmappixels
),
343 wxT("DoDrawBitmap: Unable to lock pixels"));
344 Rect source
= { 0, 0, h
, w
};
345 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
346 if ( useMask
&& bmp
.GetMask() )
348 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
352 GetPortBitMapForCopyBits(bmapworld
),
353 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
354 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
355 &source
, &source
, &dest
, mode
, NULL
357 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
361 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
362 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
363 &source
, &dest
, mode
, NULL
) ;
365 UnlockPixels( bmappixels
) ;
367 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
369 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
370 OffsetRect( &bitmaprect
, xx
, yy
) ;
371 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
373 m_macPenInstalled
= false ;
374 m_macBrushInstalled
= false ;
375 m_macFontInstalled
= false ;
378 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
380 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
381 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
382 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
385 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
387 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
388 wxCoord xx
, yy
, ww
, hh
;
391 ww
= XLOG2DEVREL(width
);
392 hh
= YLOG2DEVREL(height
);
393 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
394 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
397 m_clipX1
= wxMax( m_clipX1
, xx
);
398 m_clipY1
= wxMax( m_clipY1
, yy
);
399 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
400 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
412 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
414 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
415 wxMacPortSetter
helper(this) ;
418 DestroyClippingRegion();
422 region
.GetBox( x
, y
, w
, h
);
423 wxCoord xx
, yy
, ww
, hh
;
428 // if we have a scaling that we cannot map onto native regions
429 // we must use the box
430 if ( ww
!= w
|| hh
!= h
)
432 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
436 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
437 if ( xx
!= x
|| yy
!= y
)
439 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
441 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
444 m_clipX1
= wxMax( m_clipX1
, xx
);
445 m_clipY1
= wxMax( m_clipY1
, yy
);
446 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
447 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
460 void wxDC::DestroyClippingRegion()
462 wxMacPortSetter
helper(this) ;
463 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
467 void wxDC::DoGetSize( int* width
, int* height
) const
469 *width
= m_maxX
-m_minX
;
470 *height
= m_maxY
-m_minY
;
473 void wxDC::DoGetSizeMM( int* width
, int* height
) const
478 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
479 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
482 void wxDC::SetTextForeground( const wxColour
&col
)
484 wxCHECK_RET(Ok(), wxT("Invalid DC"));
485 m_textForegroundColour
= col
;
486 m_macFontInstalled
= false ;
489 void wxDC::SetTextBackground( const wxColour
&col
)
491 wxCHECK_RET(Ok(), wxT("Invalid DC"));
492 m_textBackgroundColour
= col
;
493 m_macFontInstalled
= false ;
496 void wxDC::SetMapMode( int mode
)
501 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
504 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
507 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
510 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
514 SetLogicalScale( 1.0, 1.0 );
517 if (mode
!= wxMM_TEXT
)
519 m_needComputeScaleX
= TRUE
;
520 m_needComputeScaleY
= TRUE
;
524 void wxDC::SetUserScale( double x
, double y
)
526 // allow negative ? -> no
529 ComputeScaleAndOrigin();
532 void wxDC::SetLogicalScale( double x
, double y
)
537 ComputeScaleAndOrigin();
540 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
542 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
543 m_logicalOriginY
= y
* m_signY
;
544 ComputeScaleAndOrigin();
547 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
549 m_externalDeviceOriginX
= x
;
550 m_externalDeviceOriginY
= y
;
551 ComputeScaleAndOrigin();
555 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
557 m_internalDeviceOriginX
= x
;
558 m_internalDeviceOriginY
= y
;
559 ComputeScaleAndOrigin();
561 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
563 if (x
) *x
= m_internalDeviceOriginX
;
564 if (y
) *y
= m_internalDeviceOriginY
;
568 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
570 m_signX
= (xLeftRight
? 1 : -1);
571 m_signY
= (yBottomUp
? -1 : 1);
572 ComputeScaleAndOrigin();
575 wxSize
wxDC::GetPPI() const
577 return wxSize(72, 72);
580 int wxDC::GetDepth() const
582 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
584 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
589 void wxDC::ComputeScaleAndOrigin()
591 // CMB: copy scale to see if it changes
592 double origScaleX
= m_scaleX
;
593 double origScaleY
= m_scaleY
;
594 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
595 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
596 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
597 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
598 // CMB: if scale has changed call SetPen to recalulate the line width
599 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
601 // this is a bit artificial, but we need to force wxDC to think
602 // the pen has changed
603 wxPen
* pen
= & GetPen();
610 void wxDC::SetPalette( const wxPalette
& palette
)
614 void wxDC::SetBackgroundMode( int mode
)
616 m_backgroundMode
= mode
;
619 void wxDC::SetFont( const wxFont
&font
)
622 m_macFontInstalled
= false ;
625 void wxDC::SetPen( const wxPen
&pen
)
630 m_macPenInstalled
= false ;
633 void wxDC::SetBrush( const wxBrush
&brush
)
635 if (m_brush
== brush
)
638 m_macBrushInstalled
= false ;
641 void wxDC::SetBackground( const wxBrush
&brush
)
643 if (m_backgroundBrush
== brush
)
645 m_backgroundBrush
= brush
;
646 if (!m_backgroundBrush
.Ok())
648 m_macBrushInstalled
= false ;
651 void wxDC::SetLogicalFunction( int function
)
653 if (m_logicalFunction
== function
)
655 m_logicalFunction
= function
;
656 m_macFontInstalled
= false ;
657 m_macBrushInstalled
= false ;
658 m_macPenInstalled
= false ;
661 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
662 const wxColour
& col
, int style
);
664 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
665 const wxColour
& col
, int style
)
667 return wxDoFloodFill(this, x
, y
, col
, style
);
670 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
672 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
673 wxMacPortSetter
helper(this) ;
675 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
676 // Convert from Mac colour to wx
677 col
->Set( colour
.red
>> 8,
683 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
685 wxCHECK_RET(Ok(), wxT("Invalid DC"));
686 wxMacPortSetter
helper(this) ;
687 if (m_pen
.GetStyle() != wxTRANSPARENT
)
690 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
691 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
692 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
693 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
694 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
695 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
696 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
697 (m_pen
.GetWidth() <= 1))
699 // Implement LAST_NOT for MAC at least for
700 // orthogonal lines. RR.
721 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
723 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
724 wxMacPortSetter
helper(this) ;
725 if (m_pen
.GetStyle() != wxTRANSPARENT
)
730 wxCoord xx
= XLOG2DEVMAC(x
);
731 wxCoord yy
= YLOG2DEVMAC(y
);
733 ::MoveTo( XLOG2DEVMAC(0), yy
);
734 ::LineTo( XLOG2DEVMAC(w
), yy
);
735 ::MoveTo( xx
, YLOG2DEVMAC(0) );
736 ::LineTo( xx
, YLOG2DEVMAC(h
) );
737 CalcBoundingBox(x
, y
);
738 CalcBoundingBox(x
+w
, y
+h
);
743 * To draw arcs properly the angles need to be converted from the WX style:
744 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
745 * a normal axis on paper).
748 * Angles start on the +ve y axis and go clockwise.
751 static double wxConvertWXangleToMACangle(double angle
)
753 double newAngle
= 90 - angle
;
759 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
760 wxCoord x2
, wxCoord y2
,
761 wxCoord xc
, wxCoord yc
)
763 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
764 wxMacPortSetter
helper(this) ;
765 wxCoord xx1
= XLOG2DEVMAC(x1
);
766 wxCoord yy1
= YLOG2DEVMAC(y1
);
767 wxCoord xx2
= XLOG2DEVMAC(x2
);
768 wxCoord yy2
= YLOG2DEVMAC(y2
);
769 wxCoord xxc
= XLOG2DEVMAC(xc
);
770 wxCoord yyc
= YLOG2DEVMAC(yc
);
771 double dx
= xx1
- xxc
;
772 double dy
= yy1
- yyc
;
773 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
774 wxCoord rad
= (wxCoord
)radius
;
775 double radius1
, radius2
;
776 if (xx1
== xx2
&& yy1
== yy2
)
781 else if (radius
== 0.0)
783 radius1
= radius2
= 0.0;
787 radius1
= (xx1
- xxc
== 0) ?
788 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
789 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
790 radius2
= (xx2
- xxc
== 0) ?
791 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
792 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
794 wxCoord alpha2
= wxCoord(radius2
- radius1
);
795 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
796 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
799 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
800 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
802 PaintArc(&r
, alpha1
, alpha2
);
804 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
806 FrameArc(&r
, alpha1
, alpha2
);
810 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
811 double sa
, double ea
)
813 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
814 wxMacPortSetter
helper(this) ;
816 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
817 // we have to make sure that the filling is always counter-clockwise
820 wxCoord xx
= XLOG2DEVMAC(x
);
821 wxCoord yy
= YLOG2DEVMAC(y
);
822 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
823 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
824 // handle -ve width and/or height
825 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
826 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
827 sa
= wxConvertWXangleToMACangle(sa
);
832 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
834 PaintArc(&r
, (short)sa
, (short)angle
);
836 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
838 FrameArc(&r
, (short)sa
, (short)angle
);
842 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
844 wxCHECK_RET(Ok(), wxT("Invalid DC"));
845 wxMacPortSetter
helper(this) ;
846 if (m_pen
.GetStyle() != wxTRANSPARENT
)
848 wxCoord xx1
= XLOG2DEVMAC(x
);
849 wxCoord yy1
= YLOG2DEVMAC(y
);
850 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
851 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
852 CalcBoundingBox(x
, y
);
856 void wxDC::DoDrawLines(int n
, wxPoint points
[],
857 wxCoord xoffset
, wxCoord yoffset
)
859 wxCHECK_RET(Ok(), wxT("Invalid DC"));
860 wxMacPortSetter
helper(this) ;
861 if (m_pen
.GetStyle() == wxTRANSPARENT
)
864 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
865 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
866 wxCoord x1
, x2
, y1
, y2
;
867 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
868 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
869 ::MoveTo(x1
- offset
, y1
- offset
);
870 for (int i
= 0; i
< n
-1; i
++)
872 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
873 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
874 ::LineTo( x2
- offset
, y2
- offset
);
878 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
879 wxCoord xoffset
, wxCoord yoffset
,
882 wxCHECK_RET(Ok(), wxT("Invalid DC"));
883 wxMacPortSetter
helper(this) ;
884 wxCoord x1
, x2
, y1
, y2
;
885 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
887 PolyHandle polygon
= OpenPoly();
888 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
889 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
891 for (int i
= 1; i
< n
; i
++)
893 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
894 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
897 // close the polyline if necessary
898 if ( x1
!= x2
|| y1
!= y2
)
903 if (m_brush
.GetStyle() != wxTRANSPARENT
)
906 ::PaintPoly( polygon
);
908 if (m_pen
.GetStyle() != wxTRANSPARENT
)
911 ::FramePoly( polygon
) ;
916 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
918 wxCHECK_RET(Ok(), wxT("Invalid DC"));
919 wxMacPortSetter
helper(this) ;
920 wxCoord xx
= XLOG2DEVMAC(x
);
921 wxCoord yy
= YLOG2DEVMAC(y
);
922 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
923 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
924 // CMB: draw nothing if transformed w or h is 0
925 if (ww
== 0 || hh
== 0)
927 // CMB: handle -ve width and/or height
938 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
939 if (m_brush
.GetStyle() != wxTRANSPARENT
)
942 ::PaintRect( &rect
) ;
944 if (m_pen
.GetStyle() != wxTRANSPARENT
)
947 ::FrameRect( &rect
) ;
951 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
952 wxCoord width
, wxCoord height
,
955 wxCHECK_RET(Ok(), wxT("Invalid DC"));
956 wxMacPortSetter
helper(this) ;
958 radius
= - radius
* ((width
< height
) ? width
: height
);
959 wxCoord xx
= XLOG2DEVMAC(x
);
960 wxCoord yy
= YLOG2DEVMAC(y
);
961 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
962 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
963 // CMB: draw nothing if transformed w or h is 0
964 if (ww
== 0 || hh
== 0)
966 // CMB: handle -ve width and/or height
977 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
978 if (m_brush
.GetStyle() != wxTRANSPARENT
)
981 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
983 if (m_pen
.GetStyle() != wxTRANSPARENT
)
986 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
990 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
992 wxCHECK_RET(Ok(), wxT("Invalid DC"));
993 wxMacPortSetter
helper(this) ;
994 wxCoord xx
= XLOG2DEVMAC(x
);
995 wxCoord yy
= YLOG2DEVMAC(y
);
996 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
997 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
998 // CMB: draw nothing if transformed w or h is 0
999 if (ww
== 0 || hh
== 0)
1001 // CMB: handle -ve width and/or height
1012 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1013 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1016 ::PaintOval( &rect
) ;
1018 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1021 ::FrameOval( &rect
) ;
1025 bool wxDC::CanDrawBitmap(void) const
1030 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1031 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1032 wxCoord xsrcMask
, wxCoord ysrcMask
)
1034 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1035 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1036 if ( logical_func
== wxNO_OP
)
1038 if (xsrcMask
== -1 && ysrcMask
== -1)
1040 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1042 // correct the parameter in case this dc does not have a mask at all
1043 if ( useMask
&& !source
->m_macMask
)
1045 Rect srcrect
, dstrect
;
1046 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1047 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1048 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1049 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1050 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1051 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1052 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1053 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1054 short mode
= kUnsupportedMode
;
1055 bool invertDestinationFirst
= false ;
1056 switch ( logical_func
)
1058 case wxAND
: // src AND dst
1059 mode
= adMin
; // ok
1061 case wxAND_INVERT
: // (NOT src) AND dst
1062 mode
= notSrcOr
; // ok
1064 case wxAND_REVERSE
:// src AND (NOT dst)
1065 invertDestinationFirst
= true ;
1069 mode
= kEmulatedMode
;
1072 mode
= srcCopy
; // ok
1074 case wxEQUIV
: // (NOT src) XOR dst
1075 mode
= srcXor
; // ok
1077 case wxINVERT
: // NOT dst
1078 mode
= kEmulatedMode
; //or hilite ;
1080 case wxNAND
: // (NOT src) OR (NOT dst)
1081 invertDestinationFirst
= true ;
1084 case wxNOR
: // (NOT src) AND (NOT dst)
1085 invertDestinationFirst
= true ;
1088 case wxNO_OP
: // dst
1089 mode
= kEmulatedMode
; // this has already been handled upon entry
1091 case wxOR
: // src OR dst
1094 case wxOR_INVERT
: // (NOT src) OR dst
1097 case wxOR_REVERSE
: // src OR (NOT dst)
1098 invertDestinationFirst
= true ;
1102 mode
= kEmulatedMode
;
1104 case wxSRC_INVERT
: // (NOT src)
1105 mode
= notSrcCopy
; // ok
1107 case wxXOR
: // src XOR dst
1108 mode
= notSrcXor
; // ok
1113 if ( mode
== kUnsupportedMode
)
1115 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1118 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1119 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1120 if ( LockPixels(bmappixels
) )
1122 wxMacPortSetter
helper(this) ;
1123 if ( source
->GetDepth() == 1 )
1125 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1126 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1130 // the modes need this, otherwise we'll end up having really nice colors...
1131 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1132 RGBColor black
= { 0,0,0} ;
1133 RGBForeColor( &black
) ;
1134 RGBBackColor( &white
) ;
1136 if ( useMask
&& source
->m_macMask
)
1138 if ( mode
== srcCopy
)
1140 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1142 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1143 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1144 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1145 &srcrect
, &srcrect
, &dstrect
) ;
1146 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1151 RgnHandle clipRgn
= NewRgn() ;
1152 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1153 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1154 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1155 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1156 if ( mode
== kEmulatedMode
)
1159 ::PenPat(GetQDGlobalsBlack(&pat
));
1160 if ( logical_func
== wxSET
)
1162 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1163 ::RGBForeColor( &col
) ;
1164 ::PaintRgn( clipRgn
) ;
1166 else if ( logical_func
== wxCLEAR
)
1168 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1169 ::RGBForeColor( &col
) ;
1170 ::PaintRgn( clipRgn
) ;
1172 else if ( logical_func
== wxINVERT
)
1174 MacInvertRgn( clipRgn
) ;
1178 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1180 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1182 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1183 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1184 if ( PtInRgn( dstPoint
, clipRgn
) )
1188 SetPort( (GrafPtr
) sourcePort
) ;
1189 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1190 SetPort( (GrafPtr
) m_macPort
) ;
1191 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1192 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1193 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1201 if ( invertDestinationFirst
)
1203 MacInvertRgn( clipRgn
) ;
1205 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1206 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1207 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1209 DisposeRgn( clipRgn
) ;
1214 RgnHandle clipRgn
= NewRgn() ;
1215 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1216 if ( mode
== kEmulatedMode
)
1219 ::PenPat(GetQDGlobalsBlack(&pat
));
1220 if ( logical_func
== wxSET
)
1222 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1223 ::RGBForeColor( &col
) ;
1224 ::PaintRgn( clipRgn
) ;
1226 else if ( logical_func
== wxCLEAR
)
1228 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1229 ::RGBForeColor( &col
) ;
1230 ::PaintRgn( clipRgn
) ;
1232 else if ( logical_func
== wxINVERT
)
1234 MacInvertRgn( clipRgn
) ;
1238 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1240 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1242 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1243 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1247 SetPort( (GrafPtr
) sourcePort
) ;
1248 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1249 SetPort( (GrafPtr
) m_macPort
) ;
1250 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1251 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1252 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1260 if ( invertDestinationFirst
)
1262 MacInvertRgn( clipRgn
) ;
1264 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1265 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1266 &srcrect
, &dstrect
, mode
, NULL
) ;
1268 DisposeRgn( clipRgn
) ;
1270 UnlockPixels( bmappixels
) ;
1272 m_macPenInstalled
= false ;
1273 m_macBrushInstalled
= false ;
1274 m_macFontInstalled
= false ;
1278 inline Fixed
IntToFixed( int inInt
)
1280 return (((SInt32
) inInt
) << 16);
1283 inline int FixedToInt( Fixed inFixed
)
1285 return (((SInt32
) inFixed
) >> 16);
1288 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1291 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1294 DrawText(str
, x
, y
);
1297 if ( str
.Length() == 0 )
1300 wxMacPortSetter
helper(this) ;
1303 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1306 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1307 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1308 m_macAliasWasEnabled
= true ;
1310 OSStatus status
= noErr
;
1311 ATSUTextLayout atsuLayout
;
1312 UniCharCount chars
= str
.Length() ;
1314 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1315 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1318 status
= TECCreateConverter(&ec
,
1319 wxApp::s_macDefaultEncodingIsPC
? kTextEncodingWindowsLatin1
: kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1321 wxASSERT_MSG( status
== noErr
, wxT("couldn't start converter") ) ;
1322 ByteCount byteOutLen
;
1323 ByteCount byteInLen
= str
.Length() ;
1324 ByteCount byteBufferLen
= byteInLen
*2 ;
1325 char* buf
= new char[byteBufferLen
] ;
1326 status
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
,
1327 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1328 wxASSERT_MSG( status
== noErr
, wxT("couldn't convert text") ) ;
1329 status
= TECDisposeConverter(ec
);
1330 wxASSERT_MSG( status
== noErr
, wxT("couldn't dispose converter") ) ;
1331 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1332 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1334 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1335 int iAngle
= int( angle
);
1336 int drawX
= XLOG2DEVMAC(x
) ;
1337 int drawY
= YLOG2DEVMAC(y
) ;
1339 ATSUTextMeasurement textBefore
;
1340 ATSUTextMeasurement textAfter
;
1341 ATSUTextMeasurement ascent
;
1342 ATSUTextMeasurement descent
;
1345 if ( abs(iAngle
) > 0 )
1347 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1348 ATSUAttributeTag atsuTags
[] =
1350 kATSULineRotationTag
,
1352 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1356 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1360 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1361 atsuTags
, atsuSizes
, atsuValues
) ;
1363 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1364 &textBefore
, &textAfter
, &ascent
, &descent
);
1366 drawX
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1367 drawY
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1368 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1369 IntToFixed(drawX
) , IntToFixed(drawY
) );
1370 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1372 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1373 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1374 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1375 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1376 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1377 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1378 ::ATSUDisposeTextLayout(atsuLayout
);
1385 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1387 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1388 wxMacPortSetter
helper(this) ;
1389 long xx
= XLOG2DEVMAC(x
);
1390 long yy
= YLOG2DEVMAC(y
);
1392 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1393 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1394 useDrawThemeText
= false ;
1399 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1400 SetAntiAliasedTextEnabled(true, 8);
1401 m_macAliasWasEnabled
= true ;
1404 ::GetFontInfo( &fi
) ;
1406 if ( !useDrawThemeText
)
1409 ::MoveTo( xx
, yy
);
1410 if ( m_backgroundMode
== wxTRANSPARENT
)
1412 ::TextMode( srcOr
) ;
1416 ::TextMode( srcCopy
) ;
1418 int length
= strtext
.Length() ;
1426 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1428 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1430 if ( useDrawThemeText
)
1432 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1433 wxMacCFStringHolder
mString( linetext
) ;
1434 if ( m_backgroundMode
!= wxTRANSPARENT
)
1436 Point bounds
={0,0} ;
1437 Rect background
= frame
;
1439 ::GetThemeTextDimensions( mString
,
1440 kThemeCurrentPortFont
,
1445 background
.right
= background
.left
+ bounds
.h
;
1446 background
.bottom
= background
.top
+ bounds
.v
;
1447 ::EraseRect( &background
) ;
1449 ::DrawThemeTextBox( mString
,
1450 kThemeCurrentPortFont
,
1461 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1462 ::DrawText( text
, 0 , strlen(text
) ) ;
1464 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1470 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1472 if ( useDrawThemeText
)
1474 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1475 wxMacCFStringHolder
mString( linetext
) ;
1477 if ( m_backgroundMode
!= wxTRANSPARENT
)
1479 Point bounds
={0,0} ;
1480 Rect background
= frame
;
1482 ::GetThemeTextDimensions( mString
,
1483 kThemeCurrentPortFont
,
1488 background
.right
= background
.left
+ bounds
.h
;
1489 background
.bottom
= background
.top
+ bounds
.v
;
1490 ::EraseRect( &background
) ;
1492 ::DrawThemeTextBox( mString
,
1493 kThemeCurrentPortFont
,
1503 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1504 ::DrawText( text
, 0 , strlen(text
) ) ;
1507 ::TextMode( srcOr
) ;
1510 bool wxDC::CanGetTextExtent() const
1512 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1516 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1517 wxCoord
*descent
, wxCoord
*externalLeading
,
1518 wxFont
*theFont
) const
1520 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1521 wxMacPortSetter
helper(this) ;
1522 wxFont formerFont
= m_font
;
1525 // work around the constness
1526 *((wxFont
*)(&m_font
)) = *theFont
;
1530 ::GetFontInfo( &fi
) ;
1532 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1533 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1534 useGetThemeText
= false ;
1537 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1539 *descent
=YDEV2LOGREL( fi
.descent
);
1540 if ( externalLeading
)
1541 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1542 int length
= strtext
.Length() ;
1544 const char *text = NULL ;
1546 if ( wxApp::s_macDefaultEncodingIsPC )
1548 macText = wxMacMakeMacStringFromPC( string ) ;
1550 length = macText.Length() ;
1555 length = string.Length() ;
1566 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1568 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1570 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1572 if ( useGetThemeText
)
1574 Point bounds
={0,0} ;
1576 wxMacCFStringHolder
mString( linetext
) ;
1577 ::GetThemeTextDimensions( mString
,
1578 kThemeCurrentPortFont
,
1583 curwidth
= bounds
.h
;
1588 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1589 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1591 if ( curwidth
> *width
)
1592 *width
= XDEV2LOGREL( curwidth
) ;
1598 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1600 if ( useGetThemeText
)
1602 Point bounds
={0,0} ;
1604 wxMacCFStringHolder
mString( linetext
) ;
1605 ::GetThemeTextDimensions( mString
,
1606 kThemeCurrentPortFont
,
1611 curwidth
= bounds
.h
;
1616 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1617 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
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)
1750 case wxAND
: // src AND dst
1755 case wxAND_REVERSE
:// src AND (NOT dst)
1756 case wxAND_INVERT
: // (NOT src) AND dst
1757 case wxNO_OP
: // dst
1758 case wxNOR
: // (NOT src) AND (NOT dst)
1759 case wxEQUIV
: // (NOT src) XOR dst
1760 case wxOR_INVERT
: // (NOT src) OR dst
1761 case wxNAND
: // (NOT src) OR (NOT dst)
1762 case wxOR
: // src OR dst
1764 // case wxSRC_OR: // source _bitmap_ OR destination
1765 // case wxSRC_AND: // source _bitmap_ AND destination
1769 OSStatus status
= noErr
;
1770 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1771 Style qdStyle
= font
->m_macFontStyle
;
1772 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1773 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1774 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1775 ATSUAttributeTag atsuTags
[] =
1780 // kATSUBaselineClassTag ,
1781 kATSUVerticalCharacterTag
,
1782 kATSUQDBoldfaceTag
,
1784 kATSUQDUnderlineTag
,
1785 kATSUQDCondensedTag
,
1786 kATSUQDExtendedTag
,
1788 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1790 sizeof( ATSUFontID
) ,
1792 // sizeof( RGBColor ) ,
1793 // sizeof( BslnBaselineClass ) ,
1794 sizeof( ATSUVerticalCharacterType
),
1801 Boolean kTrue
= true ;
1802 Boolean kFalse
= false ;
1803 BslnBaselineClass kBaselineDefault
= kBSLNHangingBaseline
;
1804 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1805 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1809 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1810 // &kBaselineDefault ,
1812 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1813 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1814 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1815 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1816 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1818 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1819 atsuTags
, atsuSizes
, atsuValues
);
1820 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1823 Pattern gHatchPatterns
[] =
1825 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1826 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1827 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1828 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1829 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1830 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1831 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1834 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1839 case wxBDIAGONAL_HATCH
:
1842 case wxFDIAGONAL_HATCH
:
1848 case wxHORIZONTAL_HATCH
:
1851 case wxVERTICAL_HATCH
:
1854 case wxCROSSDIAG_HATCH
:
1858 theIndex
= 1; // solid pattern
1861 *pattern
= gHatchPatterns
[theIndex
-1] ;
1864 void wxDC::MacInstallPen() const
1866 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1868 // if ( m_macPenInstalled )
1870 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1871 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1872 ::RGBForeColor( &forecolor
);
1873 ::RGBBackColor( &backcolor
);
1875 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1876 // null means only one pixel, at whatever resolution
1877 if ( penWidth
== 0 )
1879 ::PenSize(penWidth
, penWidth
);
1880 int penStyle
= m_pen
.GetStyle();
1881 if (penStyle
== wxSOLID
)
1883 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1885 else if (IS_HATCH(penStyle
))
1888 wxMacGetHatchPattern(penStyle
, &pat
);
1893 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1897 for ( int i
= 0 ; i
< 8 ; ++i
)
1903 for ( int i
= 0 ; i
< 8 ; ++i
)
1909 for ( int i
= 0 ; i
< 8 ; ++i
)
1915 for ( int i
= 0 ; i
< 8 ; ++i
)
1923 m_pen
.GetDashes(&dash
) ;
1924 // right now we don't allocate larger pixmaps
1926 m_pen
.GetDashes(&dash
) ;
1927 for ( int i
= 0 ; i
< 8 ; ++i
)
1929 pat
.pat
[i
] = dash
[0] ;
1936 short mode
= patCopy
;
1938 switch( m_logicalFunction
)
1940 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1943 case wxINVERT
: // NOT dst
1944 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1947 case wxXOR
: // src XOR dst
1950 case wxOR_REVERSE
: // src OR (NOT dst)
1953 case wxSRC_INVERT
: // (NOT src)
1956 case wxAND
: // src AND dst
1961 case wxAND_REVERSE
:// src AND (NOT dst)
1962 case wxAND_INVERT
: // (NOT src) AND dst
1963 case wxNO_OP
: // dst
1964 case wxNOR
: // (NOT src) AND (NOT dst)
1965 case wxEQUIV
: // (NOT src) XOR dst
1966 case wxOR_INVERT
: // (NOT src) OR dst
1967 case wxNAND
: // (NOT src) OR (NOT dst)
1968 case wxOR
: // src OR dst
1970 // case wxSRC_OR: // source _bitmap_ OR destination
1971 // case wxSRC_AND: // source _bitmap_ AND destination
1975 m_macPenInstalled
= true ;
1976 m_macBrushInstalled
= false ;
1977 m_macFontInstalled
= false ;
1980 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1982 Pattern whiteColor
;
1983 switch( background
.MacGetBrushKind() )
1985 case kwxMacBrushTheme
:
1987 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1990 case kwxMacBrushThemeBackground
:
1993 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1994 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1997 case kwxMacBrushColour
:
1999 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2000 int brushStyle
= background
.GetStyle();
2001 if (brushStyle
== wxSOLID
)
2002 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2003 else if (IS_HATCH(brushStyle
))
2006 wxMacGetHatchPattern(brushStyle
, &pat
);
2011 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2018 void wxDC::MacInstallBrush() const
2020 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2021 Pattern blackColor
;
2022 // if ( m_macBrushInstalled )
2025 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2026 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2027 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2028 int brushStyle
= m_brush
.GetStyle();
2029 if (brushStyle
== wxSOLID
)
2031 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2033 else if (IS_HATCH(brushStyle
))
2036 wxMacGetHatchPattern(brushStyle
, &pat
);
2039 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2041 // we force this in order to be compliant with wxMSW
2042 backgroundTransparent
= false ;
2043 // for these the text fore (and back for MASK_OPAQUE) colors are used
2044 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2045 int width
= bitmap
->GetWidth() ;
2046 int height
= bitmap
->GetHeight() ;
2047 GWorldPtr gw
= NULL
;
2048 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2049 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2051 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2052 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2053 LockPixels( gwpixmaphandle
) ;
2054 bool isMonochrome
= !IsPortColor( gw
) ;
2055 if ( !isMonochrome
)
2057 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2058 isMonochrome
= true ;
2060 if ( isMonochrome
&& width
== 8 && height
== 8 )
2062 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2063 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2064 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2065 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2066 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2068 for ( int i
= 0 ; i
< 8 ; ++i
)
2070 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2072 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2077 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2078 // caching scheme before putting this into production
2081 PixPatHandle pixpat
= NewPixPat() ;
2082 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2083 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2084 ((**(**pixpat
).patMap
).bounds
.bottom
-
2085 (**(**pixpat
).patMap
).bounds
.top
);
2086 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2087 (**pixpat
).patData
= image
;
2090 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2091 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2092 if ( ctspec
[0].rgb
.red
== 0x0000 )
2094 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2095 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2099 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2100 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2102 ::CTabChanged( ctable
) ;
2104 ::PenPixPat(pixpat
);
2105 m_macForegroundPixMap
= pixpat
;
2107 UnlockPixels( gwpixmaphandle
) ;
2111 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2113 short mode
= patCopy
;
2114 switch( m_logicalFunction
)
2117 if ( backgroundTransparent
)
2122 case wxINVERT
: // NOT dst
2123 if ( !backgroundTransparent
)
2125 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2129 case wxXOR
: // src XOR dst
2132 case wxOR_REVERSE
: // src OR (NOT dst)
2135 case wxSRC_INVERT
: // (NOT src)
2138 case wxAND
: // src AND dst
2143 case wxAND_REVERSE
:// src AND (NOT dst)
2144 case wxAND_INVERT
: // (NOT src) AND dst
2145 case wxNO_OP
: // dst
2146 case wxNOR
: // (NOT src) AND (NOT dst)
2147 case wxEQUIV
: // (NOT src) XOR dst
2148 case wxOR_INVERT
: // (NOT src) OR dst
2149 case wxNAND
: // (NOT src) OR (NOT dst)
2150 case wxOR
: // src OR dst
2152 // case wxSRC_OR: // source _bitmap_ OR destination
2153 // case wxSRC_AND: // source _bitmap_ AND destination
2157 m_macBrushInstalled
= true ;
2158 m_macPenInstalled
= false ;
2159 m_macFontInstalled
= false ;
2162 // ---------------------------------------------------------------------------
2163 // coordinates transformations
2164 // ---------------------------------------------------------------------------
2166 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2168 return ((wxDC
*)this)->XDEV2LOG(x
);
2171 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2173 return ((wxDC
*)this)->YDEV2LOG(y
);
2176 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2178 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2181 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2183 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2186 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2188 return ((wxDC
*)this)->XLOG2DEV(x
);
2191 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2193 return ((wxDC
*)this)->YLOG2DEV(y
);
2196 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2198 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2201 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2203 return ((wxDC
*)this)->YLOG2DEVREL(y
);