1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/dcprint.h"
21 #include "wx/region.h"
30 #include "wx/mac/private.h"
31 #include <ATSUnicode.h>
32 #include <TextCommon.h>
33 #include <TextEncodingConverter.h>
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 #define mm2inches 0.0393700787402
44 #define inches2mm 25.4
45 #define mm2twips 56.6929133859
46 #define twips2mm 0.0176388888889
47 #define mm2pt 2.83464566929
48 #define pt2mm 0.352777777778
50 const double RAD2DEG
= 180.0 / M_PI
;
51 const short kEmulatedMode
= -1 ;
52 const short kUnsupportedMode
= -2 ;
54 extern TECObjectRef s_TECNativeCToUnicode
;
56 // set to 0 if problems arise
57 #define wxMAC_EXPERIMENTAL_DC 1
59 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
60 m_ph( (GrafPtr
) dc
->m_macPort
)
62 wxASSERT( dc
->Ok() ) ;
64 dc
->MacSetupPort(&m_ph
) ;
66 wxMacPortSetter::~wxMacPortSetter()
68 m_dc
->MacCleanupPort(&m_ph
) ;
71 #if wxMAC_EXPERIMENTAL_DC
72 class wxMacFastPortSetter
75 wxMacFastPortSetter( const wxDC
*dc
)
77 wxASSERT( dc
->Ok() ) ;
78 m_swapped
= QDSwapPort( (GrafPtr
) dc
->m_macPort
, &m_oldPort
) ;
79 m_clipRgn
= NewRgn() ;
80 GetClip( m_clipRgn
) ;
82 dc
->MacSetupPort( NULL
) ;
84 ~wxMacFastPortSetter()
86 // SetPort( (GrafPtr) m_dc->m_macPort ) ;
87 SetClip( m_clipRgn
) ;
89 SetPort( m_oldPort
) ;
90 m_dc
->MacCleanupPort( NULL
) ;
91 DisposeRgn( m_clipRgn
) ;
101 typedef wxMacPortSetter wxMacFastPortSetter
;
104 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
105 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
107 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
108 m_formerClip
= NewRgn() ;
109 m_newClip
= NewRgn() ;
110 GetClip( m_formerClip
) ;
115 win
->MacWindowToRootWindow( &x
,&y
) ;
116 // get area including focus rect
117 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
118 if ( !EmptyRgn( m_newClip
) )
119 OffsetRgn( m_newClip
, x
, y
) ;
121 SetClip( m_newClip
) ;
125 wxMacWindowClipper::~wxMacWindowClipper()
127 SetPort( m_newPort
) ;
128 SetClip( m_formerClip
) ;
129 DisposeRgn( m_newClip
) ;
130 DisposeRgn( m_formerClip
) ;
133 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
134 wxMacWindowClipper( win
)
136 // the port is already set at this point
137 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
138 GetThemeDrawingState( &m_themeDrawingState
) ;
141 wxMacWindowStateSaver::~wxMacWindowStateSaver()
143 SetPort( m_newPort
) ;
144 SetThemeDrawingState( m_themeDrawingState
, true ) ;
147 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
150 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
151 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
152 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
154 //-----------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
157 // this function emulates all wx colour manipulations, used to verify the implementation
158 // by setting the mode in the blitting functions to kEmulatedMode
159 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
161 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
163 switch ( logical_func
)
165 case wxAND
: // src AND dst
166 dstColor
.red
= dstColor
.red
& srcColor
.red
;
167 dstColor
.green
= dstColor
.green
& srcColor
.green
;
168 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
170 case wxAND_INVERT
: // (NOT src) AND dst
171 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
172 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
173 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
175 case wxAND_REVERSE
:// src AND (NOT dst)
176 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
177 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
178 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
186 dstColor
.red
= srcColor
.red
;
187 dstColor
.green
= srcColor
.green
;
188 dstColor
.blue
= srcColor
.blue
;
190 case wxEQUIV
: // (NOT src) XOR dst
191 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
192 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
193 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
195 case wxINVERT
: // NOT dst
196 dstColor
.red
= ~dstColor
.red
;
197 dstColor
.green
= ~dstColor
.green
;
198 dstColor
.blue
= ~dstColor
.blue
;
200 case wxNAND
: // (NOT src) OR (NOT dst)
201 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
202 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
203 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
205 case wxNOR
: // (NOT src) AND (NOT dst)
206 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
207 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
208 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
212 case wxOR
: // src OR dst
213 dstColor
.red
= dstColor
.red
| srcColor
.red
;
214 dstColor
.green
= dstColor
.green
| srcColor
.green
;
215 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
217 case wxOR_INVERT
: // (NOT src) OR dst
218 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
219 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
220 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
222 case wxOR_REVERSE
: // src OR (NOT dst)
223 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
224 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
225 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
228 dstColor
.red
= 0xFFFF ;
229 dstColor
.green
= 0xFFFF ;
230 dstColor
.blue
= 0xFFFF ;
232 case wxSRC_INVERT
: // (NOT src)
233 dstColor
.red
= ~srcColor
.red
;
234 dstColor
.green
= ~srcColor
.green
;
235 dstColor
.blue
= ~srcColor
.blue
;
237 case wxXOR
: // src XOR dst
238 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
239 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
240 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
249 m_mm_to_pix_x
= mm2pt
;
250 m_mm_to_pix_y
= mm2pt
;
251 m_internalDeviceOriginX
= 0;
252 m_internalDeviceOriginY
= 0;
253 m_externalDeviceOriginX
= 0;
254 m_externalDeviceOriginY
= 0;
255 m_logicalScaleX
= 1.0;
256 m_logicalScaleY
= 1.0;
261 m_needComputeScaleX
= false;
262 m_needComputeScaleY
= false;
266 m_macFontInstalled
= false ;
267 m_macBrushInstalled
= false ;
268 m_macPenInstalled
= false ;
269 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
270 m_macBoundaryClipRgn
= NewRgn() ;
271 m_macCurrentClipRgn
= NewRgn() ;
272 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
273 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
274 m_pen
= *wxBLACK_PEN
;
275 m_font
= *wxNORMAL_FONT
;
276 m_brush
= *wxWHITE_BRUSH
;
278 // needed to debug possible errors with two active drawing methods at the same time on
280 m_macCurrentPortStateHelper
= NULL
;
282 m_macATSUIStyle
= NULL
;
283 m_macAliasWasEnabled
= false;
284 m_macForegroundPixMap
= NULL
;
285 m_macBackgroundPixMap
= NULL
;
290 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
291 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
294 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
297 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
298 m_macCurrentPortStateHelper
= help
;
300 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
301 #if ! wxMAC_EXPERIMENTAL_DC
302 m_macFontInstalled
= false ;
303 m_macBrushInstalled
= false ;
304 m_macPenInstalled
= false ;
307 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
310 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
311 m_macCurrentPortStateHelper
= NULL
;
313 if( m_macATSUIStyle
)
315 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
316 m_macATSUIStyle
= NULL
;
318 if ( m_macAliasWasEnabled
)
320 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
321 m_macAliasWasEnabled
= false ;
323 if ( m_macForegroundPixMap
)
326 ::PenPat(GetQDGlobalsBlack(&blackColor
));
327 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
328 m_macForegroundPixMap
= NULL
;
330 if ( m_macBackgroundPixMap
)
333 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
334 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
335 m_macBackgroundPixMap
= NULL
;
339 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
341 wxCHECK_RET( Ok(), wxT("invalid window dc") );
342 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
343 wxMacFastPortSetter
helper(this) ;
344 wxCoord xx
= XLOG2DEVMAC(x
);
345 wxCoord yy
= YLOG2DEVMAC(y
);
346 wxCoord w
= bmp
.GetWidth();
347 wxCoord h
= bmp
.GetHeight();
348 wxCoord ww
= XLOG2DEVREL(w
);
349 wxCoord hh
= YLOG2DEVREL(h
);
350 // Set up drawing mode
351 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
352 //m_logicalFunction == wxCLEAR ? WHITENESS :
353 //m_logicalFunction == wxSET ? BLACKNESS :
354 m_logicalFunction
== wxINVERT
? hilite
:
355 //m_logicalFunction == wxAND ? MERGECOPY :
356 m_logicalFunction
== wxOR
? srcOr
:
357 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
358 m_logicalFunction
== wxXOR
? srcXor
:
359 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
360 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
361 //m_logicalFunction == wxSRC_OR ? srcOr :
362 //m_logicalFunction == wxSRC_AND ? SRCAND :
364 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
365 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
366 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
367 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
369 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
371 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
372 PixMapHandle bmappixels
;
373 // Set foreground and background colours (for bitmaps depth = 1)
374 if(bmp
.GetDepth() == 1)
376 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
377 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
383 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
384 RGBColor black
= { 0,0,0} ;
385 RGBForeColor( &black
) ;
386 RGBBackColor( &white
) ;
388 bmappixels
= GetGWorldPixMap( bmapworld
) ;
389 wxCHECK_RET(LockPixels(bmappixels
),
390 wxT("DoDrawBitmap: Unable to lock pixels"));
391 Rect source
= { 0, 0, h
, w
};
392 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
393 if ( useMask
&& bmp
.GetMask() )
395 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
399 GetPortBitMapForCopyBits(bmapworld
),
400 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
401 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
402 &source
, &source
, &dest
, mode
, NULL
404 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
408 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
409 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
410 &source
, &dest
, mode
, NULL
) ;
412 UnlockPixels( bmappixels
) ;
414 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
416 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
417 OffsetRect( &bitmaprect
, xx
, yy
) ;
418 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
420 m_macPenInstalled
= false ;
421 m_macBrushInstalled
= false ;
422 m_macFontInstalled
= false ;
425 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
427 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
428 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
429 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
432 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
434 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
435 wxCoord xx
, yy
, ww
, hh
;
438 ww
= XLOG2DEVREL(width
);
439 hh
= YLOG2DEVREL(height
);
440 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
441 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
444 m_clipX1
= wxMax( m_clipX1
, xx
);
445 m_clipY1
= wxMax( m_clipY1
, yy
);
446 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
447 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
459 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
461 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
464 DestroyClippingRegion();
467 wxMacFastPortSetter
helper(this) ;
469 region
.GetBox( x
, y
, w
, h
);
470 wxCoord xx
, yy
, ww
, hh
;
475 // if we have a scaling that we cannot map onto native regions
476 // we must use the box
477 if ( ww
!= w
|| hh
!= h
)
479 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
483 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
484 if ( xx
!= x
|| yy
!= y
)
486 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
488 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
491 m_clipX1
= wxMax( m_clipX1
, xx
);
492 m_clipY1
= wxMax( m_clipY1
, yy
);
493 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
494 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
507 void wxDC::DestroyClippingRegion()
509 wxMacFastPortSetter
helper(this) ;
510 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
514 void wxDC::DoGetSizeMM( int* width
, int* height
) const
519 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
520 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
523 void wxDC::SetTextForeground( const wxColour
&col
)
525 wxCHECK_RET(Ok(), wxT("Invalid DC"));
526 m_textForegroundColour
= col
;
527 m_macFontInstalled
= false ;
530 void wxDC::SetTextBackground( const wxColour
&col
)
532 wxCHECK_RET(Ok(), wxT("Invalid DC"));
533 m_textBackgroundColour
= col
;
534 m_macFontInstalled
= false ;
537 void wxDC::SetMapMode( int mode
)
542 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
545 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
548 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
551 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
555 SetLogicalScale( 1.0, 1.0 );
558 if (mode
!= wxMM_TEXT
)
560 m_needComputeScaleX
= true;
561 m_needComputeScaleY
= true;
565 void wxDC::SetUserScale( double x
, double y
)
567 // allow negative ? -> no
570 ComputeScaleAndOrigin();
573 void wxDC::SetLogicalScale( double x
, double y
)
578 ComputeScaleAndOrigin();
581 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
583 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
584 m_logicalOriginY
= y
* m_signY
;
585 ComputeScaleAndOrigin();
588 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
590 m_externalDeviceOriginX
= x
;
591 m_externalDeviceOriginY
= y
;
592 ComputeScaleAndOrigin();
595 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
597 m_signX
= (xLeftRight
? 1 : -1);
598 m_signY
= (yBottomUp
? -1 : 1);
599 ComputeScaleAndOrigin();
602 wxSize
wxDC::GetPPI() const
604 return wxSize(72, 72);
607 int wxDC::GetDepth() const
609 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
611 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
616 void wxDC::ComputeScaleAndOrigin()
618 // CMB: copy scale to see if it changes
619 double origScaleX
= m_scaleX
;
620 double origScaleY
= m_scaleY
;
621 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
622 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
623 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
624 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
625 // CMB: if scale has changed call SetPen to recalulate the line width
626 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
628 // this is a bit artificial, but we need to force wxDC to think
629 // the pen has changed
636 void wxDC::SetPalette( const wxPalette
& palette
)
640 void wxDC::SetBackgroundMode( int mode
)
642 m_backgroundMode
= mode
;
645 void wxDC::SetFont( const wxFont
&font
)
648 m_macFontInstalled
= false ;
651 void wxDC::SetPen( const wxPen
&pen
)
656 m_macPenInstalled
= false ;
659 void wxDC::SetBrush( const wxBrush
&brush
)
661 if (m_brush
== brush
)
664 m_macBrushInstalled
= false ;
667 void wxDC::SetBackground( const wxBrush
&brush
)
669 if (m_backgroundBrush
== brush
)
671 m_backgroundBrush
= brush
;
672 if (!m_backgroundBrush
.Ok())
674 m_macBrushInstalled
= false ;
677 void wxDC::SetLogicalFunction( int function
)
679 if (m_logicalFunction
== function
)
681 m_logicalFunction
= function
;
682 m_macFontInstalled
= false ;
683 m_macBrushInstalled
= false ;
684 m_macPenInstalled
= false ;
687 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
688 const wxColour
& col
, int style
);
690 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
691 const wxColour
& col
, int style
)
693 return wxDoFloodFill(this, x
, y
, col
, style
);
696 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
698 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
699 wxMacFastPortSetter
helper(this) ;
701 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
702 // Convert from Mac colour to wx
703 col
->Set( colour
.red
>> 8,
709 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
711 wxCHECK_RET(Ok(), wxT("Invalid DC"));
712 wxMacFastPortSetter
helper(this) ;
713 if (m_pen
.GetStyle() != wxTRANSPARENT
)
716 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
717 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
718 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
719 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
720 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
721 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
722 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
723 (m_pen
.GetWidth() <= 1))
725 // Implement LAST_NOT for MAC at least for
726 // orthogonal lines. RR.
747 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
749 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
750 wxMacFastPortSetter
helper(this) ;
751 if (m_pen
.GetStyle() != wxTRANSPARENT
)
756 wxCoord xx
= XLOG2DEVMAC(x
);
757 wxCoord yy
= YLOG2DEVMAC(y
);
759 ::MoveTo( XLOG2DEVMAC(0), yy
);
760 ::LineTo( XLOG2DEVMAC(w
), yy
);
761 ::MoveTo( xx
, YLOG2DEVMAC(0) );
762 ::LineTo( xx
, YLOG2DEVMAC(h
) );
763 CalcBoundingBox(x
, y
);
764 CalcBoundingBox(x
+w
, y
+h
);
769 * To draw arcs properly the angles need to be converted from the WX style:
770 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
771 * a normal axis on paper).
774 * Angles start on the +ve y axis and go clockwise.
777 static double wxConvertWXangleToMACangle(double angle
)
779 double newAngle
= 90 - angle
;
780 while ( newAngle
> 360 ) newAngle
-= 360 ;
781 while ( newAngle
< 0 ) newAngle
+= 360 ;
785 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
786 wxCoord x2
, wxCoord y2
,
787 wxCoord xc
, wxCoord yc
)
789 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
790 wxMacFastPortSetter
helper(this) ;
791 wxCoord xx1
= XLOG2DEVMAC(x1
);
792 wxCoord yy1
= YLOG2DEVMAC(y1
);
793 wxCoord xx2
= XLOG2DEVMAC(x2
);
794 wxCoord yy2
= YLOG2DEVMAC(y2
);
795 wxCoord xxc
= XLOG2DEVMAC(xc
);
796 wxCoord yyc
= YLOG2DEVMAC(yc
);
797 double dx
= xx1
- xxc
;
798 double dy
= yy1
- yyc
;
799 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
800 wxCoord rad
= (wxCoord
)radius
;
801 double radius1
, radius2
;
802 if (xx1
== xx2
&& yy1
== yy2
)
807 else if (radius
== 0.0)
809 radius1
= radius2
= 0.0;
813 radius1
= (xx1
- xxc
== 0) ?
814 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
815 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
816 radius2
= (xx2
- xxc
== 0) ?
817 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
818 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
820 wxCoord alpha2
= wxCoord(radius2
- radius1
);
821 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
822 while( alpha2
< 0 ) alpha2
+= 360 ;
824 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
825 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
827 PaintArc(&r
, alpha1
, alpha2
);
829 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
831 FrameArc(&r
, alpha1
, alpha2
);
835 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
836 double sa
, double ea
)
838 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
839 wxMacFastPortSetter
helper(this) ;
841 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
842 // we have to make sure that the filling is always counter-clockwise
845 wxCoord xx
= XLOG2DEVMAC(x
);
846 wxCoord yy
= YLOG2DEVMAC(y
);
847 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
848 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
849 // handle -ve width and/or height
850 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
851 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
852 sa
= wxConvertWXangleToMACangle(sa
);
857 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
859 PaintArc(&r
, (short)sa
, (short)angle
);
861 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
863 FrameArc(&r
, (short)sa
, (short)angle
);
867 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
869 wxCHECK_RET(Ok(), wxT("Invalid DC"));
870 wxMacFastPortSetter
helper(this) ;
871 if (m_pen
.GetStyle() != wxTRANSPARENT
)
873 wxCoord xx1
= XLOG2DEVMAC(x
);
874 wxCoord yy1
= YLOG2DEVMAC(y
);
875 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
876 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
877 CalcBoundingBox(x
, y
);
881 void wxDC::DoDrawLines(int n
, wxPoint points
[],
882 wxCoord xoffset
, wxCoord yoffset
)
884 wxCHECK_RET(Ok(), wxT("Invalid DC"));
885 wxMacFastPortSetter
helper(this) ;
886 if (m_pen
.GetStyle() == wxTRANSPARENT
)
889 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
890 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
891 wxCoord x1
, x2
, y1
, y2
;
892 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
893 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
894 ::MoveTo(x1
- offset
, y1
- offset
);
895 for (int i
= 0; i
< n
-1; i
++)
897 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
898 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
899 ::LineTo( x2
- offset
, y2
- offset
);
903 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
904 wxCoord xoffset
, wxCoord yoffset
,
907 wxCHECK_RET(Ok(), wxT("Invalid DC"));
908 wxMacFastPortSetter
helper(this) ;
909 wxCoord x1
, x2
, y1
, y2
;
910 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
912 PolyHandle polygon
= OpenPoly();
913 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
914 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
916 for (int i
= 1; i
< n
; i
++)
918 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
919 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
922 // close the polyline if necessary
923 if ( x1
!= x2
|| y1
!= y2
)
928 if (m_brush
.GetStyle() != wxTRANSPARENT
)
931 ::PaintPoly( polygon
);
933 if (m_pen
.GetStyle() != wxTRANSPARENT
)
936 ::FramePoly( polygon
) ;
941 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
943 wxCHECK_RET(Ok(), wxT("Invalid DC"));
944 wxMacFastPortSetter
helper(this) ;
945 wxCoord xx
= XLOG2DEVMAC(x
);
946 wxCoord yy
= YLOG2DEVMAC(y
);
947 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
948 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
949 // CMB: draw nothing if transformed w or h is 0
950 if (ww
== 0 || hh
== 0)
952 // CMB: handle -ve width and/or height
963 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
964 if (m_brush
.GetStyle() != wxTRANSPARENT
)
967 ::PaintRect( &rect
) ;
969 if (m_pen
.GetStyle() != wxTRANSPARENT
)
972 ::FrameRect( &rect
) ;
976 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
977 wxCoord width
, wxCoord height
,
980 wxCHECK_RET(Ok(), wxT("Invalid DC"));
981 wxMacFastPortSetter
helper(this) ;
983 radius
= - radius
* ((width
< height
) ? width
: height
);
984 wxCoord xx
= XLOG2DEVMAC(x
);
985 wxCoord yy
= YLOG2DEVMAC(y
);
986 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
987 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
988 // CMB: draw nothing if transformed w or h is 0
989 if (ww
== 0 || hh
== 0)
991 // CMB: handle -ve width and/or height
1002 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1003 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1006 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1008 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1011 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1015 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1017 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1018 wxMacFastPortSetter
helper(this) ;
1019 wxCoord xx
= XLOG2DEVMAC(x
);
1020 wxCoord yy
= YLOG2DEVMAC(y
);
1021 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1022 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1023 // CMB: draw nothing if transformed w or h is 0
1024 if (ww
== 0 || hh
== 0)
1026 // CMB: handle -ve width and/or height
1037 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1038 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1041 ::PaintOval( &rect
) ;
1043 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1046 ::FrameOval( &rect
) ;
1050 bool wxDC::CanDrawBitmap(void) const
1055 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1056 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1057 wxCoord xsrcMask
, wxCoord ysrcMask
)
1059 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1060 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1061 if ( logical_func
== wxNO_OP
)
1063 if (xsrcMask
== -1 && ysrcMask
== -1)
1065 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1067 // correct the parameter in case this dc does not have a mask at all
1068 if ( useMask
&& !source
->m_macMask
)
1070 Rect srcrect
, dstrect
;
1071 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1072 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1073 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1074 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1075 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1076 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1077 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1078 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1079 short mode
= kUnsupportedMode
;
1080 bool invertDestinationFirst
= false ;
1081 switch ( logical_func
)
1083 case wxAND
: // src AND dst
1084 mode
= adMin
; // ok
1086 case wxAND_INVERT
: // (NOT src) AND dst
1087 mode
= notSrcOr
; // ok
1089 case wxAND_REVERSE
:// src AND (NOT dst)
1090 invertDestinationFirst
= true ;
1094 mode
= kEmulatedMode
;
1097 mode
= srcCopy
; // ok
1099 case wxEQUIV
: // (NOT src) XOR dst
1100 mode
= srcXor
; // ok
1102 case wxINVERT
: // NOT dst
1103 mode
= kEmulatedMode
; //or hilite ;
1105 case wxNAND
: // (NOT src) OR (NOT dst)
1106 invertDestinationFirst
= true ;
1109 case wxNOR
: // (NOT src) AND (NOT dst)
1110 invertDestinationFirst
= true ;
1113 case wxNO_OP
: // dst
1114 mode
= kEmulatedMode
; // this has already been handled upon entry
1116 case wxOR
: // src OR dst
1119 case wxOR_INVERT
: // (NOT src) OR dst
1122 case wxOR_REVERSE
: // src OR (NOT dst)
1123 invertDestinationFirst
= true ;
1127 mode
= kEmulatedMode
;
1129 case wxSRC_INVERT
: // (NOT src)
1130 mode
= notSrcCopy
; // ok
1132 case wxXOR
: // src XOR dst
1133 mode
= notSrcXor
; // ok
1138 if ( mode
== kUnsupportedMode
)
1140 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1143 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1144 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1145 if ( LockPixels(bmappixels
) )
1147 wxMacFastPortSetter
helper(this) ;
1148 if ( source
->GetDepth() == 1 )
1150 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1151 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1155 // the modes need this, otherwise we'll end up having really nice colors...
1156 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1157 RGBColor black
= { 0,0,0} ;
1158 RGBForeColor( &black
) ;
1159 RGBBackColor( &white
) ;
1161 if ( useMask
&& source
->m_macMask
)
1163 if ( mode
== srcCopy
)
1165 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1167 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1168 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1169 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1170 &srcrect
, &srcrect
, &dstrect
) ;
1171 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1176 RgnHandle clipRgn
= NewRgn() ;
1177 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1178 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1179 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1180 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1181 if ( mode
== kEmulatedMode
)
1184 ::PenPat(GetQDGlobalsBlack(&pat
));
1185 if ( logical_func
== wxSET
)
1187 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1188 ::RGBForeColor( &col
) ;
1189 ::PaintRgn( clipRgn
) ;
1191 else if ( logical_func
== wxCLEAR
)
1193 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1194 ::RGBForeColor( &col
) ;
1195 ::PaintRgn( clipRgn
) ;
1197 else if ( logical_func
== wxINVERT
)
1199 MacInvertRgn( clipRgn
) ;
1203 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1205 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1207 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1208 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1209 if ( PtInRgn( dstPoint
, clipRgn
) )
1213 SetPort( (GrafPtr
) sourcePort
) ;
1214 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1215 SetPort( (GrafPtr
) m_macPort
) ;
1216 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1217 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1218 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1226 if ( invertDestinationFirst
)
1228 MacInvertRgn( clipRgn
) ;
1230 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1231 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1232 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1234 DisposeRgn( clipRgn
) ;
1239 RgnHandle clipRgn
= NewRgn() ;
1240 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1241 if ( mode
== kEmulatedMode
)
1244 ::PenPat(GetQDGlobalsBlack(&pat
));
1245 if ( logical_func
== wxSET
)
1247 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1248 ::RGBForeColor( &col
) ;
1249 ::PaintRgn( clipRgn
) ;
1251 else if ( logical_func
== wxCLEAR
)
1253 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1254 ::RGBForeColor( &col
) ;
1255 ::PaintRgn( clipRgn
) ;
1257 else if ( logical_func
== wxINVERT
)
1259 MacInvertRgn( clipRgn
) ;
1263 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1265 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1267 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1268 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1272 SetPort( (GrafPtr
) sourcePort
) ;
1273 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1274 SetPort( (GrafPtr
) m_macPort
) ;
1275 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1276 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1277 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1285 if ( invertDestinationFirst
)
1287 MacInvertRgn( clipRgn
) ;
1289 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1290 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1291 &srcrect
, &dstrect
, mode
, NULL
) ;
1293 DisposeRgn( clipRgn
) ;
1295 UnlockPixels( bmappixels
) ;
1297 m_macPenInstalled
= false ;
1298 m_macBrushInstalled
= false ;
1299 m_macFontInstalled
= false ;
1304 // as macro in FixMath.h for 10.3
1305 inline Fixed
IntToFixed( int inInt
)
1307 return (((SInt32
) inInt
) << 16);
1310 inline int FixedToInt( Fixed inFixed
)
1312 return (((SInt32
) inFixed
) >> 16);
1316 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1319 // TODO support text background color (only possible by hand, ATSUI does not support it)
1320 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1322 if ( str
.Length() == 0 )
1325 wxMacFastPortSetter
helper(this) ;
1330 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1331 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1332 m_macAliasWasEnabled
= true ;
1334 OSStatus status
= noErr
;
1335 ATSUTextLayout atsuLayout
;
1336 UniCharCount chars
= str
.Length() ;
1337 UniChar
* ubuf
= NULL
;
1338 #if SIZEOF_WCHAR_T == 4
1339 wxMBConvUTF16BE converter
;
1341 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1342 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1343 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1345 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1346 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1347 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1348 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1350 chars
= unicharlen
/ 2 ;
1353 ubuf
= (UniChar
*) str
.wc_str() ;
1355 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1356 chars
= wxWcslen( wchar
.data() ) ;
1357 ubuf
= (UniChar
*) wchar
.data() ;
1361 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1362 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1364 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1365 int iAngle
= int( angle
);
1366 int drawX
= XLOG2DEVMAC(x
) ;
1367 int drawY
= YLOG2DEVMAC(y
) ;
1369 ATSUTextMeasurement textBefore
;
1370 ATSUTextMeasurement textAfter
;
1371 ATSUTextMeasurement ascent
;
1372 ATSUTextMeasurement descent
;
1375 if ( abs(iAngle
) > 0 )
1377 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1378 ATSUAttributeTag atsuTags
[] =
1380 kATSULineRotationTag
,
1382 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1386 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1390 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1391 atsuTags
, atsuSizes
, atsuValues
) ;
1393 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1394 &textBefore
, &textAfter
, &ascent
, &descent
);
1396 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1397 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1398 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1399 IntToFixed(drawX
) , IntToFixed(drawY
) );
1400 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1402 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1403 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1404 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1405 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1406 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1407 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1408 ::ATSUDisposeTextLayout(atsuLayout
);
1409 #if SIZEOF_WCHAR_T == 4
1414 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1416 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1418 wxMacFastPortSetter
helper(this) ;
1419 long xx
= XLOG2DEVMAC(x
);
1420 long yy
= YLOG2DEVMAC(y
);
1422 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1423 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1424 useDrawThemeText
= false ;
1429 ::GetFontInfo( &fi
) ;
1431 if ( !useDrawThemeText
)
1434 ::MoveTo( xx
, yy
);
1435 if ( m_backgroundMode
== wxTRANSPARENT
)
1437 ::TextMode( srcOr
) ;
1441 ::TextMode( srcCopy
) ;
1445 wxString linetext
= strtext
;
1447 if ( useDrawThemeText
)
1449 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1450 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1452 if ( m_backgroundMode
!= wxTRANSPARENT
)
1454 Point bounds
={0,0} ;
1455 Rect background
= frame
;
1457 ::GetThemeTextDimensions( mString
,
1458 m_font
.MacGetThemeFontID() ,
1463 background
.right
= background
.left
+ bounds
.h
;
1464 background
.bottom
= background
.top
+ bounds
.v
;
1465 ::EraseRect( &background
) ;
1467 ::DrawThemeTextBox( mString
,
1468 m_font
.MacGetThemeFontID() ,
1478 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1479 ::DrawText( text
, 0 , strlen(text
) ) ;
1482 ::TextMode( srcOr
) ;
1485 bool wxDC::CanGetTextExtent() const
1487 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1491 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1492 wxCoord
*descent
, wxCoord
*externalLeading
,
1493 wxFont
*theFont
) const
1495 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1496 wxMacFastPortSetter
helper(this) ;
1497 wxFont formerFont
= m_font
;
1500 // work around the constness
1501 *((wxFont
*)(&m_font
)) = *theFont
;
1505 ::GetFontInfo( &fi
) ;
1507 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1508 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1509 useGetThemeText
= false ;
1512 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1514 *descent
=YDEV2LOGREL( fi
.descent
);
1515 if ( externalLeading
)
1516 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1522 wxString linetext
= strtext
;
1524 if ( useGetThemeText
)
1526 Point bounds
={0,0} ;
1528 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1529 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1530 ::GetThemeTextDimensions( mString
,
1536 curwidth
= bounds
.h
;
1540 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1541 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1543 if ( curwidth
> *width
)
1544 *width
= XDEV2LOGREL( curwidth
) ;
1548 // work around the constness
1549 *((wxFont
*)(&m_font
)) = formerFont
;
1550 m_macFontInstalled
= false ;
1555 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1557 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1560 widths
.Add(0, text
.Length());
1562 if (text
.Length() == 0)
1565 wxMacFastPortSetter
helper(this) ;
1568 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1569 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1570 useGetThemeText
= false ;
1572 if ( useGetThemeText
)
1574 // If anybody knows how to do this more efficiently yet still handle
1575 // the fractional glyph widths that may be present when using AA
1576 // fonts, please change it. Currently it is measuring from the
1577 // begining of the string for each succeding substring, which is much
1578 // slower than this should be.
1579 for (size_t i
=0; i
<text
.Length(); i
++)
1581 wxString
str(text
.Left(i
+1));
1582 Point bounds
= {0,0};
1584 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1585 ::GetThemeTextDimensions( mString
,
1586 m_font
.MacGetThemeFontID(),
1591 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1597 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1598 size_t len
= strlen(buff
);
1599 short* measurements
= new short[len
+1];
1600 MeasureText(len
, buff
.data(), measurements
);
1602 // Copy to widths, starting at measurements[1]
1603 // NOTE: this doesn't take into account any multi-byte characters
1604 // in buff, it probabkly should...
1605 for (size_t i
=0; i
<text
.Length(); i
++)
1606 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1608 delete [] measurements
;
1616 wxCoord
wxDC::GetCharWidth(void) const
1618 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1619 wxMacFastPortSetter
helper(this) ;
1623 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1624 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1625 useGetThemeText
= false ;
1629 if ( useGetThemeText
)
1631 Point bounds
={0,0} ;
1633 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1634 ::GetThemeTextDimensions( mString
,
1635 m_font
.MacGetThemeFontID(),
1640 CFRelease( mString
) ;
1646 width
= ::TextWidth( text
, 0 , 1 ) ;
1648 return YDEV2LOGREL(width
) ;
1651 wxCoord
wxDC::GetCharHeight(void) const
1653 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1654 wxMacFastPortSetter
helper(this) ;
1657 ::GetFontInfo( &fi
) ;
1658 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1661 void wxDC::Clear(void)
1663 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1664 wxMacFastPortSetter
helper(this) ;
1665 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1666 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1669 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1670 ::EraseRect( &rect
) ;
1674 void wxDC::MacInstallFont() const
1676 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1677 // if ( m_macFontInstalled )
1679 Pattern blackColor
;
1680 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1681 if ( m_backgroundMode
!= wxTRANSPARENT
)
1683 Pattern whiteColor
;
1684 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1688 ::TextFont( m_font
.MacGetFontNum() ) ;
1689 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1690 ::TextFace( m_font
.MacGetFontStyle() ) ;
1691 m_macFontInstalled
= true ;
1692 m_macBrushInstalled
= false ;
1693 m_macPenInstalled
= false ;
1694 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1695 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1696 ::RGBForeColor( &forecolor
);
1697 ::RGBBackColor( &backcolor
);
1701 FontFamilyID fontId
;
1705 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1706 GetFNum( fontName
, &fontId
);
1707 ::TextFont( fontId
) ;
1708 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1709 ::TextFace( fontStyle
) ;
1710 // todo reset after spacing changes - or store the current spacing somewhere
1711 m_macFontInstalled
= true ;
1712 m_macBrushInstalled
= false ;
1713 m_macPenInstalled
= false ;
1714 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1715 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1716 ::RGBForeColor( &forecolor
);
1717 ::RGBBackColor( &backcolor
);
1719 short mode
= patCopy
;
1721 switch( m_logicalFunction
)
1726 case wxINVERT
: // NOT dst
1727 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1730 case wxXOR
: // src XOR dst
1733 case wxOR_REVERSE
: // src OR (NOT dst)
1736 case wxSRC_INVERT
: // (NOT src)
1739 case wxAND
: // src AND dst
1744 case wxAND_REVERSE
:// src AND (NOT dst)
1745 case wxAND_INVERT
: // (NOT src) AND dst
1746 case wxNO_OP
: // dst
1747 case wxNOR
: // (NOT src) AND (NOT dst)
1748 case wxEQUIV
: // (NOT src) XOR dst
1749 case wxOR_INVERT
: // (NOT src) OR dst
1750 case wxNAND
: // (NOT src) OR (NOT dst)
1751 case wxOR
: // src OR dst
1753 // case wxSRC_OR: // source _bitmap_ OR destination
1754 // case wxSRC_AND: // source _bitmap_ AND destination
1758 OSStatus status
= noErr
;
1759 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1760 Style qdStyle
= m_font
.MacGetATSUAdditionalQDStyles() ;
1761 ATSUFontID atsuFont
= m_font
.MacGetATSUFontID() ;
1762 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1763 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1764 ATSUAttributeTag atsuTags
[] =
1769 // kATSUBaselineClassTag ,
1770 kATSUVerticalCharacterTag
,
1771 kATSUQDBoldfaceTag
,
1773 kATSUQDUnderlineTag
,
1774 kATSUQDCondensedTag
,
1775 kATSUQDExtendedTag
,
1777 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1779 sizeof( ATSUFontID
) ,
1781 // sizeof( RGBColor ) ,
1782 // sizeof( BslnBaselineClass ) ,
1783 sizeof( ATSUVerticalCharacterType
),
1790 Boolean kTrue
= true ;
1791 Boolean kFalse
= false ;
1792 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1793 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1794 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1798 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1799 // &kBaselineDefault ,
1801 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1802 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1803 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1804 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1805 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1807 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1808 atsuTags
, atsuSizes
, atsuValues
);
1809 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1812 Pattern gPatterns
[] =
1814 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1815 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1816 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1817 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1818 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1819 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1820 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1822 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1823 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1824 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1825 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1828 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1830 int index
= 0; // solid pattern by default
1834 case wxBDIAGONAL_HATCH
: index
= 1; break;
1835 case wxFDIAGONAL_HATCH
: index
= 2; break;
1836 case wxCROSS_HATCH
: index
= 3; break;
1837 case wxHORIZONTAL_HATCH
: index
= 4; break;
1838 case wxVERTICAL_HATCH
: index
= 5; break;
1839 case wxCROSSDIAG_HATCH
: index
= 6; break;
1841 case wxDOT
: index
= 7; break;
1842 case wxLONG_DASH
: index
= 8; break;
1843 case wxSHORT_DASH
: index
= 9; break;
1844 case wxDOT_DASH
: index
= 10; break;
1846 *pattern
= gPatterns
[index
];
1849 void wxDC::MacInstallPen() const
1851 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1852 //Pattern blackColor;
1853 // if ( m_macPenInstalled )
1855 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1856 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1857 ::RGBForeColor( &forecolor
);
1858 ::RGBBackColor( &backcolor
);
1860 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1861 // null means only one pixel, at whatever resolution
1862 if ( penWidth
== 0 )
1864 ::PenSize(penWidth
, penWidth
);
1866 int penStyle
= m_pen
.GetStyle();
1868 if (penStyle
== wxUSER_DASH
)
1870 // FIXME: there should be exactly 8 items in the dash
1872 int number
= m_pen
.GetDashes(&dash
) ;
1874 for ( int i
= 0 ; i
< 8 ; ++i
)
1876 pat
.pat
[i
] = dash
[index
] ;
1877 if (index
< number
- 1)
1883 wxMacGetPattern(penStyle
, &pat
);
1887 short mode
= patCopy
;
1889 switch( m_logicalFunction
)
1891 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1894 case wxINVERT
: // NOT dst
1895 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1898 case wxXOR
: // src XOR dst
1901 case wxOR_REVERSE
: // src OR (NOT dst)
1904 case wxSRC_INVERT
: // (NOT src)
1907 case wxAND
: // src AND dst
1912 case wxAND_REVERSE
:// src AND (NOT dst)
1913 case wxAND_INVERT
: // (NOT src) AND dst
1914 case wxNO_OP
: // dst
1915 case wxNOR
: // (NOT src) AND (NOT dst)
1916 case wxEQUIV
: // (NOT src) XOR dst
1917 case wxOR_INVERT
: // (NOT src) OR dst
1918 case wxNAND
: // (NOT src) OR (NOT dst)
1919 case wxOR
: // src OR dst
1921 // case wxSRC_OR: // source _bitmap_ OR destination
1922 // case wxSRC_AND: // source _bitmap_ AND destination
1926 m_macPenInstalled
= true ;
1927 m_macBrushInstalled
= false ;
1928 m_macFontInstalled
= false ;
1931 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1933 Pattern whiteColor
;
1934 if ( background
.Ok() )
1936 switch( background
.MacGetBrushKind() )
1938 case kwxMacBrushTheme
:
1940 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
1943 case kwxMacBrushThemeBackground
:
1946 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
1947 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1950 case kwxMacBrushColour
:
1952 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1953 int brushStyle
= background
.GetStyle();
1954 if (brushStyle
== wxSOLID
)
1955 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1956 else if (background
.IsHatch())
1959 wxMacGetPattern(brushStyle
, &pat
);
1964 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1972 void wxDC::MacInstallBrush() const
1974 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1975 Pattern blackColor
;
1976 // if ( m_macBrushInstalled )
1979 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1980 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1981 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1982 int brushStyle
= m_brush
.GetStyle();
1983 if (brushStyle
== wxSOLID
)
1985 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1987 else if (m_brush
.IsHatch())
1990 wxMacGetPattern(brushStyle
, &pat
);
1993 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1995 // we force this in order to be compliant with wxMSW
1996 backgroundTransparent
= false ;
1997 // for these the text fore (and back for MASK_OPAQUE) colors are used
1998 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1999 int width
= bitmap
->GetWidth() ;
2000 int height
= bitmap
->GetHeight() ;
2001 GWorldPtr gw
= NULL
;
2002 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2003 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2005 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2006 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2007 LockPixels( gwpixmaphandle
) ;
2008 bool isMonochrome
= !IsPortColor( gw
) ;
2009 if ( !isMonochrome
)
2011 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2012 isMonochrome
= true ;
2014 if ( isMonochrome
&& width
== 8 && height
== 8 )
2016 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2017 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2018 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2019 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2020 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2022 for ( int i
= 0 ; i
< 8 ; ++i
)
2024 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2026 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2031 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2032 // caching scheme before putting this into production
2035 PixPatHandle pixpat
= NewPixPat() ;
2036 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2037 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2038 ((**(**pixpat
).patMap
).bounds
.bottom
-
2039 (**(**pixpat
).patMap
).bounds
.top
);
2040 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2041 (**pixpat
).patData
= image
;
2044 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2045 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2046 if ( ctspec
[0].rgb
.red
== 0x0000 )
2048 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2049 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2053 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2054 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2056 ::CTabChanged( ctable
) ;
2058 ::PenPixPat(pixpat
);
2059 m_macForegroundPixMap
= pixpat
;
2061 UnlockPixels( gwpixmaphandle
) ;
2065 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2067 short mode
= patCopy
;
2068 switch( m_logicalFunction
)
2071 if ( backgroundTransparent
)
2076 case wxINVERT
: // NOT dst
2077 if ( !backgroundTransparent
)
2079 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2083 case wxXOR
: // src XOR dst
2086 case wxOR_REVERSE
: // src OR (NOT dst)
2089 case wxSRC_INVERT
: // (NOT src)
2092 case wxAND
: // src AND dst
2097 case wxAND_REVERSE
:// src AND (NOT dst)
2098 case wxAND_INVERT
: // (NOT src) AND dst
2099 case wxNO_OP
: // dst
2100 case wxNOR
: // (NOT src) AND (NOT dst)
2101 case wxEQUIV
: // (NOT src) XOR dst
2102 case wxOR_INVERT
: // (NOT src) OR dst
2103 case wxNAND
: // (NOT src) OR (NOT dst)
2104 case wxOR
: // src OR dst
2106 // case wxSRC_OR: // source _bitmap_ OR destination
2107 // case wxSRC_AND: // source _bitmap_ AND destination
2111 m_macBrushInstalled
= true ;
2112 m_macPenInstalled
= false ;
2113 m_macFontInstalled
= false ;
2116 // ---------------------------------------------------------------------------
2117 // coordinates transformations
2118 // ---------------------------------------------------------------------------
2120 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2122 return ((wxDC
*)this)->XDEV2LOG(x
);
2125 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2127 return ((wxDC
*)this)->YDEV2LOG(y
);
2130 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2132 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2135 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2137 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2140 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2142 return ((wxDC
*)this)->XLOG2DEV(x
);
2145 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2147 return ((wxDC
*)this)->YLOG2DEV(y
);
2150 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2152 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2155 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2157 return ((wxDC
*)this)->YLOG2DEVREL(y
);