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>
36 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 const double RAD2DEG
= 180.0 / M_PI
;
43 const short kEmulatedMode
= -1 ;
44 const short kUnsupportedMode
= -2 ;
46 extern TECObjectRef s_TECNativeCToUnicode
;
48 // set to 0 if problems arise
49 #define wxMAC_EXPERIMENTAL_DC 1
51 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
52 m_ph( (GrafPtr
) dc
->m_macPort
)
54 wxASSERT( dc
->Ok() ) ;
56 dc
->MacSetupPort(&m_ph
) ;
58 wxMacPortSetter::~wxMacPortSetter()
60 m_dc
->MacCleanupPort(&m_ph
) ;
63 #if wxMAC_EXPERIMENTAL_DC
64 class wxMacFastPortSetter
67 wxMacFastPortSetter( const wxDC
*dc
)
69 wxASSERT( dc
->Ok() ) ;
70 GetPort( &m_oldPort
) ;
71 SetPort( (GrafPtr
) dc
->m_macPort
) ;
72 m_clipRgn
= NewRgn() ;
73 GetClip( m_clipRgn
) ;
75 dc
->MacSetupPort( NULL
) ;
77 ~wxMacFastPortSetter()
79 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
80 SetClip( m_clipRgn
) ;
81 SetPort( m_oldPort
) ;
82 m_dc
->MacCleanupPort( NULL
) ;
83 DisposeRgn( m_clipRgn
) ;
92 typedef wxMacPortSetter wxMacFastPortSetter
;
97 // start moving to a dual implementation for QD and CGContextRef
99 class wxMacGraphicsContext
102 void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
) = 0 ;
103 void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0 ;
104 void SetClippingRegion( const wxRegion
®ion
) = 0 ;
105 void DestroyClippingRegion() = 0 ;
106 void SetTextForeground( const wxColour
&col
) = 0 ;
107 void SetTextBackground( const wxColour
&col
) = 0 ;
108 void SetLogicalScale( double x
, double y
) = 0 ;
109 void SetUserScale( double x
, double y
) = 0;
112 class wxMacQuickDrawContext
: public wxMacGraphicsContext
119 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
121 m_formerClip
= NewRgn() ;
122 m_newClip
= NewRgn() ;
123 GetClip( m_formerClip
) ;
128 // this clipping area was set to the parent window's drawing area, lead to problems
129 // with MacOSX controls drawing outside their wx' rectangle
130 RgnHandle insidergn
= NewRgn() ;
132 wxWindow
*parent
= win
->GetParent() ;
133 parent
->MacWindowToRootWindow( &x
,&y
) ;
134 wxSize size
= parent
->GetSize() ;
135 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
136 size
.x
- parent
->MacGetRightBorderSize(),
137 size
.y
- parent
->MacGetBottomBorderSize()) ;
138 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
139 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
140 OffsetRgn( m_newClip
, x
, y
) ;
141 SetClip( m_newClip
) ;
142 DisposeRgn( insidergn
) ;
145 win
->MacWindowToRootWindow( &x
,&y
) ;
146 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
147 OffsetRgn( m_newClip
, x
, y
) ;
148 SetClip( m_newClip
) ;
153 wxMacWindowClipper::~wxMacWindowClipper()
155 SetClip( m_formerClip
) ;
156 DisposeRgn( m_newClip
) ;
157 DisposeRgn( m_formerClip
) ;
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
163 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
164 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
165 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
167 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
170 // this function emulates all wx colour manipulations, used to verify the implementation
171 // by setting the mode in the blitting functions to kEmulatedMode
172 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
174 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
176 switch ( logical_func
)
178 case wxAND
: // src AND dst
179 dstColor
.red
= dstColor
.red
& srcColor
.red
;
180 dstColor
.green
= dstColor
.green
& srcColor
.green
;
181 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
183 case wxAND_INVERT
: // (NOT src) AND dst
184 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
185 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
186 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
188 case wxAND_REVERSE
:// src AND (NOT dst)
189 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
190 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
191 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
199 dstColor
.red
= srcColor
.red
;
200 dstColor
.green
= srcColor
.green
;
201 dstColor
.blue
= srcColor
.blue
;
203 case wxEQUIV
: // (NOT src) XOR dst
204 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
205 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
206 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
208 case wxINVERT
: // NOT dst
209 dstColor
.red
= ~dstColor
.red
;
210 dstColor
.green
= ~dstColor
.green
;
211 dstColor
.blue
= ~dstColor
.blue
;
213 case wxNAND
: // (NOT src) OR (NOT dst)
214 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
215 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
216 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
218 case wxNOR
: // (NOT src) AND (NOT dst)
219 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
220 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
221 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
225 case wxOR
: // src OR dst
226 dstColor
.red
= dstColor
.red
| srcColor
.red
;
227 dstColor
.green
= dstColor
.green
| srcColor
.green
;
228 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
230 case wxOR_INVERT
: // (NOT src) OR dst
231 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
232 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
233 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
235 case wxOR_REVERSE
: // src OR (NOT dst)
236 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
237 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
238 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
241 dstColor
.red
= 0xFFFF ;
242 dstColor
.green
= 0xFFFF ;
243 dstColor
.blue
= 0xFFFF ;
245 case wxSRC_INVERT
: // (NOT src)
246 dstColor
.red
= ~srcColor
.red
;
247 dstColor
.green
= ~srcColor
.green
;
248 dstColor
.blue
= ~srcColor
.blue
;
250 case wxXOR
: // src XOR dst
251 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
252 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
253 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
262 m_mm_to_pix_x
= mm2pt
;
263 m_mm_to_pix_y
= mm2pt
;
264 m_internalDeviceOriginX
= 0;
265 m_internalDeviceOriginY
= 0;
266 m_externalDeviceOriginX
= 0;
267 m_externalDeviceOriginY
= 0;
268 m_logicalScaleX
= 1.0;
269 m_logicalScaleY
= 1.0;
274 m_needComputeScaleX
= false;
275 m_needComputeScaleY
= false;
279 m_macFontInstalled
= false ;
280 m_macBrushInstalled
= false ;
281 m_macPenInstalled
= false ;
282 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
283 m_macBoundaryClipRgn
= NewRgn() ;
284 m_macCurrentClipRgn
= NewRgn() ;
285 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
286 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
287 m_pen
= *wxBLACK_PEN
;
288 m_font
= *wxNORMAL_FONT
;
289 m_brush
= *wxWHITE_BRUSH
;
291 // needed to debug possible errors with two active drawing methods at the same time on
293 m_macCurrentPortStateHelper
= NULL
;
295 m_macATSUIStyle
= NULL
;
296 m_macAliasWasEnabled
= false;
297 m_macForegroundPixMap
= NULL
;
298 m_macBackgroundPixMap
= NULL
;
303 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
304 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
307 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
310 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
311 m_macCurrentPortStateHelper
= help
;
313 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
314 #if ! wxMAC_EXPERIMENTAL_DC
315 m_macFontInstalled
= false ;
316 m_macBrushInstalled
= false ;
317 m_macPenInstalled
= false ;
320 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
323 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
324 m_macCurrentPortStateHelper
= NULL
;
326 if( m_macATSUIStyle
)
328 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
329 m_macATSUIStyle
= NULL
;
331 if ( m_macAliasWasEnabled
)
333 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
334 m_macAliasWasEnabled
= false ;
336 if ( m_macForegroundPixMap
)
339 ::PenPat(GetQDGlobalsBlack(&blackColor
));
340 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
341 m_macForegroundPixMap
= NULL
;
343 if ( m_macBackgroundPixMap
)
346 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
347 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
348 m_macBackgroundPixMap
= NULL
;
352 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
354 wxCHECK_RET( Ok(), wxT("invalid window dc") );
355 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
356 wxMacFastPortSetter
helper(this) ;
357 wxCoord xx
= XLOG2DEVMAC(x
);
358 wxCoord yy
= YLOG2DEVMAC(y
);
359 wxCoord w
= bmp
.GetWidth();
360 wxCoord h
= bmp
.GetHeight();
361 wxCoord ww
= XLOG2DEVREL(w
);
362 wxCoord hh
= YLOG2DEVREL(h
);
363 // Set up drawing mode
364 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
365 //m_logicalFunction == wxCLEAR ? WHITENESS :
366 //m_logicalFunction == wxSET ? BLACKNESS :
367 m_logicalFunction
== wxINVERT
? hilite
:
368 //m_logicalFunction == wxAND ? MERGECOPY :
369 m_logicalFunction
== wxOR
? srcOr
:
370 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
371 m_logicalFunction
== wxXOR
? srcXor
:
372 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
373 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
374 //m_logicalFunction == wxSRC_OR ? srcOr :
375 //m_logicalFunction == wxSRC_AND ? SRCAND :
377 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
378 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
379 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
380 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
382 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
384 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
385 PixMapHandle bmappixels
;
386 // Set foreground and background colours (for bitmaps depth = 1)
387 if(bmp
.GetDepth() == 1)
389 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
390 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
396 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
397 RGBColor black
= { 0,0,0} ;
398 RGBForeColor( &black
) ;
399 RGBBackColor( &white
) ;
401 bmappixels
= GetGWorldPixMap( bmapworld
) ;
402 wxCHECK_RET(LockPixels(bmappixels
),
403 wxT("DoDrawBitmap: Unable to lock pixels"));
404 Rect source
= { 0, 0, h
, w
};
405 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
406 if ( useMask
&& bmp
.GetMask() )
408 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
412 GetPortBitMapForCopyBits(bmapworld
),
413 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
414 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
415 &source
, &source
, &dest
, mode
, NULL
417 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
421 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
422 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
423 &source
, &dest
, mode
, NULL
) ;
425 UnlockPixels( bmappixels
) ;
427 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
429 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
430 OffsetRect( &bitmaprect
, xx
, yy
) ;
431 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
433 m_macPenInstalled
= false ;
434 m_macBrushInstalled
= false ;
435 m_macFontInstalled
= false ;
438 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
440 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
441 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
442 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
445 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
447 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
448 wxCoord xx
, yy
, ww
, hh
;
451 ww
= XLOG2DEVREL(width
);
452 hh
= YLOG2DEVREL(height
);
453 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
454 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
457 m_clipX1
= wxMax( m_clipX1
, xx
);
458 m_clipY1
= wxMax( m_clipY1
, yy
);
459 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
460 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
472 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
474 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
477 DestroyClippingRegion();
480 wxMacFastPortSetter
helper(this) ;
482 region
.GetBox( x
, y
, w
, h
);
483 wxCoord xx
, yy
, ww
, hh
;
488 // if we have a scaling that we cannot map onto native regions
489 // we must use the box
490 if ( ww
!= w
|| hh
!= h
)
492 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
496 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
497 if ( xx
!= x
|| yy
!= y
)
499 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
501 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
504 m_clipX1
= wxMax( m_clipX1
, xx
);
505 m_clipY1
= wxMax( m_clipY1
, yy
);
506 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
507 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
520 void wxDC::DestroyClippingRegion()
522 wxMacFastPortSetter
helper(this) ;
523 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
527 void wxDC::DoGetSizeMM( int* width
, int* height
) const
532 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
533 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
536 void wxDC::SetTextForeground( const wxColour
&col
)
538 wxCHECK_RET(Ok(), wxT("Invalid DC"));
539 m_textForegroundColour
= col
;
540 m_macFontInstalled
= false ;
543 void wxDC::SetTextBackground( const wxColour
&col
)
545 wxCHECK_RET(Ok(), wxT("Invalid DC"));
546 m_textBackgroundColour
= col
;
547 m_macFontInstalled
= false ;
550 void wxDC::SetMapMode( int mode
)
555 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
558 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
561 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
564 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
568 SetLogicalScale( 1.0, 1.0 );
571 if (mode
!= wxMM_TEXT
)
573 m_needComputeScaleX
= true;
574 m_needComputeScaleY
= true;
578 void wxDC::SetUserScale( double x
, double y
)
580 // allow negative ? -> no
583 ComputeScaleAndOrigin();
586 void wxDC::SetLogicalScale( double x
, double y
)
591 ComputeScaleAndOrigin();
594 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
596 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
597 m_logicalOriginY
= y
* m_signY
;
598 ComputeScaleAndOrigin();
601 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
603 m_externalDeviceOriginX
= x
;
604 m_externalDeviceOriginY
= y
;
605 ComputeScaleAndOrigin();
609 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
611 m_internalDeviceOriginX
= x
;
612 m_internalDeviceOriginY
= y
;
613 ComputeScaleAndOrigin();
615 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
617 if (x
) *x
= m_internalDeviceOriginX
;
618 if (y
) *y
= m_internalDeviceOriginY
;
622 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
624 m_signX
= (xLeftRight
? 1 : -1);
625 m_signY
= (yBottomUp
? -1 : 1);
626 ComputeScaleAndOrigin();
629 wxSize
wxDC::GetPPI() const
631 return wxSize(72, 72);
634 int wxDC::GetDepth() const
636 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
638 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
643 void wxDC::ComputeScaleAndOrigin()
645 // CMB: copy scale to see if it changes
646 double origScaleX
= m_scaleX
;
647 double origScaleY
= m_scaleY
;
648 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
649 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
650 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
651 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
652 // CMB: if scale has changed call SetPen to recalulate the line width
653 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
655 // this is a bit artificial, but we need to force wxDC to think
656 // the pen has changed
657 wxPen
* pen
= & GetPen();
664 void wxDC::SetPalette( const wxPalette
& palette
)
668 void wxDC::SetBackgroundMode( int mode
)
670 m_backgroundMode
= mode
;
673 void wxDC::SetFont( const wxFont
&font
)
676 m_macFontInstalled
= false ;
679 void wxDC::SetPen( const wxPen
&pen
)
684 m_macPenInstalled
= false ;
687 void wxDC::SetBrush( const wxBrush
&brush
)
689 if (m_brush
== brush
)
692 m_macBrushInstalled
= false ;
695 void wxDC::SetBackground( const wxBrush
&brush
)
697 if (m_backgroundBrush
== brush
)
699 m_backgroundBrush
= brush
;
700 if (!m_backgroundBrush
.Ok())
702 m_macBrushInstalled
= false ;
705 void wxDC::SetLogicalFunction( int function
)
707 if (m_logicalFunction
== function
)
709 m_logicalFunction
= function
;
710 m_macFontInstalled
= false ;
711 m_macBrushInstalled
= false ;
712 m_macPenInstalled
= false ;
715 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
716 const wxColour
& col
, int style
);
718 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
719 const wxColour
& col
, int style
)
721 return wxDoFloodFill(this, x
, y
, col
, style
);
724 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
726 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
727 wxMacFastPortSetter
helper(this) ;
729 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
730 // Convert from Mac colour to wx
731 col
->Set( colour
.red
>> 8,
737 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
739 wxCHECK_RET(Ok(), wxT("Invalid DC"));
740 wxMacFastPortSetter
helper(this) ;
741 if (m_pen
.GetStyle() != wxTRANSPARENT
)
744 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
745 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
746 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
747 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
748 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
749 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
750 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
751 (m_pen
.GetWidth() <= 1))
753 // Implement LAST_NOT for MAC at least for
754 // orthogonal lines. RR.
775 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
777 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
778 wxMacFastPortSetter
helper(this) ;
779 if (m_pen
.GetStyle() != wxTRANSPARENT
)
784 wxCoord xx
= XLOG2DEVMAC(x
);
785 wxCoord yy
= YLOG2DEVMAC(y
);
787 ::MoveTo( XLOG2DEVMAC(0), yy
);
788 ::LineTo( XLOG2DEVMAC(w
), yy
);
789 ::MoveTo( xx
, YLOG2DEVMAC(0) );
790 ::LineTo( xx
, YLOG2DEVMAC(h
) );
791 CalcBoundingBox(x
, y
);
792 CalcBoundingBox(x
+w
, y
+h
);
797 * To draw arcs properly the angles need to be converted from the WX style:
798 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
799 * a normal axis on paper).
802 * Angles start on the +ve y axis and go clockwise.
805 static double wxConvertWXangleToMACangle(double angle
)
807 double newAngle
= 90 - angle
;
813 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
814 wxCoord x2
, wxCoord y2
,
815 wxCoord xc
, wxCoord yc
)
817 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
818 wxMacFastPortSetter
helper(this) ;
819 wxCoord xx1
= XLOG2DEVMAC(x1
);
820 wxCoord yy1
= YLOG2DEVMAC(y1
);
821 wxCoord xx2
= XLOG2DEVMAC(x2
);
822 wxCoord yy2
= YLOG2DEVMAC(y2
);
823 wxCoord xxc
= XLOG2DEVMAC(xc
);
824 wxCoord yyc
= YLOG2DEVMAC(yc
);
825 double dx
= xx1
- xxc
;
826 double dy
= yy1
- yyc
;
827 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
828 wxCoord rad
= (wxCoord
)radius
;
829 double radius1
, radius2
;
830 if (xx1
== xx2
&& yy1
== yy2
)
835 else if (radius
== 0.0)
837 radius1
= radius2
= 0.0;
841 radius1
= (xx1
- xxc
== 0) ?
842 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
843 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
844 radius2
= (xx2
- xxc
== 0) ?
845 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
846 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
848 wxCoord alpha2
= wxCoord(radius2
- radius1
);
849 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
850 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
853 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
854 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
856 PaintArc(&r
, alpha1
, alpha2
);
858 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
860 FrameArc(&r
, alpha1
, alpha2
);
864 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
865 double sa
, double ea
)
867 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
868 wxMacFastPortSetter
helper(this) ;
870 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
871 // we have to make sure that the filling is always counter-clockwise
874 wxCoord xx
= XLOG2DEVMAC(x
);
875 wxCoord yy
= YLOG2DEVMAC(y
);
876 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
877 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
878 // handle -ve width and/or height
879 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
880 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
881 sa
= wxConvertWXangleToMACangle(sa
);
886 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
888 PaintArc(&r
, (short)sa
, (short)angle
);
890 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
892 FrameArc(&r
, (short)sa
, (short)angle
);
896 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
898 wxCHECK_RET(Ok(), wxT("Invalid DC"));
899 wxMacFastPortSetter
helper(this) ;
900 if (m_pen
.GetStyle() != wxTRANSPARENT
)
902 wxCoord xx1
= XLOG2DEVMAC(x
);
903 wxCoord yy1
= YLOG2DEVMAC(y
);
904 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
905 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
906 CalcBoundingBox(x
, y
);
910 void wxDC::DoDrawLines(int n
, wxPoint points
[],
911 wxCoord xoffset
, wxCoord yoffset
)
913 wxCHECK_RET(Ok(), wxT("Invalid DC"));
914 wxMacFastPortSetter
helper(this) ;
915 if (m_pen
.GetStyle() == wxTRANSPARENT
)
918 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
919 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
920 wxCoord x1
, x2
, y1
, y2
;
921 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
922 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
923 ::MoveTo(x1
- offset
, y1
- offset
);
924 for (int i
= 0; i
< n
-1; i
++)
926 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
927 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
928 ::LineTo( x2
- offset
, y2
- offset
);
932 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
933 wxCoord xoffset
, wxCoord yoffset
,
936 wxCHECK_RET(Ok(), wxT("Invalid DC"));
937 wxMacFastPortSetter
helper(this) ;
938 wxCoord x1
, x2
, y1
, y2
;
939 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
941 PolyHandle polygon
= OpenPoly();
942 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
943 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
945 for (int i
= 1; i
< n
; i
++)
947 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
948 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
951 // close the polyline if necessary
952 if ( x1
!= x2
|| y1
!= y2
)
957 if (m_brush
.GetStyle() != wxTRANSPARENT
)
960 ::PaintPoly( polygon
);
962 if (m_pen
.GetStyle() != wxTRANSPARENT
)
965 ::FramePoly( polygon
) ;
970 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
972 wxCHECK_RET(Ok(), wxT("Invalid DC"));
973 wxMacFastPortSetter
helper(this) ;
974 wxCoord xx
= XLOG2DEVMAC(x
);
975 wxCoord yy
= YLOG2DEVMAC(y
);
976 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
977 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
978 // CMB: draw nothing if transformed w or h is 0
979 if (ww
== 0 || hh
== 0)
981 // CMB: handle -ve width and/or height
992 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
993 if (m_brush
.GetStyle() != wxTRANSPARENT
)
996 ::PaintRect( &rect
) ;
998 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1001 ::FrameRect( &rect
) ;
1005 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1006 wxCoord width
, wxCoord height
,
1009 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1010 wxMacFastPortSetter
helper(this) ;
1012 radius
= - radius
* ((width
< height
) ? width
: height
);
1013 wxCoord xx
= XLOG2DEVMAC(x
);
1014 wxCoord yy
= YLOG2DEVMAC(y
);
1015 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1016 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1017 // CMB: draw nothing if transformed w or h is 0
1018 if (ww
== 0 || hh
== 0)
1020 // CMB: handle -ve width and/or height
1031 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1032 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1035 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1037 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1040 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1044 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1046 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1047 wxMacFastPortSetter
helper(this) ;
1048 wxCoord xx
= XLOG2DEVMAC(x
);
1049 wxCoord yy
= YLOG2DEVMAC(y
);
1050 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1051 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1052 // CMB: draw nothing if transformed w or h is 0
1053 if (ww
== 0 || hh
== 0)
1055 // CMB: handle -ve width and/or height
1066 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1067 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1070 ::PaintOval( &rect
) ;
1072 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1075 ::FrameOval( &rect
) ;
1079 bool wxDC::CanDrawBitmap(void) const
1084 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1085 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1086 wxCoord xsrcMask
, wxCoord ysrcMask
)
1088 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1089 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1090 if ( logical_func
== wxNO_OP
)
1092 if (xsrcMask
== -1 && ysrcMask
== -1)
1094 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1096 // correct the parameter in case this dc does not have a mask at all
1097 if ( useMask
&& !source
->m_macMask
)
1099 Rect srcrect
, dstrect
;
1100 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1101 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1102 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1103 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1104 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1105 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1106 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1107 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1108 short mode
= kUnsupportedMode
;
1109 bool invertDestinationFirst
= false ;
1110 switch ( logical_func
)
1112 case wxAND
: // src AND dst
1113 mode
= adMin
; // ok
1115 case wxAND_INVERT
: // (NOT src) AND dst
1116 mode
= notSrcOr
; // ok
1118 case wxAND_REVERSE
:// src AND (NOT dst)
1119 invertDestinationFirst
= true ;
1123 mode
= kEmulatedMode
;
1126 mode
= srcCopy
; // ok
1128 case wxEQUIV
: // (NOT src) XOR dst
1129 mode
= srcXor
; // ok
1131 case wxINVERT
: // NOT dst
1132 mode
= kEmulatedMode
; //or hilite ;
1134 case wxNAND
: // (NOT src) OR (NOT dst)
1135 invertDestinationFirst
= true ;
1138 case wxNOR
: // (NOT src) AND (NOT dst)
1139 invertDestinationFirst
= true ;
1142 case wxNO_OP
: // dst
1143 mode
= kEmulatedMode
; // this has already been handled upon entry
1145 case wxOR
: // src OR dst
1148 case wxOR_INVERT
: // (NOT src) OR dst
1151 case wxOR_REVERSE
: // src OR (NOT dst)
1152 invertDestinationFirst
= true ;
1156 mode
= kEmulatedMode
;
1158 case wxSRC_INVERT
: // (NOT src)
1159 mode
= notSrcCopy
; // ok
1161 case wxXOR
: // src XOR dst
1162 mode
= notSrcXor
; // ok
1167 if ( mode
== kUnsupportedMode
)
1169 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1172 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1173 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1174 if ( LockPixels(bmappixels
) )
1176 wxMacFastPortSetter
helper(this) ;
1177 if ( source
->GetDepth() == 1 )
1179 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1180 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1184 // the modes need this, otherwise we'll end up having really nice colors...
1185 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1186 RGBColor black
= { 0,0,0} ;
1187 RGBForeColor( &black
) ;
1188 RGBBackColor( &white
) ;
1190 if ( useMask
&& source
->m_macMask
)
1192 if ( mode
== srcCopy
)
1194 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1196 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1197 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1198 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1199 &srcrect
, &srcrect
, &dstrect
) ;
1200 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1205 RgnHandle clipRgn
= NewRgn() ;
1206 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1207 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1208 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1209 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1210 if ( mode
== kEmulatedMode
)
1213 ::PenPat(GetQDGlobalsBlack(&pat
));
1214 if ( logical_func
== wxSET
)
1216 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1217 ::RGBForeColor( &col
) ;
1218 ::PaintRgn( clipRgn
) ;
1220 else if ( logical_func
== wxCLEAR
)
1222 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1223 ::RGBForeColor( &col
) ;
1224 ::PaintRgn( clipRgn
) ;
1226 else if ( logical_func
== wxINVERT
)
1228 MacInvertRgn( clipRgn
) ;
1232 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1234 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1236 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1237 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1238 if ( PtInRgn( dstPoint
, clipRgn
) )
1242 SetPort( (GrafPtr
) sourcePort
) ;
1243 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1244 SetPort( (GrafPtr
) m_macPort
) ;
1245 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1246 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1247 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1255 if ( invertDestinationFirst
)
1257 MacInvertRgn( clipRgn
) ;
1259 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1260 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1261 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1263 DisposeRgn( clipRgn
) ;
1268 RgnHandle clipRgn
= NewRgn() ;
1269 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1270 if ( mode
== kEmulatedMode
)
1273 ::PenPat(GetQDGlobalsBlack(&pat
));
1274 if ( logical_func
== wxSET
)
1276 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1277 ::RGBForeColor( &col
) ;
1278 ::PaintRgn( clipRgn
) ;
1280 else if ( logical_func
== wxCLEAR
)
1282 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1283 ::RGBForeColor( &col
) ;
1284 ::PaintRgn( clipRgn
) ;
1286 else if ( logical_func
== wxINVERT
)
1288 MacInvertRgn( clipRgn
) ;
1292 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1294 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1296 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1297 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1301 SetPort( (GrafPtr
) sourcePort
) ;
1302 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1303 SetPort( (GrafPtr
) m_macPort
) ;
1304 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1305 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1306 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1314 if ( invertDestinationFirst
)
1316 MacInvertRgn( clipRgn
) ;
1318 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1319 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1320 &srcrect
, &dstrect
, mode
, NULL
) ;
1322 DisposeRgn( clipRgn
) ;
1324 UnlockPixels( bmappixels
) ;
1326 m_macPenInstalled
= false ;
1327 m_macBrushInstalled
= false ;
1328 m_macFontInstalled
= false ;
1333 // as macro in FixMath.h for 10.3
1334 inline Fixed
IntToFixed( int inInt
)
1336 return (((SInt32
) inInt
) << 16);
1339 inline int FixedToInt( Fixed inFixed
)
1341 return (((SInt32
) inFixed
) >> 16);
1345 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1348 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1352 DrawText(str
, x
, y
);
1356 if ( str
.Length() == 0 )
1359 wxMacFastPortSetter
helper(this) ;
1364 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1365 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.GetMacFontSize()));
1366 m_macAliasWasEnabled
= true ;
1368 OSStatus status
= noErr
;
1369 ATSUTextLayout atsuLayout
;
1370 UniCharCount chars
= str
.Length() ;
1372 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1373 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1375 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1376 int wlen
= wxWcslen( wchar
.data() ) ;
1377 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1378 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1380 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1381 int iAngle
= int( angle
);
1382 int drawX
= XLOG2DEVMAC(x
) ;
1383 int drawY
= YLOG2DEVMAC(y
) ;
1385 ATSUTextMeasurement textBefore
;
1386 ATSUTextMeasurement textAfter
;
1387 ATSUTextMeasurement ascent
;
1388 ATSUTextMeasurement descent
;
1391 if ( abs(iAngle
) > 0 )
1393 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1394 ATSUAttributeTag atsuTags
[] =
1396 kATSULineRotationTag
,
1398 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1402 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1406 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1407 atsuTags
, atsuSizes
, atsuValues
) ;
1409 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1410 &textBefore
, &textAfter
, &ascent
, &descent
);
1412 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1413 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1414 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1415 IntToFixed(drawX
) , IntToFixed(drawY
) );
1416 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1418 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1419 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1420 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1421 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1422 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1423 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1424 ::ATSUDisposeTextLayout(atsuLayout
);
1427 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1429 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1431 wxMacFastPortSetter
helper(this) ;
1432 long xx
= XLOG2DEVMAC(x
);
1433 long yy
= YLOG2DEVMAC(y
);
1435 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1436 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1437 useDrawThemeText
= false ;
1442 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1443 SetAntiAliasedTextEnabled(true, 8);
1444 m_macAliasWasEnabled
= true ;
1447 ::GetFontInfo( &fi
) ;
1449 if ( !useDrawThemeText
)
1452 ::MoveTo( xx
, yy
);
1453 if ( m_backgroundMode
== wxTRANSPARENT
)
1455 ::TextMode( srcOr
) ;
1459 ::TextMode( srcCopy
) ;
1461 int length
= strtext
.Length() ;
1467 #if 0 // we don't have to do all that here
1470 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1472 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1474 if ( useDrawThemeText
)
1476 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1477 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1478 if ( m_backgroundMode
!= wxTRANSPARENT
)
1480 Point bounds
={0,0} ;
1481 Rect background
= frame
;
1483 ::GetThemeTextDimensions( mString
,
1484 kThemeCurrentPortFont
,
1489 background
.right
= background
.left
+ bounds
.h
;
1490 background
.bottom
= background
.top
+ bounds
.v
;
1491 ::EraseRect( &background
) ;
1493 ::DrawThemeTextBox( mString
,
1494 kThemeCurrentPortFont
,
1505 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1506 ::DrawText( text
, 0 , strlen(text
) ) ;
1507 if ( m_backgroundMode
!= wxTRANSPARENT
)
1509 Point bounds
={0,0} ;
1510 Rect background
= frame
;
1512 ::GetThemeTextDimensions( mString
,
1513 kThemeCurrentPortFont
,
1518 background
.right
= background
.left
+ bounds
.h
;
1519 background
.bottom
= background
.top
+ bounds
.v
;
1520 ::EraseRect( &background
) ;
1523 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1529 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1531 wxString linetext
= strtext
;
1533 if ( useDrawThemeText
)
1535 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1536 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1538 if ( m_backgroundMode
!= wxTRANSPARENT
)
1540 Point bounds
={0,0} ;
1541 Rect background
= frame
;
1543 ::GetThemeTextDimensions( mString
,
1544 kThemeCurrentPortFont
,
1549 background
.right
= background
.left
+ bounds
.h
;
1550 background
.bottom
= background
.top
+ bounds
.v
;
1551 ::EraseRect( &background
) ;
1553 ::DrawThemeTextBox( mString
,
1554 kThemeCurrentPortFont
,
1564 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1565 if ( m_backgroundMode
!= wxTRANSPARENT
)
1567 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 } ;
1568 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1569 frame
.right
= frame
.left
+ width
;
1571 ::EraseRect( &frame
) ;
1573 ::DrawText( text
, 0 , strlen(text
) ) ;
1576 ::TextMode( srcOr
) ;
1579 bool wxDC::CanGetTextExtent() const
1581 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1585 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1586 wxCoord
*descent
, wxCoord
*externalLeading
,
1587 wxFont
*theFont
) const
1589 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1590 wxMacFastPortSetter
helper(this) ;
1591 wxFont formerFont
= m_font
;
1594 // work around the constness
1595 *((wxFont
*)(&m_font
)) = *theFont
;
1599 ::GetFontInfo( &fi
) ;
1601 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1602 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1603 useGetThemeText
= false ;
1606 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1608 *descent
=YDEV2LOGREL( fi
.descent
);
1609 if ( externalLeading
)
1610 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1611 int length
= strtext
.Length() ;
1619 #if 0 // apparently we don't have to do all that
1622 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1624 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1626 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1628 if ( useGetThemeText
)
1630 Point bounds
={0,0} ;
1632 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1633 ::GetThemeTextDimensions( mString
,
1634 kThemeCurrentPortFont
,
1639 curwidth
= bounds
.h
;
1644 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1645 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1647 if ( curwidth
> *width
)
1648 *width
= XDEV2LOGREL( curwidth
) ;
1654 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1656 wxString linetext
= strtext
;
1658 if ( useGetThemeText
)
1660 Point bounds
={0,0} ;
1662 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1663 ::GetThemeTextDimensions( mString
,
1664 kThemeCurrentPortFont
,
1669 curwidth
= bounds
.h
;
1674 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1675 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1677 if ( curwidth
> *width
)
1678 *width
= XDEV2LOGREL( curwidth
) ;
1682 // work around the constness
1683 *((wxFont
*)(&m_font
)) = formerFont
;
1684 m_macFontInstalled
= false ;
1689 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1691 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1694 widths
.Add(0, text
.Length());
1696 if (text
.Length() == 0)
1699 wxMacFastPortSetter
helper(this) ;
1702 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1703 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1704 useGetThemeText
= false ;
1706 if ( useGetThemeText
)
1708 // If anybody knows how to do this more efficiently yet still handle
1709 // the fractional glyph widths that may be present when using AA
1710 // fonts, please change it. Currently it is measuring from the
1711 // begining of the string for each succeding substring, which is much
1712 // slower than this should be.
1713 for (size_t i
=0; i
<text
.Length(); i
++)
1715 wxString
str(text
.Left(i
+1));
1716 Point bounds
= {0,0};
1718 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1719 ::GetThemeTextDimensions( mString
,
1720 kThemeCurrentPortFont
,
1725 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1731 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1732 size_t len
= strlen(buff
);
1733 short* measurements
= new short[len
+1];
1734 MeasureText(len
, buff
.data(), measurements
);
1736 // Copy to widths, starting at measurements[1]
1737 // NOTE: this doesn't take into account any multi-byte characters
1738 // in buff, it probabkly should...
1739 for (size_t i
=0; i
<text
.Length(); i
++)
1740 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1742 delete [] measurements
;
1750 wxCoord
wxDC::GetCharWidth(void) const
1752 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1753 wxMacFastPortSetter
helper(this) ;
1757 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1758 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1759 useGetThemeText
= false ;
1763 if ( useGetThemeText
)
1765 Point bounds
={0,0} ;
1767 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1768 ::GetThemeTextDimensions( mString
,
1769 kThemeCurrentPortFont
,
1774 CFRelease( mString
) ;
1780 width
= ::TextWidth( text
, 0 , 1 ) ;
1782 return YDEV2LOGREL(width
) ;
1785 wxCoord
wxDC::GetCharHeight(void) const
1787 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1788 wxMacFastPortSetter
helper(this) ;
1791 ::GetFontInfo( &fi
) ;
1792 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1795 void wxDC::Clear(void)
1797 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1798 wxMacFastPortSetter
helper(this) ;
1799 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1800 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1803 //MacInstallBrush() ;
1804 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1805 ::EraseRect( &rect
) ;
1809 void wxDC::MacInstallFont() const
1811 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1812 // if ( m_macFontInstalled )
1814 Pattern blackColor
;
1815 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1818 ::TextFont( m_font
.GetMacFontNum() ) ;
1819 ::TextSize( (short)(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1820 ::TextFace( m_font
.GetMacFontStyle() ) ;
1821 m_macFontInstalled
= true ;
1822 m_macBrushInstalled
= false ;
1823 m_macPenInstalled
= false ;
1824 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1825 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1826 ::RGBForeColor( &forecolor
);
1827 ::RGBBackColor( &backcolor
);
1831 FontFamilyID fontId
;
1835 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1836 GetFNum( fontName
, &fontId
);
1837 ::TextFont( fontId
) ;
1838 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1839 ::TextFace( fontStyle
) ;
1840 // todo reset after spacing changes - or store the current spacing somewhere
1841 m_macFontInstalled
= true ;
1842 m_macBrushInstalled
= false ;
1843 m_macPenInstalled
= false ;
1844 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1845 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1846 ::RGBForeColor( &forecolor
);
1847 ::RGBBackColor( &backcolor
);
1849 short mode
= patCopy
;
1851 switch( m_logicalFunction
)
1856 case wxINVERT
: // NOT dst
1857 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1860 case wxXOR
: // src XOR dst
1863 case wxOR_REVERSE
: // src OR (NOT dst)
1866 case wxSRC_INVERT
: // (NOT src)
1869 case wxAND
: // src AND dst
1874 case wxAND_REVERSE
:// src AND (NOT dst)
1875 case wxAND_INVERT
: // (NOT src) AND dst
1876 case wxNO_OP
: // dst
1877 case wxNOR
: // (NOT src) AND (NOT dst)
1878 case wxEQUIV
: // (NOT src) XOR dst
1879 case wxOR_INVERT
: // (NOT src) OR dst
1880 case wxNAND
: // (NOT src) OR (NOT dst)
1881 case wxOR
: // src OR dst
1883 // case wxSRC_OR: // source _bitmap_ OR destination
1884 // case wxSRC_AND: // source _bitmap_ AND destination
1888 OSStatus status
= noErr
;
1889 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1890 Style qdStyle
= m_font
.GetMacFontStyle() ;
1891 ATSUFontID atsuFont
= m_font
.GetMacATSUFontID() ;
1892 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1893 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1894 ATSUAttributeTag atsuTags
[] =
1899 // kATSUBaselineClassTag ,
1900 kATSUVerticalCharacterTag
,
1901 kATSUQDBoldfaceTag
,
1903 kATSUQDUnderlineTag
,
1904 kATSUQDCondensedTag
,
1905 kATSUQDExtendedTag
,
1907 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1909 sizeof( ATSUFontID
) ,
1911 // sizeof( RGBColor ) ,
1912 // sizeof( BslnBaselineClass ) ,
1913 sizeof( ATSUVerticalCharacterType
),
1920 Boolean kTrue
= true ;
1921 Boolean kFalse
= false ;
1922 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1923 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1924 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1928 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1929 // &kBaselineDefault ,
1931 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1932 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1933 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1934 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1935 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1937 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1938 atsuTags
, atsuSizes
, atsuValues
);
1939 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1942 Pattern gPatterns
[] =
1944 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1945 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1946 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1947 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1948 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1949 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1950 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1952 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1953 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1954 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1955 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1958 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1960 int index
= 0; // solid pattern by default
1964 case wxBDIAGONAL_HATCH
: index
= 1; break;
1965 case wxFDIAGONAL_HATCH
: index
= 2; break;
1966 case wxCROSS_HATCH
: index
= 3; break;
1967 case wxHORIZONTAL_HATCH
: index
= 4; break;
1968 case wxVERTICAL_HATCH
: index
= 5; break;
1969 case wxCROSSDIAG_HATCH
: index
= 6; break;
1971 case wxDOT
: index
= 7; break;
1972 case wxLONG_DASH
: index
= 8; break;
1973 case wxSHORT_DASH
: index
= 9; break;
1974 case wxDOT_DASH
: index
= 10; break;
1976 *pattern
= gPatterns
[index
];
1979 void wxDC::MacInstallPen() const
1981 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1982 //Pattern blackColor;
1983 // if ( m_macPenInstalled )
1985 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1986 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1987 ::RGBForeColor( &forecolor
);
1988 ::RGBBackColor( &backcolor
);
1990 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1991 // null means only one pixel, at whatever resolution
1992 if ( penWidth
== 0 )
1994 ::PenSize(penWidth
, penWidth
);
1996 int penStyle
= m_pen
.GetStyle();
1998 if (penStyle
== wxUSER_DASH
)
2000 // FIXME: there should be exactly 8 items in the dash
2002 int number
= m_pen
.GetDashes(&dash
) ;
2004 for ( int i
= 0 ; i
< 8 ; ++i
)
2006 pat
.pat
[i
] = dash
[index
] ;
2007 if (index
< number
- 1)
2013 wxMacGetPattern(penStyle
, &pat
);
2017 short mode
= patCopy
;
2019 switch( m_logicalFunction
)
2021 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2024 case wxINVERT
: // NOT dst
2025 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2028 case wxXOR
: // src XOR dst
2031 case wxOR_REVERSE
: // src OR (NOT dst)
2034 case wxSRC_INVERT
: // (NOT src)
2037 case wxAND
: // src AND dst
2042 case wxAND_REVERSE
:// src AND (NOT dst)
2043 case wxAND_INVERT
: // (NOT src) AND dst
2044 case wxNO_OP
: // dst
2045 case wxNOR
: // (NOT src) AND (NOT dst)
2046 case wxEQUIV
: // (NOT src) XOR dst
2047 case wxOR_INVERT
: // (NOT src) OR dst
2048 case wxNAND
: // (NOT src) OR (NOT dst)
2049 case wxOR
: // src OR dst
2051 // case wxSRC_OR: // source _bitmap_ OR destination
2052 // case wxSRC_AND: // source _bitmap_ AND destination
2056 m_macPenInstalled
= true ;
2057 m_macBrushInstalled
= false ;
2058 m_macFontInstalled
= false ;
2061 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2063 Pattern whiteColor
;
2064 switch( background
.MacGetBrushKind() )
2066 case kwxMacBrushTheme
:
2068 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2071 case kwxMacBrushThemeBackground
:
2074 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2075 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2078 case kwxMacBrushColour
:
2080 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2081 int brushStyle
= background
.GetStyle();
2082 if (brushStyle
== wxSOLID
)
2083 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2084 else if (background
.IsHatch())
2087 wxMacGetPattern(brushStyle
, &pat
);
2092 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2099 void wxDC::MacInstallBrush() const
2101 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2102 Pattern blackColor
;
2103 // if ( m_macBrushInstalled )
2106 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2107 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2108 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2109 int brushStyle
= m_brush
.GetStyle();
2110 if (brushStyle
== wxSOLID
)
2112 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2114 else if (m_brush
.IsHatch())
2117 wxMacGetPattern(brushStyle
, &pat
);
2120 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2122 // we force this in order to be compliant with wxMSW
2123 backgroundTransparent
= false ;
2124 // for these the text fore (and back for MASK_OPAQUE) colors are used
2125 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2126 int width
= bitmap
->GetWidth() ;
2127 int height
= bitmap
->GetHeight() ;
2128 GWorldPtr gw
= NULL
;
2129 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2130 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2132 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2133 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2134 LockPixels( gwpixmaphandle
) ;
2135 bool isMonochrome
= !IsPortColor( gw
) ;
2136 if ( !isMonochrome
)
2138 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2139 isMonochrome
= true ;
2141 if ( isMonochrome
&& width
== 8 && height
== 8 )
2143 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2144 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2145 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2146 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2147 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2149 for ( int i
= 0 ; i
< 8 ; ++i
)
2151 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2153 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2158 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2159 // caching scheme before putting this into production
2162 PixPatHandle pixpat
= NewPixPat() ;
2163 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2164 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2165 ((**(**pixpat
).patMap
).bounds
.bottom
-
2166 (**(**pixpat
).patMap
).bounds
.top
);
2167 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2168 (**pixpat
).patData
= image
;
2171 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2172 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2173 if ( ctspec
[0].rgb
.red
== 0x0000 )
2175 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2176 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2180 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2181 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2183 ::CTabChanged( ctable
) ;
2185 ::PenPixPat(pixpat
);
2186 m_macForegroundPixMap
= pixpat
;
2188 UnlockPixels( gwpixmaphandle
) ;
2192 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2194 short mode
= patCopy
;
2195 switch( m_logicalFunction
)
2198 if ( backgroundTransparent
)
2203 case wxINVERT
: // NOT dst
2204 if ( !backgroundTransparent
)
2206 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2210 case wxXOR
: // src XOR dst
2213 case wxOR_REVERSE
: // src OR (NOT dst)
2216 case wxSRC_INVERT
: // (NOT src)
2219 case wxAND
: // src AND dst
2224 case wxAND_REVERSE
:// src AND (NOT dst)
2225 case wxAND_INVERT
: // (NOT src) AND dst
2226 case wxNO_OP
: // dst
2227 case wxNOR
: // (NOT src) AND (NOT dst)
2228 case wxEQUIV
: // (NOT src) XOR dst
2229 case wxOR_INVERT
: // (NOT src) OR dst
2230 case wxNAND
: // (NOT src) OR (NOT dst)
2231 case wxOR
: // src OR dst
2233 // case wxSRC_OR: // source _bitmap_ OR destination
2234 // case wxSRC_AND: // source _bitmap_ AND destination
2238 m_macBrushInstalled
= true ;
2239 m_macPenInstalled
= false ;
2240 m_macFontInstalled
= false ;
2243 // ---------------------------------------------------------------------------
2244 // coordinates transformations
2245 // ---------------------------------------------------------------------------
2247 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2249 return ((wxDC
*)this)->XDEV2LOG(x
);
2252 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2254 return ((wxDC
*)this)->YDEV2LOG(y
);
2257 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2259 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2262 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2264 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2267 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2269 return ((wxDC
*)this)->XLOG2DEV(x
);
2272 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2274 return ((wxDC
*)this)->YLOG2DEV(y
);
2277 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2279 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2282 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2284 return ((wxDC
*)this)->YLOG2DEVREL(y
);