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 m_swapped
= QDSwapPort( (GrafPtr
) dc
->m_macPort
, &m_oldPort
) ;
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
) ;
82 SetPort( m_oldPort
) ;
83 m_dc
->MacCleanupPort( NULL
) ;
84 DisposeRgn( m_clipRgn
) ;
94 typedef wxMacPortSetter wxMacFastPortSetter
;
97 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
) :
98 wxMacPortSaver( (GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) )
100 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
101 m_formerClip
= NewRgn() ;
102 m_newClip
= NewRgn() ;
103 GetClip( m_formerClip
) ;
108 win
->MacWindowToRootWindow( &x
,&y
) ;
109 // get area including focus rect
110 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip
) ;
111 if ( !EmptyRgn( m_newClip
) )
112 OffsetRgn( m_newClip
, x
, y
) ;
114 SetClip( m_newClip
) ;
118 wxMacWindowClipper::~wxMacWindowClipper()
120 SetPort( m_newPort
) ;
121 SetClip( m_formerClip
) ;
122 DisposeRgn( m_newClip
) ;
123 DisposeRgn( m_formerClip
) ;
126 wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow
* win
) :
127 wxMacWindowClipper( win
)
129 // the port is already set at this point
130 m_newPort
=(GrafPtr
) GetWindowPort((WindowRef
) win
->MacGetTopLevelWindowRef()) ;
131 GetThemeDrawingState( &m_themeDrawingState
) ;
134 wxMacWindowStateSaver::~wxMacWindowStateSaver()
136 SetPort( m_newPort
) ;
137 SetThemeDrawingState( m_themeDrawingState
, true ) ;
140 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
144 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
145 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
147 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
150 // this function emulates all wx colour manipulations, used to verify the implementation
151 // by setting the mode in the blitting functions to kEmulatedMode
152 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
154 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
156 switch ( logical_func
)
158 case wxAND
: // src AND dst
159 dstColor
.red
= dstColor
.red
& srcColor
.red
;
160 dstColor
.green
= dstColor
.green
& srcColor
.green
;
161 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
163 case wxAND_INVERT
: // (NOT src) AND dst
164 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
165 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
166 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
168 case wxAND_REVERSE
:// src AND (NOT dst)
169 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
170 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
171 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
179 dstColor
.red
= srcColor
.red
;
180 dstColor
.green
= srcColor
.green
;
181 dstColor
.blue
= srcColor
.blue
;
183 case wxEQUIV
: // (NOT src) XOR dst
184 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
185 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
186 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
188 case wxINVERT
: // NOT dst
189 dstColor
.red
= ~dstColor
.red
;
190 dstColor
.green
= ~dstColor
.green
;
191 dstColor
.blue
= ~dstColor
.blue
;
193 case wxNAND
: // (NOT src) OR (NOT dst)
194 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
195 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
196 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
198 case wxNOR
: // (NOT src) AND (NOT dst)
199 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
200 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
201 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
205 case wxOR
: // src OR dst
206 dstColor
.red
= dstColor
.red
| srcColor
.red
;
207 dstColor
.green
= dstColor
.green
| srcColor
.green
;
208 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
210 case wxOR_INVERT
: // (NOT src) OR dst
211 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
212 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
213 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
215 case wxOR_REVERSE
: // src OR (NOT dst)
216 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
217 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
218 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
221 dstColor
.red
= 0xFFFF ;
222 dstColor
.green
= 0xFFFF ;
223 dstColor
.blue
= 0xFFFF ;
225 case wxSRC_INVERT
: // (NOT src)
226 dstColor
.red
= ~srcColor
.red
;
227 dstColor
.green
= ~srcColor
.green
;
228 dstColor
.blue
= ~srcColor
.blue
;
230 case wxXOR
: // src XOR dst
231 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
232 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
233 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
242 m_mm_to_pix_x
= mm2pt
;
243 m_mm_to_pix_y
= mm2pt
;
244 m_internalDeviceOriginX
= 0;
245 m_internalDeviceOriginY
= 0;
246 m_externalDeviceOriginX
= 0;
247 m_externalDeviceOriginY
= 0;
248 m_logicalScaleX
= 1.0;
249 m_logicalScaleY
= 1.0;
254 m_needComputeScaleX
= false;
255 m_needComputeScaleY
= false;
259 m_macFontInstalled
= false ;
260 m_macBrushInstalled
= false ;
261 m_macPenInstalled
= false ;
262 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
263 m_macBoundaryClipRgn
= NewRgn() ;
264 m_macCurrentClipRgn
= NewRgn() ;
265 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
266 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
267 m_pen
= *wxBLACK_PEN
;
268 m_font
= *wxNORMAL_FONT
;
269 m_brush
= *wxWHITE_BRUSH
;
271 // needed to debug possible errors with two active drawing methods at the same time on
273 m_macCurrentPortStateHelper
= NULL
;
275 m_macATSUIStyle
= NULL
;
276 m_macAliasWasEnabled
= false;
277 m_macForegroundPixMap
= NULL
;
278 m_macBackgroundPixMap
= NULL
;
283 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
284 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
287 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
290 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
291 m_macCurrentPortStateHelper
= help
;
293 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
294 #if ! wxMAC_EXPERIMENTAL_DC
295 m_macFontInstalled
= false ;
296 m_macBrushInstalled
= false ;
297 m_macPenInstalled
= false ;
300 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
303 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
304 m_macCurrentPortStateHelper
= NULL
;
306 if( m_macATSUIStyle
)
308 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
309 m_macATSUIStyle
= NULL
;
311 if ( m_macAliasWasEnabled
)
313 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
314 m_macAliasWasEnabled
= false ;
316 if ( m_macForegroundPixMap
)
319 ::PenPat(GetQDGlobalsBlack(&blackColor
));
320 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
321 m_macForegroundPixMap
= NULL
;
323 if ( m_macBackgroundPixMap
)
326 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
327 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
328 m_macBackgroundPixMap
= NULL
;
332 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
334 wxCHECK_RET( Ok(), wxT("invalid window dc") );
335 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
336 wxMacFastPortSetter
helper(this) ;
337 wxCoord xx
= XLOG2DEVMAC(x
);
338 wxCoord yy
= YLOG2DEVMAC(y
);
339 wxCoord w
= bmp
.GetWidth();
340 wxCoord h
= bmp
.GetHeight();
341 wxCoord ww
= XLOG2DEVREL(w
);
342 wxCoord hh
= YLOG2DEVREL(h
);
343 // Set up drawing mode
344 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
345 //m_logicalFunction == wxCLEAR ? WHITENESS :
346 //m_logicalFunction == wxSET ? BLACKNESS :
347 m_logicalFunction
== wxINVERT
? hilite
:
348 //m_logicalFunction == wxAND ? MERGECOPY :
349 m_logicalFunction
== wxOR
? srcOr
:
350 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
351 m_logicalFunction
== wxXOR
? srcXor
:
352 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
353 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
354 //m_logicalFunction == wxSRC_OR ? srcOr :
355 //m_logicalFunction == wxSRC_AND ? SRCAND :
357 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
358 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
359 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
360 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
362 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
364 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
365 PixMapHandle bmappixels
;
366 // Set foreground and background colours (for bitmaps depth = 1)
367 if(bmp
.GetDepth() == 1)
369 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
370 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
376 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
377 RGBColor black
= { 0,0,0} ;
378 RGBForeColor( &black
) ;
379 RGBBackColor( &white
) ;
381 bmappixels
= GetGWorldPixMap( bmapworld
) ;
382 wxCHECK_RET(LockPixels(bmappixels
),
383 wxT("DoDrawBitmap: Unable to lock pixels"));
384 Rect source
= { 0, 0, h
, w
};
385 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
386 if ( useMask
&& bmp
.GetMask() )
388 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
392 GetPortBitMapForCopyBits(bmapworld
),
393 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
394 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
395 &source
, &source
, &dest
, mode
, NULL
397 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
401 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
402 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
403 &source
, &dest
, mode
, NULL
) ;
405 UnlockPixels( bmappixels
) ;
407 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
409 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
410 OffsetRect( &bitmaprect
, xx
, yy
) ;
411 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
413 m_macPenInstalled
= false ;
414 m_macBrushInstalled
= false ;
415 m_macFontInstalled
= false ;
418 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
420 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
421 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
422 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
425 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
427 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
428 wxCoord xx
, yy
, ww
, hh
;
431 ww
= XLOG2DEVREL(width
);
432 hh
= YLOG2DEVREL(height
);
433 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
434 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
437 m_clipX1
= wxMax( m_clipX1
, xx
);
438 m_clipY1
= wxMax( m_clipY1
, yy
);
439 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
440 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
452 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
454 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
457 DestroyClippingRegion();
460 wxMacFastPortSetter
helper(this) ;
462 region
.GetBox( x
, y
, w
, h
);
463 wxCoord xx
, yy
, ww
, hh
;
468 // if we have a scaling that we cannot map onto native regions
469 // we must use the box
470 if ( ww
!= w
|| hh
!= h
)
472 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
476 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
477 if ( xx
!= x
|| yy
!= y
)
479 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
481 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
484 m_clipX1
= wxMax( m_clipX1
, xx
);
485 m_clipY1
= wxMax( m_clipY1
, yy
);
486 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
487 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
500 void wxDC::DestroyClippingRegion()
502 wxMacFastPortSetter
helper(this) ;
503 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
507 void wxDC::DoGetSizeMM( int* width
, int* height
) const
512 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
513 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
516 void wxDC::SetTextForeground( const wxColour
&col
)
518 wxCHECK_RET(Ok(), wxT("Invalid DC"));
519 m_textForegroundColour
= col
;
520 m_macFontInstalled
= false ;
523 void wxDC::SetTextBackground( const wxColour
&col
)
525 wxCHECK_RET(Ok(), wxT("Invalid DC"));
526 m_textBackgroundColour
= col
;
527 m_macFontInstalled
= false ;
530 void wxDC::SetMapMode( int mode
)
535 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
538 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
541 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
544 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
548 SetLogicalScale( 1.0, 1.0 );
551 if (mode
!= wxMM_TEXT
)
553 m_needComputeScaleX
= true;
554 m_needComputeScaleY
= true;
558 void wxDC::SetUserScale( double x
, double y
)
560 // allow negative ? -> no
563 ComputeScaleAndOrigin();
566 void wxDC::SetLogicalScale( double x
, double y
)
571 ComputeScaleAndOrigin();
574 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
576 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
577 m_logicalOriginY
= y
* m_signY
;
578 ComputeScaleAndOrigin();
581 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
583 m_externalDeviceOriginX
= x
;
584 m_externalDeviceOriginY
= y
;
585 ComputeScaleAndOrigin();
588 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
590 m_signX
= (xLeftRight
? 1 : -1);
591 m_signY
= (yBottomUp
? -1 : 1);
592 ComputeScaleAndOrigin();
595 wxSize
wxDC::GetPPI() const
597 return wxSize(72, 72);
600 int wxDC::GetDepth() const
602 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
604 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
609 void wxDC::ComputeScaleAndOrigin()
611 // CMB: copy scale to see if it changes
612 double origScaleX
= m_scaleX
;
613 double origScaleY
= m_scaleY
;
614 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
615 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
616 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
617 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
618 // CMB: if scale has changed call SetPen to recalulate the line width
619 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
621 // this is a bit artificial, but we need to force wxDC to think
622 // the pen has changed
629 void wxDC::SetPalette( const wxPalette
& palette
)
633 void wxDC::SetBackgroundMode( int mode
)
635 m_backgroundMode
= mode
;
638 void wxDC::SetFont( const wxFont
&font
)
641 m_macFontInstalled
= false ;
644 void wxDC::SetPen( const wxPen
&pen
)
649 m_macPenInstalled
= false ;
652 void wxDC::SetBrush( const wxBrush
&brush
)
654 if (m_brush
== brush
)
657 m_macBrushInstalled
= false ;
660 void wxDC::SetBackground( const wxBrush
&brush
)
662 if (m_backgroundBrush
== brush
)
664 m_backgroundBrush
= brush
;
665 if (!m_backgroundBrush
.Ok())
667 m_macBrushInstalled
= false ;
670 void wxDC::SetLogicalFunction( int function
)
672 if (m_logicalFunction
== function
)
674 m_logicalFunction
= function
;
675 m_macFontInstalled
= false ;
676 m_macBrushInstalled
= false ;
677 m_macPenInstalled
= false ;
680 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
681 const wxColour
& col
, int style
);
683 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
684 const wxColour
& col
, int style
)
686 return wxDoFloodFill(this, x
, y
, col
, style
);
689 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
691 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
692 wxMacFastPortSetter
helper(this) ;
694 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
695 // Convert from Mac colour to wx
696 col
->Set( colour
.red
>> 8,
702 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
704 wxCHECK_RET(Ok(), wxT("Invalid DC"));
705 wxMacFastPortSetter
helper(this) ;
706 if (m_pen
.GetStyle() != wxTRANSPARENT
)
709 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
710 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
711 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
712 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
713 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
714 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
715 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
716 (m_pen
.GetWidth() <= 1))
718 // Implement LAST_NOT for MAC at least for
719 // orthogonal lines. RR.
740 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
742 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
743 wxMacFastPortSetter
helper(this) ;
744 if (m_pen
.GetStyle() != wxTRANSPARENT
)
749 wxCoord xx
= XLOG2DEVMAC(x
);
750 wxCoord yy
= YLOG2DEVMAC(y
);
752 ::MoveTo( XLOG2DEVMAC(0), yy
);
753 ::LineTo( XLOG2DEVMAC(w
), yy
);
754 ::MoveTo( xx
, YLOG2DEVMAC(0) );
755 ::LineTo( xx
, YLOG2DEVMAC(h
) );
756 CalcBoundingBox(x
, y
);
757 CalcBoundingBox(x
+w
, y
+h
);
762 * To draw arcs properly the angles need to be converted from the WX style:
763 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
764 * a normal axis on paper).
767 * Angles start on the +ve y axis and go clockwise.
770 static double wxConvertWXangleToMACangle(double angle
)
772 double newAngle
= 90 - angle
;
773 while ( newAngle
> 360 ) newAngle
-= 360 ;
774 while ( newAngle
< 0 ) newAngle
+= 360 ;
778 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
779 wxCoord x2
, wxCoord y2
,
780 wxCoord xc
, wxCoord yc
)
782 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
783 wxMacFastPortSetter
helper(this) ;
784 wxCoord xx1
= XLOG2DEVMAC(x1
);
785 wxCoord yy1
= YLOG2DEVMAC(y1
);
786 wxCoord xx2
= XLOG2DEVMAC(x2
);
787 wxCoord yy2
= YLOG2DEVMAC(y2
);
788 wxCoord xxc
= XLOG2DEVMAC(xc
);
789 wxCoord yyc
= YLOG2DEVMAC(yc
);
790 double dx
= xx1
- xxc
;
791 double dy
= yy1
- yyc
;
792 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
793 wxCoord rad
= (wxCoord
)radius
;
794 double radius1
, radius2
;
795 if (xx1
== xx2
&& yy1
== yy2
)
800 else if (radius
== 0.0)
802 radius1
= radius2
= 0.0;
806 radius1
= (xx1
- xxc
== 0) ?
807 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
808 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
809 radius2
= (xx2
- xxc
== 0) ?
810 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
811 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
813 wxCoord alpha2
= wxCoord(radius2
- radius1
);
814 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
815 while( alpha2
< 0 ) alpha2
+= 360 ;
817 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
818 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
820 PaintArc(&r
, alpha1
, alpha2
);
822 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
824 FrameArc(&r
, alpha1
, alpha2
);
828 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
829 double sa
, double ea
)
831 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
832 wxMacFastPortSetter
helper(this) ;
834 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
835 // we have to make sure that the filling is always counter-clockwise
838 wxCoord xx
= XLOG2DEVMAC(x
);
839 wxCoord yy
= YLOG2DEVMAC(y
);
840 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
841 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
842 // handle -ve width and/or height
843 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
844 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
845 sa
= wxConvertWXangleToMACangle(sa
);
850 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
852 PaintArc(&r
, (short)sa
, (short)angle
);
854 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
856 FrameArc(&r
, (short)sa
, (short)angle
);
860 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
862 wxCHECK_RET(Ok(), wxT("Invalid DC"));
863 wxMacFastPortSetter
helper(this) ;
864 if (m_pen
.GetStyle() != wxTRANSPARENT
)
866 wxCoord xx1
= XLOG2DEVMAC(x
);
867 wxCoord yy1
= YLOG2DEVMAC(y
);
868 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
869 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
870 CalcBoundingBox(x
, y
);
874 void wxDC::DoDrawLines(int n
, wxPoint points
[],
875 wxCoord xoffset
, wxCoord yoffset
)
877 wxCHECK_RET(Ok(), wxT("Invalid DC"));
878 wxMacFastPortSetter
helper(this) ;
879 if (m_pen
.GetStyle() == wxTRANSPARENT
)
882 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
883 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
884 wxCoord x1
, x2
, y1
, y2
;
885 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
886 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
887 ::MoveTo(x1
- offset
, y1
- offset
);
888 for (int i
= 0; i
< n
-1; i
++)
890 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
891 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
892 ::LineTo( x2
- offset
, y2
- offset
);
896 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
897 wxCoord xoffset
, wxCoord yoffset
,
900 wxCHECK_RET(Ok(), wxT("Invalid DC"));
901 wxMacFastPortSetter
helper(this) ;
902 wxCoord x1
, x2
, y1
, y2
;
903 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
905 PolyHandle polygon
= OpenPoly();
906 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
907 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
909 for (int i
= 1; i
< n
; i
++)
911 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
912 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
915 // close the polyline if necessary
916 if ( x1
!= x2
|| y1
!= y2
)
921 if (m_brush
.GetStyle() != wxTRANSPARENT
)
924 ::PaintPoly( polygon
);
926 if (m_pen
.GetStyle() != wxTRANSPARENT
)
929 ::FramePoly( polygon
) ;
934 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
936 wxCHECK_RET(Ok(), wxT("Invalid DC"));
937 wxMacFastPortSetter
helper(this) ;
938 wxCoord xx
= XLOG2DEVMAC(x
);
939 wxCoord yy
= YLOG2DEVMAC(y
);
940 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
941 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
942 // CMB: draw nothing if transformed w or h is 0
943 if (ww
== 0 || hh
== 0)
945 // CMB: handle -ve width and/or height
956 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
957 if (m_brush
.GetStyle() != wxTRANSPARENT
)
960 ::PaintRect( &rect
) ;
962 if (m_pen
.GetStyle() != wxTRANSPARENT
)
965 ::FrameRect( &rect
) ;
969 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
970 wxCoord width
, wxCoord height
,
973 wxCHECK_RET(Ok(), wxT("Invalid DC"));
974 wxMacFastPortSetter
helper(this) ;
976 radius
= - radius
* ((width
< height
) ? width
: height
);
977 wxCoord xx
= XLOG2DEVMAC(x
);
978 wxCoord yy
= YLOG2DEVMAC(y
);
979 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
980 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
981 // CMB: draw nothing if transformed w or h is 0
982 if (ww
== 0 || hh
== 0)
984 // CMB: handle -ve width and/or height
995 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
996 if (m_brush
.GetStyle() != wxTRANSPARENT
)
999 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1001 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1004 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1008 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1010 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1011 wxMacFastPortSetter
helper(this) ;
1012 wxCoord xx
= XLOG2DEVMAC(x
);
1013 wxCoord yy
= YLOG2DEVMAC(y
);
1014 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1015 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1016 // CMB: draw nothing if transformed w or h is 0
1017 if (ww
== 0 || hh
== 0)
1019 // CMB: handle -ve width and/or height
1030 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1031 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1034 ::PaintOval( &rect
) ;
1036 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1039 ::FrameOval( &rect
) ;
1043 bool wxDC::CanDrawBitmap(void) const
1048 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1049 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1050 wxCoord xsrcMask
, wxCoord ysrcMask
)
1052 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1053 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1054 if ( logical_func
== wxNO_OP
)
1056 if (xsrcMask
== -1 && ysrcMask
== -1)
1058 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1060 // correct the parameter in case this dc does not have a mask at all
1061 if ( useMask
&& !source
->m_macMask
)
1063 Rect srcrect
, dstrect
;
1064 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1065 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1066 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1067 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1068 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1069 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1070 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1071 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1072 short mode
= kUnsupportedMode
;
1073 bool invertDestinationFirst
= false ;
1074 switch ( logical_func
)
1076 case wxAND
: // src AND dst
1077 mode
= adMin
; // ok
1079 case wxAND_INVERT
: // (NOT src) AND dst
1080 mode
= notSrcOr
; // ok
1082 case wxAND_REVERSE
:// src AND (NOT dst)
1083 invertDestinationFirst
= true ;
1087 mode
= kEmulatedMode
;
1090 mode
= srcCopy
; // ok
1092 case wxEQUIV
: // (NOT src) XOR dst
1093 mode
= srcXor
; // ok
1095 case wxINVERT
: // NOT dst
1096 mode
= kEmulatedMode
; //or hilite ;
1098 case wxNAND
: // (NOT src) OR (NOT dst)
1099 invertDestinationFirst
= true ;
1102 case wxNOR
: // (NOT src) AND (NOT dst)
1103 invertDestinationFirst
= true ;
1106 case wxNO_OP
: // dst
1107 mode
= kEmulatedMode
; // this has already been handled upon entry
1109 case wxOR
: // src OR dst
1112 case wxOR_INVERT
: // (NOT src) OR dst
1115 case wxOR_REVERSE
: // src OR (NOT dst)
1116 invertDestinationFirst
= true ;
1120 mode
= kEmulatedMode
;
1122 case wxSRC_INVERT
: // (NOT src)
1123 mode
= notSrcCopy
; // ok
1125 case wxXOR
: // src XOR dst
1126 mode
= notSrcXor
; // ok
1131 if ( mode
== kUnsupportedMode
)
1133 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1136 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1137 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1138 if ( LockPixels(bmappixels
) )
1140 wxMacFastPortSetter
helper(this) ;
1141 if ( source
->GetDepth() == 1 )
1143 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1144 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1148 // the modes need this, otherwise we'll end up having really nice colors...
1149 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1150 RGBColor black
= { 0,0,0} ;
1151 RGBForeColor( &black
) ;
1152 RGBBackColor( &white
) ;
1154 if ( useMask
&& source
->m_macMask
)
1156 if ( mode
== srcCopy
)
1158 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1160 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1161 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1162 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1163 &srcrect
, &srcrect
, &dstrect
) ;
1164 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1169 RgnHandle clipRgn
= NewRgn() ;
1170 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1171 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1172 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1173 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1174 if ( mode
== kEmulatedMode
)
1177 ::PenPat(GetQDGlobalsBlack(&pat
));
1178 if ( logical_func
== wxSET
)
1180 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1181 ::RGBForeColor( &col
) ;
1182 ::PaintRgn( clipRgn
) ;
1184 else if ( logical_func
== wxCLEAR
)
1186 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1187 ::RGBForeColor( &col
) ;
1188 ::PaintRgn( clipRgn
) ;
1190 else if ( logical_func
== wxINVERT
)
1192 MacInvertRgn( clipRgn
) ;
1196 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1198 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1200 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1201 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1202 if ( PtInRgn( dstPoint
, clipRgn
) )
1206 SetPort( (GrafPtr
) sourcePort
) ;
1207 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1208 SetPort( (GrafPtr
) m_macPort
) ;
1209 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1210 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1211 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1219 if ( invertDestinationFirst
)
1221 MacInvertRgn( clipRgn
) ;
1223 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1224 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1225 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1227 DisposeRgn( clipRgn
) ;
1232 RgnHandle clipRgn
= NewRgn() ;
1233 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1234 if ( mode
== kEmulatedMode
)
1237 ::PenPat(GetQDGlobalsBlack(&pat
));
1238 if ( logical_func
== wxSET
)
1240 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1241 ::RGBForeColor( &col
) ;
1242 ::PaintRgn( clipRgn
) ;
1244 else if ( logical_func
== wxCLEAR
)
1246 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1247 ::RGBForeColor( &col
) ;
1248 ::PaintRgn( clipRgn
) ;
1250 else if ( logical_func
== wxINVERT
)
1252 MacInvertRgn( clipRgn
) ;
1256 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1258 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1260 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1261 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1265 SetPort( (GrafPtr
) sourcePort
) ;
1266 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1267 SetPort( (GrafPtr
) m_macPort
) ;
1268 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1269 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1270 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1278 if ( invertDestinationFirst
)
1280 MacInvertRgn( clipRgn
) ;
1282 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1283 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1284 &srcrect
, &dstrect
, mode
, NULL
) ;
1286 DisposeRgn( clipRgn
) ;
1288 UnlockPixels( bmappixels
) ;
1290 m_macPenInstalled
= false ;
1291 m_macBrushInstalled
= false ;
1292 m_macFontInstalled
= false ;
1297 // as macro in FixMath.h for 10.3
1298 inline Fixed
IntToFixed( int inInt
)
1300 return (((SInt32
) inInt
) << 16);
1303 inline int FixedToInt( Fixed inFixed
)
1305 return (((SInt32
) inFixed
) >> 16);
1309 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1312 // TODO support text background color (only possible by hand, ATSUI does not support it)
1313 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1315 if ( str
.Length() == 0 )
1318 wxMacFastPortSetter
helper(this) ;
1323 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1324 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* m_font
.MacGetFontSize()));
1325 m_macAliasWasEnabled
= true ;
1327 OSStatus status
= noErr
;
1328 ATSUTextLayout atsuLayout
;
1329 UniCharCount chars
= str
.Length() ;
1330 UniChar
* ubuf
= NULL
;
1331 #if SIZEOF_WCHAR_T == 4
1332 wxMBConvUTF16BE converter
;
1334 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1335 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1336 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 ) ;
1338 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1339 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 ) ;
1340 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 ) ;
1341 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 ) ;
1343 chars
= unicharlen
/ 2 ;
1346 ubuf
= (UniChar
*) str
.wc_str() ;
1348 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
) ;
1349 chars
= wxWcslen( wchar
.data() ) ;
1350 ubuf
= (UniChar
*) wchar
.data() ;
1354 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1355 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1357 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1358 int iAngle
= int( angle
);
1359 int drawX
= XLOG2DEVMAC(x
) ;
1360 int drawY
= YLOG2DEVMAC(y
) ;
1362 ATSUTextMeasurement textBefore
;
1363 ATSUTextMeasurement textAfter
;
1364 ATSUTextMeasurement ascent
;
1365 ATSUTextMeasurement descent
;
1368 if ( abs(iAngle
) > 0 )
1370 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1371 ATSUAttributeTag atsuTags
[] =
1373 kATSULineRotationTag
,
1375 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1379 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1383 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1384 atsuTags
, atsuSizes
, atsuValues
) ;
1386 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1387 &textBefore
, &textAfter
, &ascent
, &descent
);
1389 drawX
+= (int)(sin(angle
/RAD2DEG
) * FixedToInt(ascent
));
1390 drawY
+= (int)(cos(angle
/RAD2DEG
) * FixedToInt(ascent
));
1391 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1392 IntToFixed(drawX
) , IntToFixed(drawY
) );
1393 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1395 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1396 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1397 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1398 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1399 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1400 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1401 ::ATSUDisposeTextLayout(atsuLayout
);
1402 #if SIZEOF_WCHAR_T == 4
1407 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1409 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1411 wxMacFastPortSetter
helper(this) ;
1412 long xx
= XLOG2DEVMAC(x
);
1413 long yy
= YLOG2DEVMAC(y
);
1415 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1416 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1417 useDrawThemeText
= false ;
1422 ::GetFontInfo( &fi
) ;
1424 if ( !useDrawThemeText
)
1427 ::MoveTo( xx
, yy
);
1428 if ( m_backgroundMode
== wxTRANSPARENT
)
1430 ::TextMode( srcOr
) ;
1434 ::TextMode( srcCopy
) ;
1438 wxString linetext
= strtext
;
1440 if ( useDrawThemeText
)
1442 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1443 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding()) ;
1445 if ( m_backgroundMode
!= wxTRANSPARENT
)
1447 Point bounds
={0,0} ;
1448 Rect background
= frame
;
1450 ::GetThemeTextDimensions( mString
,
1451 m_font
.MacGetThemeFontID() ,
1456 background
.right
= background
.left
+ bounds
.h
;
1457 background
.bottom
= background
.top
+ bounds
.v
;
1458 ::EraseRect( &background
) ;
1460 ::DrawThemeTextBox( mString
,
1461 m_font
.MacGetThemeFontID() ,
1471 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1472 ::DrawText( text
, 0 , strlen(text
) ) ;
1475 ::TextMode( srcOr
) ;
1478 bool wxDC::CanGetTextExtent() const
1480 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1484 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1485 wxCoord
*descent
, wxCoord
*externalLeading
,
1486 wxFont
*theFont
) const
1488 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1489 wxMacFastPortSetter
helper(this) ;
1490 wxFont formerFont
= m_font
;
1493 // work around the constness
1494 *((wxFont
*)(&m_font
)) = *theFont
;
1498 ::GetFontInfo( &fi
) ;
1500 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1501 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1502 useGetThemeText
= false ;
1505 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1507 *descent
=YDEV2LOGREL( fi
.descent
);
1508 if ( externalLeading
)
1509 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1515 wxString linetext
= strtext
;
1517 if ( useGetThemeText
)
1519 Point bounds
={0,0} ;
1521 wxMacCFStringHolder
mString( linetext
, m_font
.GetEncoding() ) ;
1522 ThemeFontID themeFont
= m_font
.MacGetThemeFontID() ;
1523 ::GetThemeTextDimensions( mString
,
1529 curwidth
= bounds
.h
;
1533 wxCharBuffer text
= linetext
.mb_str(wxConvLocal
) ;
1534 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1536 if ( curwidth
> *width
)
1537 *width
= XDEV2LOGREL( curwidth
) ;
1541 // work around the constness
1542 *((wxFont
*)(&m_font
)) = formerFont
;
1543 m_macFontInstalled
= false ;
1548 bool wxDC::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
1550 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1553 widths
.Add(0, text
.Length());
1555 if (text
.Length() == 0)
1558 wxMacFastPortSetter
helper(this) ;
1561 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1562 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1563 useGetThemeText
= false ;
1565 if ( useGetThemeText
)
1567 // If anybody knows how to do this more efficiently yet still handle
1568 // the fractional glyph widths that may be present when using AA
1569 // fonts, please change it. Currently it is measuring from the
1570 // begining of the string for each succeding substring, which is much
1571 // slower than this should be.
1572 for (size_t i
=0; i
<text
.Length(); i
++)
1574 wxString
str(text
.Left(i
+1));
1575 Point bounds
= {0,0};
1577 wxMacCFStringHolder
mString(str
, m_font
.GetEncoding());
1578 ::GetThemeTextDimensions( mString
,
1579 m_font
.MacGetThemeFontID(),
1584 widths
[i
] = XDEV2LOGREL(bounds
.h
);
1590 wxCharBuffer buff
= text
.mb_str(wxConvLocal
);
1591 size_t len
= strlen(buff
);
1592 short* measurements
= new short[len
+1];
1593 MeasureText(len
, buff
.data(), measurements
);
1595 // Copy to widths, starting at measurements[1]
1596 // NOTE: this doesn't take into account any multi-byte characters
1597 // in buff, it probabkly should...
1598 for (size_t i
=0; i
<text
.Length(); i
++)
1599 widths
[i
] = XDEV2LOGREL(measurements
[i
+1]);
1601 delete [] measurements
;
1609 wxCoord
wxDC::GetCharWidth(void) const
1611 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1612 wxMacFastPortSetter
helper(this) ;
1616 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1617 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1618 useGetThemeText
= false ;
1622 if ( useGetThemeText
)
1624 Point bounds
={0,0} ;
1626 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1627 ::GetThemeTextDimensions( mString
,
1628 m_font
.MacGetThemeFontID(),
1633 CFRelease( mString
) ;
1639 width
= ::TextWidth( text
, 0 , 1 ) ;
1641 return YDEV2LOGREL(width
) ;
1644 wxCoord
wxDC::GetCharHeight(void) const
1646 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1647 wxMacFastPortSetter
helper(this) ;
1650 ::GetFontInfo( &fi
) ;
1651 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1654 void wxDC::Clear(void)
1656 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1657 wxMacFastPortSetter
helper(this) ;
1658 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1659 if ( m_backgroundBrush
.Ok() && m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1662 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1663 ::EraseRect( &rect
) ;
1667 void wxDC::MacInstallFont() const
1669 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1670 // if ( m_macFontInstalled )
1672 Pattern blackColor
;
1673 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1674 if ( m_backgroundMode
!= wxTRANSPARENT
)
1676 Pattern whiteColor
;
1677 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1681 ::TextFont( m_font
.MacGetFontNum() ) ;
1682 ::TextSize( (short)(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1683 ::TextFace( m_font
.MacGetFontStyle() ) ;
1684 m_macFontInstalled
= true ;
1685 m_macBrushInstalled
= false ;
1686 m_macPenInstalled
= false ;
1687 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1688 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1689 ::RGBForeColor( &forecolor
);
1690 ::RGBBackColor( &backcolor
);
1694 FontFamilyID fontId
;
1698 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1699 GetFNum( fontName
, &fontId
);
1700 ::TextFont( fontId
) ;
1701 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1702 ::TextFace( fontStyle
) ;
1703 // todo reset after spacing changes - or store the current spacing somewhere
1704 m_macFontInstalled
= true ;
1705 m_macBrushInstalled
= false ;
1706 m_macPenInstalled
= false ;
1707 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1708 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1709 ::RGBForeColor( &forecolor
);
1710 ::RGBBackColor( &backcolor
);
1712 short mode
= patCopy
;
1714 switch( m_logicalFunction
)
1719 case wxINVERT
: // NOT dst
1720 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1723 case wxXOR
: // src XOR dst
1726 case wxOR_REVERSE
: // src OR (NOT dst)
1729 case wxSRC_INVERT
: // (NOT src)
1732 case wxAND
: // src AND dst
1737 case wxAND_REVERSE
:// src AND (NOT dst)
1738 case wxAND_INVERT
: // (NOT src) AND dst
1739 case wxNO_OP
: // dst
1740 case wxNOR
: // (NOT src) AND (NOT dst)
1741 case wxEQUIV
: // (NOT src) XOR dst
1742 case wxOR_INVERT
: // (NOT src) OR dst
1743 case wxNAND
: // (NOT src) OR (NOT dst)
1744 case wxOR
: // src OR dst
1746 // case wxSRC_OR: // source _bitmap_ OR destination
1747 // case wxSRC_AND: // source _bitmap_ AND destination
1751 OSStatus status
= noErr
;
1752 Fixed atsuSize
= IntToFixed( int(m_scaleY
* m_font
.MacGetFontSize()) ) ;
1753 Style qdStyle
= m_font
.MacGetATSUAdditionalQDStyles() ;
1754 ATSUFontID atsuFont
= m_font
.MacGetATSUFontID() ;
1755 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUIStyle
) ;
1756 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1757 ATSUAttributeTag atsuTags
[] =
1762 // kATSUBaselineClassTag ,
1763 kATSUVerticalCharacterTag
,
1764 kATSUQDBoldfaceTag
,
1766 kATSUQDUnderlineTag
,
1767 kATSUQDCondensedTag
,
1768 kATSUQDExtendedTag
,
1770 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1772 sizeof( ATSUFontID
) ,
1774 // sizeof( RGBColor ) ,
1775 // sizeof( BslnBaselineClass ) ,
1776 sizeof( ATSUVerticalCharacterType
),
1783 Boolean kTrue
= true ;
1784 Boolean kFalse
= false ;
1785 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
1786 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1787 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1791 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1792 // &kBaselineDefault ,
1794 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1795 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1796 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1797 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1798 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1800 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1801 atsuTags
, atsuSizes
, atsuValues
);
1802 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1805 Pattern gPatterns
[] =
1807 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1808 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1809 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1810 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1811 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1812 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1813 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
1815 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1816 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1817 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1818 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
1821 static void wxMacGetPattern(int penStyle
, Pattern
*pattern
)
1823 int index
= 0; // solid pattern by default
1827 case wxBDIAGONAL_HATCH
: index
= 1; break;
1828 case wxFDIAGONAL_HATCH
: index
= 2; break;
1829 case wxCROSS_HATCH
: index
= 3; break;
1830 case wxHORIZONTAL_HATCH
: index
= 4; break;
1831 case wxVERTICAL_HATCH
: index
= 5; break;
1832 case wxCROSSDIAG_HATCH
: index
= 6; break;
1834 case wxDOT
: index
= 7; break;
1835 case wxLONG_DASH
: index
= 8; break;
1836 case wxSHORT_DASH
: index
= 9; break;
1837 case wxDOT_DASH
: index
= 10; break;
1839 *pattern
= gPatterns
[index
];
1842 void wxDC::MacInstallPen() const
1844 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1845 //Pattern blackColor;
1846 // if ( m_macPenInstalled )
1848 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1849 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1850 ::RGBForeColor( &forecolor
);
1851 ::RGBBackColor( &backcolor
);
1853 int penWidth
= (int) (m_pen
.GetWidth() * m_scaleX
) ; ;
1854 // null means only one pixel, at whatever resolution
1855 if ( penWidth
== 0 )
1857 ::PenSize(penWidth
, penWidth
);
1859 int penStyle
= m_pen
.GetStyle();
1861 if (penStyle
== wxUSER_DASH
)
1863 // FIXME: there should be exactly 8 items in the dash
1865 int number
= m_pen
.GetDashes(&dash
) ;
1867 for ( int i
= 0 ; i
< 8 ; ++i
)
1869 pat
.pat
[i
] = dash
[index
] ;
1870 if (index
< number
- 1)
1876 wxMacGetPattern(penStyle
, &pat
);
1880 short mode
= patCopy
;
1882 switch( m_logicalFunction
)
1884 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1887 case wxINVERT
: // NOT dst
1888 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1891 case wxXOR
: // src XOR dst
1894 case wxOR_REVERSE
: // src OR (NOT dst)
1897 case wxSRC_INVERT
: // (NOT src)
1900 case wxAND
: // src AND dst
1905 case wxAND_REVERSE
:// src AND (NOT dst)
1906 case wxAND_INVERT
: // (NOT src) AND dst
1907 case wxNO_OP
: // dst
1908 case wxNOR
: // (NOT src) AND (NOT dst)
1909 case wxEQUIV
: // (NOT src) XOR dst
1910 case wxOR_INVERT
: // (NOT src) OR dst
1911 case wxNAND
: // (NOT src) OR (NOT dst)
1912 case wxOR
: // src OR dst
1914 // case wxSRC_OR: // source _bitmap_ OR destination
1915 // case wxSRC_AND: // source _bitmap_ AND destination
1919 m_macPenInstalled
= true ;
1920 m_macBrushInstalled
= false ;
1921 m_macFontInstalled
= false ;
1924 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1926 Pattern whiteColor
;
1927 if ( background
.Ok() )
1929 switch( background
.MacGetBrushKind() )
1931 case kwxMacBrushTheme
:
1933 ::SetThemeBackground( background
.MacGetTheme() , wxDisplayDepth() , true ) ;
1936 case kwxMacBrushThemeBackground
:
1939 ThemeBackgroundKind bg
= background
.MacGetThemeBackground( &extent
) ;
1940 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1943 case kwxMacBrushColour
:
1945 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1946 int brushStyle
= background
.GetStyle();
1947 if (brushStyle
== wxSOLID
)
1948 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1949 else if (background
.IsHatch())
1952 wxMacGetPattern(brushStyle
, &pat
);
1957 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1965 void wxDC::MacInstallBrush() const
1967 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1968 Pattern blackColor
;
1969 // if ( m_macBrushInstalled )
1972 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1973 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1974 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1975 int brushStyle
= m_brush
.GetStyle();
1976 if (brushStyle
== wxSOLID
)
1978 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1980 else if (m_brush
.IsHatch())
1983 wxMacGetPattern(brushStyle
, &pat
);
1986 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1988 // we force this in order to be compliant with wxMSW
1989 backgroundTransparent
= false ;
1990 // for these the text fore (and back for MASK_OPAQUE) colors are used
1991 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1992 int width
= bitmap
->GetWidth() ;
1993 int height
= bitmap
->GetHeight() ;
1994 GWorldPtr gw
= NULL
;
1995 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1996 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1998 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1999 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2000 LockPixels( gwpixmaphandle
) ;
2001 bool isMonochrome
= !IsPortColor( gw
) ;
2002 if ( !isMonochrome
)
2004 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2005 isMonochrome
= true ;
2007 if ( isMonochrome
&& width
== 8 && height
== 8 )
2009 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2010 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2011 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2012 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2013 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2015 for ( int i
= 0 ; i
< 8 ; ++i
)
2017 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2019 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2024 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2025 // caching scheme before putting this into production
2028 PixPatHandle pixpat
= NewPixPat() ;
2029 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2030 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2031 ((**(**pixpat
).patMap
).bounds
.bottom
-
2032 (**(**pixpat
).patMap
).bounds
.top
);
2033 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2034 (**pixpat
).patData
= image
;
2037 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2038 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2039 if ( ctspec
[0].rgb
.red
== 0x0000 )
2041 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2042 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2046 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2047 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2049 ::CTabChanged( ctable
) ;
2051 ::PenPixPat(pixpat
);
2052 m_macForegroundPixMap
= pixpat
;
2054 UnlockPixels( gwpixmaphandle
) ;
2058 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2060 short mode
= patCopy
;
2061 switch( m_logicalFunction
)
2064 if ( backgroundTransparent
)
2069 case wxINVERT
: // NOT dst
2070 if ( !backgroundTransparent
)
2072 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2076 case wxXOR
: // src XOR dst
2079 case wxOR_REVERSE
: // src OR (NOT dst)
2082 case wxSRC_INVERT
: // (NOT src)
2085 case wxAND
: // src AND dst
2090 case wxAND_REVERSE
:// src AND (NOT dst)
2091 case wxAND_INVERT
: // (NOT src) AND dst
2092 case wxNO_OP
: // dst
2093 case wxNOR
: // (NOT src) AND (NOT dst)
2094 case wxEQUIV
: // (NOT src) XOR dst
2095 case wxOR_INVERT
: // (NOT src) OR dst
2096 case wxNAND
: // (NOT src) OR (NOT dst)
2097 case wxOR
: // src OR dst
2099 // case wxSRC_OR: // source _bitmap_ OR destination
2100 // case wxSRC_AND: // source _bitmap_ AND destination
2104 m_macBrushInstalled
= true ;
2105 m_macPenInstalled
= false ;
2106 m_macFontInstalled
= false ;
2109 // ---------------------------------------------------------------------------
2110 // coordinates transformations
2111 // ---------------------------------------------------------------------------
2113 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2115 return ((wxDC
*)this)->XDEV2LOG(x
);
2118 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2120 return ((wxDC
*)this)->YDEV2LOG(y
);
2123 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2125 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2128 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2130 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2133 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2135 return ((wxDC
*)this)->XLOG2DEV(x
);
2138 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2140 return ((wxDC
*)this)->YLOG2DEV(y
);
2143 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2145 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2148 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2150 return ((wxDC
*)this)->YLOG2DEVREL(y
);