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 const double RAD2DEG
= 180.0 / M_PI
;
44 const short kEmulatedMode
= -1 ;
45 const short kUnsupportedMode
= -2 ;
47 extern TECObjectRef s_TECNativeCToUnicode
;
49 // set to 0 if problems arise
50 #define wxMAC_EXPERIMENTAL_DC 1
52 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
53 m_ph( (GrafPtr
) dc
->m_macPort
)
55 wxASSERT( dc
->Ok() ) ;
57 dc
->MacSetupPort(&m_ph
) ;
59 wxMacPortSetter::~wxMacPortSetter()
61 m_dc
->MacCleanupPort(&m_ph
) ;
64 #if wxMAC_EXPERIMENTAL_DC
65 class wxMacFastPortSetter
68 wxMacFastPortSetter( const wxDC
*dc
)
70 wxASSERT( dc
->Ok() ) ;
71 GetPort( &m_oldPort
) ;
72 SetPort( (GrafPtr
) dc
->m_macPort
) ;
73 m_clipRgn
= NewRgn() ;
74 GetClip( m_clipRgn
) ;
76 dc
->MacSetupPort( NULL
) ;
78 ~wxMacFastPortSetter()
80 SetPort( (GrafPtr
) m_dc
->m_macPort
) ;
81 SetClip( m_clipRgn
) ;
82 SetPort( m_oldPort
) ;
83 m_dc
->MacCleanupPort( NULL
) ;
84 DisposeRgn( m_clipRgn
) ;
93 typedef wxMacPortSetter wxMacFastPortSetter
;
98 // start moving to a dual implementation for QD and CGContextRef
100 class wxMacGraphicsContext
103 void DrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
) = 0 ;
104 void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0 ;
105 void SetClippingRegion( const wxRegion
®ion
) = 0 ;
106 void DestroyClippingRegion() = 0 ;
107 void SetTextForeground( const wxColour
&col
) = 0 ;
108 void SetTextBackground( const wxColour
&col
) = 0 ;
109 void SetLogicalScale( double x
, double y
) = 0 ;
110 void SetUserScale( double x
, double y
) = 0;
113 class wxMacQuickDrawContext
: public wxMacGraphicsContext
120 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
122 m_formerClip
= NewRgn() ;
123 m_newClip
= NewRgn() ;
124 GetClip( m_formerClip
) ;
129 // this clipping area was set to the parent window's drawing area, lead to problems
130 // with MacOSX controls drawing outside their wx' rectangle
131 RgnHandle insidergn
= NewRgn() ;
133 wxWindow
*parent
= win
->GetParent() ;
134 parent
->MacWindowToRootWindow( &x
,&y
) ;
135 wxSize size
= parent
->GetSize() ;
136 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
137 size
.x
- parent
->MacGetRightBorderSize(),
138 size
.y
- parent
->MacGetBottomBorderSize()) ;
139 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
140 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
141 OffsetRgn( m_newClip
, x
, y
) ;
142 SetClip( m_newClip
) ;
143 DisposeRgn( insidergn
) ;
146 win
->MacWindowToRootWindow( &x
,&y
) ;
147 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
148 OffsetRgn( m_newClip
, x
, y
) ;
149 SetClip( m_newClip
) ;
154 wxMacWindowClipper::~wxMacWindowClipper()
156 SetClip( m_formerClip
) ;
157 DisposeRgn( m_newClip
) ;
158 DisposeRgn( m_formerClip
) ;
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
164 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
165 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
166 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 // this function emulates all wx colour manipulations, used to verify the implementation
172 // by setting the mode in the blitting functions to kEmulatedMode
173 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
175 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
177 switch ( logical_func
)
179 case wxAND
: // src AND dst
180 dstColor
.red
= dstColor
.red
& srcColor
.red
;
181 dstColor
.green
= dstColor
.green
& srcColor
.green
;
182 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
184 case wxAND_INVERT
: // (NOT src) AND dst
185 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
186 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
187 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
189 case wxAND_REVERSE
:// src AND (NOT dst)
190 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
191 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
192 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
200 dstColor
.red
= srcColor
.red
;
201 dstColor
.green
= srcColor
.green
;
202 dstColor
.blue
= srcColor
.blue
;
204 case wxEQUIV
: // (NOT src) XOR dst
205 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
206 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
207 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
209 case wxINVERT
: // NOT dst
210 dstColor
.red
= ~dstColor
.red
;
211 dstColor
.green
= ~dstColor
.green
;
212 dstColor
.blue
= ~dstColor
.blue
;
214 case wxNAND
: // (NOT src) OR (NOT dst)
215 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
216 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
217 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
219 case wxNOR
: // (NOT src) AND (NOT dst)
220 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
221 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
222 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
226 case wxOR
: // src OR dst
227 dstColor
.red
= dstColor
.red
| srcColor
.red
;
228 dstColor
.green
= dstColor
.green
| srcColor
.green
;
229 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
231 case wxOR_INVERT
: // (NOT src) OR dst
232 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
233 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
234 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
236 case wxOR_REVERSE
: // src OR (NOT dst)
237 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
238 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
239 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
242 dstColor
.red
= 0xFFFF ;
243 dstColor
.green
= 0xFFFF ;
244 dstColor
.blue
= 0xFFFF ;
246 case wxSRC_INVERT
: // (NOT src)
247 dstColor
.red
= ~srcColor
.red
;
248 dstColor
.green
= ~srcColor
.green
;
249 dstColor
.blue
= ~srcColor
.blue
;
251 case wxXOR
: // src XOR dst
252 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
253 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
254 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
263 m_mm_to_pix_x
= mm2pt
;
264 m_mm_to_pix_y
= mm2pt
;
265 m_internalDeviceOriginX
= 0;
266 m_internalDeviceOriginY
= 0;
267 m_externalDeviceOriginX
= 0;
268 m_externalDeviceOriginY
= 0;
269 m_logicalScaleX
= 1.0;
270 m_logicalScaleY
= 1.0;
275 m_needComputeScaleX
= false;
276 m_needComputeScaleY
= false;
280 m_macFontInstalled
= false ;
281 m_macBrushInstalled
= false ;
282 m_macPenInstalled
= false ;
283 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
284 m_macBoundaryClipRgn
= NewRgn() ;
285 m_macCurrentClipRgn
= NewRgn() ;
286 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
287 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
288 m_pen
= *wxBLACK_PEN
;
289 m_font
= *wxNORMAL_FONT
;
290 m_brush
= *wxWHITE_BRUSH
;
292 // needed to debug possible errors with two active drawing methods at the same time on
294 m_macCurrentPortStateHelper
= NULL
;
296 m_macATSUIStyle
= NULL
;
297 m_macAliasWasEnabled
= false;
298 m_macForegroundPixMap
= NULL
;
299 m_macBackgroundPixMap
= NULL
;
304 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
305 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
308 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
311 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
312 m_macCurrentPortStateHelper
= help
;
314 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
315 #if ! wxMAC_EXPERIMENTAL_DC
316 m_macFontInstalled
= false ;
317 m_macBrushInstalled
= false ;
318 m_macPenInstalled
= false ;
321 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
324 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
325 m_macCurrentPortStateHelper
= NULL
;
327 if( m_macATSUIStyle
)
329 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
330 m_macATSUIStyle
= NULL
;
332 if ( m_macAliasWasEnabled
)
334 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
335 m_macAliasWasEnabled
= false ;
337 if ( m_macForegroundPixMap
)
340 ::PenPat(GetQDGlobalsBlack(&blackColor
));
341 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
342 m_macForegroundPixMap
= NULL
;
344 if ( m_macBackgroundPixMap
)
347 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
348 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
349 m_macBackgroundPixMap
= NULL
;
353 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
355 wxCHECK_RET( Ok(), wxT("invalid window dc") );
356 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
357 wxMacFastPortSetter
helper(this) ;
358 wxCoord xx
= XLOG2DEVMAC(x
);
359 wxCoord yy
= YLOG2DEVMAC(y
);
360 wxCoord w
= bmp
.GetWidth();
361 wxCoord h
= bmp
.GetHeight();
362 wxCoord ww
= XLOG2DEVREL(w
);
363 wxCoord hh
= YLOG2DEVREL(h
);
364 // Set up drawing mode
365 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
366 //m_logicalFunction == wxCLEAR ? WHITENESS :
367 //m_logicalFunction == wxSET ? BLACKNESS :
368 m_logicalFunction
== wxINVERT
? hilite
:
369 //m_logicalFunction == wxAND ? MERGECOPY :
370 m_logicalFunction
== wxOR
? srcOr
:
371 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
372 m_logicalFunction
== wxXOR
? srcXor
:
373 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
374 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
375 //m_logicalFunction == wxSRC_OR ? srcOr :
376 //m_logicalFunction == wxSRC_AND ? SRCAND :
378 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
379 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
380 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
381 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
383 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
385 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
386 PixMapHandle bmappixels
;
387 // Set foreground and background colours (for bitmaps depth = 1)
388 if(bmp
.GetDepth() == 1)
390 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
391 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
397 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
398 RGBColor black
= { 0,0,0} ;
399 RGBForeColor( &black
) ;
400 RGBBackColor( &white
) ;
402 bmappixels
= GetGWorldPixMap( bmapworld
) ;
403 wxCHECK_RET(LockPixels(bmappixels
),
404 wxT("DoDrawBitmap: Unable to lock pixels"));
405 Rect source
= { 0, 0, h
, w
};
406 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
407 if ( useMask
&& bmp
.GetMask() )
409 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
413 GetPortBitMapForCopyBits(bmapworld
),
414 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
415 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
416 &source
, &source
, &dest
, mode
, NULL
418 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
422 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
423 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
424 &source
, &dest
, mode
, NULL
) ;
426 UnlockPixels( bmappixels
) ;
428 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
430 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
431 OffsetRect( &bitmaprect
, xx
, yy
) ;
432 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
434 m_macPenInstalled
= false ;
435 m_macBrushInstalled
= false ;
436 m_macFontInstalled
= false ;
439 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
441 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
442 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
443 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
446 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
448 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
449 wxCoord xx
, yy
, ww
, hh
;
452 ww
= XLOG2DEVREL(width
);
453 hh
= YLOG2DEVREL(height
);
454 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
455 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
458 m_clipX1
= wxMax( m_clipX1
, xx
);
459 m_clipY1
= wxMax( m_clipY1
, yy
);
460 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
461 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
473 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
475 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
478 DestroyClippingRegion();
481 wxMacFastPortSetter
helper(this) ;
483 region
.GetBox( x
, y
, w
, h
);
484 wxCoord xx
, yy
, ww
, hh
;
489 // if we have a scaling that we cannot map onto native regions
490 // we must use the box
491 if ( ww
!= w
|| hh
!= h
)
493 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
497 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
498 if ( xx
!= x
|| yy
!= y
)
500 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
502 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
505 m_clipX1
= wxMax( m_clipX1
, xx
);
506 m_clipY1
= wxMax( m_clipY1
, yy
);
507 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
508 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
521 void wxDC::DestroyClippingRegion()
523 wxMacFastPortSetter
helper(this) ;
524 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
528 void wxDC::DoGetSizeMM( int* width
, int* height
) const
533 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
534 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
537 void wxDC::SetTextForeground( const wxColour
&col
)
539 wxCHECK_RET(Ok(), wxT("Invalid DC"));
540 m_textForegroundColour
= col
;
541 m_macFontInstalled
= false ;
544 void wxDC::SetTextBackground( const wxColour
&col
)
546 wxCHECK_RET(Ok(), wxT("Invalid DC"));
547 m_textBackgroundColour
= col
;
548 m_macFontInstalled
= false ;
551 void wxDC::SetMapMode( int mode
)
556 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
559 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
562 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
565 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
569 SetLogicalScale( 1.0, 1.0 );
572 if (mode
!= wxMM_TEXT
)
574 m_needComputeScaleX
= true;
575 m_needComputeScaleY
= true;
579 void wxDC::SetUserScale( double x
, double y
)
581 // allow negative ? -> no
584 ComputeScaleAndOrigin();
587 void wxDC::SetLogicalScale( double x
, double y
)
592 ComputeScaleAndOrigin();
595 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
597 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
598 m_logicalOriginY
= y
* m_signY
;
599 ComputeScaleAndOrigin();
602 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
604 m_externalDeviceOriginX
= x
;
605 m_externalDeviceOriginY
= y
;
606 ComputeScaleAndOrigin();
610 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
612 m_internalDeviceOriginX
= x
;
613 m_internalDeviceOriginY
= y
;
614 ComputeScaleAndOrigin();
616 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
618 if (x
) *x
= m_internalDeviceOriginX
;
619 if (y
) *y
= m_internalDeviceOriginY
;
623 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
625 m_signX
= (xLeftRight
? 1 : -1);
626 m_signY
= (yBottomUp
? -1 : 1);
627 ComputeScaleAndOrigin();
630 wxSize
wxDC::GetPPI() const
632 return wxSize(72, 72);
635 int wxDC::GetDepth() const
637 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
639 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
644 void wxDC::ComputeScaleAndOrigin()
646 // CMB: copy scale to see if it changes
647 double origScaleX
= m_scaleX
;
648 double origScaleY
= m_scaleY
;
649 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
650 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
651 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
652 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
653 // CMB: if scale has changed call SetPen to recalulate the line width
654 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
656 // this is a bit artificial, but we need to force wxDC to think
657 // the pen has changed
658 wxPen
* pen
= & GetPen();
665 void wxDC::SetPalette( const wxPalette
& palette
)
669 void wxDC::SetBackgroundMode( int mode
)
671 m_backgroundMode
= mode
;
674 void wxDC::SetFont( const wxFont
&font
)
677 m_macFontInstalled
= false ;
680 void wxDC::SetPen( const wxPen
&pen
)
685 m_macPenInstalled
= false ;
688 void wxDC::SetBrush( const wxBrush
&brush
)
690 if (m_brush
== brush
)
693 m_macBrushInstalled
= false ;
696 void wxDC::SetBackground( const wxBrush
&brush
)
698 if (m_backgroundBrush
== brush
)
700 m_backgroundBrush
= brush
;
701 if (!m_backgroundBrush
.Ok())
703 m_macBrushInstalled
= false ;
706 void wxDC::SetLogicalFunction( int function
)
708 if (m_logicalFunction
== function
)
710 m_logicalFunction
= function
;
711 m_macFontInstalled
= false ;
712 m_macBrushInstalled
= false ;
713 m_macPenInstalled
= false ;
716 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
717 const wxColour
& col
, int style
);
719 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
720 const wxColour
& col
, int style
)
722 return wxDoFloodFill(this, x
, y
, col
, style
);
725 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
727 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
728 wxMacFastPortSetter
helper(this) ;
730 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
731 // Convert from Mac colour to wx
732 col
->Set( colour
.red
>> 8,
738 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
740 wxCHECK_RET(Ok(), wxT("Invalid DC"));
741 wxMacFastPortSetter
helper(this) ;
742 if (m_pen
.GetStyle() != wxTRANSPARENT
)
745 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
746 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
747 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
748 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
749 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
750 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
751 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
752 (m_pen
.GetWidth() <= 1))
754 // Implement LAST_NOT for MAC at least for
755 // orthogonal lines. RR.
776 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
778 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
779 wxMacFastPortSetter
helper(this) ;
780 if (m_pen
.GetStyle() != wxTRANSPARENT
)
785 wxCoord xx
= XLOG2DEVMAC(x
);
786 wxCoord yy
= YLOG2DEVMAC(y
);
788 ::MoveTo( XLOG2DEVMAC(0), yy
);
789 ::LineTo( XLOG2DEVMAC(w
), yy
);
790 ::MoveTo( xx
, YLOG2DEVMAC(0) );
791 ::LineTo( xx
, YLOG2DEVMAC(h
) );
792 CalcBoundingBox(x
, y
);
793 CalcBoundingBox(x
+w
, y
+h
);
798 * To draw arcs properly the angles need to be converted from the WX style:
799 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
800 * a normal axis on paper).
803 * Angles start on the +ve y axis and go clockwise.
806 static double wxConvertWXangleToMACangle(double angle
)
808 double newAngle
= 90 - angle
;
814 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
815 wxCoord x2
, wxCoord y2
,
816 wxCoord xc
, wxCoord yc
)
818 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
819 wxMacFastPortSetter
helper(this) ;
820 wxCoord xx1
= XLOG2DEVMAC(x1
);
821 wxCoord yy1
= YLOG2DEVMAC(y1
);
822 wxCoord xx2
= XLOG2DEVMAC(x2
);
823 wxCoord yy2
= YLOG2DEVMAC(y2
);
824 wxCoord xxc
= XLOG2DEVMAC(xc
);
825 wxCoord yyc
= YLOG2DEVMAC(yc
);
826 double dx
= xx1
- xxc
;
827 double dy
= yy1
- yyc
;
828 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
829 wxCoord rad
= (wxCoord
)radius
;
830 double radius1
, radius2
;
831 if (xx1
== xx2
&& yy1
== yy2
)
836 else if (radius
== 0.0)
838 radius1
= radius2
= 0.0;
842 radius1
= (xx1
- xxc
== 0) ?
843 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
844 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
845 radius2
= (xx2
- xxc
== 0) ?
846 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
847 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
849 wxCoord alpha2
= wxCoord(radius2
- radius1
);
850 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
851 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
854 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
855 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
857 PaintArc(&r
, alpha1
, alpha2
);
859 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
861 FrameArc(&r
, alpha1
, alpha2
);
865 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
866 double sa
, double ea
)
868 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
869 wxMacFastPortSetter
helper(this) ;
871 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
872 // we have to make sure that the filling is always counter-clockwise
875 wxCoord xx
= XLOG2DEVMAC(x
);
876 wxCoord yy
= YLOG2DEVMAC(y
);
877 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
878 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
879 // handle -ve width and/or height
880 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
881 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
882 sa
= wxConvertWXangleToMACangle(sa
);
887 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
889 PaintArc(&r
, (short)sa
, (short)angle
);
891 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
893 FrameArc(&r
, (short)sa
, (short)angle
);
897 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
899 wxCHECK_RET(Ok(), wxT("Invalid DC"));
900 wxMacFastPortSetter
helper(this) ;
901 if (m_pen
.GetStyle() != wxTRANSPARENT
)
903 wxCoord xx1
= XLOG2DEVMAC(x
);
904 wxCoord yy1
= YLOG2DEVMAC(y
);
905 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
906 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
907 CalcBoundingBox(x
, y
);
911 void wxDC::DoDrawLines(int n
, wxPoint points
[],
912 wxCoord xoffset
, wxCoord yoffset
)
914 wxCHECK_RET(Ok(), wxT("Invalid DC"));
915 wxMacFastPortSetter
helper(this) ;
916 if (m_pen
.GetStyle() == wxTRANSPARENT
)
919 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
920 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
921 wxCoord x1
, x2
, y1
, y2
;
922 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
923 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
924 ::MoveTo(x1
- offset
, y1
- offset
);
925 for (int i
= 0; i
< n
-1; i
++)
927 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
928 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
929 ::LineTo( x2
- offset
, y2
- offset
);
933 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
934 wxCoord xoffset
, wxCoord yoffset
,
937 wxCHECK_RET(Ok(), wxT("Invalid DC"));
938 wxMacFastPortSetter
helper(this) ;
939 wxCoord x1
, x2
, y1
, y2
;
940 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
942 PolyHandle polygon
= OpenPoly();
943 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
944 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
946 for (int i
= 1; i
< n
; i
++)
948 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
949 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
952 // close the polyline if necessary
953 if ( x1
!= x2
|| y1
!= y2
)
958 if (m_brush
.GetStyle() != wxTRANSPARENT
)
961 ::PaintPoly( polygon
);
963 if (m_pen
.GetStyle() != wxTRANSPARENT
)
966 ::FramePoly( polygon
) ;
971 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
973 wxCHECK_RET(Ok(), wxT("Invalid DC"));
974 wxMacFastPortSetter
helper(this) ;
975 wxCoord xx
= XLOG2DEVMAC(x
);
976 wxCoord yy
= YLOG2DEVMAC(y
);
977 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
978 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
979 // CMB: draw nothing if transformed w or h is 0
980 if (ww
== 0 || hh
== 0)
982 // CMB: handle -ve width and/or height
993 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
994 if (m_brush
.GetStyle() != wxTRANSPARENT
)
997 ::PaintRect( &rect
) ;
999 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1002 ::FrameRect( &rect
) ;
1006 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
1007 wxCoord width
, wxCoord height
,
1010 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1011 wxMacFastPortSetter
helper(this) ;
1013 radius
= - radius
* ((width
< height
) ? width
: height
);
1014 wxCoord xx
= XLOG2DEVMAC(x
);
1015 wxCoord yy
= YLOG2DEVMAC(y
);
1016 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1017 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1018 // CMB: draw nothing if transformed w or h is 0
1019 if (ww
== 0 || hh
== 0)
1021 // CMB: handle -ve width and/or height
1032 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1033 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1036 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1038 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1041 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1045 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1047 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1048 wxMacFastPortSetter
helper(this) ;
1049 wxCoord xx
= XLOG2DEVMAC(x
);
1050 wxCoord yy
= YLOG2DEVMAC(y
);
1051 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1052 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1053 // CMB: draw nothing if transformed w or h is 0
1054 if (ww
== 0 || hh
== 0)
1056 // CMB: handle -ve width and/or height
1067 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1068 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1071 ::PaintOval( &rect
) ;
1073 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1076 ::FrameOval( &rect
) ;
1080 bool wxDC::CanDrawBitmap(void) const
1085 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1086 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1087 wxCoord xsrcMask
, wxCoord ysrcMask
)
1089 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1090 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1091 if ( logical_func
== wxNO_OP
)
1093 if (xsrcMask
== -1 && ysrcMask
== -1)
1095 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1097 // correct the parameter in case this dc does not have a mask at all
1098 if ( useMask
&& !source
->m_macMask
)
1100 Rect srcrect
, dstrect
;
1101 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1102 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1103 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1104 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1105 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1106 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1107 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1108 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1109 short mode
= kUnsupportedMode
;
1110 bool invertDestinationFirst
= false ;
1111 switch ( logical_func
)
1113 case wxAND
: // src AND dst
1114 mode
= adMin
; // ok
1116 case wxAND_INVERT
: // (NOT src) AND dst
1117 mode
= notSrcOr
; // ok
1119 case wxAND_REVERSE
:// src AND (NOT dst)
1120 invertDestinationFirst
= true ;
1124 mode
= kEmulatedMode
;
1127 mode
= srcCopy
; // ok
1129 case wxEQUIV
: // (NOT src) XOR dst
1130 mode
= srcXor
; // ok
1132 case wxINVERT
: // NOT dst
1133 mode
= kEmulatedMode
; //or hilite ;
1135 case wxNAND
: // (NOT src) OR (NOT dst)
1136 invertDestinationFirst
= true ;
1139 case wxNOR
: // (NOT src) AND (NOT dst)
1140 invertDestinationFirst
= true ;
1143 case wxNO_OP
: // dst
1144 mode
= kEmulatedMode
; // this has already been handled upon entry
1146 case wxOR
: // src OR dst
1149 case wxOR_INVERT
: // (NOT src) OR dst
1152 case wxOR_REVERSE
: // src OR (NOT dst)
1153 invertDestinationFirst
= true ;
1157 mode
= kEmulatedMode
;
1159 case wxSRC_INVERT
: // (NOT src)
1160 mode
= notSrcCopy
; // ok
1162 case wxXOR
: // src XOR dst
1163 mode
= notSrcXor
; // ok
1168 if ( mode
== kUnsupportedMode
)
1170 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1173 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1174 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1175 if ( LockPixels(bmappixels
) )
1177 wxMacFastPortSetter
helper(this) ;
1178 if ( source
->GetDepth() == 1 )
1180 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1181 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1185 // the modes need this, otherwise we'll end up having really nice colors...
1186 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1187 RGBColor black
= { 0,0,0} ;
1188 RGBForeColor( &black
) ;
1189 RGBBackColor( &white
) ;
1191 if ( useMask
&& source
->m_macMask
)
1193 if ( mode
== srcCopy
)
1195 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1197 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1198 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1199 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1200 &srcrect
, &srcrect
, &dstrect
) ;
1201 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1206 RgnHandle clipRgn
= NewRgn() ;
1207 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1208 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1209 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1210 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1211 if ( mode
== kEmulatedMode
)
1214 ::PenPat(GetQDGlobalsBlack(&pat
));
1215 if ( logical_func
== wxSET
)
1217 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1218 ::RGBForeColor( &col
) ;
1219 ::PaintRgn( clipRgn
) ;
1221 else if ( logical_func
== wxCLEAR
)
1223 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1224 ::RGBForeColor( &col
) ;
1225 ::PaintRgn( clipRgn
) ;
1227 else if ( logical_func
== wxINVERT
)
1229 MacInvertRgn( clipRgn
) ;
1233 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1235 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1237 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1238 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1239 if ( PtInRgn( dstPoint
, clipRgn
) )
1243 SetPort( (GrafPtr
) sourcePort
) ;
1244 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1245 SetPort( (GrafPtr
) m_macPort
) ;
1246 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1247 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1248 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1256 if ( invertDestinationFirst
)
1258 MacInvertRgn( clipRgn
) ;
1260 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1261 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1262 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1264 DisposeRgn( clipRgn
) ;
1269 RgnHandle clipRgn
= NewRgn() ;
1270 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1271 if ( mode
== kEmulatedMode
)
1274 ::PenPat(GetQDGlobalsBlack(&pat
));
1275 if ( logical_func
== wxSET
)
1277 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1278 ::RGBForeColor( &col
) ;
1279 ::PaintRgn( clipRgn
) ;
1281 else if ( logical_func
== wxCLEAR
)
1283 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1284 ::RGBForeColor( &col
) ;
1285 ::PaintRgn( clipRgn
) ;
1287 else if ( logical_func
== wxINVERT
)
1289 MacInvertRgn( clipRgn
) ;
1293 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1295 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1297 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1298 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1302 SetPort( (GrafPtr
) sourcePort
) ;
1303 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1304 SetPort( (GrafPtr
) m_macPort
) ;
1305 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1306 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1307 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1315 if ( invertDestinationFirst
)
1317 MacInvertRgn( clipRgn
) ;
1319 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1320 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1321 &srcrect
, &dstrect
, mode
, NULL
) ;
1323 DisposeRgn( clipRgn
) ;
1325 UnlockPixels( bmappixels
) ;
1327 m_macPenInstalled
= false ;
1328 m_macBrushInstalled
= false ;
1329 m_macFontInstalled
= false ;
1334 // as macro in FixMath.h for 10.3
1335 inline Fixed
IntToFixed( int inInt
)
1337 return (((SInt32
) inInt
) << 16);
1340 inline int FixedToInt( Fixed inFixed
)
1342 return (((SInt32
) inFixed
) >> 16);
1346 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1349 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1353 DrawText(str
, x
, y
);
1357 if ( str
.Length() == 0 )
1360 wxMacFastPortSetter
helper(this) ;
1365 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1366 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.GetMacFontSize()));
1367 m_macAliasWasEnabled
= true ;
1369 OSStatus status
= noErr
;
1370 ATSUTextLayout atsuLayout
;
1371 UniCharCount chars
= str
.Length() ;
1373 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1374 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1376 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1377 int wlen
= wxWcslen( wchar
.data() ) ;
1378 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) wchar
.data() , 0 , wlen
, wlen
, 1 ,
1379 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1381 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1382 int iAngle
= int( angle
);
1383 int drawX
= XLOG2DEVMAC(x
) ;
1384 int drawY
= YLOG2DEVMAC(y
) ;
1386 ATSUTextMeasurement textBefore
;
1387 ATSUTextMeasurement textAfter
;
1388 ATSUTextMeasurement ascent
;
1389 ATSUTextMeasurement descent
;
1392 if ( abs(iAngle
) > 0 )
1394 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1395 ATSUAttributeTag atsuTags
[] =
1397 kATSULineRotationTag
,
1399 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1403 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1407 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1408 atsuTags
, atsuSizes
, atsuValues
) ;
1410 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1411 &textBefore
, &textAfter
, &ascent
, &descent
);
1413 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1414 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1415 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1416 IntToFixed(drawX
) , IntToFixed(drawY
) );
1417 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1419 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1420 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1421 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1422 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1423 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1424 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1425 ::ATSUDisposeTextLayout(atsuLayout
);
1428 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1430 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1432 wxMacFastPortSetter
helper(this) ;
1433 long xx
= XLOG2DEVMAC(x
);
1434 long yy
= YLOG2DEVMAC(y
);
1436 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1437 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1438 useDrawThemeText
= false ;
1443 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1444 SetAntiAliasedTextEnabled(true, 8);
1445 m_macAliasWasEnabled
= true ;
1448 ::GetFontInfo( &fi
) ;
1450 if ( !useDrawThemeText
)
1453 ::MoveTo( xx
, yy
);
1454 if ( m_backgroundMode
== wxTRANSPARENT
)
1456 ::TextMode( srcOr
) ;
1460 ::TextMode( srcCopy
) ;
1462 int length
= strtext
.Length() ;
1468 #if 0 // we don't have to do all that here
1471 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1473 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1475 if ( useDrawThemeText
)
1477 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1478 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1479 if ( m_backgroundMode
!= wxTRANSPARENT
)
1481 Point bounds
={0,0} ;
1482 Rect background
= frame
;
1484 ::GetThemeTextDimensions( mString
,
1485 kThemeCurrentPortFont
,
1490 background
.right
= background
.left
+ bounds
.h
;
1491 background
.bottom
= background
.top
+ bounds
.v
;
1492 ::EraseRect( &background
) ;
1494 ::DrawThemeTextBox( mString
,
1495 kThemeCurrentPortFont
,
1506 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1507 ::DrawText( text
, 0 , strlen(text
) ) ;
1508 if ( m_backgroundMode
!= wxTRANSPARENT
)
1510 Point bounds
={0,0} ;
1511 Rect background
= frame
;
1513 ::GetThemeTextDimensions( mString
,
1514 kThemeCurrentPortFont
,
1519 background
.right
= background
.left
+ bounds
.h
;
1520 background
.bottom
= background
.top
+ bounds
.v
;
1521 ::EraseRect( &background
) ;
1524 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1530 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1532 wxString linetext
= strtext
;
1534 if ( useDrawThemeText
)
1536 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1537 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1539 if ( m_backgroundMode
!= wxTRANSPARENT
)
1541 Point bounds
={0,0} ;
1542 Rect background
= frame
;
1544 ::GetThemeTextDimensions( mString
,
1545 kThemeCurrentPortFont
,
1550 background
.right
= background
.left
+ bounds
.h
;
1551 background
.bottom
= background
.top
+ bounds
.v
;
1552 ::EraseRect( &background
) ;
1554 ::DrawThemeTextBox( mString
,
1555 kThemeCurrentPortFont
,
1565 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1566 if ( m_backgroundMode
!= wxTRANSPARENT
)
1568 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 } ;
1569 short width
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1570 frame
.right
= frame
.left
+ width
;
1572 ::EraseRect( &frame
) ;
1574 ::DrawText( text
, 0 , strlen(text
) ) ;
1577 ::TextMode( srcOr
) ;
1580 bool wxDC::CanGetTextExtent() const
1582 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1586 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1587 wxCoord
*descent
, wxCoord
*externalLeading
,
1588 wxFont
*theFont
) const
1590 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1591 wxMacFastPortSetter
helper(this) ;
1592 wxFont formerFont
= m_font
;
1595 // work around the constness
1596 *((wxFont
*)(&m_font
)) = *theFont
;
1600 ::GetFontInfo( &fi
) ;
1602 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1603 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1604 useGetThemeText
= false ;
1607 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1609 *descent
=YDEV2LOGREL( fi
.descent
);
1610 if ( externalLeading
)
1611 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1612 int length
= strtext
.Length() ;
1620 #if 0 // apparently we don't have to do all that
1623 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1625 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1627 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1629 if ( useGetThemeText
)
1631 Point bounds
={0,0} ;
1633 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1634 ::GetThemeTextDimensions( mString
,
1635 kThemeCurrentPortFont
,
1640 curwidth
= bounds
.h
;
1645 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1646 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1648 if ( curwidth
> *width
)
1649 *width
= XDEV2LOGREL( curwidth
) ;
1655 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1657 wxString linetext
= strtext
;
1659 if ( useGetThemeText
)
1661 Point bounds
={0,0} ;
1663 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1664 ::GetThemeTextDimensions( mString
,
1665 kThemeCurrentPortFont
,
1670 curwidth
= bounds
.h
;
1675 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1676 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1678 if ( curwidth
> *width
)
1679 *width
= XDEV2LOGREL( curwidth
) ;
1683 // work around the constness
1684 *((wxFont
*)(&m_font
)) = formerFont
;
1685 m_macFontInstalled
= false ;
1690 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1692 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1695 widths
.Add(0, text
.Length());
1697 if (text
.Length() == 0)
1700 wxMacFastPortSetter
helper(this) ;
1703 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1704 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1705 useGetThemeText
= false ;
1707 if ( useGetThemeText
)
1709 // If anybody knows how to do this more efficiently yet still handle
1710 // the fractional glyph widths that may be present when using AA
1711 // fonts, please change it. Currently it is measuring from the
1712 // begining of the string for each succeding substring, which is much
1713 // slower than this should be.
1714 for (size_t i
=0; i
<text
.Length(); i
++)
1716 wxString
str(text
.Left(i
+1));
1717 Point bounds
= {0,0};
1719 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1720 ::GetThemeTextDimensions( mString
,
1721 kThemeCurrentPortFont
,
1726 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1732 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1733 size_t len
= strlen(buff
);
1734 short* measurements
= new short[len
+1];
1735 MeasureText(len
, buff
.data(), measurements
);
1737 // Copy to widths, starting at measurements[1]
1738 // NOTE: this doesn't take into account any multi-byte characters
1739 // in buff, it probabkly should...
1740 for (size_t i
=0; i
<text
.Length(); i
++)
1741 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1743 delete [] measurements
;
1751 wxCoord
wxDC::GetCharWidth(void) const
1753 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1754 wxMacFastPortSetter
helper(this) ;
1758 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1759 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1760 useGetThemeText
= false ;
1764 if ( useGetThemeText
)
1766 Point bounds
={0,0} ;
1768 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1769 ::GetThemeTextDimensions( mString
,
1770 kThemeCurrentPortFont
,
1775 CFRelease( mString
) ;
1781 width
= ::TextWidth( text
, 0 , 1 ) ;
1783 return YDEV2LOGREL(width
) ;
1786 wxCoord
wxDC::GetCharHeight(void) const
1788 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1789 wxMacFastPortSetter
helper(this) ;
1792 ::GetFontInfo( &fi
) ;
1793 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1796 void wxDC::Clear(void)
1798 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1799 wxMacFastPortSetter
helper(this) ;
1800 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1801 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1804 //MacInstallBrush() ;
1805 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1806 ::EraseRect( &rect
) ;
1810 void wxDC::MacInstallFont() const
1812 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1813 // if ( m_macFontInstalled )
1815 Pattern blackColor
;
1816 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1819 ::TextFont( m_font
.GetMacFontNum() ) ;
1820 ::TextSize( (short)(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1821 ::TextFace( m_font
.GetMacFontStyle() ) ;
1822 m_macFontInstalled
= true ;
1823 m_macBrushInstalled
= false ;
1824 m_macPenInstalled
= false ;
1825 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1826 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1827 ::RGBForeColor( &forecolor
);
1828 ::RGBBackColor( &backcolor
);
1832 FontFamilyID fontId
;
1836 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1837 GetFNum( fontName
, &fontId
);
1838 ::TextFont( fontId
) ;
1839 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1840 ::TextFace( fontStyle
) ;
1841 // todo reset after spacing changes - or store the current spacing somewhere
1842 m_macFontInstalled
= true ;
1843 m_macBrushInstalled
= false ;
1844 m_macPenInstalled
= false ;
1845 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1846 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1847 ::RGBForeColor( &forecolor
);
1848 ::RGBBackColor( &backcolor
);
1850 short mode
= patCopy
;
1852 switch( m_logicalFunction
)
1857 case wxINVERT
: // NOT dst
1858 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1861 case wxXOR
: // src XOR dst
1864 case wxOR_REVERSE
: // src OR (NOT dst)
1867 case wxSRC_INVERT
: // (NOT src)
1870 case wxAND
: // src AND dst
1875 case wxAND_REVERSE
:// src AND (NOT dst)
1876 case wxAND_INVERT
: // (NOT src) AND dst
1877 case wxNO_OP
: // dst
1878 case wxNOR
: // (NOT src) AND (NOT dst)
1879 case wxEQUIV
: // (NOT src) XOR dst
1880 case wxOR_INVERT
: // (NOT src) OR dst
1881 case wxNAND
: // (NOT src) OR (NOT dst)
1882 case wxOR
: // src OR dst
1884 // case wxSRC_OR: // source _bitmap_ OR destination
1885 // case wxSRC_AND: // source _bitmap_ AND destination
1889 OSStatus status
= noErr
;
1890 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.GetMacFontSize()) ) ;
1891 Style qdStyle
= m_font
.GetMacFontStyle() ;
1892 ATSUFontID atsuFont
= m_font
.GetMacATSUFontID() ;
1893 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1894 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1895 ATSUAttributeTag atsuTags
[] =
1900 // kATSUBaselineClassTag ,
1901 kATSUVerticalCharacterTag
,
1902 kATSUQDBoldfaceTag
,
1904 kATSUQDUnderlineTag
,
1905 kATSUQDCondensedTag
,
1906 kATSUQDExtendedTag
,
1908 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1910 sizeof( ATSUFontID
) ,
1912 // sizeof( RGBColor ) ,
1913 // sizeof( BslnBaselineClass ) ,
1914 sizeof( ATSUVerticalCharacterType
),
1921 Boolean kTrue
= true ;
1922 Boolean kFalse
= false ;
1923 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1924 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1925 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1929 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1930 // &kBaselineDefault ,
1932 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1933 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1934 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1935 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1936 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1938 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1939 atsuTags
, atsuSizes
, atsuValues
);
1940 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1943 Pattern gPatterns
[] =
1945 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1946 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1947 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1948 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1949 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1950 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1951 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1953 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1954 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1955 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1956 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1959 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1961 int index
= 0; // solid pattern by default
1965 case wxBDIAGONAL_HATCH
: index
= 1; break;
1966 case wxFDIAGONAL_HATCH
: index
= 2; break;
1967 case wxCROSS_HATCH
: index
= 3; break;
1968 case wxHORIZONTAL_HATCH
: index
= 4; break;
1969 case wxVERTICAL_HATCH
: index
= 5; break;
1970 case wxCROSSDIAG_HATCH
: index
= 6; break;
1972 case wxDOT
: index
= 7; break;
1973 case wxLONG_DASH
: index
= 8; break;
1974 case wxSHORT_DASH
: index
= 9; break;
1975 case wxDOT_DASH
: index
= 10; break;
1977 *pattern
= gPatterns
[index
];
1980 void wxDC::MacInstallPen() const
1982 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1983 //Pattern blackColor;
1984 // if ( m_macPenInstalled )
1986 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1987 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1988 ::RGBForeColor( &forecolor
);
1989 ::RGBBackColor( &backcolor
);
1991 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1992 // null means only one pixel, at whatever resolution
1993 if ( penWidth
== 0 )
1995 ::PenSize(penWidth
, penWidth
);
1997 int penStyle
= m_pen
.GetStyle();
1999 if (penStyle
== wxUSER_DASH
)
2001 // FIXME: there should be exactly 8 items in the dash
2003 int number
= m_pen
.GetDashes(&dash
) ;
2005 for ( int i
= 0 ; i
< 8 ; ++i
)
2007 pat
.pat
[i
] = dash
[index
] ;
2008 if (index
< number
- 1)
2014 wxMacGetPattern(penStyle
, &pat
);
2018 short mode
= patCopy
;
2020 switch( m_logicalFunction
)
2022 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
2025 case wxINVERT
: // NOT dst
2026 // ::PenPat(GetQDGlobalsBlack(&blackColor));
2029 case wxXOR
: // src XOR dst
2032 case wxOR_REVERSE
: // src OR (NOT dst)
2035 case wxSRC_INVERT
: // (NOT src)
2038 case wxAND
: // src AND dst
2043 case wxAND_REVERSE
:// src AND (NOT dst)
2044 case wxAND_INVERT
: // (NOT src) AND dst
2045 case wxNO_OP
: // dst
2046 case wxNOR
: // (NOT src) AND (NOT dst)
2047 case wxEQUIV
: // (NOT src) XOR dst
2048 case wxOR_INVERT
: // (NOT src) OR dst
2049 case wxNAND
: // (NOT src) OR (NOT dst)
2050 case wxOR
: // src OR dst
2052 // case wxSRC_OR: // source _bitmap_ OR destination
2053 // case wxSRC_AND: // source _bitmap_ AND destination
2057 m_macPenInstalled
= true ;
2058 m_macBrushInstalled
= false ;
2059 m_macFontInstalled
= false ;
2062 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
2064 Pattern whiteColor
;
2065 switch( background
.MacGetBrushKind() )
2067 case kwxMacBrushTheme
:
2069 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
2072 case kwxMacBrushThemeBackground
:
2075 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2076 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2079 case kwxMacBrushColour
:
2081 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2082 int brushStyle
= background
.GetStyle();
2083 if (brushStyle
== wxSOLID
)
2084 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2085 else if (background
.IsHatch())
2088 wxMacGetPattern(brushStyle
, &pat
);
2093 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2100 void wxDC::MacInstallBrush() const
2102 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2103 Pattern blackColor
;
2104 // if ( m_macBrushInstalled )
2107 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2108 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2109 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2110 int brushStyle
= m_brush
.GetStyle();
2111 if (brushStyle
== wxSOLID
)
2113 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2115 else if (m_brush
.IsHatch())
2118 wxMacGetPattern(brushStyle
, &pat
);
2121 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2123 // we force this in order to be compliant with wxMSW
2124 backgroundTransparent
= false ;
2125 // for these the text fore (and back for MASK_OPAQUE) colors are used
2126 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2127 int width
= bitmap
->GetWidth() ;
2128 int height
= bitmap
->GetHeight() ;
2129 GWorldPtr gw
= NULL
;
2130 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2131 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2133 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2134 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2135 LockPixels( gwpixmaphandle
) ;
2136 bool isMonochrome
= !IsPortColor( gw
) ;
2137 if ( !isMonochrome
)
2139 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2140 isMonochrome
= true ;
2142 if ( isMonochrome
&& width
== 8 && height
== 8 )
2144 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2145 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2146 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2147 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2148 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2150 for ( int i
= 0 ; i
< 8 ; ++i
)
2152 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2154 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2159 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2160 // caching scheme before putting this into production
2163 PixPatHandle pixpat
= NewPixPat() ;
2164 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2165 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2166 ((**(**pixpat
).patMap
).bounds
.bottom
-
2167 (**(**pixpat
).patMap
).bounds
.top
);
2168 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2169 (**pixpat
).patData
= image
;
2172 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2173 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2174 if ( ctspec
[0].rgb
.red
== 0x0000 )
2176 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2177 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2181 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2182 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2184 ::CTabChanged( ctable
) ;
2186 ::PenPixPat(pixpat
);
2187 m_macForegroundPixMap
= pixpat
;
2189 UnlockPixels( gwpixmaphandle
) ;
2193 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2195 short mode
= patCopy
;
2196 switch( m_logicalFunction
)
2199 if ( backgroundTransparent
)
2204 case wxINVERT
: // NOT dst
2205 if ( !backgroundTransparent
)
2207 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2211 case wxXOR
: // src XOR dst
2214 case wxOR_REVERSE
: // src OR (NOT dst)
2217 case wxSRC_INVERT
: // (NOT src)
2220 case wxAND
: // src AND dst
2225 case wxAND_REVERSE
:// src AND (NOT dst)
2226 case wxAND_INVERT
: // (NOT src) AND dst
2227 case wxNO_OP
: // dst
2228 case wxNOR
: // (NOT src) AND (NOT dst)
2229 case wxEQUIV
: // (NOT src) XOR dst
2230 case wxOR_INVERT
: // (NOT src) OR dst
2231 case wxNAND
: // (NOT src) OR (NOT dst)
2232 case wxOR
: // src OR dst
2234 // case wxSRC_OR: // source _bitmap_ OR destination
2235 // case wxSRC_AND: // source _bitmap_ AND destination
2239 m_macBrushInstalled
= true ;
2240 m_macPenInstalled
= false ;
2241 m_macFontInstalled
= false ;
2244 // ---------------------------------------------------------------------------
2245 // coordinates transformations
2246 // ---------------------------------------------------------------------------
2248 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2250 return ((wxDC
*)this)->XDEV2LOG(x
);
2253 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2255 return ((wxDC
*)this)->YDEV2LOG(y
);
2258 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2260 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2263 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2265 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2268 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2270 return ((wxDC
*)this)->XLOG2DEV(x
);
2273 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2275 return ((wxDC
*)this)->YLOG2DEV(y
);
2278 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2280 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2283 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2285 return ((wxDC
*)this)->YLOG2DEVREL(y
);