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
;
240 // needed to debug possible errors with two active drawing methods at the same time on
242 m_macCurrentPortStateHelper
= NULL
;
244 m_macATSUIStyle
= NULL
;
245 m_macAliasWasEnabled
= false;
246 m_macForegroundPixMap
= NULL
;
247 m_macBackgroundPixMap
= NULL
;
252 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
253 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
256 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
259 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
260 m_macCurrentPortStateHelper
= help
;
262 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
263 m_macFontInstalled
= false ;
264 m_macBrushInstalled
= false ;
265 m_macPenInstalled
= false ;
268 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
271 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
272 m_macCurrentPortStateHelper
= NULL
;
274 if( m_macATSUIStyle
)
276 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
277 m_macATSUIStyle
= NULL
;
279 if ( m_macAliasWasEnabled
)
281 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
282 m_macAliasWasEnabled
= false ;
284 if ( m_macForegroundPixMap
)
287 ::PenPat(GetQDGlobalsBlack(&blackColor
));
288 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
289 m_macForegroundPixMap
= NULL
;
291 if ( m_macBackgroundPixMap
)
294 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
295 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
296 m_macBackgroundPixMap
= NULL
;
300 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
302 wxCHECK_RET( Ok(), wxT("invalid window dc") );
303 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
304 wxMacPortSetter
helper(this) ;
305 wxCoord xx
= XLOG2DEVMAC(x
);
306 wxCoord yy
= YLOG2DEVMAC(y
);
307 wxCoord w
= bmp
.GetWidth();
308 wxCoord h
= bmp
.GetHeight();
309 wxCoord ww
= XLOG2DEVREL(w
);
310 wxCoord hh
= YLOG2DEVREL(h
);
311 // Set up drawing mode
312 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
313 //m_logicalFunction == wxCLEAR ? WHITENESS :
314 //m_logicalFunction == wxSET ? BLACKNESS :
315 m_logicalFunction
== wxINVERT
? hilite
:
316 //m_logicalFunction == wxAND ? MERGECOPY :
317 m_logicalFunction
== wxOR
? srcOr
:
318 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
319 m_logicalFunction
== wxXOR
? srcXor
:
320 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
321 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
322 //m_logicalFunction == wxSRC_OR ? srcOr :
323 //m_logicalFunction == wxSRC_AND ? SRCAND :
325 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
326 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
327 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
328 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
330 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
332 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
333 PixMapHandle bmappixels
;
334 // Set foreground and background colours (for bitmaps depth = 1)
335 if(bmp
.GetDepth() == 1)
337 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
338 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
344 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
345 RGBColor black
= { 0,0,0} ;
346 RGBForeColor( &black
) ;
347 RGBBackColor( &white
) ;
349 bmappixels
= GetGWorldPixMap( bmapworld
) ;
350 wxCHECK_RET(LockPixels(bmappixels
),
351 wxT("DoDrawBitmap: Unable to lock pixels"));
352 Rect source
= { 0, 0, h
, w
};
353 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
354 if ( useMask
&& bmp
.GetMask() )
356 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
360 GetPortBitMapForCopyBits(bmapworld
),
361 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
362 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
363 &source
, &source
, &dest
, mode
, NULL
365 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
369 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
370 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
371 &source
, &dest
, mode
, NULL
) ;
373 UnlockPixels( bmappixels
) ;
375 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
377 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
378 OffsetRect( &bitmaprect
, xx
, yy
) ;
379 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
381 m_macPenInstalled
= false ;
382 m_macBrushInstalled
= false ;
383 m_macFontInstalled
= false ;
386 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
388 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
389 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
390 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
393 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
395 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
396 wxCoord xx
, yy
, ww
, hh
;
399 ww
= XLOG2DEVREL(width
);
400 hh
= YLOG2DEVREL(height
);
401 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
402 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
405 m_clipX1
= wxMax( m_clipX1
, xx
);
406 m_clipY1
= wxMax( m_clipY1
, yy
);
407 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
408 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
420 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
422 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
423 wxMacPortSetter
helper(this) ;
426 DestroyClippingRegion();
430 region
.GetBox( x
, y
, w
, h
);
431 wxCoord xx
, yy
, ww
, hh
;
436 // if we have a scaling that we cannot map onto native regions
437 // we must use the box
438 if ( ww
!= w
|| hh
!= h
)
440 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
444 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
445 if ( xx
!= x
|| yy
!= y
)
447 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
449 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
452 m_clipX1
= wxMax( m_clipX1
, xx
);
453 m_clipY1
= wxMax( m_clipY1
, yy
);
454 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
455 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
468 void wxDC::DestroyClippingRegion()
470 wxMacPortSetter
helper(this) ;
471 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
475 void wxDC::DoGetSizeMM( int* width
, int* height
) const
480 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
481 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
484 void wxDC::SetTextForeground( const wxColour
&col
)
486 wxCHECK_RET(Ok(), wxT("Invalid DC"));
487 m_textForegroundColour
= col
;
488 m_macFontInstalled
= false ;
491 void wxDC::SetTextBackground( const wxColour
&col
)
493 wxCHECK_RET(Ok(), wxT("Invalid DC"));
494 m_textBackgroundColour
= col
;
495 m_macFontInstalled
= false ;
498 void wxDC::SetMapMode( int mode
)
503 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
506 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
509 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
512 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
516 SetLogicalScale( 1.0, 1.0 );
519 if (mode
!= wxMM_TEXT
)
521 m_needComputeScaleX
= TRUE
;
522 m_needComputeScaleY
= TRUE
;
526 void wxDC::SetUserScale( double x
, double y
)
528 // allow negative ? -> no
531 ComputeScaleAndOrigin();
534 void wxDC::SetLogicalScale( double x
, double y
)
539 ComputeScaleAndOrigin();
542 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
544 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
545 m_logicalOriginY
= y
* m_signY
;
546 ComputeScaleAndOrigin();
549 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
551 m_externalDeviceOriginX
= x
;
552 m_externalDeviceOriginY
= y
;
553 ComputeScaleAndOrigin();
557 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
559 m_internalDeviceOriginX
= x
;
560 m_internalDeviceOriginY
= y
;
561 ComputeScaleAndOrigin();
563 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
565 if (x
) *x
= m_internalDeviceOriginX
;
566 if (y
) *y
= m_internalDeviceOriginY
;
570 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
572 m_signX
= (xLeftRight
? 1 : -1);
573 m_signY
= (yBottomUp
? -1 : 1);
574 ComputeScaleAndOrigin();
577 wxSize
wxDC::GetPPI() const
579 return wxSize(72, 72);
582 int wxDC::GetDepth() const
584 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
586 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
591 void wxDC::ComputeScaleAndOrigin()
593 // CMB: copy scale to see if it changes
594 double origScaleX
= m_scaleX
;
595 double origScaleY
= m_scaleY
;
596 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
597 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
598 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
599 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
600 // CMB: if scale has changed call SetPen to recalulate the line width
601 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
603 // this is a bit artificial, but we need to force wxDC to think
604 // the pen has changed
605 wxPen
* pen
= & GetPen();
612 void wxDC::SetPalette( const wxPalette
& palette
)
616 void wxDC::SetBackgroundMode( int mode
)
618 m_backgroundMode
= mode
;
621 void wxDC::SetFont( const wxFont
&font
)
624 m_macFontInstalled
= false ;
627 void wxDC::SetPen( const wxPen
&pen
)
632 m_macPenInstalled
= false ;
635 void wxDC::SetBrush( const wxBrush
&brush
)
637 if (m_brush
== brush
)
640 m_macBrushInstalled
= false ;
643 void wxDC::SetBackground( const wxBrush
&brush
)
645 if (m_backgroundBrush
== brush
)
647 m_backgroundBrush
= brush
;
648 if (!m_backgroundBrush
.Ok())
650 m_macBrushInstalled
= false ;
653 void wxDC::SetLogicalFunction( int function
)
655 if (m_logicalFunction
== function
)
657 m_logicalFunction
= function
;
658 m_macFontInstalled
= false ;
659 m_macBrushInstalled
= false ;
660 m_macPenInstalled
= false ;
663 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
664 const wxColour
& col
, int style
);
666 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
667 const wxColour
& col
, int style
)
669 return wxDoFloodFill(this, x
, y
, col
, style
);
672 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
674 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
675 wxMacPortSetter
helper(this) ;
677 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
678 // Convert from Mac colour to wx
679 col
->Set( colour
.red
>> 8,
685 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
687 wxCHECK_RET(Ok(), wxT("Invalid DC"));
688 wxMacPortSetter
helper(this) ;
689 if (m_pen
.GetStyle() != wxTRANSPARENT
)
692 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
693 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
694 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
695 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
696 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
697 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
698 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
699 (m_pen
.GetWidth() <= 1))
701 // Implement LAST_NOT for MAC at least for
702 // orthogonal lines. RR.
723 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
725 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
726 wxMacPortSetter
helper(this) ;
727 if (m_pen
.GetStyle() != wxTRANSPARENT
)
732 wxCoord xx
= XLOG2DEVMAC(x
);
733 wxCoord yy
= YLOG2DEVMAC(y
);
735 ::MoveTo( XLOG2DEVMAC(0), yy
);
736 ::LineTo( XLOG2DEVMAC(w
), yy
);
737 ::MoveTo( xx
, YLOG2DEVMAC(0) );
738 ::LineTo( xx
, YLOG2DEVMAC(h
) );
739 CalcBoundingBox(x
, y
);
740 CalcBoundingBox(x
+w
, y
+h
);
745 * To draw arcs properly the angles need to be converted from the WX style:
746 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
747 * a normal axis on paper).
750 * Angles start on the +ve y axis and go clockwise.
753 static double wxConvertWXangleToMACangle(double angle
)
755 double newAngle
= 90 - angle
;
761 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
762 wxCoord x2
, wxCoord y2
,
763 wxCoord xc
, wxCoord yc
)
765 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
766 wxMacPortSetter
helper(this) ;
767 wxCoord xx1
= XLOG2DEVMAC(x1
);
768 wxCoord yy1
= YLOG2DEVMAC(y1
);
769 wxCoord xx2
= XLOG2DEVMAC(x2
);
770 wxCoord yy2
= YLOG2DEVMAC(y2
);
771 wxCoord xxc
= XLOG2DEVMAC(xc
);
772 wxCoord yyc
= YLOG2DEVMAC(yc
);
773 double dx
= xx1
- xxc
;
774 double dy
= yy1
- yyc
;
775 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
776 wxCoord rad
= (wxCoord
)radius
;
777 double radius1
, radius2
;
778 if (xx1
== xx2
&& yy1
== yy2
)
783 else if (radius
== 0.0)
785 radius1
= radius2
= 0.0;
789 radius1
= (xx1
- xxc
== 0) ?
790 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
791 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
792 radius2
= (xx2
- xxc
== 0) ?
793 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
794 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
796 wxCoord alpha2
= wxCoord(radius2
- radius1
);
797 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
798 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
801 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
802 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
804 PaintArc(&r
, alpha1
, alpha2
);
806 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
808 FrameArc(&r
, alpha1
, alpha2
);
812 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
813 double sa
, double ea
)
815 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
816 wxMacPortSetter
helper(this) ;
818 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
819 // we have to make sure that the filling is always counter-clockwise
822 wxCoord xx
= XLOG2DEVMAC(x
);
823 wxCoord yy
= YLOG2DEVMAC(y
);
824 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
825 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
826 // handle -ve width and/or height
827 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
828 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
829 sa
= wxConvertWXangleToMACangle(sa
);
834 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
836 PaintArc(&r
, (short)sa
, (short)angle
);
838 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
840 FrameArc(&r
, (short)sa
, (short)angle
);
844 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
846 wxCHECK_RET(Ok(), wxT("Invalid DC"));
847 wxMacPortSetter
helper(this) ;
848 if (m_pen
.GetStyle() != wxTRANSPARENT
)
850 wxCoord xx1
= XLOG2DEVMAC(x
);
851 wxCoord yy1
= YLOG2DEVMAC(y
);
852 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
853 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
854 CalcBoundingBox(x
, y
);
858 void wxDC::DoDrawLines(int n
, wxPoint points
[],
859 wxCoord xoffset
, wxCoord yoffset
)
861 wxCHECK_RET(Ok(), wxT("Invalid DC"));
862 wxMacPortSetter
helper(this) ;
863 if (m_pen
.GetStyle() == wxTRANSPARENT
)
866 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
867 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
868 wxCoord x1
, x2
, y1
, y2
;
869 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
870 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
871 ::MoveTo(x1
- offset
, y1
- offset
);
872 for (int i
= 0; i
< n
-1; i
++)
874 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
875 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
876 ::LineTo( x2
- offset
, y2
- offset
);
880 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
881 wxCoord xoffset
, wxCoord yoffset
,
884 wxCHECK_RET(Ok(), wxT("Invalid DC"));
885 wxMacPortSetter
helper(this) ;
886 wxCoord x1
, x2
, y1
, y2
;
887 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
889 PolyHandle polygon
= OpenPoly();
890 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
891 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
893 for (int i
= 1; i
< n
; i
++)
895 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
896 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
899 // close the polyline if necessary
900 if ( x1
!= x2
|| y1
!= y2
)
905 if (m_brush
.GetStyle() != wxTRANSPARENT
)
908 ::PaintPoly( polygon
);
910 if (m_pen
.GetStyle() != wxTRANSPARENT
)
913 ::FramePoly( polygon
) ;
918 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
920 wxCHECK_RET(Ok(), wxT("Invalid DC"));
921 wxMacPortSetter
helper(this) ;
922 wxCoord xx
= XLOG2DEVMAC(x
);
923 wxCoord yy
= YLOG2DEVMAC(y
);
924 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
925 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
926 // CMB: draw nothing if transformed w or h is 0
927 if (ww
== 0 || hh
== 0)
929 // CMB: handle -ve width and/or height
940 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
941 if (m_brush
.GetStyle() != wxTRANSPARENT
)
944 ::PaintRect( &rect
) ;
946 if (m_pen
.GetStyle() != wxTRANSPARENT
)
949 ::FrameRect( &rect
) ;
953 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
954 wxCoord width
, wxCoord height
,
957 wxCHECK_RET(Ok(), wxT("Invalid DC"));
958 wxMacPortSetter
helper(this) ;
960 radius
= - radius
* ((width
< height
) ? width
: height
);
961 wxCoord xx
= XLOG2DEVMAC(x
);
962 wxCoord yy
= YLOG2DEVMAC(y
);
963 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
964 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
965 // CMB: draw nothing if transformed w or h is 0
966 if (ww
== 0 || hh
== 0)
968 // CMB: handle -ve width and/or height
979 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
980 if (m_brush
.GetStyle() != wxTRANSPARENT
)
983 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
985 if (m_pen
.GetStyle() != wxTRANSPARENT
)
988 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
992 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
994 wxCHECK_RET(Ok(), wxT("Invalid DC"));
995 wxMacPortSetter
helper(this) ;
996 wxCoord xx
= XLOG2DEVMAC(x
);
997 wxCoord yy
= YLOG2DEVMAC(y
);
998 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
999 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1000 // CMB: draw nothing if transformed w or h is 0
1001 if (ww
== 0 || hh
== 0)
1003 // CMB: handle -ve width and/or height
1014 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1015 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1018 ::PaintOval( &rect
) ;
1020 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1023 ::FrameOval( &rect
) ;
1027 bool wxDC::CanDrawBitmap(void) const
1032 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1033 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1034 wxCoord xsrcMask
, wxCoord ysrcMask
)
1036 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1037 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1038 if ( logical_func
== wxNO_OP
)
1040 if (xsrcMask
== -1 && ysrcMask
== -1)
1042 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1044 // correct the parameter in case this dc does not have a mask at all
1045 if ( useMask
&& !source
->m_macMask
)
1047 Rect srcrect
, dstrect
;
1048 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1049 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1050 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1051 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1052 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1053 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1054 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1055 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1056 short mode
= kUnsupportedMode
;
1057 bool invertDestinationFirst
= false ;
1058 switch ( logical_func
)
1060 case wxAND
: // src AND dst
1061 mode
= adMin
; // ok
1063 case wxAND_INVERT
: // (NOT src) AND dst
1064 mode
= notSrcOr
; // ok
1066 case wxAND_REVERSE
:// src AND (NOT dst)
1067 invertDestinationFirst
= true ;
1071 mode
= kEmulatedMode
;
1074 mode
= srcCopy
; // ok
1076 case wxEQUIV
: // (NOT src) XOR dst
1077 mode
= srcXor
; // ok
1079 case wxINVERT
: // NOT dst
1080 mode
= kEmulatedMode
; //or hilite ;
1082 case wxNAND
: // (NOT src) OR (NOT dst)
1083 invertDestinationFirst
= true ;
1086 case wxNOR
: // (NOT src) AND (NOT dst)
1087 invertDestinationFirst
= true ;
1090 case wxNO_OP
: // dst
1091 mode
= kEmulatedMode
; // this has already been handled upon entry
1093 case wxOR
: // src OR dst
1096 case wxOR_INVERT
: // (NOT src) OR dst
1099 case wxOR_REVERSE
: // src OR (NOT dst)
1100 invertDestinationFirst
= true ;
1104 mode
= kEmulatedMode
;
1106 case wxSRC_INVERT
: // (NOT src)
1107 mode
= notSrcCopy
; // ok
1109 case wxXOR
: // src XOR dst
1110 mode
= notSrcXor
; // ok
1115 if ( mode
== kUnsupportedMode
)
1117 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1120 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1121 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1122 if ( LockPixels(bmappixels
) )
1124 wxMacPortSetter
helper(this) ;
1125 if ( source
->GetDepth() == 1 )
1127 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1128 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1132 // the modes need this, otherwise we'll end up having really nice colors...
1133 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1134 RGBColor black
= { 0,0,0} ;
1135 RGBForeColor( &black
) ;
1136 RGBBackColor( &white
) ;
1138 if ( useMask
&& source
->m_macMask
)
1140 if ( mode
== srcCopy
)
1142 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1144 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1145 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1146 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1147 &srcrect
, &srcrect
, &dstrect
) ;
1148 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1153 RgnHandle clipRgn
= NewRgn() ;
1154 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1155 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1156 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1157 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1158 if ( mode
== kEmulatedMode
)
1161 ::PenPat(GetQDGlobalsBlack(&pat
));
1162 if ( logical_func
== wxSET
)
1164 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1165 ::RGBForeColor( &col
) ;
1166 ::PaintRgn( clipRgn
) ;
1168 else if ( logical_func
== wxCLEAR
)
1170 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1171 ::RGBForeColor( &col
) ;
1172 ::PaintRgn( clipRgn
) ;
1174 else if ( logical_func
== wxINVERT
)
1176 MacInvertRgn( clipRgn
) ;
1180 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1182 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1184 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1185 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1186 if ( PtInRgn( dstPoint
, clipRgn
) )
1190 SetPort( (GrafPtr
) sourcePort
) ;
1191 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1192 SetPort( (GrafPtr
) m_macPort
) ;
1193 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1194 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1195 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1203 if ( invertDestinationFirst
)
1205 MacInvertRgn( clipRgn
) ;
1207 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1208 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1209 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1211 DisposeRgn( clipRgn
) ;
1216 RgnHandle clipRgn
= NewRgn() ;
1217 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1218 if ( mode
== kEmulatedMode
)
1221 ::PenPat(GetQDGlobalsBlack(&pat
));
1222 if ( logical_func
== wxSET
)
1224 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1225 ::RGBForeColor( &col
) ;
1226 ::PaintRgn( clipRgn
) ;
1228 else if ( logical_func
== wxCLEAR
)
1230 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1231 ::RGBForeColor( &col
) ;
1232 ::PaintRgn( clipRgn
) ;
1234 else if ( logical_func
== wxINVERT
)
1236 MacInvertRgn( clipRgn
) ;
1240 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1242 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1244 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1245 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1249 SetPort( (GrafPtr
) sourcePort
) ;
1250 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1251 SetPort( (GrafPtr
) m_macPort
) ;
1252 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1253 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1254 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1262 if ( invertDestinationFirst
)
1264 MacInvertRgn( clipRgn
) ;
1266 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1267 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1268 &srcrect
, &dstrect
, mode
, NULL
) ;
1270 DisposeRgn( clipRgn
) ;
1272 UnlockPixels( bmappixels
) ;
1274 m_macPenInstalled
= false ;
1275 m_macBrushInstalled
= false ;
1276 m_macFontInstalled
= false ;
1280 inline Fixed
IntToFixed( int inInt
)
1282 return (((SInt32
) inInt
) << 16);
1285 inline int FixedToInt( Fixed inFixed
)
1287 return (((SInt32
) inFixed
) >> 16);
1290 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1293 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1297 DrawText(str
, x
, y
);
1301 if ( str
.Length() == 0 )
1304 wxMacPortSetter
helper(this) ;
1307 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1310 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1311 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1312 m_macAliasWasEnabled
= true ;
1314 OSStatus status
= noErr
;
1315 ATSUTextLayout atsuLayout
;
1316 UniCharCount chars
= str
.Length() ;
1318 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1319 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1322 status
= TECCreateConverter(&ec
,
1323 wxApp::s_macDefaultEncodingIsPC
? kTextEncodingWindowsLatin1
: kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1325 wxASSERT_MSG( status
== noErr
, wxT("couldn't start converter") ) ;
1326 ByteCount byteOutLen
;
1327 ByteCount byteInLen
= str
.Length() ;
1328 ByteCount byteBufferLen
= byteInLen
*2 ;
1329 char* buf
= new char[byteBufferLen
] ;
1330 status
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
,
1331 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1332 wxASSERT_MSG( status
== noErr
, wxT("couldn't convert text") ) ;
1333 status
= TECDisposeConverter(ec
);
1334 wxASSERT_MSG( status
== noErr
, wxT("couldn't dispose converter") ) ;
1335 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1336 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1338 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1339 int iAngle
= int( angle
);
1340 int drawX
= XLOG2DEVMAC(x
) ;
1341 int drawY
= YLOG2DEVMAC(y
) ;
1343 ATSUTextMeasurement textBefore
;
1344 ATSUTextMeasurement textAfter
;
1345 ATSUTextMeasurement ascent
;
1346 ATSUTextMeasurement descent
;
1349 if ( abs(iAngle
) > 0 )
1351 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1352 ATSUAttributeTag atsuTags
[] =
1354 kATSULineRotationTag
,
1356 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1360 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1364 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1365 atsuTags
, atsuSizes
, atsuValues
) ;
1367 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1368 &textBefore
, &textAfter
, &ascent
, &descent
);
1370 drawX
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1371 drawY
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1372 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1373 IntToFixed(drawX
) , IntToFixed(drawY
) );
1374 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1376 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1377 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1378 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1379 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1380 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1381 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1382 ::ATSUDisposeTextLayout(atsuLayout
);
1389 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1391 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1393 wxMacPortSetter
helper(this) ;
1394 long xx
= XLOG2DEVMAC(x
);
1395 long yy
= YLOG2DEVMAC(y
);
1398 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1399 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1400 useDrawThemeText
= false ;
1405 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1406 SetAntiAliasedTextEnabled(true, 8);
1407 m_macAliasWasEnabled
= true ;
1410 ::GetFontInfo( &fi
) ;
1412 if ( !useDrawThemeText
)
1415 ::MoveTo( xx
, yy
);
1416 if ( m_backgroundMode
== wxTRANSPARENT
)
1418 ::TextMode( srcOr
) ;
1422 ::TextMode( srcCopy
) ;
1424 int length
= strtext
.Length() ;
1432 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1434 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1436 if ( useDrawThemeText
)
1438 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1439 wxMacCFStringHolder
mString( linetext
) ;
1440 if ( m_backgroundMode
!= wxTRANSPARENT
)
1442 Point bounds
={0,0} ;
1443 Rect background
= frame
;
1445 ::GetThemeTextDimensions( mString
,
1446 kThemeCurrentPortFont
,
1451 background
.right
= background
.left
+ bounds
.h
;
1452 background
.bottom
= background
.top
+ bounds
.v
;
1453 ::EraseRect( &background
) ;
1455 ::DrawThemeTextBox( mString
,
1456 kThemeCurrentPortFont
,
1467 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1468 ::DrawText( text
, 0 , strlen(text
) ) ;
1470 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1476 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1478 if ( useDrawThemeText
)
1480 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1481 wxMacCFStringHolder
mString( linetext
) ;
1483 if ( m_backgroundMode
!= wxTRANSPARENT
)
1485 Point bounds
={0,0} ;
1486 Rect background
= frame
;
1488 ::GetThemeTextDimensions( mString
,
1489 kThemeCurrentPortFont
,
1494 background
.right
= background
.left
+ bounds
.h
;
1495 background
.bottom
= background
.top
+ bounds
.v
;
1496 ::EraseRect( &background
) ;
1498 ::DrawThemeTextBox( mString
,
1499 kThemeCurrentPortFont
,
1509 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1510 ::DrawText( text
, 0 , strlen(text
) ) ;
1513 ::TextMode( srcOr
) ;
1516 bool wxDC::CanGetTextExtent() const
1518 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1522 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1523 wxCoord
*descent
, wxCoord
*externalLeading
,
1524 wxFont
*theFont
) const
1526 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1527 wxMacPortSetter
helper(this) ;
1528 wxFont formerFont
= m_font
;
1531 // work around the constness
1532 *((wxFont
*)(&m_font
)) = *theFont
;
1536 ::GetFontInfo( &fi
) ;
1538 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1539 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1540 useGetThemeText
= false ;
1543 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1545 *descent
=YDEV2LOGREL( fi
.descent
);
1546 if ( externalLeading
)
1547 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1548 int length
= strtext
.Length() ;
1550 const char *text = NULL ;
1552 if ( wxApp::s_macDefaultEncodingIsPC )
1554 macText = wxMacMakeMacStringFromPC( string ) ;
1556 length = macText.Length() ;
1561 length = string.Length() ;
1572 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1574 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1576 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1578 if ( useGetThemeText
)
1580 Point bounds
={0,0} ;
1582 wxMacCFStringHolder
mString( linetext
) ;
1583 ::GetThemeTextDimensions( mString
,
1584 kThemeCurrentPortFont
,
1589 curwidth
= bounds
.h
;
1594 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1595 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1597 if ( curwidth
> *width
)
1598 *width
= XDEV2LOGREL( curwidth
) ;
1604 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1606 if ( useGetThemeText
)
1608 Point bounds
={0,0} ;
1610 wxMacCFStringHolder
mString( linetext
) ;
1611 ::GetThemeTextDimensions( mString
,
1612 kThemeCurrentPortFont
,
1617 curwidth
= bounds
.h
;
1622 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1623 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1625 if ( curwidth
> *width
)
1626 *width
= XDEV2LOGREL( curwidth
) ;
1630 // work around the constness
1631 *((wxFont
*)(&m_font
)) = formerFont
;
1632 m_macFontInstalled
= false ;
1636 wxCoord
wxDC::GetCharWidth(void) const
1638 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1639 wxMacPortSetter
helper(this) ;
1643 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1644 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1645 useGetThemeText
= false ;
1649 if ( useGetThemeText
)
1651 Point bounds
={0,0} ;
1653 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1654 ::GetThemeTextDimensions( mString
,
1655 kThemeCurrentPortFont
,
1660 CFRelease( mString
) ;
1666 width
= ::TextWidth( text
, 0 , 1 ) ;
1668 return YDEV2LOGREL(width
) ;
1671 wxCoord
wxDC::GetCharHeight(void) const
1673 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1674 wxMacPortSetter
helper(this) ;
1677 ::GetFontInfo( &fi
) ;
1678 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1681 void wxDC::Clear(void)
1683 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1684 wxMacPortSetter
helper(this) ;
1685 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1686 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1689 //MacInstallBrush() ;
1690 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1691 ::EraseRect( &rect
) ;
1695 void wxDC::MacInstallFont() const
1697 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1698 // if ( m_macFontInstalled )
1700 Pattern blackColor
;
1701 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1702 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1705 ::TextFont( font
->m_macFontNum
) ;
1706 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1707 ::TextFace( font
->m_macFontStyle
) ;
1708 m_macFontInstalled
= true ;
1709 m_macBrushInstalled
= false ;
1710 m_macPenInstalled
= false ;
1711 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1712 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1713 ::RGBForeColor( &forecolor
);
1714 ::RGBBackColor( &backcolor
);
1718 FontFamilyID fontId
;
1722 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1723 GetFNum( fontName
, &fontId
);
1724 ::TextFont( fontId
) ;
1725 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1726 ::TextFace( fontStyle
) ;
1727 // todo reset after spacing changes - or store the current spacing somewhere
1728 m_macFontInstalled
= true ;
1729 m_macBrushInstalled
= false ;
1730 m_macPenInstalled
= false ;
1731 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1732 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1733 ::RGBForeColor( &forecolor
);
1734 ::RGBBackColor( &backcolor
);
1736 short mode
= patCopy
;
1738 switch( m_logicalFunction
)
1743 case wxINVERT
: // NOT dst
1744 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1747 case wxXOR
: // src XOR dst
1750 case wxOR_REVERSE
: // src OR (NOT dst)
1753 case wxSRC_INVERT
: // (NOT src)
1756 case wxAND
: // src AND dst
1761 case wxAND_REVERSE
:// src AND (NOT dst)
1762 case wxAND_INVERT
: // (NOT src) AND dst
1763 case wxNO_OP
: // dst
1764 case wxNOR
: // (NOT src) AND (NOT dst)
1765 case wxEQUIV
: // (NOT src) XOR dst
1766 case wxOR_INVERT
: // (NOT src) OR dst
1767 case wxNAND
: // (NOT src) OR (NOT dst)
1768 case wxOR
: // src OR dst
1770 // case wxSRC_OR: // source _bitmap_ OR destination
1771 // case wxSRC_AND: // source _bitmap_ AND destination
1775 OSStatus status
= noErr
;
1776 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1777 Style qdStyle
= font
->m_macFontStyle
;
1778 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1779 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1780 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1781 ATSUAttributeTag atsuTags
[] =
1786 // kATSUBaselineClassTag ,
1787 kATSUVerticalCharacterTag
,
1788 kATSUQDBoldfaceTag
,
1790 kATSUQDUnderlineTag
,
1791 kATSUQDCondensedTag
,
1792 kATSUQDExtendedTag
,
1794 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1796 sizeof( ATSUFontID
) ,
1798 // sizeof( RGBColor ) ,
1799 // sizeof( BslnBaselineClass ) ,
1800 sizeof( ATSUVerticalCharacterType
),
1807 Boolean kTrue
= true ;
1808 Boolean kFalse
= false ;
1809 BslnBaselineClass kBaselineDefault
= kBSLNHangingBaseline
;
1810 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1811 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1815 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1816 // &kBaselineDefault ,
1818 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1819 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1820 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1821 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1822 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1824 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1825 atsuTags
, atsuSizes
, atsuValues
);
1826 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1829 Pattern gHatchPatterns
[] =
1831 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1832 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1833 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1834 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1835 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1836 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1837 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1840 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1845 case wxBDIAGONAL_HATCH
:
1848 case wxFDIAGONAL_HATCH
:
1854 case wxHORIZONTAL_HATCH
:
1857 case wxVERTICAL_HATCH
:
1860 case wxCROSSDIAG_HATCH
:
1864 theIndex
= 1; // solid pattern
1867 *pattern
= gHatchPatterns
[theIndex
-1] ;
1870 void wxDC::MacInstallPen() const
1872 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1874 // if ( m_macPenInstalled )
1876 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1877 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1878 ::RGBForeColor( &forecolor
);
1879 ::RGBBackColor( &backcolor
);
1881 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1882 // null means only one pixel, at whatever resolution
1883 if ( penWidth
== 0 )
1885 ::PenSize(penWidth
, penWidth
);
1886 int penStyle
= m_pen
.GetStyle();
1887 if (penStyle
== wxSOLID
)
1889 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1891 else if (IS_HATCH(penStyle
))
1894 wxMacGetHatchPattern(penStyle
, &pat
);
1899 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1903 for ( int i
= 0 ; i
< 8 ; ++i
)
1909 for ( int i
= 0 ; i
< 8 ; ++i
)
1915 for ( int i
= 0 ; i
< 8 ; ++i
)
1921 for ( int i
= 0 ; i
< 8 ; ++i
)
1929 m_pen
.GetDashes(&dash
) ;
1930 // right now we don't allocate larger pixmaps
1932 m_pen
.GetDashes(&dash
) ;
1933 for ( int i
= 0 ; i
< 8 ; ++i
)
1935 pat
.pat
[i
] = dash
[0] ;
1942 short mode
= patCopy
;
1944 switch( m_logicalFunction
)
1946 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1949 case wxINVERT
: // NOT dst
1950 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1953 case wxXOR
: // src XOR dst
1956 case wxOR_REVERSE
: // src OR (NOT dst)
1959 case wxSRC_INVERT
: // (NOT src)
1962 case wxAND
: // src AND dst
1967 case wxAND_REVERSE
:// src AND (NOT dst)
1968 case wxAND_INVERT
: // (NOT src) AND dst
1969 case wxNO_OP
: // dst
1970 case wxNOR
: // (NOT src) AND (NOT dst)
1971 case wxEQUIV
: // (NOT src) XOR dst
1972 case wxOR_INVERT
: // (NOT src) OR dst
1973 case wxNAND
: // (NOT src) OR (NOT dst)
1974 case wxOR
: // src OR dst
1976 // case wxSRC_OR: // source _bitmap_ OR destination
1977 // case wxSRC_AND: // source _bitmap_ AND destination
1981 m_macPenInstalled
= true ;
1982 m_macBrushInstalled
= false ;
1983 m_macFontInstalled
= false ;
1986 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1988 Pattern whiteColor
;
1989 switch( background
.MacGetBrushKind() )
1991 case kwxMacBrushTheme
:
1993 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1996 case kwxMacBrushThemeBackground
:
1999 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2000 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2003 case kwxMacBrushColour
:
2005 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2006 int brushStyle
= background
.GetStyle();
2007 if (brushStyle
== wxSOLID
)
2008 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2009 else if (IS_HATCH(brushStyle
))
2012 wxMacGetHatchPattern(brushStyle
, &pat
);
2017 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2024 void wxDC::MacInstallBrush() const
2026 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2027 Pattern blackColor
;
2028 // if ( m_macBrushInstalled )
2031 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2032 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2033 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2034 int brushStyle
= m_brush
.GetStyle();
2035 if (brushStyle
== wxSOLID
)
2037 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2039 else if (IS_HATCH(brushStyle
))
2042 wxMacGetHatchPattern(brushStyle
, &pat
);
2045 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2047 // we force this in order to be compliant with wxMSW
2048 backgroundTransparent
= false ;
2049 // for these the text fore (and back for MASK_OPAQUE) colors are used
2050 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2051 int width
= bitmap
->GetWidth() ;
2052 int height
= bitmap
->GetHeight() ;
2053 GWorldPtr gw
= NULL
;
2054 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2055 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2057 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2058 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2059 LockPixels( gwpixmaphandle
) ;
2060 bool isMonochrome
= !IsPortColor( gw
) ;
2061 if ( !isMonochrome
)
2063 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2064 isMonochrome
= true ;
2066 if ( isMonochrome
&& width
== 8 && height
== 8 )
2068 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2069 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2070 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2071 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2072 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2074 for ( int i
= 0 ; i
< 8 ; ++i
)
2076 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2078 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2083 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2084 // caching scheme before putting this into production
2087 PixPatHandle pixpat
= NewPixPat() ;
2088 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2089 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2090 ((**(**pixpat
).patMap
).bounds
.bottom
-
2091 (**(**pixpat
).patMap
).bounds
.top
);
2092 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2093 (**pixpat
).patData
= image
;
2096 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2097 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2098 if ( ctspec
[0].rgb
.red
== 0x0000 )
2100 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2101 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2105 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2106 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2108 ::CTabChanged( ctable
) ;
2110 ::PenPixPat(pixpat
);
2111 m_macForegroundPixMap
= pixpat
;
2113 UnlockPixels( gwpixmaphandle
) ;
2117 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2119 short mode
= patCopy
;
2120 switch( m_logicalFunction
)
2123 if ( backgroundTransparent
)
2128 case wxINVERT
: // NOT dst
2129 if ( !backgroundTransparent
)
2131 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2135 case wxXOR
: // src XOR dst
2138 case wxOR_REVERSE
: // src OR (NOT dst)
2141 case wxSRC_INVERT
: // (NOT src)
2144 case wxAND
: // src AND dst
2149 case wxAND_REVERSE
:// src AND (NOT dst)
2150 case wxAND_INVERT
: // (NOT src) AND dst
2151 case wxNO_OP
: // dst
2152 case wxNOR
: // (NOT src) AND (NOT dst)
2153 case wxEQUIV
: // (NOT src) XOR dst
2154 case wxOR_INVERT
: // (NOT src) OR dst
2155 case wxNAND
: // (NOT src) OR (NOT dst)
2156 case wxOR
: // src OR dst
2158 // case wxSRC_OR: // source _bitmap_ OR destination
2159 // case wxSRC_AND: // source _bitmap_ AND destination
2163 m_macBrushInstalled
= true ;
2164 m_macPenInstalled
= false ;
2165 m_macFontInstalled
= false ;
2168 // ---------------------------------------------------------------------------
2169 // coordinates transformations
2170 // ---------------------------------------------------------------------------
2172 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2174 return ((wxDC
*)this)->XDEV2LOG(x
);
2177 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2179 return ((wxDC
*)this)->YDEV2LOG(y
);
2182 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2184 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2187 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2189 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2192 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2194 return ((wxDC
*)this)->XLOG2DEV(x
);
2197 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2199 return ((wxDC
*)this)->YLOG2DEV(y
);
2202 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2204 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2207 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2209 return ((wxDC
*)this)->YLOG2DEVREL(y
);