1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
21 #include "wx/region.h"
30 #include "wx/mac/private.h"
31 #include "ATSUnicode.h"
32 #include "TextCommon.h"
33 #include "TextEncodingConverter.h"
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 #define mm2inches 0.0393700787402
44 #define inches2mm 25.4
45 #define mm2twips 56.6929133859
46 #define twips2mm 0.0176388888889
47 #define mm2pt 2.83464566929
48 #define pt2mm 0.352777777778
49 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
51 const double M_PI
= 3.14159265358979 ;
54 const double RAD2DEG
= 180.0 / M_PI
;
55 const short kEmulatedMode
= -1 ;
56 const short kUnsupportedMode
= -2 ;
58 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
59 m_ph( (GrafPtr
) dc
->m_macPort
)
61 wxASSERT( dc
->Ok() ) ;
63 dc
->MacSetupPort(&m_ph
) ;
66 wxMacPortSetter::~wxMacPortSetter()
68 m_dc
->MacCleanupPort(&m_ph
) ;
71 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
73 m_formerClip
= NewRgn() ;
74 m_newClip
= NewRgn() ;
75 GetClip( m_formerClip
) ;
80 // this clipping area was set to the parent window's drawing area, lead to problems
81 // with MacOSX controls drawing outside their wx' rectangle
82 RgnHandle insidergn
= NewRgn() ;
84 wxWindow
*parent
= win
->GetParent() ;
85 parent
->MacWindowToRootWindow( &x
,&y
) ;
86 wxSize size
= parent
->GetSize() ;
87 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
88 size
.x
- parent
->MacGetRightBorderSize(),
89 size
.y
- parent
->MacGetBottomBorderSize()) ;
90 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
91 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
92 OffsetRgn( m_newClip
, x
, y
) ;
93 SetClip( m_newClip
) ;
94 DisposeRgn( insidergn
) ;
97 win
->MacWindowToRootWindow( &x
,&y
) ;
98 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
99 OffsetRgn( m_newClip
, x
, y
) ;
100 SetClip( m_newClip
) ;
105 wxMacWindowClipper::~wxMacWindowClipper()
107 SetClip( m_formerClip
) ;
108 DisposeRgn( m_newClip
) ;
109 DisposeRgn( m_formerClip
) ;
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
116 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
117 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
119 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
122 // this function emulates all wx colour manipulations, used to verify the implementation
123 // by setting the mode in the blitting functions to kEmulatedMode
124 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
126 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
128 switch ( logical_func
)
130 case wxAND
: // 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_INVERT
: // (NOT src) AND dst
136 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
137 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
138 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
140 case wxAND_REVERSE
:// src AND (NOT dst)
141 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
142 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
143 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
151 dstColor
.red
= srcColor
.red
;
152 dstColor
.green
= srcColor
.green
;
153 dstColor
.blue
= srcColor
.blue
;
155 case wxEQUIV
: // (NOT src) XOR dst
156 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
157 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
158 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
160 case wxINVERT
: // NOT dst
161 dstColor
.red
= ~dstColor
.red
;
162 dstColor
.green
= ~dstColor
.green
;
163 dstColor
.blue
= ~dstColor
.blue
;
165 case wxNAND
: // (NOT src) OR (NOT dst)
166 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
167 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
168 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
170 case wxNOR
: // (NOT src) AND (NOT dst)
171 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
172 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
173 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
177 case wxOR
: // 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_INVERT
: // (NOT src) OR dst
183 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
184 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
185 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
187 case wxOR_REVERSE
: // src OR (NOT dst)
188 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
189 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
190 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
193 dstColor
.red
= 0xFFFF ;
194 dstColor
.green
= 0xFFFF ;
195 dstColor
.blue
= 0xFFFF ;
197 case wxSRC_INVERT
: // (NOT src)
198 dstColor
.red
= ~srcColor
.red
;
199 dstColor
.green
= ~srcColor
.green
;
200 dstColor
.blue
= ~srcColor
.blue
;
202 case wxXOR
: // src XOR dst
203 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
204 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
205 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
214 m_mm_to_pix_x
= mm2pt
;
215 m_mm_to_pix_y
= mm2pt
;
216 m_internalDeviceOriginX
= 0;
217 m_internalDeviceOriginY
= 0;
218 m_externalDeviceOriginX
= 0;
219 m_externalDeviceOriginY
= 0;
220 m_logicalScaleX
= 1.0;
221 m_logicalScaleY
= 1.0;
226 m_needComputeScaleX
= FALSE
;
227 m_needComputeScaleY
= FALSE
;
231 m_macFontInstalled
= false ;
232 m_macBrushInstalled
= false ;
233 m_macPenInstalled
= false ;
234 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
235 m_macBoundaryClipRgn
= NewRgn() ;
236 m_macCurrentClipRgn
= NewRgn() ;
237 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
238 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
239 m_pen
= *wxBLACK_PEN
;
240 m_font
= *wxNORMAL_FONT
;
241 m_brush
= *wxWHITE_BRUSH
;
243 // needed to debug possible errors with two active drawing methods at the same time on
245 m_macCurrentPortStateHelper
= NULL
;
247 m_macATSUIStyle
= NULL
;
248 m_macAliasWasEnabled
= false;
249 m_macForegroundPixMap
= NULL
;
250 m_macBackgroundPixMap
= NULL
;
255 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
256 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
259 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
262 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
263 m_macCurrentPortStateHelper
= help
;
265 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
266 m_macFontInstalled
= false ;
267 m_macBrushInstalled
= false ;
268 m_macPenInstalled
= false ;
271 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
274 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
275 m_macCurrentPortStateHelper
= NULL
;
277 if( m_macATSUIStyle
)
279 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
280 m_macATSUIStyle
= NULL
;
282 if ( m_macAliasWasEnabled
)
284 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
285 m_macAliasWasEnabled
= false ;
287 if ( m_macForegroundPixMap
)
290 ::PenPat(GetQDGlobalsBlack(&blackColor
));
291 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
292 m_macForegroundPixMap
= NULL
;
294 if ( m_macBackgroundPixMap
)
297 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
298 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
299 m_macBackgroundPixMap
= NULL
;
303 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
305 wxCHECK_RET( Ok(), wxT("invalid window dc") );
306 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
307 wxMacPortSetter
helper(this) ;
308 wxCoord xx
= XLOG2DEVMAC(x
);
309 wxCoord yy
= YLOG2DEVMAC(y
);
310 wxCoord w
= bmp
.GetWidth();
311 wxCoord h
= bmp
.GetHeight();
312 wxCoord ww
= XLOG2DEVREL(w
);
313 wxCoord hh
= YLOG2DEVREL(h
);
314 // Set up drawing mode
315 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
316 //m_logicalFunction == wxCLEAR ? WHITENESS :
317 //m_logicalFunction == wxSET ? BLACKNESS :
318 m_logicalFunction
== wxINVERT
? hilite
:
319 //m_logicalFunction == wxAND ? MERGECOPY :
320 m_logicalFunction
== wxOR
? srcOr
:
321 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
322 m_logicalFunction
== wxXOR
? srcXor
:
323 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
324 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
325 //m_logicalFunction == wxSRC_OR ? srcOr :
326 //m_logicalFunction == wxSRC_AND ? SRCAND :
328 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
329 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
330 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
331 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
333 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
335 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
336 PixMapHandle bmappixels
;
337 // Set foreground and background colours (for bitmaps depth = 1)
338 if(bmp
.GetDepth() == 1)
340 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
341 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
347 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
348 RGBColor black
= { 0,0,0} ;
349 RGBForeColor( &black
) ;
350 RGBBackColor( &white
) ;
352 bmappixels
= GetGWorldPixMap( bmapworld
) ;
353 wxCHECK_RET(LockPixels(bmappixels
),
354 wxT("DoDrawBitmap: Unable to lock pixels"));
355 Rect source
= { 0, 0, h
, w
};
356 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
357 if ( useMask
&& bmp
.GetMask() )
359 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
363 GetPortBitMapForCopyBits(bmapworld
),
364 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
365 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
366 &source
, &source
, &dest
, mode
, NULL
368 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
372 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
373 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
374 &source
, &dest
, mode
, NULL
) ;
376 UnlockPixels( bmappixels
) ;
378 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
380 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
381 OffsetRect( &bitmaprect
, xx
, yy
) ;
382 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
384 m_macPenInstalled
= false ;
385 m_macBrushInstalled
= false ;
386 m_macFontInstalled
= false ;
389 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
391 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
392 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
393 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
396 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
398 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
399 wxCoord xx
, yy
, ww
, hh
;
402 ww
= XLOG2DEVREL(width
);
403 hh
= YLOG2DEVREL(height
);
404 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
405 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
408 m_clipX1
= wxMax( m_clipX1
, xx
);
409 m_clipY1
= wxMax( m_clipY1
, yy
);
410 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
411 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
423 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
425 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
428 DestroyClippingRegion();
431 wxMacPortSetter
helper(this) ;
433 region
.GetBox( x
, y
, w
, h
);
434 wxCoord xx
, yy
, ww
, hh
;
439 // if we have a scaling that we cannot map onto native regions
440 // we must use the box
441 if ( ww
!= w
|| hh
!= h
)
443 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
447 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
448 if ( xx
!= x
|| yy
!= y
)
450 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
452 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
455 m_clipX1
= wxMax( m_clipX1
, xx
);
456 m_clipY1
= wxMax( m_clipY1
, yy
);
457 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
458 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
471 void wxDC::DestroyClippingRegion()
473 wxMacPortSetter
helper(this) ;
474 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
478 void wxDC::DoGetSizeMM( int* width
, int* height
) const
483 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
484 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
487 void wxDC::SetTextForeground( const wxColour
&col
)
489 wxCHECK_RET(Ok(), wxT("Invalid DC"));
490 m_textForegroundColour
= col
;
491 m_macFontInstalled
= false ;
494 void wxDC::SetTextBackground( const wxColour
&col
)
496 wxCHECK_RET(Ok(), wxT("Invalid DC"));
497 m_textBackgroundColour
= col
;
498 m_macFontInstalled
= false ;
501 void wxDC::SetMapMode( int mode
)
506 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
509 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
512 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
515 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
519 SetLogicalScale( 1.0, 1.0 );
522 if (mode
!= wxMM_TEXT
)
524 m_needComputeScaleX
= TRUE
;
525 m_needComputeScaleY
= TRUE
;
529 void wxDC::SetUserScale( double x
, double y
)
531 // allow negative ? -> no
534 ComputeScaleAndOrigin();
537 void wxDC::SetLogicalScale( double x
, double y
)
542 ComputeScaleAndOrigin();
545 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
547 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
548 m_logicalOriginY
= y
* m_signY
;
549 ComputeScaleAndOrigin();
552 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
554 m_externalDeviceOriginX
= x
;
555 m_externalDeviceOriginY
= y
;
556 ComputeScaleAndOrigin();
560 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
562 m_internalDeviceOriginX
= x
;
563 m_internalDeviceOriginY
= y
;
564 ComputeScaleAndOrigin();
566 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
568 if (x
) *x
= m_internalDeviceOriginX
;
569 if (y
) *y
= m_internalDeviceOriginY
;
573 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
575 m_signX
= (xLeftRight
? 1 : -1);
576 m_signY
= (yBottomUp
? -1 : 1);
577 ComputeScaleAndOrigin();
580 wxSize
wxDC::GetPPI() const
582 return wxSize(72, 72);
585 int wxDC::GetDepth() const
587 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
589 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
594 void wxDC::ComputeScaleAndOrigin()
596 // CMB: copy scale to see if it changes
597 double origScaleX
= m_scaleX
;
598 double origScaleY
= m_scaleY
;
599 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
600 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
601 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
602 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
603 // CMB: if scale has changed call SetPen to recalulate the line width
604 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
606 // this is a bit artificial, but we need to force wxDC to think
607 // the pen has changed
608 wxPen
* pen
= & GetPen();
615 void wxDC::SetPalette( const wxPalette
& palette
)
619 void wxDC::SetBackgroundMode( int mode
)
621 m_backgroundMode
= mode
;
624 void wxDC::SetFont( const wxFont
&font
)
627 m_macFontInstalled
= false ;
630 void wxDC::SetPen( const wxPen
&pen
)
635 m_macPenInstalled
= false ;
638 void wxDC::SetBrush( const wxBrush
&brush
)
640 if (m_brush
== brush
)
643 m_macBrushInstalled
= false ;
646 void wxDC::SetBackground( const wxBrush
&brush
)
648 if (m_backgroundBrush
== brush
)
650 m_backgroundBrush
= brush
;
651 if (!m_backgroundBrush
.Ok())
653 m_macBrushInstalled
= false ;
656 void wxDC::SetLogicalFunction( int function
)
658 if (m_logicalFunction
== function
)
660 m_logicalFunction
= function
;
661 m_macFontInstalled
= false ;
662 m_macBrushInstalled
= false ;
663 m_macPenInstalled
= false ;
666 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
667 const wxColour
& col
, int style
);
669 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
670 const wxColour
& col
, int style
)
672 return wxDoFloodFill(this, x
, y
, col
, style
);
675 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
677 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
678 wxMacPortSetter
helper(this) ;
680 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
681 // Convert from Mac colour to wx
682 col
->Set( colour
.red
>> 8,
688 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
690 wxCHECK_RET(Ok(), wxT("Invalid DC"));
691 wxMacPortSetter
helper(this) ;
692 if (m_pen
.GetStyle() != wxTRANSPARENT
)
695 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
696 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
697 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
698 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
699 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
700 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
701 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
702 (m_pen
.GetWidth() <= 1))
704 // Implement LAST_NOT for MAC at least for
705 // orthogonal lines. RR.
726 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
728 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
729 wxMacPortSetter
helper(this) ;
730 if (m_pen
.GetStyle() != wxTRANSPARENT
)
735 wxCoord xx
= XLOG2DEVMAC(x
);
736 wxCoord yy
= YLOG2DEVMAC(y
);
738 ::MoveTo( XLOG2DEVMAC(0), yy
);
739 ::LineTo( XLOG2DEVMAC(w
), yy
);
740 ::MoveTo( xx
, YLOG2DEVMAC(0) );
741 ::LineTo( xx
, YLOG2DEVMAC(h
) );
742 CalcBoundingBox(x
, y
);
743 CalcBoundingBox(x
+w
, y
+h
);
748 * To draw arcs properly the angles need to be converted from the WX style:
749 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
750 * a normal axis on paper).
753 * Angles start on the +ve y axis and go clockwise.
756 static double wxConvertWXangleToMACangle(double angle
)
758 double newAngle
= 90 - angle
;
764 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
765 wxCoord x2
, wxCoord y2
,
766 wxCoord xc
, wxCoord yc
)
768 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
769 wxMacPortSetter
helper(this) ;
770 wxCoord xx1
= XLOG2DEVMAC(x1
);
771 wxCoord yy1
= YLOG2DEVMAC(y1
);
772 wxCoord xx2
= XLOG2DEVMAC(x2
);
773 wxCoord yy2
= YLOG2DEVMAC(y2
);
774 wxCoord xxc
= XLOG2DEVMAC(xc
);
775 wxCoord yyc
= YLOG2DEVMAC(yc
);
776 double dx
= xx1
- xxc
;
777 double dy
= yy1
- yyc
;
778 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
779 wxCoord rad
= (wxCoord
)radius
;
780 double radius1
, radius2
;
781 if (xx1
== xx2
&& yy1
== yy2
)
786 else if (radius
== 0.0)
788 radius1
= radius2
= 0.0;
792 radius1
= (xx1
- xxc
== 0) ?
793 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
794 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
795 radius2
= (xx2
- xxc
== 0) ?
796 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
797 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
799 wxCoord alpha2
= wxCoord(radius2
- radius1
);
800 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
801 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
804 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
805 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
807 PaintArc(&r
, alpha1
, alpha2
);
809 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
811 FrameArc(&r
, alpha1
, alpha2
);
815 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
816 double sa
, double ea
)
818 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
819 wxMacPortSetter
helper(this) ;
821 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
822 // we have to make sure that the filling is always counter-clockwise
825 wxCoord xx
= XLOG2DEVMAC(x
);
826 wxCoord yy
= YLOG2DEVMAC(y
);
827 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
828 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
829 // handle -ve width and/or height
830 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
831 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
832 sa
= wxConvertWXangleToMACangle(sa
);
837 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
839 PaintArc(&r
, (short)sa
, (short)angle
);
841 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
843 FrameArc(&r
, (short)sa
, (short)angle
);
847 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
849 wxCHECK_RET(Ok(), wxT("Invalid DC"));
850 wxMacPortSetter
helper(this) ;
851 if (m_pen
.GetStyle() != wxTRANSPARENT
)
853 wxCoord xx1
= XLOG2DEVMAC(x
);
854 wxCoord yy1
= YLOG2DEVMAC(y
);
855 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
856 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
857 CalcBoundingBox(x
, y
);
861 void wxDC::DoDrawLines(int n
, wxPoint points
[],
862 wxCoord xoffset
, wxCoord yoffset
)
864 wxCHECK_RET(Ok(), wxT("Invalid DC"));
865 wxMacPortSetter
helper(this) ;
866 if (m_pen
.GetStyle() == wxTRANSPARENT
)
869 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
870 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
871 wxCoord x1
, x2
, y1
, y2
;
872 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
873 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
874 ::MoveTo(x1
- offset
, y1
- offset
);
875 for (int i
= 0; i
< n
-1; i
++)
877 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
878 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
879 ::LineTo( x2
- offset
, y2
- offset
);
883 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
884 wxCoord xoffset
, wxCoord yoffset
,
887 wxCHECK_RET(Ok(), wxT("Invalid DC"));
888 wxMacPortSetter
helper(this) ;
889 wxCoord x1
, x2
, y1
, y2
;
890 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
892 PolyHandle polygon
= OpenPoly();
893 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
894 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
896 for (int i
= 1; i
< n
; i
++)
898 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
899 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
902 // close the polyline if necessary
903 if ( x1
!= x2
|| y1
!= y2
)
908 if (m_brush
.GetStyle() != wxTRANSPARENT
)
911 ::PaintPoly( polygon
);
913 if (m_pen
.GetStyle() != wxTRANSPARENT
)
916 ::FramePoly( polygon
) ;
921 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
923 wxCHECK_RET(Ok(), wxT("Invalid DC"));
924 wxMacPortSetter
helper(this) ;
925 wxCoord xx
= XLOG2DEVMAC(x
);
926 wxCoord yy
= YLOG2DEVMAC(y
);
927 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
928 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
929 // CMB: draw nothing if transformed w or h is 0
930 if (ww
== 0 || hh
== 0)
932 // CMB: handle -ve width and/or height
943 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
944 if (m_brush
.GetStyle() != wxTRANSPARENT
)
947 ::PaintRect( &rect
) ;
949 if (m_pen
.GetStyle() != wxTRANSPARENT
)
952 ::FrameRect( &rect
) ;
956 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
957 wxCoord width
, wxCoord height
,
960 wxCHECK_RET(Ok(), wxT("Invalid DC"));
961 wxMacPortSetter
helper(this) ;
963 radius
= - radius
* ((width
< height
) ? width
: height
);
964 wxCoord xx
= XLOG2DEVMAC(x
);
965 wxCoord yy
= YLOG2DEVMAC(y
);
966 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
967 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
968 // CMB: draw nothing if transformed w or h is 0
969 if (ww
== 0 || hh
== 0)
971 // CMB: handle -ve width and/or height
982 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
983 if (m_brush
.GetStyle() != wxTRANSPARENT
)
986 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
988 if (m_pen
.GetStyle() != wxTRANSPARENT
)
991 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
995 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
997 wxCHECK_RET(Ok(), wxT("Invalid DC"));
998 wxMacPortSetter
helper(this) ;
999 wxCoord xx
= XLOG2DEVMAC(x
);
1000 wxCoord yy
= YLOG2DEVMAC(y
);
1001 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1002 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1003 // CMB: draw nothing if transformed w or h is 0
1004 if (ww
== 0 || hh
== 0)
1006 // CMB: handle -ve width and/or height
1017 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1018 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1021 ::PaintOval( &rect
) ;
1023 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1026 ::FrameOval( &rect
) ;
1030 bool wxDC::CanDrawBitmap(void) const
1035 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1036 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1037 wxCoord xsrcMask
, wxCoord ysrcMask
)
1039 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1040 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1041 if ( logical_func
== wxNO_OP
)
1043 if (xsrcMask
== -1 && ysrcMask
== -1)
1045 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1047 // correct the parameter in case this dc does not have a mask at all
1048 if ( useMask
&& !source
->m_macMask
)
1050 Rect srcrect
, dstrect
;
1051 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1052 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1053 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1054 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1055 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1056 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1057 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1058 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1059 short mode
= kUnsupportedMode
;
1060 bool invertDestinationFirst
= false ;
1061 switch ( logical_func
)
1063 case wxAND
: // src AND dst
1064 mode
= adMin
; // ok
1066 case wxAND_INVERT
: // (NOT src) AND dst
1067 mode
= notSrcOr
; // ok
1069 case wxAND_REVERSE
:// src AND (NOT dst)
1070 invertDestinationFirst
= true ;
1074 mode
= kEmulatedMode
;
1077 mode
= srcCopy
; // ok
1079 case wxEQUIV
: // (NOT src) XOR dst
1080 mode
= srcXor
; // ok
1082 case wxINVERT
: // NOT dst
1083 mode
= kEmulatedMode
; //or hilite ;
1085 case wxNAND
: // (NOT src) OR (NOT dst)
1086 invertDestinationFirst
= true ;
1089 case wxNOR
: // (NOT src) AND (NOT dst)
1090 invertDestinationFirst
= true ;
1093 case wxNO_OP
: // dst
1094 mode
= kEmulatedMode
; // this has already been handled upon entry
1096 case wxOR
: // src OR dst
1099 case wxOR_INVERT
: // (NOT src) OR dst
1102 case wxOR_REVERSE
: // src OR (NOT dst)
1103 invertDestinationFirst
= true ;
1107 mode
= kEmulatedMode
;
1109 case wxSRC_INVERT
: // (NOT src)
1110 mode
= notSrcCopy
; // ok
1112 case wxXOR
: // src XOR dst
1113 mode
= notSrcXor
; // ok
1118 if ( mode
== kUnsupportedMode
)
1120 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1123 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1124 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1125 if ( LockPixels(bmappixels
) )
1127 wxMacPortSetter
helper(this) ;
1128 if ( source
->GetDepth() == 1 )
1130 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1131 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1135 // the modes need this, otherwise we'll end up having really nice colors...
1136 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1137 RGBColor black
= { 0,0,0} ;
1138 RGBForeColor( &black
) ;
1139 RGBBackColor( &white
) ;
1141 if ( useMask
&& source
->m_macMask
)
1143 if ( mode
== srcCopy
)
1145 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1147 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1148 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1149 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1150 &srcrect
, &srcrect
, &dstrect
) ;
1151 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1156 RgnHandle clipRgn
= NewRgn() ;
1157 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1158 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1159 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1160 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1161 if ( mode
== kEmulatedMode
)
1164 ::PenPat(GetQDGlobalsBlack(&pat
));
1165 if ( logical_func
== wxSET
)
1167 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1168 ::RGBForeColor( &col
) ;
1169 ::PaintRgn( clipRgn
) ;
1171 else if ( logical_func
== wxCLEAR
)
1173 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1174 ::RGBForeColor( &col
) ;
1175 ::PaintRgn( clipRgn
) ;
1177 else if ( logical_func
== wxINVERT
)
1179 MacInvertRgn( clipRgn
) ;
1183 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1185 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1187 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1188 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1189 if ( PtInRgn( dstPoint
, clipRgn
) )
1193 SetPort( (GrafPtr
) sourcePort
) ;
1194 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1195 SetPort( (GrafPtr
) m_macPort
) ;
1196 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1197 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1198 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1206 if ( invertDestinationFirst
)
1208 MacInvertRgn( clipRgn
) ;
1210 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1211 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1212 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1214 DisposeRgn( clipRgn
) ;
1219 RgnHandle clipRgn
= NewRgn() ;
1220 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1221 if ( mode
== kEmulatedMode
)
1224 ::PenPat(GetQDGlobalsBlack(&pat
));
1225 if ( logical_func
== wxSET
)
1227 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1228 ::RGBForeColor( &col
) ;
1229 ::PaintRgn( clipRgn
) ;
1231 else if ( logical_func
== wxCLEAR
)
1233 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1234 ::RGBForeColor( &col
) ;
1235 ::PaintRgn( clipRgn
) ;
1237 else if ( logical_func
== wxINVERT
)
1239 MacInvertRgn( clipRgn
) ;
1243 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1245 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1247 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1248 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1252 SetPort( (GrafPtr
) sourcePort
) ;
1253 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1254 SetPort( (GrafPtr
) m_macPort
) ;
1255 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1256 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1257 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1265 if ( invertDestinationFirst
)
1267 MacInvertRgn( clipRgn
) ;
1269 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1270 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1271 &srcrect
, &dstrect
, mode
, NULL
) ;
1273 DisposeRgn( clipRgn
) ;
1275 UnlockPixels( bmappixels
) ;
1277 m_macPenInstalled
= false ;
1278 m_macBrushInstalled
= false ;
1279 m_macFontInstalled
= false ;
1284 // as macro in FixMath.h for 10.3
1285 inline Fixed
IntToFixed( int inInt
)
1287 return (((SInt32
) inInt
) << 16);
1290 inline int FixedToInt( Fixed inFixed
)
1292 return (((SInt32
) inFixed
) >> 16);
1296 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1299 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1303 DrawText(str
, x
, y
);
1307 if ( str
.Length() == 0 )
1310 wxMacPortSetter
helper(this) ;
1313 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1316 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1317 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1318 m_macAliasWasEnabled
= true ;
1320 OSStatus status
= noErr
;
1321 ATSUTextLayout atsuLayout
;
1322 UniCharCount chars
= str
.Length() ;
1324 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1325 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1328 status
= TECCreateConverter(&ec
,
1329 wxApp::s_macDefaultEncodingIsPC
1330 ? (int)kTextEncodingWindowsLatin1
1331 : (int)kTextEncodingMacRoman
,
1332 kTextEncodingUnicodeDefault
);
1334 wxASSERT_MSG( status
== noErr
, wxT("couldn't start converter") ) ;
1335 ByteCount byteOutLen
;
1336 ByteCount byteInLen
= str
.Length() ;
1337 ByteCount byteBufferLen
= byteInLen
*2 ;
1338 char* buf
= new char[byteBufferLen
] ;
1339 status
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
,
1340 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1341 wxASSERT_MSG( status
== noErr
, wxT("couldn't convert text") ) ;
1342 status
= TECDisposeConverter(ec
);
1343 wxASSERT_MSG( status
== noErr
, wxT("couldn't dispose converter") ) ;
1344 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1345 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1347 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1348 int iAngle
= int( angle
);
1349 int drawX
= XLOG2DEVMAC(x
) ;
1350 int drawY
= YLOG2DEVMAC(y
) ;
1352 ATSUTextMeasurement textBefore
;
1353 ATSUTextMeasurement textAfter
;
1354 ATSUTextMeasurement ascent
;
1355 ATSUTextMeasurement descent
;
1358 if ( abs(iAngle
) > 0 )
1360 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1361 ATSUAttributeTag atsuTags
[] =
1363 kATSULineRotationTag
,
1365 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1369 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1373 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1374 atsuTags
, atsuSizes
, atsuValues
) ;
1376 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1377 &textBefore
, &textAfter
, &ascent
, &descent
);
1379 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1380 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1381 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1382 IntToFixed(drawX
) , IntToFixed(drawY
) );
1383 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1385 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1386 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1387 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1388 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1389 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1390 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1391 ::ATSUDisposeTextLayout(atsuLayout
);
1398 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1400 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1402 wxMacPortSetter
helper(this) ;
1403 long xx
= XLOG2DEVMAC(x
);
1404 long yy
= YLOG2DEVMAC(y
);
1407 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1408 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1409 useDrawThemeText
= false ;
1414 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1415 SetAntiAliasedTextEnabled(true, 8);
1416 m_macAliasWasEnabled
= true ;
1419 ::GetFontInfo( &fi
) ;
1421 if ( !useDrawThemeText
)
1424 ::MoveTo( xx
, yy
);
1425 if ( m_backgroundMode
== wxTRANSPARENT
)
1427 ::TextMode( srcOr
) ;
1431 ::TextMode( srcCopy
) ;
1433 int length
= strtext
.Length() ;
1441 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1443 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1445 if ( useDrawThemeText
)
1447 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1448 wxMacCFStringHolder
mString( linetext
) ;
1449 if ( m_backgroundMode
!= wxTRANSPARENT
)
1451 Point bounds
={0,0} ;
1452 Rect background
= frame
;
1454 ::GetThemeTextDimensions( mString
,
1455 kThemeCurrentPortFont
,
1460 background
.right
= background
.left
+ bounds
.h
;
1461 background
.bottom
= background
.top
+ bounds
.v
;
1462 ::EraseRect( &background
) ;
1464 ::DrawThemeTextBox( mString
,
1465 kThemeCurrentPortFont
,
1476 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1477 ::DrawText( text
, 0 , strlen(text
) ) ;
1479 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1485 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1487 if ( useDrawThemeText
)
1489 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1490 wxMacCFStringHolder
mString( linetext
) ;
1492 if ( m_backgroundMode
!= wxTRANSPARENT
)
1494 Point bounds
={0,0} ;
1495 Rect background
= frame
;
1497 ::GetThemeTextDimensions( mString
,
1498 kThemeCurrentPortFont
,
1503 background
.right
= background
.left
+ bounds
.h
;
1504 background
.bottom
= background
.top
+ bounds
.v
;
1505 ::EraseRect( &background
) ;
1507 ::DrawThemeTextBox( mString
,
1508 kThemeCurrentPortFont
,
1518 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1519 ::DrawText( text
, 0 , strlen(text
) ) ;
1522 ::TextMode( srcOr
) ;
1525 bool wxDC::CanGetTextExtent() const
1527 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1531 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1532 wxCoord
*descent
, wxCoord
*externalLeading
,
1533 wxFont
*theFont
) const
1535 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1536 wxMacPortSetter
helper(this) ;
1537 wxFont formerFont
= m_font
;
1540 // work around the constness
1541 *((wxFont
*)(&m_font
)) = *theFont
;
1545 ::GetFontInfo( &fi
) ;
1547 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1548 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1549 useGetThemeText
= false ;
1552 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1554 *descent
=YDEV2LOGREL( fi
.descent
);
1555 if ( externalLeading
)
1556 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1557 int length
= strtext
.Length() ;
1559 const char *text = NULL ;
1561 if ( wxApp::s_macDefaultEncodingIsPC )
1563 macText = wxMacMakeMacStringFromPC( string ) ;
1565 length = macText.Length() ;
1570 length = string.Length() ;
1581 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1583 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1585 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1587 if ( useGetThemeText
)
1589 Point bounds
={0,0} ;
1591 wxMacCFStringHolder
mString( linetext
) ;
1592 ::GetThemeTextDimensions( mString
,
1593 kThemeCurrentPortFont
,
1598 curwidth
= bounds
.h
;
1603 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1604 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1606 if ( curwidth
> *width
)
1607 *width
= XDEV2LOGREL( curwidth
) ;
1613 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1615 if ( useGetThemeText
)
1617 Point bounds
={0,0} ;
1619 wxMacCFStringHolder
mString( linetext
) ;
1620 ::GetThemeTextDimensions( mString
,
1621 kThemeCurrentPortFont
,
1626 curwidth
= bounds
.h
;
1631 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1632 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1634 if ( curwidth
> *width
)
1635 *width
= XDEV2LOGREL( curwidth
) ;
1639 // work around the constness
1640 *((wxFont
*)(&m_font
)) = formerFont
;
1641 m_macFontInstalled
= false ;
1645 wxCoord
wxDC::GetCharWidth(void) const
1647 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1648 wxMacPortSetter
helper(this) ;
1652 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1653 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1654 useGetThemeText
= false ;
1658 if ( useGetThemeText
)
1660 Point bounds
={0,0} ;
1662 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1663 ::GetThemeTextDimensions( mString
,
1664 kThemeCurrentPortFont
,
1669 CFRelease( mString
) ;
1675 width
= ::TextWidth( text
, 0 , 1 ) ;
1677 return YDEV2LOGREL(width
) ;
1680 wxCoord
wxDC::GetCharHeight(void) const
1682 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1683 wxMacPortSetter
helper(this) ;
1686 ::GetFontInfo( &fi
) ;
1687 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1690 void wxDC::Clear(void)
1692 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1693 wxMacPortSetter
helper(this) ;
1694 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1695 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1698 //MacInstallBrush() ;
1699 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1700 ::EraseRect( &rect
) ;
1704 void wxDC::MacInstallFont() const
1706 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1707 // if ( m_macFontInstalled )
1709 Pattern blackColor
;
1710 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1711 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1714 ::TextFont( font
->m_macFontNum
) ;
1715 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1716 ::TextFace( font
->m_macFontStyle
) ;
1717 m_macFontInstalled
= true ;
1718 m_macBrushInstalled
= false ;
1719 m_macPenInstalled
= false ;
1720 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1721 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1722 ::RGBForeColor( &forecolor
);
1723 ::RGBBackColor( &backcolor
);
1727 FontFamilyID fontId
;
1731 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1732 GetFNum( fontName
, &fontId
);
1733 ::TextFont( fontId
) ;
1734 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1735 ::TextFace( fontStyle
) ;
1736 // todo reset after spacing changes - or store the current spacing somewhere
1737 m_macFontInstalled
= true ;
1738 m_macBrushInstalled
= false ;
1739 m_macPenInstalled
= false ;
1740 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1741 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1742 ::RGBForeColor( &forecolor
);
1743 ::RGBBackColor( &backcolor
);
1745 short mode
= patCopy
;
1747 switch( m_logicalFunction
)
1752 case wxINVERT
: // NOT dst
1753 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1756 case wxXOR
: // src XOR dst
1759 case wxOR_REVERSE
: // src OR (NOT dst)
1762 case wxSRC_INVERT
: // (NOT src)
1765 case wxAND
: // src AND dst
1770 case wxAND_REVERSE
:// src AND (NOT dst)
1771 case wxAND_INVERT
: // (NOT src) AND dst
1772 case wxNO_OP
: // dst
1773 case wxNOR
: // (NOT src) AND (NOT dst)
1774 case wxEQUIV
: // (NOT src) XOR dst
1775 case wxOR_INVERT
: // (NOT src) OR dst
1776 case wxNAND
: // (NOT src) OR (NOT dst)
1777 case wxOR
: // src OR dst
1779 // case wxSRC_OR: // source _bitmap_ OR destination
1780 // case wxSRC_AND: // source _bitmap_ AND destination
1784 OSStatus status
= noErr
;
1785 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1786 Style qdStyle
= font
->m_macFontStyle
;
1787 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1788 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1789 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1790 ATSUAttributeTag atsuTags
[] =
1795 // kATSUBaselineClassTag ,
1796 kATSUVerticalCharacterTag
,
1797 kATSUQDBoldfaceTag
,
1799 kATSUQDUnderlineTag
,
1800 kATSUQDCondensedTag
,
1801 kATSUQDExtendedTag
,
1803 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1805 sizeof( ATSUFontID
) ,
1807 // sizeof( RGBColor ) ,
1808 // sizeof( BslnBaselineClass ) ,
1809 sizeof( ATSUVerticalCharacterType
),
1816 Boolean kTrue
= true ;
1817 Boolean kFalse
= false ;
1818 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1819 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1820 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1824 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1825 // &kBaselineDefault ,
1827 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1828 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1829 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1830 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1831 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1833 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1834 atsuTags
, atsuSizes
, atsuValues
);
1835 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1838 Pattern gHatchPatterns
[] =
1840 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1841 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1842 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1843 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1844 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1845 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1846 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1849 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1854 case wxBDIAGONAL_HATCH
:
1857 case wxFDIAGONAL_HATCH
:
1863 case wxHORIZONTAL_HATCH
:
1866 case wxVERTICAL_HATCH
:
1869 case wxCROSSDIAG_HATCH
:
1873 theIndex
= 1; // solid pattern
1876 *pattern
= gHatchPatterns
[theIndex
-1] ;
1879 void wxDC::MacInstallPen() const
1881 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1883 // if ( m_macPenInstalled )
1885 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1886 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1887 ::RGBForeColor( &forecolor
);
1888 ::RGBBackColor( &backcolor
);
1890 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1891 // null means only one pixel, at whatever resolution
1892 if ( penWidth
== 0 )
1894 ::PenSize(penWidth
, penWidth
);
1895 int penStyle
= m_pen
.GetStyle();
1896 if (penStyle
== wxSOLID
)
1898 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1900 else if (IS_HATCH(penStyle
))
1903 wxMacGetHatchPattern(penStyle
, &pat
);
1908 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1912 for ( int i
= 0 ; i
< 8 ; ++i
)
1918 for ( int i
= 0 ; i
< 8 ; ++i
)
1924 for ( int i
= 0 ; i
< 8 ; ++i
)
1930 for ( int i
= 0 ; i
< 8 ; ++i
)
1938 m_pen
.GetDashes(&dash
) ;
1939 // right now we don't allocate larger pixmaps
1941 m_pen
.GetDashes(&dash
) ;
1942 for ( int i
= 0 ; i
< 8 ; ++i
)
1944 pat
.pat
[i
] = dash
[0] ;
1951 short mode
= patCopy
;
1953 switch( m_logicalFunction
)
1955 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1958 case wxINVERT
: // NOT dst
1959 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1962 case wxXOR
: // src XOR dst
1965 case wxOR_REVERSE
: // src OR (NOT dst)
1968 case wxSRC_INVERT
: // (NOT src)
1971 case wxAND
: // src AND dst
1976 case wxAND_REVERSE
:// src AND (NOT dst)
1977 case wxAND_INVERT
: // (NOT src) AND dst
1978 case wxNO_OP
: // dst
1979 case wxNOR
: // (NOT src) AND (NOT dst)
1980 case wxEQUIV
: // (NOT src) XOR dst
1981 case wxOR_INVERT
: // (NOT src) OR dst
1982 case wxNAND
: // (NOT src) OR (NOT dst)
1983 case wxOR
: // src OR dst
1985 // case wxSRC_OR: // source _bitmap_ OR destination
1986 // case wxSRC_AND: // source _bitmap_ AND destination
1990 m_macPenInstalled
= true ;
1991 m_macBrushInstalled
= false ;
1992 m_macFontInstalled
= false ;
1995 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1997 Pattern whiteColor
;
1998 switch( background
.MacGetBrushKind() )
2000 case kwxMacBrushTheme
:
2002 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2005 case kwxMacBrushThemeBackground
:
2008 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2009 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2012 case kwxMacBrushColour
:
2014 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2015 int brushStyle
= background
.GetStyle();
2016 if (brushStyle
== wxSOLID
)
2017 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2018 else if (IS_HATCH(brushStyle
))
2021 wxMacGetHatchPattern(brushStyle
, &pat
);
2026 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2033 void wxDC::MacInstallBrush() const
2035 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2036 Pattern blackColor
;
2037 // if ( m_macBrushInstalled )
2040 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2041 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2042 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2043 int brushStyle
= m_brush
.GetStyle();
2044 if (brushStyle
== wxSOLID
)
2046 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2048 else if (IS_HATCH(brushStyle
))
2051 wxMacGetHatchPattern(brushStyle
, &pat
);
2054 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2056 // we force this in order to be compliant with wxMSW
2057 backgroundTransparent
= false ;
2058 // for these the text fore (and back for MASK_OPAQUE) colors are used
2059 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2060 int width
= bitmap
->GetWidth() ;
2061 int height
= bitmap
->GetHeight() ;
2062 GWorldPtr gw
= NULL
;
2063 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2064 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2066 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2067 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2068 LockPixels( gwpixmaphandle
) ;
2069 bool isMonochrome
= !IsPortColor( gw
) ;
2070 if ( !isMonochrome
)
2072 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2073 isMonochrome
= true ;
2075 if ( isMonochrome
&& width
== 8 && height
== 8 )
2077 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2078 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2079 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2080 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2081 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2083 for ( int i
= 0 ; i
< 8 ; ++i
)
2085 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2087 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2092 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2093 // caching scheme before putting this into production
2096 PixPatHandle pixpat
= NewPixPat() ;
2097 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2098 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2099 ((**(**pixpat
).patMap
).bounds
.bottom
-
2100 (**(**pixpat
).patMap
).bounds
.top
);
2101 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2102 (**pixpat
).patData
= image
;
2105 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2106 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2107 if ( ctspec
[0].rgb
.red
== 0x0000 )
2109 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2110 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2114 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2115 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2117 ::CTabChanged( ctable
) ;
2119 ::PenPixPat(pixpat
);
2120 m_macForegroundPixMap
= pixpat
;
2122 UnlockPixels( gwpixmaphandle
) ;
2126 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2128 short mode
= patCopy
;
2129 switch( m_logicalFunction
)
2132 if ( backgroundTransparent
)
2137 case wxINVERT
: // NOT dst
2138 if ( !backgroundTransparent
)
2140 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2144 case wxXOR
: // src XOR dst
2147 case wxOR_REVERSE
: // src OR (NOT dst)
2150 case wxSRC_INVERT
: // (NOT src)
2153 case wxAND
: // src AND dst
2158 case wxAND_REVERSE
:// src AND (NOT dst)
2159 case wxAND_INVERT
: // (NOT src) AND dst
2160 case wxNO_OP
: // dst
2161 case wxNOR
: // (NOT src) AND (NOT dst)
2162 case wxEQUIV
: // (NOT src) XOR dst
2163 case wxOR_INVERT
: // (NOT src) OR dst
2164 case wxNAND
: // (NOT src) OR (NOT dst)
2165 case wxOR
: // src OR dst
2167 // case wxSRC_OR: // source _bitmap_ OR destination
2168 // case wxSRC_AND: // source _bitmap_ AND destination
2172 m_macBrushInstalled
= true ;
2173 m_macPenInstalled
= false ;
2174 m_macFontInstalled
= false ;
2177 // ---------------------------------------------------------------------------
2178 // coordinates transformations
2179 // ---------------------------------------------------------------------------
2181 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2183 return ((wxDC
*)this)->XDEV2LOG(x
);
2186 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2188 return ((wxDC
*)this)->YDEV2LOG(y
);
2191 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2193 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2196 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2198 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2201 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2203 return ((wxDC
*)this)->XLOG2DEV(x
);
2206 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2208 return ((wxDC
*)this)->YLOG2DEV(y
);
2211 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2213 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2216 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2218 return ((wxDC
*)this)->YLOG2DEVREL(y
);