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 GetPort( &m_oldPort
) ;
79 SetPort( (GrafPtr
) dc
->m_macPort
) ;
80 m_clipRgn
= NewRgn() ;
81 GetClip( m_clipRgn
) ;
83 dc
->MacSetupPort( NULL
) ;
85 ~wxMacFastPortSetter()
87 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
88 SetClip( m_clipRgn
) ;
89 SetPort( m_oldPort
) ;
90 m_dc
->MacCleanupPort( NULL
) ;
91 DisposeRgn( m_clipRgn
) ;
100 typedef wxMacPortSetter wxMacFastPortSetter
;
105 // start moving to a dual implementation for QD and CGContextRef
107 class wxMacGraphicsContext
110 void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
) = 0 ;
111 void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0 ;
112 void SetClippingRegion( const wxRegion
®ion
) = 0 ;
113 void DestroyClippingRegion() = 0 ;
114 void SetTextForeground( const wxColour
&col
) = 0 ;
115 void SetTextBackground( const wxColour
&col
) = 0 ;
116 void SetLogicalScale( double x
, double y
) = 0 ;
117 void SetUserScale( double x
, double y
) = 0;
120 class wxMacQuickDrawContext
: public wxMacGraphicsContext
127 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
129 m_formerClip
= NewRgn() ;
130 m_newClip
= NewRgn() ;
131 GetClip( m_formerClip
) ;
136 // this clipping area was set to the parent window's drawing area, lead to problems
137 // with MacOSX controls drawing outside their wx' rectangle
138 RgnHandle insidergn
= NewRgn() ;
140 wxWindow
*parent
= win
->GetParent() ;
141 parent
->MacWindowToRootWindow( &x
,&y
) ;
142 wxSize size
= parent
->GetSize() ;
143 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
144 size
.x
- parent
->MacGetRightBorderSize(),
145 size
.y
- parent
->MacGetBottomBorderSize()) ;
146 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
147 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
148 OffsetRgn( m_newClip
, x
, y
) ;
149 SetClip( m_newClip
) ;
150 DisposeRgn( insidergn
) ;
153 win
->MacWindowToRootWindow( &x
,&y
) ;
154 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
155 OffsetRgn( m_newClip
, x
, y
) ;
156 SetClip( m_newClip
) ;
161 wxMacWindowClipper::~wxMacWindowClipper()
163 SetClip( m_formerClip
) ;
164 DisposeRgn( m_newClip
) ;
165 DisposeRgn( m_formerClip
) ;
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
172 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
173 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
175 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
178 // this function emulates all wx colour manipulations, used to verify the implementation
179 // by setting the mode in the blitting functions to kEmulatedMode
180 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
182 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
184 switch ( logical_func
)
186 case wxAND
: // src AND dst
187 dstColor
.red
= dstColor
.red
& srcColor
.red
;
188 dstColor
.green
= dstColor
.green
& srcColor
.green
;
189 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
191 case wxAND_INVERT
: // (NOT src) AND dst
192 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
193 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
194 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
196 case wxAND_REVERSE
:// src AND (NOT dst)
197 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
198 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
199 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
207 dstColor
.red
= srcColor
.red
;
208 dstColor
.green
= srcColor
.green
;
209 dstColor
.blue
= srcColor
.blue
;
211 case wxEQUIV
: // (NOT src) XOR dst
212 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
213 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
214 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
216 case wxINVERT
: // NOT dst
217 dstColor
.red
= ~dstColor
.red
;
218 dstColor
.green
= ~dstColor
.green
;
219 dstColor
.blue
= ~dstColor
.blue
;
221 case wxNAND
: // (NOT src) OR (NOT dst)
222 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
223 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
224 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
226 case wxNOR
: // (NOT src) AND (NOT dst)
227 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
228 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
229 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
233 case wxOR
: // src OR dst
234 dstColor
.red
= dstColor
.red
| srcColor
.red
;
235 dstColor
.green
= dstColor
.green
| srcColor
.green
;
236 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
238 case wxOR_INVERT
: // (NOT src) OR dst
239 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
240 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
241 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
243 case wxOR_REVERSE
: // src OR (NOT dst)
244 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
245 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
246 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
249 dstColor
.red
= 0xFFFF ;
250 dstColor
.green
= 0xFFFF ;
251 dstColor
.blue
= 0xFFFF ;
253 case wxSRC_INVERT
: // (NOT src)
254 dstColor
.red
= ~srcColor
.red
;
255 dstColor
.green
= ~srcColor
.green
;
256 dstColor
.blue
= ~srcColor
.blue
;
258 case wxXOR
: // src XOR dst
259 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
260 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
261 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
270 m_mm_to_pix_x
= mm2pt
;
271 m_mm_to_pix_y
= mm2pt
;
272 m_internalDeviceOriginX
= 0;
273 m_internalDeviceOriginY
= 0;
274 m_externalDeviceOriginX
= 0;
275 m_externalDeviceOriginY
= 0;
276 m_logicalScaleX
= 1.0;
277 m_logicalScaleY
= 1.0;
282 m_needComputeScaleX
= false;
283 m_needComputeScaleY
= false;
287 m_macFontInstalled
= false ;
288 m_macBrushInstalled
= false ;
289 m_macPenInstalled
= false ;
290 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
291 m_macBoundaryClipRgn
= NewRgn() ;
292 m_macCurrentClipRgn
= NewRgn() ;
293 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
294 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
295 m_pen
= *wxBLACK_PEN
;
296 m_font
= *wxNORMAL_FONT
;
297 m_brush
= *wxWHITE_BRUSH
;
299 // needed to debug possible errors with two active drawing methods at the same time on
301 m_macCurrentPortStateHelper
= NULL
;
303 m_macATSUIStyle
= NULL
;
304 m_macAliasWasEnabled
= false;
305 m_macForegroundPixMap
= NULL
;
306 m_macBackgroundPixMap
= NULL
;
311 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
312 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
315 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
318 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
319 m_macCurrentPortStateHelper
= help
;
321 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
322 #if ! wxMAC_EXPERIMENTAL_DC
323 m_macFontInstalled
= false ;
324 m_macBrushInstalled
= false ;
325 m_macPenInstalled
= false ;
328 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
331 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
332 m_macCurrentPortStateHelper
= NULL
;
334 if( m_macATSUIStyle
)
336 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
337 m_macATSUIStyle
= NULL
;
339 if ( m_macAliasWasEnabled
)
341 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
342 m_macAliasWasEnabled
= false ;
344 if ( m_macForegroundPixMap
)
347 ::PenPat(GetQDGlobalsBlack(&blackColor
));
348 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
349 m_macForegroundPixMap
= NULL
;
351 if ( m_macBackgroundPixMap
)
354 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
355 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
356 m_macBackgroundPixMap
= NULL
;
360 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
362 wxCHECK_RET( Ok(), wxT("invalid window dc") );
363 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
364 wxMacFastPortSetter
helper(this) ;
365 wxCoord xx
= XLOG2DEVMAC(x
);
366 wxCoord yy
= YLOG2DEVMAC(y
);
367 wxCoord w
= bmp
.GetWidth();
368 wxCoord h
= bmp
.GetHeight();
369 wxCoord ww
= XLOG2DEVREL(w
);
370 wxCoord hh
= YLOG2DEVREL(h
);
371 // Set up drawing mode
372 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
373 //m_logicalFunction == wxCLEAR ? WHITENESS :
374 //m_logicalFunction == wxSET ? BLACKNESS :
375 m_logicalFunction
== wxINVERT
? hilite
:
376 //m_logicalFunction == wxAND ? MERGECOPY :
377 m_logicalFunction
== wxOR
? srcOr
:
378 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
379 m_logicalFunction
== wxXOR
? srcXor
:
380 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
381 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
382 //m_logicalFunction == wxSRC_OR ? srcOr :
383 //m_logicalFunction == wxSRC_AND ? SRCAND :
385 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
386 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
387 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
388 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
390 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
392 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
393 PixMapHandle bmappixels
;
394 // Set foreground and background colours (for bitmaps depth = 1)
395 if(bmp
.GetDepth() == 1)
397 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
398 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
404 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
405 RGBColor black
= { 0,0,0} ;
406 RGBForeColor( &black
) ;
407 RGBBackColor( &white
) ;
409 bmappixels
= GetGWorldPixMap( bmapworld
) ;
410 wxCHECK_RET(LockPixels(bmappixels
),
411 wxT("DoDrawBitmap: Unable to lock pixels"));
412 Rect source
= { 0, 0, h
, w
};
413 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
414 if ( useMask
&& bmp
.GetMask() )
416 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
420 GetPortBitMapForCopyBits(bmapworld
),
421 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
422 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
423 &source
, &source
, &dest
, mode
, NULL
425 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
429 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
430 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
431 &source
, &dest
, mode
, NULL
) ;
433 UnlockPixels( bmappixels
) ;
435 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
437 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
438 OffsetRect( &bitmaprect
, xx
, yy
) ;
439 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
441 m_macPenInstalled
= false ;
442 m_macBrushInstalled
= false ;
443 m_macFontInstalled
= false ;
446 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
448 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
449 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
450 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
453 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
455 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
456 wxCoord xx
, yy
, ww
, hh
;
459 ww
= XLOG2DEVREL(width
);
460 hh
= YLOG2DEVREL(height
);
461 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
462 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
465 m_clipX1
= wxMax( m_clipX1
, xx
);
466 m_clipY1
= wxMax( m_clipY1
, yy
);
467 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
468 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
480 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
482 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
485 DestroyClippingRegion();
488 wxMacFastPortSetter
helper(this) ;
490 region
.GetBox( x
, y
, w
, h
);
491 wxCoord xx
, yy
, ww
, hh
;
496 // if we have a scaling that we cannot map onto native regions
497 // we must use the box
498 if ( ww
!= w
|| hh
!= h
)
500 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
504 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
505 if ( xx
!= x
|| yy
!= y
)
507 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
509 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
512 m_clipX1
= wxMax( m_clipX1
, xx
);
513 m_clipY1
= wxMax( m_clipY1
, yy
);
514 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
515 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
528 void wxDC::DestroyClippingRegion()
530 wxMacFastPortSetter
helper(this) ;
531 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
535 void wxDC::DoGetSizeMM( int* width
, int* height
) const
540 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
541 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
544 void wxDC::SetTextForeground( const wxColour
&col
)
546 wxCHECK_RET(Ok(), wxT("Invalid DC"));
547 m_textForegroundColour
= col
;
548 m_macFontInstalled
= false ;
551 void wxDC::SetTextBackground( const wxColour
&col
)
553 wxCHECK_RET(Ok(), wxT("Invalid DC"));
554 m_textBackgroundColour
= col
;
555 m_macFontInstalled
= false ;
558 void wxDC::SetMapMode( int mode
)
563 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
566 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
569 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
572 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
576 SetLogicalScale( 1.0, 1.0 );
579 if (mode
!= wxMM_TEXT
)
581 m_needComputeScaleX
= true;
582 m_needComputeScaleY
= true;
586 void wxDC::SetUserScale( double x
, double y
)
588 // allow negative ? -> no
591 ComputeScaleAndOrigin();
594 void wxDC::SetLogicalScale( double x
, double y
)
599 ComputeScaleAndOrigin();
602 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
604 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
605 m_logicalOriginY
= y
* m_signY
;
606 ComputeScaleAndOrigin();
609 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
611 m_externalDeviceOriginX
= x
;
612 m_externalDeviceOriginY
= y
;
613 ComputeScaleAndOrigin();
617 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
619 m_internalDeviceOriginX
= x
;
620 m_internalDeviceOriginY
= y
;
621 ComputeScaleAndOrigin();
623 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
625 if (x
) *x
= m_internalDeviceOriginX
;
626 if (y
) *y
= m_internalDeviceOriginY
;
630 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
632 m_signX
= (xLeftRight
? 1 : -1);
633 m_signY
= (yBottomUp
? -1 : 1);
634 ComputeScaleAndOrigin();
637 wxSize
wxDC::GetPPI() const
639 return wxSize(72, 72);
642 int wxDC::GetDepth() const
644 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
646 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
651 void wxDC::ComputeScaleAndOrigin()
653 // CMB: copy scale to see if it changes
654 double origScaleX
= m_scaleX
;
655 double origScaleY
= m_scaleY
;
656 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
657 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
658 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
659 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
660 // CMB: if scale has changed call SetPen to recalulate the line width
661 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
663 // this is a bit artificial, but we need to force wxDC to think
664 // the pen has changed
665 wxPen
* pen
= & GetPen();
672 void wxDC::SetPalette( const wxPalette
& palette
)
676 void wxDC::SetBackgroundMode( int mode
)
678 m_backgroundMode
= mode
;
681 void wxDC::SetFont( const wxFont
&font
)
684 m_macFontInstalled
= false ;
687 void wxDC::SetPen( const wxPen
&pen
)
692 m_macPenInstalled
= false ;
695 void wxDC::SetBrush( const wxBrush
&brush
)
697 if (m_brush
== brush
)
700 m_macBrushInstalled
= false ;
703 void wxDC::SetBackground( const wxBrush
&brush
)
705 if (m_backgroundBrush
== brush
)
707 m_backgroundBrush
= brush
;
708 if (!m_backgroundBrush
.Ok())
710 m_macBrushInstalled
= false ;
713 void wxDC::SetLogicalFunction( int function
)
715 if (m_logicalFunction
== function
)
717 m_logicalFunction
= function
;
718 m_macFontInstalled
= false ;
719 m_macBrushInstalled
= false ;
720 m_macPenInstalled
= false ;
723 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
724 const wxColour
& col
, int style
);
726 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
727 const wxColour
& col
, int style
)
729 return wxDoFloodFill(this, x
, y
, col
, style
);
732 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
734 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
735 wxMacFastPortSetter
helper(this) ;
737 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
738 // Convert from Mac colour to wx
739 col
->Set( colour
.red
>> 8,
745 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
747 wxCHECK_RET(Ok(), wxT("Invalid DC"));
748 wxMacFastPortSetter
helper(this) ;
749 if (m_pen
.GetStyle() != wxTRANSPARENT
)
752 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
753 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
754 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
755 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
756 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
757 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
758 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
759 (m_pen
.GetWidth() <= 1))
761 // Implement LAST_NOT for MAC at least for
762 // orthogonal lines. RR.
783 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
785 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
786 wxMacFastPortSetter
helper(this) ;
787 if (m_pen
.GetStyle() != wxTRANSPARENT
)
792 wxCoord xx
= XLOG2DEVMAC(x
);
793 wxCoord yy
= YLOG2DEVMAC(y
);
795 ::MoveTo( XLOG2DEVMAC(0), yy
);
796 ::LineTo( XLOG2DEVMAC(w
), yy
);
797 ::MoveTo( xx
, YLOG2DEVMAC(0) );
798 ::LineTo( xx
, YLOG2DEVMAC(h
) );
799 CalcBoundingBox(x
, y
);
800 CalcBoundingBox(x
+w
, y
+h
);
805 * To draw arcs properly the angles need to be converted from the WX style:
806 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
807 * a normal axis on paper).
810 * Angles start on the +ve y axis and go clockwise.
813 static double wxConvertWXangleToMACangle(double angle
)
815 double newAngle
= 90 - angle
;
821 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
822 wxCoord x2
, wxCoord y2
,
823 wxCoord xc
, wxCoord yc
)
825 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
826 wxMacFastPortSetter
helper(this) ;
827 wxCoord xx1
= XLOG2DEVMAC(x1
);
828 wxCoord yy1
= YLOG2DEVMAC(y1
);
829 wxCoord xx2
= XLOG2DEVMAC(x2
);
830 wxCoord yy2
= YLOG2DEVMAC(y2
);
831 wxCoord xxc
= XLOG2DEVMAC(xc
);
832 wxCoord yyc
= YLOG2DEVMAC(yc
);
833 double dx
= xx1
- xxc
;
834 double dy
= yy1
- yyc
;
835 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
836 wxCoord rad
= (wxCoord
)radius
;
837 double radius1
, radius2
;
838 if (xx1
== xx2
&& yy1
== yy2
)
843 else if (radius
== 0.0)
845 radius1
= radius2
= 0.0;
849 radius1
= (xx1
- xxc
== 0) ?
850 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
851 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
852 radius2
= (xx2
- xxc
== 0) ?
853 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
854 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
856 wxCoord alpha2
= wxCoord(radius2
- radius1
);
857 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
858 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
861 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
862 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
864 PaintArc(&r
, alpha1
, alpha2
);
866 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
868 FrameArc(&r
, alpha1
, alpha2
);
872 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
873 double sa
, double ea
)
875 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
876 wxMacFastPortSetter
helper(this) ;
878 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
879 // we have to make sure that the filling is always counter-clockwise
882 wxCoord xx
= XLOG2DEVMAC(x
);
883 wxCoord yy
= YLOG2DEVMAC(y
);
884 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
885 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
886 // handle -ve width and/or height
887 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
888 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
889 sa
= wxConvertWXangleToMACangle(sa
);
894 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
896 PaintArc(&r
, (short)sa
, (short)angle
);
898 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
900 FrameArc(&r
, (short)sa
, (short)angle
);
904 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
906 wxCHECK_RET(Ok(), wxT("Invalid DC"));
907 wxMacFastPortSetter
helper(this) ;
908 if (m_pen
.GetStyle() != wxTRANSPARENT
)
910 wxCoord xx1
= XLOG2DEVMAC(x
);
911 wxCoord yy1
= YLOG2DEVMAC(y
);
912 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
913 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
914 CalcBoundingBox(x
, y
);
918 void wxDC::DoDrawLines(int n
, wxPoint points
[],
919 wxCoord xoffset
, wxCoord yoffset
)
921 wxCHECK_RET(Ok(), wxT("Invalid DC"));
922 wxMacFastPortSetter
helper(this) ;
923 if (m_pen
.GetStyle() == wxTRANSPARENT
)
926 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
927 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
928 wxCoord x1
, x2
, y1
, y2
;
929 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
930 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
931 ::MoveTo(x1
- offset
, y1
- offset
);
932 for (int i
= 0; i
< n
-1; i
++)
934 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
935 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
936 ::LineTo( x2
- offset
, y2
- offset
);
940 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
941 wxCoord xoffset
, wxCoord yoffset
,
944 wxCHECK_RET(Ok(), wxT("Invalid DC"));
945 wxMacFastPortSetter
helper(this) ;
946 wxCoord x1
, x2
, y1
, y2
;
947 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
949 PolyHandle polygon
= OpenPoly();
950 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
951 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
953 for (int i
= 1; i
< n
; i
++)
955 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
956 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
959 // close the polyline if necessary
960 if ( x1
!= x2
|| y1
!= y2
)
965 if (m_brush
.GetStyle() != wxTRANSPARENT
)
968 ::PaintPoly( polygon
);
970 if (m_pen
.GetStyle() != wxTRANSPARENT
)
973 ::FramePoly( polygon
) ;
978 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
980 wxCHECK_RET(Ok(), wxT("Invalid DC"));
981 wxMacFastPortSetter
helper(this) ;
982 wxCoord xx
= XLOG2DEVMAC(x
);
983 wxCoord yy
= YLOG2DEVMAC(y
);
984 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
985 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
986 // CMB: draw nothing if transformed w or h is 0
987 if (ww
== 0 || hh
== 0)
989 // CMB: handle -ve width and/or height
1000 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1001 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1004 ::PaintRect( &rect
) ;
1006 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1009 ::FrameRect( &rect
) ;
1013 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1014 wxCoord width
, wxCoord height
,
1017 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1018 wxMacFastPortSetter
helper(this) ;
1020 radius
= - radius
* ((width
< height
) ? width
: height
);
1021 wxCoord xx
= XLOG2DEVMAC(x
);
1022 wxCoord yy
= YLOG2DEVMAC(y
);
1023 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1024 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1025 // CMB: draw nothing if transformed w or h is 0
1026 if (ww
== 0 || hh
== 0)
1028 // CMB: handle -ve width and/or height
1039 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1040 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1043 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1045 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1048 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1052 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1054 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1055 wxMacFastPortSetter
helper(this) ;
1056 wxCoord xx
= XLOG2DEVMAC(x
);
1057 wxCoord yy
= YLOG2DEVMAC(y
);
1058 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1059 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1060 // CMB: draw nothing if transformed w or h is 0
1061 if (ww
== 0 || hh
== 0)
1063 // CMB: handle -ve width and/or height
1074 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1075 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1078 ::PaintOval( &rect
) ;
1080 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1083 ::FrameOval( &rect
) ;
1087 bool wxDC::CanDrawBitmap(void) const
1092 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1093 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1094 wxCoord xsrcMask
, wxCoord ysrcMask
)
1096 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1097 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1098 if ( logical_func
== wxNO_OP
)
1100 if (xsrcMask
== -1 && ysrcMask
== -1)
1102 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1104 // correct the parameter in case this dc does not have a mask at all
1105 if ( useMask
&& !source
->m_macMask
)
1107 Rect srcrect
, dstrect
;
1108 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1109 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1110 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1111 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1112 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1113 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1114 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1115 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1116 short mode
= kUnsupportedMode
;
1117 bool invertDestinationFirst
= false ;
1118 switch ( logical_func
)
1120 case wxAND
: // src AND dst
1121 mode
= adMin
; // ok
1123 case wxAND_INVERT
: // (NOT src) AND dst
1124 mode
= notSrcOr
; // ok
1126 case wxAND_REVERSE
:// src AND (NOT dst)
1127 invertDestinationFirst
= true ;
1131 mode
= kEmulatedMode
;
1134 mode
= srcCopy
; // ok
1136 case wxEQUIV
: // (NOT src) XOR dst
1137 mode
= srcXor
; // ok
1139 case wxINVERT
: // NOT dst
1140 mode
= kEmulatedMode
; //or hilite ;
1142 case wxNAND
: // (NOT src) OR (NOT dst)
1143 invertDestinationFirst
= true ;
1146 case wxNOR
: // (NOT src) AND (NOT dst)
1147 invertDestinationFirst
= true ;
1150 case wxNO_OP
: // dst
1151 mode
= kEmulatedMode
; // this has already been handled upon entry
1153 case wxOR
: // src OR dst
1156 case wxOR_INVERT
: // (NOT src) OR dst
1159 case wxOR_REVERSE
: // src OR (NOT dst)
1160 invertDestinationFirst
= true ;
1164 mode
= kEmulatedMode
;
1166 case wxSRC_INVERT
: // (NOT src)
1167 mode
= notSrcCopy
; // ok
1169 case wxXOR
: // src XOR dst
1170 mode
= notSrcXor
; // ok
1175 if ( mode
== kUnsupportedMode
)
1177 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1180 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1181 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1182 if ( LockPixels(bmappixels
) )
1184 wxMacFastPortSetter
helper(this) ;
1185 if ( source
->GetDepth() == 1 )
1187 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1188 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1192 // the modes need this, otherwise we'll end up having really nice colors...
1193 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1194 RGBColor black
= { 0,0,0} ;
1195 RGBForeColor( &black
) ;
1196 RGBBackColor( &white
) ;
1198 if ( useMask
&& source
->m_macMask
)
1200 if ( mode
== srcCopy
)
1202 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1204 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1205 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1206 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1207 &srcrect
, &srcrect
, &dstrect
) ;
1208 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1213 RgnHandle clipRgn
= NewRgn() ;
1214 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1215 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1216 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1217 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1218 if ( mode
== kEmulatedMode
)
1221 ::PenPat(GetQDGlobalsBlack(&pat
));
1222 if ( logical_func
== wxSET
)
1224 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1225 ::RGBForeColor( &col
) ;
1226 ::PaintRgn( clipRgn
) ;
1228 else if ( logical_func
== wxCLEAR
)
1230 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1231 ::RGBForeColor( &col
) ;
1232 ::PaintRgn( clipRgn
) ;
1234 else if ( logical_func
== wxINVERT
)
1236 MacInvertRgn( clipRgn
) ;
1240 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1242 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1244 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1245 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1246 if ( PtInRgn( dstPoint
, clipRgn
) )
1250 SetPort( (GrafPtr
) sourcePort
) ;
1251 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1252 SetPort( (GrafPtr
) m_macPort
) ;
1253 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1254 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1255 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1263 if ( invertDestinationFirst
)
1265 MacInvertRgn( clipRgn
) ;
1267 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1268 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1269 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1271 DisposeRgn( clipRgn
) ;
1276 RgnHandle clipRgn
= NewRgn() ;
1277 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1278 if ( mode
== kEmulatedMode
)
1281 ::PenPat(GetQDGlobalsBlack(&pat
));
1282 if ( logical_func
== wxSET
)
1284 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1285 ::RGBForeColor( &col
) ;
1286 ::PaintRgn( clipRgn
) ;
1288 else if ( logical_func
== wxCLEAR
)
1290 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1291 ::RGBForeColor( &col
) ;
1292 ::PaintRgn( clipRgn
) ;
1294 else if ( logical_func
== wxINVERT
)
1296 MacInvertRgn( clipRgn
) ;
1300 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1302 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1304 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1305 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1309 SetPort( (GrafPtr
) sourcePort
) ;
1310 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1311 SetPort( (GrafPtr
) m_macPort
) ;
1312 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1313 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1314 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1322 if ( invertDestinationFirst
)
1324 MacInvertRgn( clipRgn
) ;
1326 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1327 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1328 &srcrect
, &dstrect
, mode
, NULL
) ;
1330 DisposeRgn( clipRgn
) ;
1332 UnlockPixels( bmappixels
) ;
1334 m_macPenInstalled
= false ;
1335 m_macBrushInstalled
= false ;
1336 m_macFontInstalled
= false ;
1341 // as macro in FixMath.h for 10.3
1342 inline Fixed
IntToFixed( int inInt
)
1344 return (((SInt32
) inInt
) << 16);
1347 inline int FixedToInt( Fixed inFixed
)
1349 return (((SInt32
) inFixed
) >> 16);
1353 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1356 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1360 DrawText(str
, x
, y
);
1364 if ( str
.Length() == 0 )
1367 wxMacFastPortSetter
helper(this) ;
1372 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1373 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.GetMacFontSize()));
1374 m_macAliasWasEnabled
= true ;
1376 OSStatus status
= noErr
;
1377 ATSUTextLayout atsuLayout
;
1378 UniCharCount chars
= str
.Length() ;
1380 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1381 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1383 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1384 int wlen
= wxWcslen( wchar
.data() ) ;
1385 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1386 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1388 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1389 int iAngle
= int( angle
);
1390 int drawX
= XLOG2DEVMAC(x
) ;
1391 int drawY
= YLOG2DEVMAC(y
) ;
1393 ATSUTextMeasurement textBefore
;
1394 ATSUTextMeasurement textAfter
;
1395 ATSUTextMeasurement ascent
;
1396 ATSUTextMeasurement descent
;
1399 if ( abs(iAngle
) > 0 )
1401 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1402 ATSUAttributeTag atsuTags
[] =
1404 kATSULineRotationTag
,
1406 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1410 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1414 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1415 atsuTags
, atsuSizes
, atsuValues
) ;
1417 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1418 &textBefore
, &textAfter
, &ascent
, &descent
);
1420 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1421 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1422 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1423 IntToFixed(drawX
) , IntToFixed(drawY
) );
1424 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1426 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1427 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1428 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1429 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1430 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1431 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1432 ::ATSUDisposeTextLayout(atsuLayout
);
1435 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1437 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1439 wxMacFastPortSetter
helper(this) ;
1440 long xx
= XLOG2DEVMAC(x
);
1441 long yy
= YLOG2DEVMAC(y
);
1443 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1444 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1445 useDrawThemeText
= false ;
1450 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1451 SetAntiAliasedTextEnabled(true, 8);
1452 m_macAliasWasEnabled
= true ;
1455 ::GetFontInfo( &fi
) ;
1457 if ( !useDrawThemeText
)
1460 ::MoveTo( xx
, yy
);
1461 if ( m_backgroundMode
== wxTRANSPARENT
)
1463 ::TextMode( srcOr
) ;
1467 ::TextMode( srcCopy
) ;
1469 int length
= strtext
.Length() ;
1475 #if 0 // we don't have to do all that here
1478 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1480 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1482 if ( useDrawThemeText
)
1484 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1485 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1486 if ( m_backgroundMode
!= wxTRANSPARENT
)
1488 Point bounds
={0,0} ;
1489 Rect background
= frame
;
1491 ::GetThemeTextDimensions( mString
,
1492 kThemeCurrentPortFont
,
1497 background
.right
= background
.left
+ bounds
.h
;
1498 background
.bottom
= background
.top
+ bounds
.v
;
1499 ::EraseRect( &background
) ;
1501 ::DrawThemeTextBox( mString
,
1502 kThemeCurrentPortFont
,
1513 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1514 ::DrawText( text
, 0 , strlen(text
) ) ;
1515 if ( m_backgroundMode
!= wxTRANSPARENT
)
1517 Point bounds
={0,0} ;
1518 Rect background
= frame
;
1520 ::GetThemeTextDimensions( mString
,
1521 kThemeCurrentPortFont
,
1526 background
.right
= background
.left
+ bounds
.h
;
1527 background
.bottom
= background
.top
+ bounds
.v
;
1528 ::EraseRect( &background
) ;
1531 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1537 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1539 wxString linetext
= strtext
;
1541 if ( useDrawThemeText
)
1543 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1544 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1546 if ( m_backgroundMode
!= wxTRANSPARENT
)
1548 Point bounds
={0,0} ;
1549 Rect background
= frame
;
1551 ::GetThemeTextDimensions( mString
,
1552 kThemeCurrentPortFont
,
1557 background
.right
= background
.left
+ bounds
.h
;
1558 background
.bottom
= background
.top
+ bounds
.v
;
1559 ::EraseRect( &background
) ;
1561 ::DrawThemeTextBox( mString
,
1562 kThemeCurrentPortFont
,
1572 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1573 if ( m_backgroundMode
!= wxTRANSPARENT
)
1575 Rect frame
= { yy
- fi
.ascent
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
- fi
.ascent
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1576 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1577 frame
.right
= frame
.left
+ width
;
1579 ::EraseRect( &frame
) ;
1581 ::DrawText( text
, 0 , strlen(text
) ) ;
1584 ::TextMode( srcOr
) ;
1587 bool wxDC::CanGetTextExtent() const
1589 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1593 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1594 wxCoord
*descent
, wxCoord
*externalLeading
,
1595 wxFont
*theFont
) const
1597 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1598 wxMacFastPortSetter
helper(this) ;
1599 wxFont formerFont
= m_font
;
1602 // work around the constness
1603 *((wxFont
*)(&m_font
)) = *theFont
;
1607 ::GetFontInfo( &fi
) ;
1609 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1610 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1611 useGetThemeText
= false ;
1614 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1616 *descent
=YDEV2LOGREL( fi
.descent
);
1617 if ( externalLeading
)
1618 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1619 int length
= strtext
.Length() ;
1627 #if 0 // apparently we don't have to do all that
1630 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1632 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1634 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1636 if ( useGetThemeText
)
1638 Point bounds
={0,0} ;
1640 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1641 ::GetThemeTextDimensions( mString
,
1642 kThemeCurrentPortFont
,
1647 curwidth
= bounds
.h
;
1652 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1653 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1655 if ( curwidth
> *width
)
1656 *width
= XDEV2LOGREL( curwidth
) ;
1662 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1664 wxString linetext
= strtext
;
1666 if ( useGetThemeText
)
1668 Point bounds
={0,0} ;
1670 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1671 ::GetThemeTextDimensions( mString
,
1672 kThemeCurrentPortFont
,
1677 curwidth
= bounds
.h
;
1682 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1683 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1685 if ( curwidth
> *width
)
1686 *width
= XDEV2LOGREL( curwidth
) ;
1690 // work around the constness
1691 *((wxFont
*)(&m_font
)) = formerFont
;
1692 m_macFontInstalled
= false ;
1697 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1699 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1702 widths
.Add(0, text
.Length());
1704 if (text
.Length() == 0)
1707 wxMacFastPortSetter
helper(this) ;
1710 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1711 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1712 useGetThemeText
= false ;
1714 if ( useGetThemeText
)
1716 // If anybody knows how to do this more efficiently yet still handle
1717 // the fractional glyph widths that may be present when using AA
1718 // fonts, please change it. Currently it is measuring from the
1719 // begining of the string for each succeding substring, which is much
1720 // slower than this should be.
1721 for (size_t i
=0; i
<text
.Length(); i
++)
1723 wxString
str(text
.Left(i
+1));
1724 Point bounds
= {0,0};
1726 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1727 ::GetThemeTextDimensions( mString
,
1728 kThemeCurrentPortFont
,
1733 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1739 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1740 size_t len
= strlen(buff
);
1741 short* measurements
= new short[len
+1];
1742 MeasureText(len
, buff
.data(), measurements
);
1744 // Copy to widths, starting at measurements[1]
1745 // NOTE: this doesn't take into account any multi-byte characters
1746 // in buff, it probabkly should...
1747 for (size_t i
=0; i
<text
.Length(); i
++)
1748 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1750 delete [] measurements
;
1758 wxCoord
wxDC::GetCharWidth(void) const
1760 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1761 wxMacFastPortSetter
helper(this) ;
1765 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1766 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1767 useGetThemeText
= false ;
1771 if ( useGetThemeText
)
1773 Point bounds
={0,0} ;
1775 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1776 ::GetThemeTextDimensions( mString
,
1777 kThemeCurrentPortFont
,
1782 CFRelease( mString
) ;
1788 width
= ::TextWidth( text
, 0 , 1 ) ;
1790 return YDEV2LOGREL(width
) ;
1793 wxCoord
wxDC::GetCharHeight(void) const
1795 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1796 wxMacFastPortSetter
helper(this) ;
1799 ::GetFontInfo( &fi
) ;
1800 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1803 void wxDC::Clear(void)
1805 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1806 wxMacFastPortSetter
helper(this) ;
1807 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1808 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1811 //MacInstallBrush() ;
1812 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1813 ::EraseRect( &rect
) ;
1817 void wxDC::MacInstallFont() const
1819 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1820 // if ( m_macFontInstalled )
1822 Pattern blackColor
;
1823 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1826 ::TextFont( m_font
.GetMacFontNum() ) ;
1827 ::TextSize( (short)(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1828 ::TextFace( m_font
.GetMacFontStyle() ) ;
1829 m_macFontInstalled
= true ;
1830 m_macBrushInstalled
= false ;
1831 m_macPenInstalled
= false ;
1832 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1833 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1834 ::RGBForeColor( &forecolor
);
1835 ::RGBBackColor( &backcolor
);
1839 FontFamilyID fontId
;
1843 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1844 GetFNum( fontName
, &fontId
);
1845 ::TextFont( fontId
) ;
1846 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1847 ::TextFace( fontStyle
) ;
1848 // todo reset after spacing changes - or store the current spacing somewhere
1849 m_macFontInstalled
= true ;
1850 m_macBrushInstalled
= false ;
1851 m_macPenInstalled
= false ;
1852 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1853 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1854 ::RGBForeColor( &forecolor
);
1855 ::RGBBackColor( &backcolor
);
1857 short mode
= patCopy
;
1859 switch( m_logicalFunction
)
1864 case wxINVERT
: // NOT dst
1865 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1868 case wxXOR
: // src XOR dst
1871 case wxOR_REVERSE
: // src OR (NOT dst)
1874 case wxSRC_INVERT
: // (NOT src)
1877 case wxAND
: // src AND dst
1882 case wxAND_REVERSE
:// src AND (NOT dst)
1883 case wxAND_INVERT
: // (NOT src) AND dst
1884 case wxNO_OP
: // dst
1885 case wxNOR
: // (NOT src) AND (NOT dst)
1886 case wxEQUIV
: // (NOT src) XOR dst
1887 case wxOR_INVERT
: // (NOT src) OR dst
1888 case wxNAND
: // (NOT src) OR (NOT dst)
1889 case wxOR
: // src OR dst
1891 // case wxSRC_OR: // source _bitmap_ OR destination
1892 // case wxSRC_AND: // source _bitmap_ AND destination
1896 OSStatus status
= noErr
;
1897 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1898 Style qdStyle
= m_font
.GetMacFontStyle() ;
1899 ATSUFontID atsuFont
= m_font
.GetMacATSUFontID() ;
1900 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1901 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1902 ATSUAttributeTag atsuTags
[] =
1907 // kATSUBaselineClassTag ,
1908 kATSUVerticalCharacterTag
,
1909 kATSUQDBoldfaceTag
,
1911 kATSUQDUnderlineTag
,
1912 kATSUQDCondensedTag
,
1913 kATSUQDExtendedTag
,
1915 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1917 sizeof( ATSUFontID
) ,
1919 // sizeof( RGBColor ) ,
1920 // sizeof( BslnBaselineClass ) ,
1921 sizeof( ATSUVerticalCharacterType
),
1928 Boolean kTrue
= true ;
1929 Boolean kFalse
= false ;
1930 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1931 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1932 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1936 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1937 // &kBaselineDefault ,
1939 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1940 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1941 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1942 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1943 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1945 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1946 atsuTags
, atsuSizes
, atsuValues
);
1947 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1950 Pattern gPatterns
[] =
1952 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1953 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1954 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1955 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1956 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1957 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1958 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1960 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1961 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1962 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1963 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1966 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1968 int index
= 0; // solid pattern by default
1972 case wxBDIAGONAL_HATCH
: index
= 1; break;
1973 case wxFDIAGONAL_HATCH
: index
= 2; break;
1974 case wxCROSS_HATCH
: index
= 3; break;
1975 case wxHORIZONTAL_HATCH
: index
= 4; break;
1976 case wxVERTICAL_HATCH
: index
= 5; break;
1977 case wxCROSSDIAG_HATCH
: index
= 6; break;
1979 case wxDOT
: index
= 7; break;
1980 case wxLONG_DASH
: index
= 8; break;
1981 case wxSHORT_DASH
: index
= 9; break;
1982 case wxDOT_DASH
: index
= 10; break;
1984 *pattern
= gPatterns
[index
];
1987 void wxDC::MacInstallPen() const
1989 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1990 //Pattern blackColor;
1991 // if ( m_macPenInstalled )
1993 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1994 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1995 ::RGBForeColor( &forecolor
);
1996 ::RGBBackColor( &backcolor
);
1998 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1999 // null means only one pixel, at whatever resolution
2000 if ( penWidth
== 0 )
2002 ::PenSize(penWidth
, penWidth
);
2004 int penStyle
= m_pen
.GetStyle();
2006 if (penStyle
== wxUSER_DASH
)
2008 // FIXME: there should be exactly 8 items in the dash
2010 int number
= m_pen
.GetDashes(&dash
) ;
2012 for ( int i
= 0 ; i
< 8 ; ++i
)
2014 pat
.pat
[i
] = dash
[index
] ;
2015 if (index
< number
- 1)
2021 wxMacGetPattern(penStyle
, &pat
);
2025 short mode
= patCopy
;
2027 switch( m_logicalFunction
)
2029 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2032 case wxINVERT
: // NOT dst
2033 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2036 case wxXOR
: // src XOR dst
2039 case wxOR_REVERSE
: // src OR (NOT dst)
2042 case wxSRC_INVERT
: // (NOT src)
2045 case wxAND
: // src AND dst
2050 case wxAND_REVERSE
:// src AND (NOT dst)
2051 case wxAND_INVERT
: // (NOT src) AND dst
2052 case wxNO_OP
: // dst
2053 case wxNOR
: // (NOT src) AND (NOT dst)
2054 case wxEQUIV
: // (NOT src) XOR dst
2055 case wxOR_INVERT
: // (NOT src) OR dst
2056 case wxNAND
: // (NOT src) OR (NOT dst)
2057 case wxOR
: // src OR dst
2059 // case wxSRC_OR: // source _bitmap_ OR destination
2060 // case wxSRC_AND: // source _bitmap_ AND destination
2064 m_macPenInstalled
= true ;
2065 m_macBrushInstalled
= false ;
2066 m_macFontInstalled
= false ;
2069 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2071 Pattern whiteColor
;
2072 switch( background
.MacGetBrushKind() )
2074 case kwxMacBrushTheme
:
2076 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2079 case kwxMacBrushThemeBackground
:
2082 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2083 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2086 case kwxMacBrushColour
:
2088 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2089 int brushStyle
= background
.GetStyle();
2090 if (brushStyle
== wxSOLID
)
2091 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2092 else if (background
.IsHatch())
2095 wxMacGetPattern(brushStyle
, &pat
);
2100 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2107 void wxDC::MacInstallBrush() const
2109 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2110 Pattern blackColor
;
2111 // if ( m_macBrushInstalled )
2114 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2115 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2116 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2117 int brushStyle
= m_brush
.GetStyle();
2118 if (brushStyle
== wxSOLID
)
2120 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2122 else if (m_brush
.IsHatch())
2125 wxMacGetPattern(brushStyle
, &pat
);
2128 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2130 // we force this in order to be compliant with wxMSW
2131 backgroundTransparent
= false ;
2132 // for these the text fore (and back for MASK_OPAQUE) colors are used
2133 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2134 int width
= bitmap
->GetWidth() ;
2135 int height
= bitmap
->GetHeight() ;
2136 GWorldPtr gw
= NULL
;
2137 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2138 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2140 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2141 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2142 LockPixels( gwpixmaphandle
) ;
2143 bool isMonochrome
= !IsPortColor( gw
) ;
2144 if ( !isMonochrome
)
2146 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2147 isMonochrome
= true ;
2149 if ( isMonochrome
&& width
== 8 && height
== 8 )
2151 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2152 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2153 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2154 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2155 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2157 for ( int i
= 0 ; i
< 8 ; ++i
)
2159 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2161 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2166 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2167 // caching scheme before putting this into production
2170 PixPatHandle pixpat
= NewPixPat() ;
2171 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2172 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2173 ((**(**pixpat
).patMap
).bounds
.bottom
-
2174 (**(**pixpat
).patMap
).bounds
.top
);
2175 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2176 (**pixpat
).patData
= image
;
2179 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2180 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2181 if ( ctspec
[0].rgb
.red
== 0x0000 )
2183 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2184 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2188 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2189 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2191 ::CTabChanged( ctable
) ;
2193 ::PenPixPat(pixpat
);
2194 m_macForegroundPixMap
= pixpat
;
2196 UnlockPixels( gwpixmaphandle
) ;
2200 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2202 short mode
= patCopy
;
2203 switch( m_logicalFunction
)
2206 if ( backgroundTransparent
)
2211 case wxINVERT
: // NOT dst
2212 if ( !backgroundTransparent
)
2214 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2218 case wxXOR
: // src XOR dst
2221 case wxOR_REVERSE
: // src OR (NOT dst)
2224 case wxSRC_INVERT
: // (NOT src)
2227 case wxAND
: // src AND dst
2232 case wxAND_REVERSE
:// src AND (NOT dst)
2233 case wxAND_INVERT
: // (NOT src) AND dst
2234 case wxNO_OP
: // dst
2235 case wxNOR
: // (NOT src) AND (NOT dst)
2236 case wxEQUIV
: // (NOT src) XOR dst
2237 case wxOR_INVERT
: // (NOT src) OR dst
2238 case wxNAND
: // (NOT src) OR (NOT dst)
2239 case wxOR
: // src OR dst
2241 // case wxSRC_OR: // source _bitmap_ OR destination
2242 // case wxSRC_AND: // source _bitmap_ AND destination
2246 m_macBrushInstalled
= true ;
2247 m_macPenInstalled
= false ;
2248 m_macFontInstalled
= false ;
2251 // ---------------------------------------------------------------------------
2252 // coordinates transformations
2253 // ---------------------------------------------------------------------------
2255 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2257 return ((wxDC
*)this)->XDEV2LOG(x
);
2260 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2262 return ((wxDC
*)this)->YDEV2LOG(y
);
2265 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2267 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2270 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2272 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2275 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2277 return ((wxDC
*)this)->XLOG2DEV(x
);
2280 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2282 return ((wxDC
*)this)->YLOG2DEV(y
);
2285 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2287 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2290 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2292 return ((wxDC
*)this)->YLOG2DEVREL(y
);