1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dc.h"
16 #include "wx/mac/uma.h"
17 #include "wx/dcmemory.h"
18 #include "wx/region.h"
26 #include "wx/mac/private.h"
27 #include "ATSUnicode.h"
28 #include "TextCommon.h"
29 #include "TextEncodingConverter.h"
30 #if !USE_SHARED_LIBRARY
31 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 #define mm2inches 0.0393700787402
37 #define inches2mm 25.4
38 #define mm2twips 56.6929133859
39 #define twips2mm 0.0176388888889
40 #define mm2pt 2.83464566929
41 #define pt2mm 0.352777777778
43 const double M_PI
= 3.14159265358979 ;
45 const double RAD2DEG
= 180.0 / M_PI
;
46 const short kEmulatedMode
= -1 ;
47 const short kUnsupportedMode
= -2 ;
48 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
49 m_ph( (GrafPtr
) dc
->m_macPort
)
51 wxASSERT( dc
->Ok() ) ;
53 dc
->MacSetupPort(&m_ph
) ;
55 wxMacPortSetter::~wxMacPortSetter()
57 m_dc
->MacCleanupPort(&m_ph
) ;
59 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
61 m_formerClip
= NewRgn() ;
62 m_newClip
= NewRgn() ;
63 GetClip( m_formerClip
) ;
68 // this clipping area was set to the parent window's drawing area, lead to problems
69 // with MacOSX controls drawing outside their wx' rectangle
70 RgnHandle insidergn
= NewRgn() ;
72 wxWindow
*parent
= win
->GetParent() ;
73 parent
->MacWindowToRootWindow( &x
,&y
) ;
74 wxSize size
= parent
->GetSize() ;
75 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
76 size
.x
- parent
->MacGetRightBorderSize(),
77 size
.y
- parent
->MacGetBottomBorderSize()) ;
78 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
79 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
80 OffsetRgn( m_newClip
, x
, y
) ;
81 SetClip( m_newClip
) ;
82 DisposeRgn( insidergn
) ;
84 RgnHandle insidergn
= NewRgn() ;
86 win
->MacWindowToRootWindow( &x
,&y
) ;
87 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
88 OffsetRgn( m_newClip
, x
, y
) ;
89 SetClip( m_newClip
) ;
92 wxMacWindowClipper::~wxMacWindowClipper()
94 SetClip( m_formerClip
) ;
95 DisposeRgn( m_newClip
) ;
96 DisposeRgn( m_formerClip
) ;
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
101 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
102 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
103 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 // this function emulates all wx colour manipulations, used to verify the implementation
108 // by setting the mode in the blitting functions to kEmulatedMode
109 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
110 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
112 switch ( logical_func
)
114 case wxAND
: // src AND dst
115 dstColor
.red
= dstColor
.red
& srcColor
.red
;
116 dstColor
.green
= dstColor
.green
& srcColor
.green
;
117 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
119 case wxAND_INVERT
: // (NOT src) AND dst
120 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
121 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
122 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
124 case wxAND_REVERSE
:// src AND (NOT dst)
125 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
126 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
127 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
135 dstColor
.red
= srcColor
.red
;
136 dstColor
.green
= srcColor
.green
;
137 dstColor
.blue
= srcColor
.blue
;
139 case wxEQUIV
: // (NOT src) XOR dst
140 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
141 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
142 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
144 case wxINVERT
: // NOT dst
145 dstColor
.red
= ~dstColor
.red
;
146 dstColor
.green
= ~dstColor
.green
;
147 dstColor
.blue
= ~dstColor
.blue
;
149 case wxNAND
: // (NOT src) OR (NOT dst)
150 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
151 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
152 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
154 case wxNOR
: // (NOT src) AND (NOT dst)
155 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
156 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
157 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
161 case wxOR
: // src OR dst
162 dstColor
.red
= dstColor
.red
| srcColor
.red
;
163 dstColor
.green
= dstColor
.green
| srcColor
.green
;
164 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
166 case wxOR_INVERT
: // (NOT src) OR dst
167 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
168 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
169 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
171 case wxOR_REVERSE
: // src OR (NOT dst)
172 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
173 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
174 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
177 dstColor
.red
= 0xFFFF ;
178 dstColor
.green
= 0xFFFF ;
179 dstColor
.blue
= 0xFFFF ;
181 case wxSRC_INVERT
: // (NOT src)
182 dstColor
.red
= ~srcColor
.red
;
183 dstColor
.green
= ~srcColor
.green
;
184 dstColor
.blue
= ~srcColor
.blue
;
186 case wxXOR
: // src XOR dst
187 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
188 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
189 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
197 m_mm_to_pix_x
= mm2pt
;
198 m_mm_to_pix_y
= mm2pt
;
199 m_internalDeviceOriginX
= 0;
200 m_internalDeviceOriginY
= 0;
201 m_externalDeviceOriginX
= 0;
202 m_externalDeviceOriginY
= 0;
203 m_logicalScaleX
= 1.0;
204 m_logicalScaleY
= 1.0;
209 m_needComputeScaleX
= FALSE
;
210 m_needComputeScaleY
= FALSE
;
214 m_macFontInstalled
= false ;
215 m_macBrushInstalled
= false ;
216 m_macPenInstalled
= false ;
217 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
218 m_macBoundaryClipRgn
= NewRgn() ;
219 m_macCurrentClipRgn
= NewRgn() ;
220 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
221 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
222 m_pen
= *wxBLACK_PEN
;
223 m_font
= *wxNORMAL_FONT
;
224 m_brush
= *wxWHITE_BRUSH
;
225 m_macCurrentPortStateHelper
= NULL
;
226 m_macATSUIStyle
= NULL
;
227 m_macAliasWasEnabled
= false;
228 m_macForegroundPixMap
= NULL
;
229 m_macBackgroundPixMap
= NULL
;
233 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
234 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
236 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
238 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
239 m_macCurrentPortStateHelper
= help
;
240 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
241 m_macFontInstalled
= false ;
242 m_macBrushInstalled
= false ;
243 m_macPenInstalled
= false ;
245 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
247 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
248 m_macCurrentPortStateHelper
= NULL
;
249 if( m_macATSUIStyle
)
251 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
252 m_macATSUIStyle
= NULL
;
254 if ( m_macAliasWasEnabled
)
256 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
257 m_macAliasWasEnabled
= false ;
259 if ( m_macForegroundPixMap
)
262 ::PenPat(GetQDGlobalsBlack(&blackColor
));
263 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
264 m_macForegroundPixMap
= NULL
;
266 if ( m_macBackgroundPixMap
)
269 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
270 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
271 m_macBackgroundPixMap
= NULL
;
274 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
276 wxCHECK_RET( Ok(), wxT("invalid window dc") );
277 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
278 wxMacPortSetter
helper(this) ;
279 wxCoord xx
= XLOG2DEVMAC(x
);
280 wxCoord yy
= YLOG2DEVMAC(y
);
281 wxCoord w
= bmp
.GetWidth();
282 wxCoord h
= bmp
.GetHeight();
283 wxCoord ww
= XLOG2DEVREL(w
);
284 wxCoord hh
= YLOG2DEVREL(h
);
285 // Set up drawing mode
286 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
287 //m_logicalFunction == wxCLEAR ? WHITENESS :
288 //m_logicalFunction == wxSET ? BLACKNESS :
289 m_logicalFunction
== wxINVERT
? hilite
:
290 //m_logicalFunction == wxAND ? MERGECOPY :
291 m_logicalFunction
== wxOR
? srcOr
:
292 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
293 m_logicalFunction
== wxXOR
? srcXor
:
294 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
295 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
296 //m_logicalFunction == wxSRC_OR ? srcOr :
297 //m_logicalFunction == wxSRC_AND ? SRCAND :
299 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
300 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
301 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
302 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
304 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
306 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
307 PixMapHandle bmappixels
;
308 // Set foreground and background colours (for bitmaps depth = 1)
309 if(bmp
.GetDepth() == 1)
311 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
312 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
318 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
319 RGBColor black
= { 0,0,0} ;
320 RGBForeColor( &black
) ;
321 RGBBackColor( &white
) ;
323 bmappixels
= GetGWorldPixMap( bmapworld
) ;
324 wxCHECK_RET(LockPixels(bmappixels
),
325 wxT("DoDrawBitmap: Unable to lock pixels"));
326 Rect source
= { 0, 0, h
, w
};
327 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
328 if ( useMask
&& bmp
.GetMask() )
330 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
334 GetPortBitMapForCopyBits(bmapworld
),
335 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
336 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
337 &source
, &source
, &dest
, mode
, NULL
339 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
343 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
344 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
345 &source
, &dest
, mode
, NULL
) ;
347 UnlockPixels( bmappixels
) ;
349 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
351 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
352 OffsetRect( &bitmaprect
, xx
, yy
) ;
353 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
355 m_macPenInstalled
= false ;
356 m_macBrushInstalled
= false ;
357 m_macFontInstalled
= false ;
359 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
361 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
362 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
363 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
365 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
367 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
368 wxCoord xx
, yy
, ww
, hh
;
371 ww
= XLOG2DEVREL(width
);
372 hh
= YLOG2DEVREL(height
);
373 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
374 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
377 m_clipX1
= wxMax( m_clipX1
, xx
);
378 m_clipY1
= wxMax( m_clipY1
, yy
);
379 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
380 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
391 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
393 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
394 wxMacPortSetter
helper(this) ;
397 DestroyClippingRegion();
401 region
.GetBox( x
, y
, w
, h
);
402 wxCoord xx
, yy
, ww
, hh
;
407 // if we have a scaling that we cannot map onto native regions
408 // we must use the box
409 if ( ww
!= w
|| hh
!= h
)
411 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
415 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
416 if ( xx
!= x
|| yy
!= y
)
418 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
420 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
423 m_clipX1
= wxMax( m_clipX1
, xx
);
424 m_clipY1
= wxMax( m_clipY1
, yy
);
425 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
426 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
438 void wxDC::DestroyClippingRegion()
440 wxMacPortSetter
helper(this) ;
441 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
444 void wxDC::DoGetSize( int* width
, int* height
) const
446 *width
= m_maxX
-m_minX
;
447 *height
= m_maxY
-m_minY
;
449 void wxDC::DoGetSizeMM( int* width
, int* height
) const
454 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
455 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
457 void wxDC::SetTextForeground( const wxColour
&col
)
459 wxCHECK_RET(Ok(), wxT("Invalid DC"));
460 m_textForegroundColour
= col
;
461 m_macFontInstalled
= false ;
463 void wxDC::SetTextBackground( const wxColour
&col
)
465 wxCHECK_RET(Ok(), wxT("Invalid DC"));
466 m_textBackgroundColour
= col
;
467 m_macFontInstalled
= false ;
469 void wxDC::SetMapMode( int mode
)
474 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
477 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
480 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
483 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
487 SetLogicalScale( 1.0, 1.0 );
490 if (mode
!= wxMM_TEXT
)
492 m_needComputeScaleX
= TRUE
;
493 m_needComputeScaleY
= TRUE
;
496 void wxDC::SetUserScale( double x
, double y
)
498 // allow negative ? -> no
501 ComputeScaleAndOrigin();
503 void wxDC::SetLogicalScale( double x
, double y
)
508 ComputeScaleAndOrigin();
510 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
512 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
513 m_logicalOriginY
= y
* m_signY
;
514 ComputeScaleAndOrigin();
516 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
518 m_externalDeviceOriginX
= x
;
519 m_externalDeviceOriginY
= y
;
520 ComputeScaleAndOrigin();
523 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
525 m_internalDeviceOriginX
= x
;
526 m_internalDeviceOriginY
= y
;
527 ComputeScaleAndOrigin();
529 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
531 if (x
) *x
= m_internalDeviceOriginX
;
532 if (y
) *y
= m_internalDeviceOriginY
;
535 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
537 m_signX
= (xLeftRight
? 1 : -1);
538 m_signY
= (yBottomUp
? -1 : 1);
539 ComputeScaleAndOrigin();
541 wxSize
wxDC::GetPPI() const
543 return wxSize(72, 72);
545 int wxDC::GetDepth() const
547 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
549 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
553 void wxDC::ComputeScaleAndOrigin()
555 // CMB: copy scale to see if it changes
556 double origScaleX
= m_scaleX
;
557 double origScaleY
= m_scaleY
;
558 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
559 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
560 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
561 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
562 // CMB: if scale has changed call SetPen to recalulate the line width
563 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
565 // this is a bit artificial, but we need to force wxDC to think
566 // the pen has changed
567 wxPen
* pen
= & GetPen();
573 void wxDC::SetPalette( const wxPalette
& palette
)
576 void wxDC::SetBackgroundMode( int mode
)
578 m_backgroundMode
= mode
;
580 void wxDC::SetFont( const wxFont
&font
)
583 m_macFontInstalled
= false ;
585 void wxDC::SetPen( const wxPen
&pen
)
590 m_macPenInstalled
= false ;
592 void wxDC::SetBrush( const wxBrush
&brush
)
594 if (m_brush
== brush
)
597 m_macBrushInstalled
= false ;
599 void wxDC::SetBackground( const wxBrush
&brush
)
601 if (m_backgroundBrush
== brush
)
603 m_backgroundBrush
= brush
;
604 if (!m_backgroundBrush
.Ok())
606 m_macBrushInstalled
= false ;
608 void wxDC::SetLogicalFunction( int function
)
610 if (m_logicalFunction
== function
)
612 m_logicalFunction
= function
;
613 m_macFontInstalled
= false ;
614 m_macBrushInstalled
= false ;
615 m_macPenInstalled
= false ;
617 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
618 const wxColour
& col
, int style
);
619 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
620 const wxColour
& col
, int style
)
622 return wxDoFloodFill(this, x
, y
, col
, style
);
624 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
626 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
627 wxMacPortSetter
helper(this) ;
629 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
630 // Convert from Mac colour to wx
631 col
->Set( colour
.red
>> 8,
636 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
638 wxCHECK_RET(Ok(), wxT("Invalid DC"));
639 wxMacPortSetter
helper(this) ;
640 if (m_pen
.GetStyle() != wxTRANSPARENT
)
643 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
644 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
645 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
646 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
647 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
648 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
649 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
650 (m_pen
.GetWidth() <= 1))
652 // Implement LAST_NOT for MAC at least for
653 // orthogonal lines. RR.
673 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
675 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
676 wxMacPortSetter
helper(this) ;
677 if (m_pen
.GetStyle() != wxTRANSPARENT
)
682 wxCoord xx
= XLOG2DEVMAC(x
);
683 wxCoord yy
= YLOG2DEVMAC(y
);
685 ::MoveTo( XLOG2DEVMAC(0), yy
);
686 ::LineTo( XLOG2DEVMAC(w
), yy
);
687 ::MoveTo( xx
, YLOG2DEVMAC(0) );
688 ::LineTo( xx
, YLOG2DEVMAC(h
) );
689 CalcBoundingBox(x
, y
);
690 CalcBoundingBox(x
+w
, y
+h
);
694 * To draw arcs properly the angles need to be converted from the WX style:
695 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
696 * a normal axis on paper).
699 * Angles start on the +ve y axis and go clockwise.
701 static double wxConvertWXangleToMACangle(double angle
)
703 double newAngle
= 90 - angle
;
708 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
709 wxCoord x2
, wxCoord y2
,
710 wxCoord xc
, wxCoord yc
)
712 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
713 wxMacPortSetter
helper(this) ;
714 wxCoord xx1
= XLOG2DEVMAC(x1
);
715 wxCoord yy1
= YLOG2DEVMAC(y1
);
716 wxCoord xx2
= XLOG2DEVMAC(x2
);
717 wxCoord yy2
= YLOG2DEVMAC(y2
);
718 wxCoord xxc
= XLOG2DEVMAC(xc
);
719 wxCoord yyc
= YLOG2DEVMAC(yc
);
720 double dx
= xx1
- xxc
;
721 double dy
= yy1
- yyc
;
722 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
723 wxCoord rad
= (wxCoord
)radius
;
724 double radius1
, radius2
;
725 if (xx1
== xx2
&& yy1
== yy2
)
730 else if (radius
== 0.0)
732 radius1
= radius2
= 0.0;
736 radius1
= (xx1
- xxc
== 0) ?
737 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
738 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
739 radius2
= (xx2
- xxc
== 0) ?
740 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
741 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
743 wxCoord alpha2
= wxCoord(radius2
- radius1
);
744 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
745 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
748 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
749 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
751 PaintArc(&r
, alpha1
, alpha2
);
753 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
755 FrameArc(&r
, alpha1
, alpha2
);
758 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
759 double sa
, double ea
)
761 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
762 wxMacPortSetter
helper(this) ;
764 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
765 // we have to make sure that the filling is always counter-clockwise
768 wxCoord xx
= XLOG2DEVMAC(x
);
769 wxCoord yy
= YLOG2DEVMAC(y
);
770 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
771 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
772 // handle -ve width and/or height
773 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
774 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
775 sa
= wxConvertWXangleToMACangle(sa
);
780 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
782 PaintArc(&r
, (short)sa
, (short)angle
);
784 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
786 FrameArc(&r
, (short)sa
, (short)angle
);
789 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
791 wxCHECK_RET(Ok(), wxT("Invalid DC"));
792 wxMacPortSetter
helper(this) ;
793 if (m_pen
.GetStyle() != wxTRANSPARENT
)
795 wxCoord xx1
= XLOG2DEVMAC(x
);
796 wxCoord yy1
= YLOG2DEVMAC(y
);
797 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
798 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
799 CalcBoundingBox(x
, y
);
802 void wxDC::DoDrawLines(int n
, wxPoint points
[],
803 wxCoord xoffset
, wxCoord yoffset
)
805 wxCHECK_RET(Ok(), wxT("Invalid DC"));
806 wxMacPortSetter
helper(this) ;
807 if (m_pen
.GetStyle() == wxTRANSPARENT
)
810 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
811 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
812 wxCoord x1
, x2
, y1
, y2
;
813 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
814 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
815 ::MoveTo(x1
- offset
, y1
- offset
);
816 for (int i
= 0; i
< n
-1; i
++)
818 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
819 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
820 ::LineTo( x2
- offset
, y2
- offset
);
823 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
824 wxCoord xoffset
, wxCoord yoffset
,
827 wxCHECK_RET(Ok(), wxT("Invalid DC"));
828 wxMacPortSetter
helper(this) ;
829 wxCoord x1
, x2
, y1
, y2
;
830 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
832 PolyHandle polygon
= OpenPoly();
833 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
834 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
836 for (int i
= 1; i
< n
; i
++)
838 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
839 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
842 // close the polyline if necessary
843 if ( x1
!= x2
|| y1
!= y2
)
848 if (m_brush
.GetStyle() != wxTRANSPARENT
)
851 ::PaintPoly( polygon
);
853 if (m_pen
.GetStyle() != wxTRANSPARENT
)
856 ::FramePoly( polygon
) ;
860 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
862 wxCHECK_RET(Ok(), wxT("Invalid DC"));
863 wxMacPortSetter
helper(this) ;
864 wxCoord xx
= XLOG2DEVMAC(x
);
865 wxCoord yy
= YLOG2DEVMAC(y
);
866 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
867 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
868 // CMB: draw nothing if transformed w or h is 0
869 if (ww
== 0 || hh
== 0)
871 // CMB: handle -ve width and/or height
882 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
883 if (m_brush
.GetStyle() != wxTRANSPARENT
)
886 ::PaintRect( &rect
) ;
888 if (m_pen
.GetStyle() != wxTRANSPARENT
)
891 ::FrameRect( &rect
) ;
894 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
895 wxCoord width
, wxCoord height
,
898 wxCHECK_RET(Ok(), wxT("Invalid DC"));
899 wxMacPortSetter
helper(this) ;
901 radius
= - radius
* ((width
< height
) ? width
: height
);
902 wxCoord xx
= XLOG2DEVMAC(x
);
903 wxCoord yy
= YLOG2DEVMAC(y
);
904 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
905 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
906 // CMB: draw nothing if transformed w or h is 0
907 if (ww
== 0 || hh
== 0)
909 // CMB: handle -ve width and/or height
920 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
921 if (m_brush
.GetStyle() != wxTRANSPARENT
)
924 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
926 if (m_pen
.GetStyle() != wxTRANSPARENT
)
929 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
932 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
934 wxCHECK_RET(Ok(), wxT("Invalid DC"));
935 wxMacPortSetter
helper(this) ;
936 wxCoord xx
= XLOG2DEVMAC(x
);
937 wxCoord yy
= YLOG2DEVMAC(y
);
938 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
939 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
940 // CMB: draw nothing if transformed w or h is 0
941 if (ww
== 0 || hh
== 0)
943 // CMB: handle -ve width and/or height
954 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
955 if (m_brush
.GetStyle() != wxTRANSPARENT
)
958 ::PaintOval( &rect
) ;
960 if (m_pen
.GetStyle() != wxTRANSPARENT
)
963 ::FrameOval( &rect
) ;
968 bool wxDC::CanDrawBitmap(void) const
973 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
974 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
975 wxCoord xsrcMask
, wxCoord ysrcMask
)
977 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
978 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
979 if ( logical_func
== wxNO_OP
)
981 if (xsrcMask
== -1 && ysrcMask
== -1)
983 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
985 // correct the parameter in case this dc does not have a mask at all
986 if ( useMask
&& !source
->m_macMask
)
988 Rect srcrect
, dstrect
;
989 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
990 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
991 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
992 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
993 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
994 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
995 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
996 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
997 short mode
= kUnsupportedMode
;
998 bool invertDestinationFirst
= false ;
999 switch ( logical_func
)
1001 case wxAND
: // src AND dst
1002 mode
= srcOr
; // ok
1004 case wxAND_INVERT
: // (NOT src) AND dst
1005 mode
= notSrcOr
; // ok
1007 case wxAND_REVERSE
:// src AND (NOT dst)
1008 invertDestinationFirst
= true ;
1012 mode
= kEmulatedMode
;
1015 mode
= srcCopy
; // ok
1017 case wxEQUIV
: // (NOT src) XOR dst
1018 mode
= srcXor
; // ok
1020 case wxINVERT
: // NOT dst
1021 mode
= kEmulatedMode
; //or hilite ;
1023 case wxNAND
: // (NOT src) OR (NOT dst)
1024 invertDestinationFirst
= true ;
1027 case wxNOR
: // (NOT src) AND (NOT dst)
1028 invertDestinationFirst
= true ;
1031 case wxNO_OP
: // dst
1032 mode
= kEmulatedMode
; // this has already been handled upon entry
1034 case wxOR
: // src OR dst
1037 case wxOR_INVERT
: // (NOT src) OR dst
1040 case wxOR_REVERSE
: // src OR (NOT dst)
1041 invertDestinationFirst
= true ;
1045 mode
= kEmulatedMode
;
1047 case wxSRC_INVERT
: // (NOT src)
1048 mode
= notSrcCopy
; // ok
1050 case wxXOR
: // src XOR dst
1051 mode
= notSrcXor
; // ok
1056 if ( mode
== kUnsupportedMode
)
1058 wxFAIL_MSG("unsupported blitting mode" );
1061 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1062 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1063 if ( LockPixels(bmappixels
) )
1065 wxMacPortSetter
helper(this) ;
1066 if ( source
->GetDepth() == 1 )
1068 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1069 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1073 // the modes need this, otherwise we'll end up having really nice colors...
1074 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1075 RGBColor black
= { 0,0,0} ;
1076 RGBForeColor( &black
) ;
1077 RGBBackColor( &white
) ;
1079 if ( useMask
&& source
->m_macMask
)
1081 if ( mode
== srcCopy
)
1083 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1085 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1086 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1087 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1088 &srcrect
, &srcrect
, &dstrect
) ;
1089 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1094 RgnHandle clipRgn
= NewRgn() ;
1095 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1096 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1097 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1098 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1099 if ( mode
== kEmulatedMode
)
1102 ::PenPat(GetQDGlobalsBlack(&pat
));
1103 if ( logical_func
== wxSET
)
1105 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1106 ::RGBForeColor( &col
) ;
1107 ::PaintRgn( clipRgn
) ;
1109 else if ( logical_func
== wxCLEAR
)
1111 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1112 ::RGBForeColor( &col
) ;
1113 ::PaintRgn( clipRgn
) ;
1115 else if ( logical_func
== wxINVERT
)
1117 MacInvertRgn( clipRgn
) ;
1121 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1123 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1125 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1126 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1127 if ( PtInRgn( dstPoint
, clipRgn
) )
1131 SetPort( (GrafPtr
) sourcePort
) ;
1132 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1133 SetPort( (GrafPtr
) m_macPort
) ;
1134 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1135 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1136 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1144 if ( invertDestinationFirst
)
1146 MacInvertRgn( clipRgn
) ;
1148 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1149 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1150 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1152 DisposeRgn( clipRgn
) ;
1157 RgnHandle clipRgn
= NewRgn() ;
1158 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1159 if ( mode
== kEmulatedMode
)
1162 ::PenPat(GetQDGlobalsBlack(&pat
));
1163 if ( logical_func
== wxSET
)
1165 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1166 ::RGBForeColor( &col
) ;
1167 ::PaintRgn( clipRgn
) ;
1169 else if ( logical_func
== wxCLEAR
)
1171 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1172 ::RGBForeColor( &col
) ;
1173 ::PaintRgn( clipRgn
) ;
1175 else if ( logical_func
== wxINVERT
)
1177 MacInvertRgn( clipRgn
) ;
1181 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1183 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1185 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1186 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
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
, NULL
) ;
1211 DisposeRgn( clipRgn
) ;
1213 UnlockPixels( bmappixels
) ;
1215 m_macPenInstalled
= false ;
1216 m_macBrushInstalled
= false ;
1217 m_macFontInstalled
= false ;
1220 inline Fixed
IntToFixed( int inInt
)
1222 return (((SInt32
) inInt
) << 16);
1224 inline int FixedToInt( Fixed inFixed
)
1226 return (((SInt32
) inFixed
) >> 16);
1229 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1232 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1235 DrawText(str
, x
, y
);
1238 if ( str
.Length() == 0 )
1240 wxMacPortSetter
helper(this) ;
1243 if ( wxApp::s_macDefaultEncodingIsPC
)
1245 text
= wxMacMakeMacStringFromPC( str
) ;
1251 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1254 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1255 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1256 m_macAliasWasEnabled
= true ;
1258 OSStatus status
= noErr
;
1260 status
= TECCreateConverter(&ec
, kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1261 wxASSERT_MSG( status
== noErr
, "couldn't start converter" ) ;
1262 ByteCount byteOutLen
;
1263 ByteCount byteInLen
= text
.Length() ;
1264 ByteCount byteBufferLen
= byteInLen
*2 ;
1265 char* buf
= new char[byteBufferLen
] ;
1266 status
= TECConvertText(ec
, (ConstTextPtr
)text
.c_str() , byteInLen
, &byteInLen
,
1267 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1268 wxASSERT_MSG( status
== noErr
, "couldn't convert text" ) ;
1269 status
= TECDisposeConverter(ec
);
1270 wxASSERT_MSG( status
== noErr
, "couldn't dispose converter" ) ;
1271 ATSUTextLayout atsuLayout
;
1272 UniCharCount chars
= byteOutLen
/ 2 ;
1273 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1274 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1275 wxASSERT_MSG( status
== noErr
, "couldn't create the layout of the rotated text" );
1276 int iAngle
= int( angle
);
1277 int drawX
= XLOG2DEVMAC(x
) ;
1278 int drawY
= YLOG2DEVMAC(y
) ;
1280 ATSUTextMeasurement textBefore
;
1281 ATSUTextMeasurement textAfter
;
1282 ATSUTextMeasurement ascent
;
1283 ATSUTextMeasurement descent
;
1286 if ( abs(iAngle
) > 0 )
1288 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1289 ATSUAttributeTag atsuTags
[] =
1291 kATSULineRotationTag
,
1293 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1297 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1301 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1302 atsuTags
, atsuSizes
, atsuValues
) ;
1304 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1305 &textBefore
, &textAfter
, &ascent
, &descent
);
1307 drawX
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1308 drawY
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1309 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1310 IntToFixed(drawX
) , IntToFixed(drawY
) );
1311 wxASSERT_MSG( status
== noErr
, "couldn't draw the rotated text" );
1313 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1314 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1315 wxASSERT_MSG( status
== noErr
, "couldn't measure the rotated text" );
1316 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1317 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1318 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1319 ::ATSUDisposeTextLayout(atsuLayout
);
1322 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1324 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1325 wxMacPortSetter
helper(this) ;
1326 long xx
= XLOG2DEVMAC(x
);
1327 long yy
= YLOG2DEVMAC(y
);
1329 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1330 if ( m_font
.GetNoAntiAliasing() )
1331 useDrawThemeText
= false ;
1336 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1337 SetAntiAliasedTextEnabled(true, 8);
1338 m_macAliasWasEnabled
= true ;
1341 ::GetFontInfo( &fi
) ;
1343 if ( !useDrawThemeText
)
1346 ::MoveTo( xx
, yy
);
1347 if ( m_backgroundMode
== wxTRANSPARENT
)
1349 ::TextMode( srcOr
) ;
1353 ::TextMode( srcCopy
) ;
1355 const char *text
= NULL
;
1358 if ( wxApp::s_macDefaultEncodingIsPC
)
1360 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1362 length
= macText
.Length() ;
1367 length
= strtext
.Length() ;
1375 if( text
[i
] == 13 || text
[i
] == 10)
1378 if ( useDrawThemeText
)
1380 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1381 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1382 if ( m_backgroundMode
!= wxTRANSPARENT
)
1384 Point bounds
={0,0} ;
1385 Rect background
= frame
;
1387 ::GetThemeTextDimensions( mString
,
1388 kThemeCurrentPortFont
,
1393 background
.right
= background
.left
+ bounds
.h
;
1394 background
.bottom
= background
.top
+ bounds
.v
;
1395 ::EraseRect( &background
) ;
1397 ::DrawThemeTextBox( mString
,
1398 kThemeCurrentPortFont
,
1404 CFRelease( mString
) ;
1410 ::DrawText( text
, laststop
, i
- laststop
) ;
1412 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1419 if ( useDrawThemeText
)
1421 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1422 CFStringRef mString
= CFStringCreateWithCString( NULL
, text
+ laststop
, kCFStringEncodingMacRoman
) ;
1423 if ( m_backgroundMode
!= wxTRANSPARENT
)
1425 Point bounds
={0,0} ;
1426 Rect background
= frame
;
1428 ::GetThemeTextDimensions( mString
,
1429 kThemeCurrentPortFont
,
1434 background
.right
= background
.left
+ bounds
.h
;
1435 background
.bottom
= background
.top
+ bounds
.v
;
1436 ::EraseRect( &background
) ;
1438 ::DrawThemeTextBox( mString
,
1439 kThemeCurrentPortFont
,
1445 CFRelease( mString
) ;
1450 ::DrawText( text
, laststop
, i
- laststop
) ;
1453 ::TextMode( srcOr
) ;
1455 bool wxDC::CanGetTextExtent() const
1457 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1460 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1461 wxCoord
*descent
, wxCoord
*externalLeading
,
1462 wxFont
*theFont
) const
1464 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1465 wxMacPortSetter
helper(this) ;
1466 wxFont formerFont
= m_font
;
1469 // work around the constness
1470 *((wxFont
*)(&m_font
)) = *theFont
;
1474 ::GetFontInfo( &fi
) ;
1476 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1477 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1478 useGetThemeText
= false ;
1481 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1483 *descent
=YDEV2LOGREL( fi
.descent
);
1484 if ( externalLeading
)
1485 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1486 const char *text
= NULL
;
1489 if ( wxApp::s_macDefaultEncodingIsPC
)
1491 macText
= wxMacMakeMacStringFromPC( string
) ;
1493 length
= macText
.Length() ;
1498 length
= string
.Length() ;
1508 if( text
[i
] == 13 || text
[i
] == 10)
1511 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1513 if ( useGetThemeText
)
1515 Point bounds
={0,0} ;
1517 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1518 ::GetThemeTextDimensions( mString
,
1519 kThemeCurrentPortFont
,
1524 CFRelease( mString
) ;
1525 curwidth
= bounds
.h
;
1530 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1532 if ( curwidth
> *width
)
1533 *width
= XDEV2LOGREL( curwidth
) ;
1540 if ( useGetThemeText
)
1542 Point bounds
={0,0} ;
1544 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
+ laststop
, i
- laststop
, CFStringGetSystemEncoding(), false ) ;
1545 ::GetThemeTextDimensions( mString
,
1546 kThemeCurrentPortFont
,
1551 CFRelease( mString
) ;
1552 curwidth
= bounds
.h
;
1557 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1559 if ( curwidth
> *width
)
1560 *width
= XDEV2LOGREL( curwidth
) ;
1564 // work around the constness
1565 *((wxFont
*)(&m_font
)) = formerFont
;
1566 m_macFontInstalled
= false ;
1569 wxCoord
wxDC::GetCharWidth(void) const
1571 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1572 wxMacPortSetter
helper(this) ;
1576 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1577 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1578 useGetThemeText
= false ;
1582 if ( useGetThemeText
)
1584 Point bounds
={0,0} ;
1586 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1587 ::GetThemeTextDimensions( mString
,
1588 kThemeCurrentPortFont
,
1593 CFRelease( mString
) ;
1599 width
= ::TextWidth( text
, 0 , 1 ) ;
1601 return YDEV2LOGREL(width
) ;
1603 wxCoord
wxDC::GetCharHeight(void) const
1605 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1606 wxMacPortSetter
helper(this) ;
1609 ::GetFontInfo( &fi
) ;
1610 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1612 void wxDC::Clear(void)
1614 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1615 wxMacPortSetter
helper(this) ;
1616 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1617 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1620 //MacInstallBrush() ;
1621 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1622 ::EraseRect( &rect
) ;
1625 void wxDC::MacInstallFont() const
1627 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1628 // if ( m_macFontInstalled )
1630 Pattern blackColor
;
1631 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1632 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1635 ::TextFont( font
->m_macFontNum
) ;
1636 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1637 ::TextFace( font
->m_macFontStyle
) ;
1638 m_macFontInstalled
= true ;
1639 m_macBrushInstalled
= false ;
1640 m_macPenInstalled
= false ;
1641 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1642 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1643 ::RGBForeColor( &forecolor
);
1644 ::RGBBackColor( &backcolor
);
1648 FontFamilyID fontId
;
1652 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1653 GetFNum( fontName
, &fontId
);
1654 ::TextFont( fontId
) ;
1655 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1656 ::TextFace( fontStyle
) ;
1657 // todo reset after spacing changes - or store the current spacing somewhere
1658 m_macFontInstalled
= true ;
1659 m_macBrushInstalled
= false ;
1660 m_macPenInstalled
= false ;
1661 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1662 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1663 ::RGBForeColor( &forecolor
);
1664 ::RGBBackColor( &backcolor
);
1666 short mode
= patCopy
;
1668 switch( m_logicalFunction
)
1673 case wxINVERT
: // NOT dst
1674 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1677 case wxXOR
: // src XOR dst
1680 case wxOR_REVERSE
: // src OR (NOT dst)
1683 case wxSRC_INVERT
: // (NOT src)
1688 case wxAND_REVERSE
:// src AND (NOT dst)
1689 case wxAND
: // src AND dst
1690 case wxAND_INVERT
: // (NOT src) AND dst
1691 case wxNO_OP
: // dst
1692 case wxNOR
: // (NOT src) AND (NOT dst)
1693 case wxEQUIV
: // (NOT src) XOR dst
1694 case wxOR_INVERT
: // (NOT src) OR dst
1695 case wxNAND
: // (NOT src) OR (NOT dst)
1696 case wxOR
: // src OR dst
1698 // case wxSRC_OR: // source _bitmap_ OR destination
1699 // case wxSRC_AND: // source _bitmap_ AND destination
1703 OSStatus status
= noErr
;
1704 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1705 Style qdStyle
= font
->m_macFontStyle
;
1706 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1707 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1708 wxASSERT_MSG( status
== noErr
, "couldn't create ATSU style" ) ;
1709 ATSUAttributeTag atsuTags
[] =
1714 // kATSUBaselineClassTag ,
1715 kATSUVerticalCharacterTag
,
1716 kATSUQDBoldfaceTag
,
1718 kATSUQDUnderlineTag
,
1719 kATSUQDCondensedTag
,
1720 kATSUQDExtendedTag
,
1722 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1724 sizeof( ATSUFontID
) ,
1726 // sizeof( RGBColor ) ,
1727 // sizeof( BslnBaselineClass ) ,
1728 sizeof( ATSUVerticalCharacterType
),
1735 Boolean kTrue
= true ;
1736 Boolean kFalse
= false ;
1737 BslnBaselineClass kBaselineDefault
= kBSLNHangingBaseline
;
1738 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1739 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1743 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1744 // &kBaselineDefault ,
1746 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1747 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1748 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1749 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1750 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1752 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1753 atsuTags
, atsuSizes
, atsuValues
);
1754 wxASSERT_MSG( status
== noErr
, "couldn't set create ATSU style" ) ;
1756 Pattern gHatchPatterns
[] =
1758 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1759 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1760 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1761 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1762 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1763 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1764 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1766 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1771 case wxBDIAGONAL_HATCH
:
1774 case wxFDIAGONAL_HATCH
:
1780 case wxHORIZONTAL_HATCH
:
1783 case wxVERTICAL_HATCH
:
1786 case wxCROSSDIAG_HATCH
:
1790 theIndex
= 1; // solid pattern
1793 *pattern
= gHatchPatterns
[theIndex
-1] ;
1795 void wxDC::MacInstallPen() const
1797 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1799 // if ( m_macPenInstalled )
1801 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1802 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1803 ::RGBForeColor( &forecolor
);
1804 ::RGBBackColor( &backcolor
);
1806 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1807 // null means only one pixel, at whatever resolution
1808 if ( penWidth
== 0 )
1810 ::PenSize(penWidth
, penWidth
);
1811 int penStyle
= m_pen
.GetStyle();
1812 if (penStyle
== wxSOLID
)
1814 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1816 else if (IS_HATCH(penStyle
))
1819 wxMacGetHatchPattern(penStyle
, &pat
);
1824 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1828 for ( int i
= 0 ; i
< 8 ; ++i
)
1834 for ( int i
= 0 ; i
< 8 ; ++i
)
1840 for ( int i
= 0 ; i
< 8 ; ++i
)
1846 for ( int i
= 0 ; i
< 8 ; ++i
)
1854 m_pen
.GetDashes(&dash
) ;
1855 // right now we don't allocate larger pixmaps
1857 m_pen
.GetDashes(&dash
) ;
1858 for ( int i
= 0 ; i
< 8 ; ++i
)
1860 pat
.pat
[i
] = dash
[0] ;
1867 short mode
= patCopy
;
1869 switch( m_logicalFunction
)
1871 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1874 case wxINVERT
: // NOT dst
1875 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1878 case wxXOR
: // src XOR dst
1881 case wxOR_REVERSE
: // src OR (NOT dst)
1884 case wxSRC_INVERT
: // (NOT src)
1889 case wxAND_REVERSE
:// src AND (NOT dst)
1890 case wxAND
: // src AND dst
1891 case wxAND_INVERT
: // (NOT src) AND dst
1892 case wxNO_OP
: // dst
1893 case wxNOR
: // (NOT src) AND (NOT dst)
1894 case wxEQUIV
: // (NOT src) XOR dst
1895 case wxOR_INVERT
: // (NOT src) OR dst
1896 case wxNAND
: // (NOT src) OR (NOT dst)
1897 case wxOR
: // src OR dst
1899 // case wxSRC_OR: // source _bitmap_ OR destination
1900 // case wxSRC_AND: // source _bitmap_ AND destination
1904 m_macPenInstalled
= true ;
1905 m_macBrushInstalled
= false ;
1906 m_macFontInstalled
= false ;
1908 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1910 Pattern whiteColor
;
1911 switch( background
.MacGetBrushKind() )
1913 case kwxMacBrushTheme
:
1915 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1918 case kwxMacBrushThemeBackground
:
1921 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1922 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1925 case kwxMacBrushColour
:
1927 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1928 int brushStyle
= background
.GetStyle();
1929 if (brushStyle
== wxSOLID
)
1930 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1931 else if (IS_HATCH(brushStyle
))
1934 wxMacGetHatchPattern(brushStyle
, &pat
);
1939 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1945 void wxDC::MacInstallBrush() const
1947 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1948 Pattern blackColor
;
1949 // if ( m_macBrushInstalled )
1952 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1953 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1954 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1955 int brushStyle
= m_brush
.GetStyle();
1956 if (brushStyle
== wxSOLID
)
1958 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1960 else if (IS_HATCH(brushStyle
))
1963 wxMacGetHatchPattern(brushStyle
, &pat
);
1966 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1968 // we force this in order to be compliant with wxMSW
1969 backgroundTransparent
= false ;
1970 // for these the text fore (and back for MASK_OPAQUE) colors are used
1971 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1972 int width
= bitmap
->GetWidth() ;
1973 int height
= bitmap
->GetHeight() ;
1974 GWorldPtr gw
= NULL
;
1975 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1976 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1978 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1979 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
1980 LockPixels( gwpixmaphandle
) ;
1981 bool isMonochrome
= !IsPortColor( gw
) ;
1982 if ( !isMonochrome
)
1984 if ( (**gwpixmaphandle
).pixelSize
== 1 )
1985 isMonochrome
= true ;
1987 if ( isMonochrome
&& width
== 8 && height
== 8 )
1989 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
1990 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
1991 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
1992 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
1993 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
1995 for ( int i
= 0 ; i
< 8 ; ++i
)
1997 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
1999 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2004 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2005 // caching scheme before putting this into production
2008 PixPatHandle pixpat
= NewPixPat() ;
2009 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2010 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2011 ((**(**pixpat
).patMap
).bounds
.bottom
-
2012 (**(**pixpat
).patMap
).bounds
.top
);
2013 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2014 (**pixpat
).patData
= image
;
2017 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2018 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2019 if ( ctspec
[0].rgb
.red
== 0x0000 )
2021 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2022 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2026 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2027 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2029 ::CTabChanged( ctable
) ;
2031 ::PenPixPat(pixpat
);
2032 m_macForegroundPixMap
= pixpat
;
2034 UnlockPixels( gwpixmaphandle
) ;
2038 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2040 short mode
= patCopy
;
2041 switch( m_logicalFunction
)
2044 if ( backgroundTransparent
)
2049 case wxINVERT
: // NOT dst
2050 if ( !backgroundTransparent
)
2052 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2056 case wxXOR
: // src XOR dst
2059 case wxOR_REVERSE
: // src OR (NOT dst)
2062 case wxSRC_INVERT
: // (NOT src)
2067 case wxAND_REVERSE
:// src AND (NOT dst)
2068 case wxAND
: // src AND dst
2069 case wxAND_INVERT
: // (NOT src) AND dst
2070 case wxNO_OP
: // dst
2071 case wxNOR
: // (NOT src) AND (NOT dst)
2072 case wxEQUIV
: // (NOT src) XOR dst
2073 case wxOR_INVERT
: // (NOT src) OR dst
2074 case wxNAND
: // (NOT src) OR (NOT dst)
2075 case wxOR
: // src OR dst
2077 // case wxSRC_OR: // source _bitmap_ OR destination
2078 // case wxSRC_AND: // source _bitmap_ AND destination
2082 m_macBrushInstalled
= true ;
2083 m_macPenInstalled
= false ;
2084 m_macFontInstalled
= false ;
2086 // ---------------------------------------------------------------------------
2087 // coordinates transformations
2088 // ---------------------------------------------------------------------------
2090 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2092 return ((wxDC
*)this)->XDEV2LOG(x
);
2094 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2096 return ((wxDC
*)this)->YDEV2LOG(y
);
2098 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2100 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2102 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2104 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2106 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2108 return ((wxDC
*)this)->XLOG2DEV(x
);
2110 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2112 return ((wxDC
*)this)->YLOG2DEV(y
);
2114 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2116 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2118 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2120 return ((wxDC
*)this)->YLOG2DEVREL(y
);