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"
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 #define mm2inches 0.0393700787402
43 #define inches2mm 25.4
44 #define mm2twips 56.6929133859
45 #define twips2mm 0.0176388888889
46 #define mm2pt 2.83464566929
47 #define pt2mm 0.352777777778
48 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
50 const double M_PI
= 3.14159265358979 ;
53 const double RAD2DEG
= 180.0 / M_PI
;
54 const short kEmulatedMode
= -1 ;
55 const short kUnsupportedMode
= -2 ;
57 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
58 m_ph( (GrafPtr
) dc
->m_macPort
)
60 wxASSERT( dc
->Ok() ) ;
62 dc
->MacSetupPort(&m_ph
) ;
65 wxMacPortSetter::~wxMacPortSetter()
67 m_dc
->MacCleanupPort(&m_ph
) ;
70 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win
)
72 m_formerClip
= NewRgn() ;
73 m_newClip
= NewRgn() ;
74 GetClip( m_formerClip
) ;
79 // this clipping area was set to the parent window's drawing area, lead to problems
80 // with MacOSX controls drawing outside their wx' rectangle
81 RgnHandle insidergn
= NewRgn() ;
83 wxWindow
*parent
= win
->GetParent() ;
84 parent
->MacWindowToRootWindow( &x
,&y
) ;
85 wxSize size
= parent
->GetSize() ;
86 SetRectRgn( insidergn
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,
87 size
.x
- parent
->MacGetRightBorderSize(),
88 size
.y
- parent
->MacGetBottomBorderSize()) ;
89 CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip
) ;
90 SectRgn( m_newClip
, insidergn
, m_newClip
) ;
91 OffsetRgn( m_newClip
, x
, y
) ;
92 SetClip( m_newClip
) ;
93 DisposeRgn( insidergn
) ;
96 win
->MacWindowToRootWindow( &x
,&y
) ;
97 CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip
) ;
98 OffsetRgn( m_newClip
, x
, y
) ;
99 SetClip( m_newClip
) ;
104 wxMacWindowClipper::~wxMacWindowClipper()
106 SetClip( m_formerClip
) ;
107 DisposeRgn( m_newClip
) ;
108 DisposeRgn( m_formerClip
) ;
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
115 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
116 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
121 // this function emulates all wx colour manipulations, used to verify the implementation
122 // by setting the mode in the blitting functions to kEmulatedMode
123 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
125 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
127 switch ( logical_func
)
129 case wxAND
: // src AND dst
130 dstColor
.red
= dstColor
.red
& srcColor
.red
;
131 dstColor
.green
= dstColor
.green
& srcColor
.green
;
132 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
134 case wxAND_INVERT
: // (NOT src) AND dst
135 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
136 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
137 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
139 case wxAND_REVERSE
:// src AND (NOT dst)
140 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
141 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
142 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
150 dstColor
.red
= srcColor
.red
;
151 dstColor
.green
= srcColor
.green
;
152 dstColor
.blue
= srcColor
.blue
;
154 case wxEQUIV
: // (NOT src) XOR dst
155 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
156 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
157 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
159 case wxINVERT
: // NOT dst
160 dstColor
.red
= ~dstColor
.red
;
161 dstColor
.green
= ~dstColor
.green
;
162 dstColor
.blue
= ~dstColor
.blue
;
164 case wxNAND
: // (NOT src) OR (NOT dst)
165 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
166 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
167 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
169 case wxNOR
: // (NOT src) AND (NOT dst)
170 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
171 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
172 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
176 case wxOR
: // src OR dst
177 dstColor
.red
= dstColor
.red
| srcColor
.red
;
178 dstColor
.green
= dstColor
.green
| srcColor
.green
;
179 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
181 case wxOR_INVERT
: // (NOT src) OR dst
182 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
183 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
184 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
186 case wxOR_REVERSE
: // src OR (NOT dst)
187 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
188 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
189 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
192 dstColor
.red
= 0xFFFF ;
193 dstColor
.green
= 0xFFFF ;
194 dstColor
.blue
= 0xFFFF ;
196 case wxSRC_INVERT
: // (NOT src)
197 dstColor
.red
= ~srcColor
.red
;
198 dstColor
.green
= ~srcColor
.green
;
199 dstColor
.blue
= ~srcColor
.blue
;
201 case wxXOR
: // src XOR dst
202 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
203 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
204 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
213 m_mm_to_pix_x
= mm2pt
;
214 m_mm_to_pix_y
= mm2pt
;
215 m_internalDeviceOriginX
= 0;
216 m_internalDeviceOriginY
= 0;
217 m_externalDeviceOriginX
= 0;
218 m_externalDeviceOriginY
= 0;
219 m_logicalScaleX
= 1.0;
220 m_logicalScaleY
= 1.0;
225 m_needComputeScaleX
= FALSE
;
226 m_needComputeScaleY
= FALSE
;
230 m_macFontInstalled
= false ;
231 m_macBrushInstalled
= false ;
232 m_macPenInstalled
= false ;
233 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
234 m_macBoundaryClipRgn
= NewRgn() ;
235 m_macCurrentClipRgn
= NewRgn() ;
236 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
237 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
238 m_pen
= *wxBLACK_PEN
;
239 m_font
= *wxNORMAL_FONT
;
240 m_brush
= *wxWHITE_BRUSH
;
242 // needed to debug possible errors with two active drawing methods at the same time on
244 m_macCurrentPortStateHelper
= NULL
;
246 m_macATSUIStyle
= NULL
;
247 m_macAliasWasEnabled
= false;
248 m_macForegroundPixMap
= NULL
;
249 m_macBackgroundPixMap
= NULL
;
254 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
255 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
258 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
261 wxASSERT( m_macCurrentPortStateHelper
== NULL
) ;
262 m_macCurrentPortStateHelper
= help
;
264 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
265 m_macFontInstalled
= false ;
266 m_macBrushInstalled
= false ;
267 m_macPenInstalled
= false ;
270 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const
273 wxASSERT( m_macCurrentPortStateHelper
== help
) ;
274 m_macCurrentPortStateHelper
= NULL
;
276 if( m_macATSUIStyle
)
278 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
279 m_macATSUIStyle
= NULL
;
281 if ( m_macAliasWasEnabled
)
283 SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
);
284 m_macAliasWasEnabled
= false ;
286 if ( m_macForegroundPixMap
)
289 ::PenPat(GetQDGlobalsBlack(&blackColor
));
290 DisposePixPat( (PixPatHandle
) m_macForegroundPixMap
) ;
291 m_macForegroundPixMap
= NULL
;
293 if ( m_macBackgroundPixMap
)
296 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
297 DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap
) ;
298 m_macBackgroundPixMap
= NULL
;
302 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
304 wxCHECK_RET( Ok(), wxT("invalid window dc") );
305 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
306 wxMacPortSetter
helper(this) ;
307 wxCoord xx
= XLOG2DEVMAC(x
);
308 wxCoord yy
= YLOG2DEVMAC(y
);
309 wxCoord w
= bmp
.GetWidth();
310 wxCoord h
= bmp
.GetHeight();
311 wxCoord ww
= XLOG2DEVREL(w
);
312 wxCoord hh
= YLOG2DEVREL(h
);
313 // Set up drawing mode
314 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
315 //m_logicalFunction == wxCLEAR ? WHITENESS :
316 //m_logicalFunction == wxSET ? BLACKNESS :
317 m_logicalFunction
== wxINVERT
? hilite
:
318 //m_logicalFunction == wxAND ? MERGECOPY :
319 m_logicalFunction
== wxOR
? srcOr
:
320 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
321 m_logicalFunction
== wxXOR
? srcXor
:
322 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
323 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
324 //m_logicalFunction == wxSRC_OR ? srcOr :
325 //m_logicalFunction == wxSRC_AND ? SRCAND :
327 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
328 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
329 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
330 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
332 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
334 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
335 PixMapHandle bmappixels
;
336 // Set foreground and background colours (for bitmaps depth = 1)
337 if(bmp
.GetDepth() == 1)
339 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
340 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
346 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
347 RGBColor black
= { 0,0,0} ;
348 RGBForeColor( &black
) ;
349 RGBBackColor( &white
) ;
351 bmappixels
= GetGWorldPixMap( bmapworld
) ;
352 wxCHECK_RET(LockPixels(bmappixels
),
353 wxT("DoDrawBitmap: Unable to lock pixels"));
354 Rect source
= { 0, 0, h
, w
};
355 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
356 if ( useMask
&& bmp
.GetMask() )
358 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
362 GetPortBitMapForCopyBits(bmapworld
),
363 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
364 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
365 &source
, &source
, &dest
, mode
, NULL
367 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
371 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
372 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
373 &source
, &dest
, mode
, NULL
) ;
375 UnlockPixels( bmappixels
) ;
377 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
379 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
380 OffsetRect( &bitmaprect
, xx
, yy
) ;
381 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
383 m_macPenInstalled
= false ;
384 m_macBrushInstalled
= false ;
385 m_macFontInstalled
= false ;
388 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
390 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
391 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
392 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
395 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
397 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
398 wxCoord xx
, yy
, ww
, hh
;
401 ww
= XLOG2DEVREL(width
);
402 hh
= YLOG2DEVREL(height
);
403 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
404 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
407 m_clipX1
= wxMax( m_clipX1
, xx
);
408 m_clipY1
= wxMax( m_clipY1
, yy
);
409 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
410 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
422 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
424 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
425 wxMacPortSetter
helper(this) ;
428 DestroyClippingRegion();
432 region
.GetBox( x
, y
, w
, h
);
433 wxCoord xx
, yy
, ww
, hh
;
438 // if we have a scaling that we cannot map onto native regions
439 // we must use the box
440 if ( ww
!= w
|| hh
!= h
)
442 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
446 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
447 if ( xx
!= x
|| yy
!= y
)
449 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
451 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
454 m_clipX1
= wxMax( m_clipX1
, xx
);
455 m_clipY1
= wxMax( m_clipY1
, yy
);
456 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
457 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
470 void wxDC::DestroyClippingRegion()
472 wxMacPortSetter
helper(this) ;
473 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
477 void wxDC::DoGetSizeMM( int* width
, int* height
) const
482 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
483 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
486 void wxDC::SetTextForeground( const wxColour
&col
)
488 wxCHECK_RET(Ok(), wxT("Invalid DC"));
489 m_textForegroundColour
= col
;
490 m_macFontInstalled
= false ;
493 void wxDC::SetTextBackground( const wxColour
&col
)
495 wxCHECK_RET(Ok(), wxT("Invalid DC"));
496 m_textBackgroundColour
= col
;
497 m_macFontInstalled
= false ;
500 void wxDC::SetMapMode( int mode
)
505 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
508 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
511 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
514 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
518 SetLogicalScale( 1.0, 1.0 );
521 if (mode
!= wxMM_TEXT
)
523 m_needComputeScaleX
= TRUE
;
524 m_needComputeScaleY
= TRUE
;
528 void wxDC::SetUserScale( double x
, double y
)
530 // allow negative ? -> no
533 ComputeScaleAndOrigin();
536 void wxDC::SetLogicalScale( double x
, double y
)
541 ComputeScaleAndOrigin();
544 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
546 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
547 m_logicalOriginY
= y
* m_signY
;
548 ComputeScaleAndOrigin();
551 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
553 m_externalDeviceOriginX
= x
;
554 m_externalDeviceOriginY
= y
;
555 ComputeScaleAndOrigin();
559 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
561 m_internalDeviceOriginX
= x
;
562 m_internalDeviceOriginY
= y
;
563 ComputeScaleAndOrigin();
565 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
567 if (x
) *x
= m_internalDeviceOriginX
;
568 if (y
) *y
= m_internalDeviceOriginY
;
572 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
574 m_signX
= (xLeftRight
? 1 : -1);
575 m_signY
= (yBottomUp
? -1 : 1);
576 ComputeScaleAndOrigin();
579 wxSize
wxDC::GetPPI() const
581 return wxSize(72, 72);
584 int wxDC::GetDepth() const
586 if ( IsPortColor( (CGrafPtr
) m_macPort
) )
588 return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize
) ;
593 void wxDC::ComputeScaleAndOrigin()
595 // CMB: copy scale to see if it changes
596 double origScaleX
= m_scaleX
;
597 double origScaleY
= m_scaleY
;
598 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
599 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
600 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
601 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
602 // CMB: if scale has changed call SetPen to recalulate the line width
603 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
605 // this is a bit artificial, but we need to force wxDC to think
606 // the pen has changed
607 wxPen
* pen
= & GetPen();
614 void wxDC::SetPalette( const wxPalette
& palette
)
618 void wxDC::SetBackgroundMode( int mode
)
620 m_backgroundMode
= mode
;
623 void wxDC::SetFont( const wxFont
&font
)
626 m_macFontInstalled
= false ;
629 void wxDC::SetPen( const wxPen
&pen
)
634 m_macPenInstalled
= false ;
637 void wxDC::SetBrush( const wxBrush
&brush
)
639 if (m_brush
== brush
)
642 m_macBrushInstalled
= false ;
645 void wxDC::SetBackground( const wxBrush
&brush
)
647 if (m_backgroundBrush
== brush
)
649 m_backgroundBrush
= brush
;
650 if (!m_backgroundBrush
.Ok())
652 m_macBrushInstalled
= false ;
655 void wxDC::SetLogicalFunction( int function
)
657 if (m_logicalFunction
== function
)
659 m_logicalFunction
= function
;
660 m_macFontInstalled
= false ;
661 m_macBrushInstalled
= false ;
662 m_macPenInstalled
= false ;
665 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
666 const wxColour
& col
, int style
);
668 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
,
669 const wxColour
& col
, int style
)
671 return wxDoFloodFill(this, x
, y
, col
, style
);
674 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
676 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
677 wxMacPortSetter
helper(this) ;
679 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
680 // Convert from Mac colour to wx
681 col
->Set( colour
.red
>> 8,
687 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
689 wxCHECK_RET(Ok(), wxT("Invalid DC"));
690 wxMacPortSetter
helper(this) ;
691 if (m_pen
.GetStyle() != wxTRANSPARENT
)
694 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
695 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
696 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
697 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
698 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
699 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
700 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
701 (m_pen
.GetWidth() <= 1))
703 // Implement LAST_NOT for MAC at least for
704 // orthogonal lines. RR.
725 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
727 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
728 wxMacPortSetter
helper(this) ;
729 if (m_pen
.GetStyle() != wxTRANSPARENT
)
734 wxCoord xx
= XLOG2DEVMAC(x
);
735 wxCoord yy
= YLOG2DEVMAC(y
);
737 ::MoveTo( XLOG2DEVMAC(0), yy
);
738 ::LineTo( XLOG2DEVMAC(w
), yy
);
739 ::MoveTo( xx
, YLOG2DEVMAC(0) );
740 ::LineTo( xx
, YLOG2DEVMAC(h
) );
741 CalcBoundingBox(x
, y
);
742 CalcBoundingBox(x
+w
, y
+h
);
747 * To draw arcs properly the angles need to be converted from the WX style:
748 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
749 * a normal axis on paper).
752 * Angles start on the +ve y axis and go clockwise.
755 static double wxConvertWXangleToMACangle(double angle
)
757 double newAngle
= 90 - angle
;
763 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
764 wxCoord x2
, wxCoord y2
,
765 wxCoord xc
, wxCoord yc
)
767 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
768 wxMacPortSetter
helper(this) ;
769 wxCoord xx1
= XLOG2DEVMAC(x1
);
770 wxCoord yy1
= YLOG2DEVMAC(y1
);
771 wxCoord xx2
= XLOG2DEVMAC(x2
);
772 wxCoord yy2
= YLOG2DEVMAC(y2
);
773 wxCoord xxc
= XLOG2DEVMAC(xc
);
774 wxCoord yyc
= YLOG2DEVMAC(yc
);
775 double dx
= xx1
- xxc
;
776 double dy
= yy1
- yyc
;
777 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
778 wxCoord rad
= (wxCoord
)radius
;
779 double radius1
, radius2
;
780 if (xx1
== xx2
&& yy1
== yy2
)
785 else if (radius
== 0.0)
787 radius1
= radius2
= 0.0;
791 radius1
= (xx1
- xxc
== 0) ?
792 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
793 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
794 radius2
= (xx2
- xxc
== 0) ?
795 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
796 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
798 wxCoord alpha2
= wxCoord(radius2
- radius1
);
799 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
800 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
803 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
804 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
806 PaintArc(&r
, alpha1
, alpha2
);
808 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
810 FrameArc(&r
, alpha1
, alpha2
);
814 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
815 double sa
, double ea
)
817 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
818 wxMacPortSetter
helper(this) ;
820 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
821 // we have to make sure that the filling is always counter-clockwise
824 wxCoord xx
= XLOG2DEVMAC(x
);
825 wxCoord yy
= YLOG2DEVMAC(y
);
826 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
827 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
828 // handle -ve width and/or height
829 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
830 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
831 sa
= wxConvertWXangleToMACangle(sa
);
836 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
838 PaintArc(&r
, (short)sa
, (short)angle
);
840 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
842 FrameArc(&r
, (short)sa
, (short)angle
);
846 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
848 wxCHECK_RET(Ok(), wxT("Invalid DC"));
849 wxMacPortSetter
helper(this) ;
850 if (m_pen
.GetStyle() != wxTRANSPARENT
)
852 wxCoord xx1
= XLOG2DEVMAC(x
);
853 wxCoord yy1
= YLOG2DEVMAC(y
);
854 RGBColor pencolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
855 ::SetCPixel( xx1
,yy1
,&pencolor
) ;
856 CalcBoundingBox(x
, y
);
860 void wxDC::DoDrawLines(int n
, wxPoint points
[],
861 wxCoord xoffset
, wxCoord yoffset
)
863 wxCHECK_RET(Ok(), wxT("Invalid DC"));
864 wxMacPortSetter
helper(this) ;
865 if (m_pen
.GetStyle() == wxTRANSPARENT
)
868 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
869 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
870 wxCoord x1
, x2
, y1
, y2
;
871 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
872 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
873 ::MoveTo(x1
- offset
, y1
- offset
);
874 for (int i
= 0; i
< n
-1; i
++)
876 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
877 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
878 ::LineTo( x2
- offset
, y2
- offset
);
882 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
883 wxCoord xoffset
, wxCoord yoffset
,
886 wxCHECK_RET(Ok(), wxT("Invalid DC"));
887 wxMacPortSetter
helper(this) ;
888 wxCoord x1
, x2
, y1
, y2
;
889 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
891 PolyHandle polygon
= OpenPoly();
892 x2
= x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
893 y2
= y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
895 for (int i
= 1; i
< n
; i
++)
897 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
898 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
901 // close the polyline if necessary
902 if ( x1
!= x2
|| y1
!= y2
)
907 if (m_brush
.GetStyle() != wxTRANSPARENT
)
910 ::PaintPoly( polygon
);
912 if (m_pen
.GetStyle() != wxTRANSPARENT
)
915 ::FramePoly( polygon
) ;
920 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
922 wxCHECK_RET(Ok(), wxT("Invalid DC"));
923 wxMacPortSetter
helper(this) ;
924 wxCoord xx
= XLOG2DEVMAC(x
);
925 wxCoord yy
= YLOG2DEVMAC(y
);
926 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
927 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
928 // CMB: draw nothing if transformed w or h is 0
929 if (ww
== 0 || hh
== 0)
931 // CMB: handle -ve width and/or height
942 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
943 if (m_brush
.GetStyle() != wxTRANSPARENT
)
946 ::PaintRect( &rect
) ;
948 if (m_pen
.GetStyle() != wxTRANSPARENT
)
951 ::FrameRect( &rect
) ;
955 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
956 wxCoord width
, wxCoord height
,
959 wxCHECK_RET(Ok(), wxT("Invalid DC"));
960 wxMacPortSetter
helper(this) ;
962 radius
= - radius
* ((width
< height
) ? width
: height
);
963 wxCoord xx
= XLOG2DEVMAC(x
);
964 wxCoord yy
= YLOG2DEVMAC(y
);
965 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
966 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
967 // CMB: draw nothing if transformed w or h is 0
968 if (ww
== 0 || hh
== 0)
970 // CMB: handle -ve width and/or height
981 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
982 if (m_brush
.GetStyle() != wxTRANSPARENT
)
985 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
987 if (m_pen
.GetStyle() != wxTRANSPARENT
)
990 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
994 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
996 wxCHECK_RET(Ok(), wxT("Invalid DC"));
997 wxMacPortSetter
helper(this) ;
998 wxCoord xx
= XLOG2DEVMAC(x
);
999 wxCoord yy
= YLOG2DEVMAC(y
);
1000 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1001 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1002 // CMB: draw nothing if transformed w or h is 0
1003 if (ww
== 0 || hh
== 0)
1005 // CMB: handle -ve width and/or height
1016 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1017 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1020 ::PaintOval( &rect
) ;
1022 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1025 ::FrameOval( &rect
) ;
1029 bool wxDC::CanDrawBitmap(void) const
1034 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1035 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1036 wxCoord xsrcMask
, wxCoord ysrcMask
)
1038 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1039 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1040 if ( logical_func
== wxNO_OP
)
1042 if (xsrcMask
== -1 && ysrcMask
== -1)
1044 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1046 // correct the parameter in case this dc does not have a mask at all
1047 if ( useMask
&& !source
->m_macMask
)
1049 Rect srcrect
, dstrect
;
1050 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1051 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1052 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1053 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1054 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1055 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1056 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1057 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1058 short mode
= kUnsupportedMode
;
1059 bool invertDestinationFirst
= false ;
1060 switch ( logical_func
)
1062 case wxAND
: // src AND dst
1063 mode
= adMin
; // ok
1065 case wxAND_INVERT
: // (NOT src) AND dst
1066 mode
= notSrcOr
; // ok
1068 case wxAND_REVERSE
:// src AND (NOT dst)
1069 invertDestinationFirst
= true ;
1073 mode
= kEmulatedMode
;
1076 mode
= srcCopy
; // ok
1078 case wxEQUIV
: // (NOT src) XOR dst
1079 mode
= srcXor
; // ok
1081 case wxINVERT
: // NOT dst
1082 mode
= kEmulatedMode
; //or hilite ;
1084 case wxNAND
: // (NOT src) OR (NOT dst)
1085 invertDestinationFirst
= true ;
1088 case wxNOR
: // (NOT src) AND (NOT dst)
1089 invertDestinationFirst
= true ;
1092 case wxNO_OP
: // dst
1093 mode
= kEmulatedMode
; // this has already been handled upon entry
1095 case wxOR
: // src OR dst
1098 case wxOR_INVERT
: // (NOT src) OR dst
1101 case wxOR_REVERSE
: // src OR (NOT dst)
1102 invertDestinationFirst
= true ;
1106 mode
= kEmulatedMode
;
1108 case wxSRC_INVERT
: // (NOT src)
1109 mode
= notSrcCopy
; // ok
1111 case wxXOR
: // src XOR dst
1112 mode
= notSrcXor
; // ok
1117 if ( mode
== kUnsupportedMode
)
1119 wxFAIL_MSG(wxT("unsupported blitting mode" ));
1122 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1123 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1124 if ( LockPixels(bmappixels
) )
1126 wxMacPortSetter
helper(this) ;
1127 if ( source
->GetDepth() == 1 )
1129 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1130 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1134 // the modes need this, otherwise we'll end up having really nice colors...
1135 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1136 RGBColor black
= { 0,0,0} ;
1137 RGBForeColor( &black
) ;
1138 RGBBackColor( &white
) ;
1140 if ( useMask
&& source
->m_macMask
)
1142 if ( mode
== srcCopy
)
1144 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1146 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1147 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1148 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1149 &srcrect
, &srcrect
, &dstrect
) ;
1150 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1155 RgnHandle clipRgn
= NewRgn() ;
1156 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1157 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1158 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1159 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1160 if ( mode
== kEmulatedMode
)
1163 ::PenPat(GetQDGlobalsBlack(&pat
));
1164 if ( logical_func
== wxSET
)
1166 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1167 ::RGBForeColor( &col
) ;
1168 ::PaintRgn( clipRgn
) ;
1170 else if ( logical_func
== wxCLEAR
)
1172 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1173 ::RGBForeColor( &col
) ;
1174 ::PaintRgn( clipRgn
) ;
1176 else if ( logical_func
== wxINVERT
)
1178 MacInvertRgn( clipRgn
) ;
1182 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1184 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1186 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1187 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1188 if ( PtInRgn( dstPoint
, clipRgn
) )
1192 SetPort( (GrafPtr
) sourcePort
) ;
1193 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1194 SetPort( (GrafPtr
) m_macPort
) ;
1195 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1196 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1197 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1205 if ( invertDestinationFirst
)
1207 MacInvertRgn( clipRgn
) ;
1209 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1210 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1211 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1213 DisposeRgn( clipRgn
) ;
1218 RgnHandle clipRgn
= NewRgn() ;
1219 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1220 if ( mode
== kEmulatedMode
)
1223 ::PenPat(GetQDGlobalsBlack(&pat
));
1224 if ( logical_func
== wxSET
)
1226 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1227 ::RGBForeColor( &col
) ;
1228 ::PaintRgn( clipRgn
) ;
1230 else if ( logical_func
== wxCLEAR
)
1232 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1233 ::RGBForeColor( &col
) ;
1234 ::PaintRgn( clipRgn
) ;
1236 else if ( logical_func
== wxINVERT
)
1238 MacInvertRgn( clipRgn
) ;
1242 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1244 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1246 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1247 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1251 SetPort( (GrafPtr
) sourcePort
) ;
1252 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1253 SetPort( (GrafPtr
) m_macPort
) ;
1254 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1255 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1256 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1264 if ( invertDestinationFirst
)
1266 MacInvertRgn( clipRgn
) ;
1268 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1269 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1270 &srcrect
, &dstrect
, mode
, NULL
) ;
1272 DisposeRgn( clipRgn
) ;
1274 UnlockPixels( bmappixels
) ;
1276 m_macPenInstalled
= false ;
1277 m_macBrushInstalled
= false ;
1278 m_macFontInstalled
= false ;
1282 inline Fixed
IntToFixed( int inInt
)
1284 return (((SInt32
) inInt
) << 16);
1287 inline int FixedToInt( Fixed inFixed
)
1289 return (((SInt32
) inFixed
) >> 16);
1292 void wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
,
1295 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1299 DrawText(str
, x
, y
);
1303 if ( str
.Length() == 0 )
1306 wxMacPortSetter
helper(this) ;
1309 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1312 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1313 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY
* font
->m_macFontSize
));
1314 m_macAliasWasEnabled
= true ;
1316 OSStatus status
= noErr
;
1317 ATSUTextLayout atsuLayout
;
1318 UniCharCount chars
= str
.Length() ;
1320 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str
, 0 , str
.Length() , str
.Length() , 1 ,
1321 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1324 status
= TECCreateConverter(&ec
,
1325 wxApp::s_macDefaultEncodingIsPC
? kTextEncodingWindowsLatin1
: kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
);
1327 wxASSERT_MSG( status
== noErr
, wxT("couldn't start converter") ) ;
1328 ByteCount byteOutLen
;
1329 ByteCount byteInLen
= str
.Length() ;
1330 ByteCount byteBufferLen
= byteInLen
*2 ;
1331 char* buf
= new char[byteBufferLen
] ;
1332 status
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
,
1333 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
1334 wxASSERT_MSG( status
== noErr
, wxT("couldn't convert text") ) ;
1335 status
= TECDisposeConverter(ec
);
1336 wxASSERT_MSG( status
== noErr
, wxT("couldn't dispose converter") ) ;
1337 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf
, 0 , byteOutLen
/ 2 , byteOutLen
/ 2 , 1 ,
1338 &chars
, (ATSUStyle
*) &m_macATSUIStyle
, &atsuLayout
) ;
1340 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1341 int iAngle
= int( angle
);
1342 int drawX
= XLOG2DEVMAC(x
) ;
1343 int drawY
= YLOG2DEVMAC(y
) ;
1345 ATSUTextMeasurement textBefore
;
1346 ATSUTextMeasurement textAfter
;
1347 ATSUTextMeasurement ascent
;
1348 ATSUTextMeasurement descent
;
1351 if ( abs(iAngle
) > 0 )
1353 Fixed atsuAngle
= IntToFixed( iAngle
) ;
1354 ATSUAttributeTag atsuTags
[] =
1356 kATSULineRotationTag
,
1358 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1362 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1366 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
),
1367 atsuTags
, atsuSizes
, atsuValues
) ;
1369 status
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1370 &textBefore
, &textAfter
, &ascent
, &descent
);
1372 drawX
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1373 drawY
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ;
1374 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1375 IntToFixed(drawX
) , IntToFixed(drawY
) );
1376 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1378 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1379 IntToFixed(drawX
) , IntToFixed(drawY
) , &rect
);
1380 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1381 OffsetRect( &rect
, -m_macLocalOrigin
.x
, -m_macLocalOrigin
.y
) ;
1382 CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) );
1383 CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) );
1384 ::ATSUDisposeTextLayout(atsuLayout
);
1391 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1393 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1395 wxMacPortSetter
helper(this) ;
1396 long xx
= XLOG2DEVMAC(x
);
1397 long yy
= YLOG2DEVMAC(y
);
1400 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1401 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || m_font
.GetNoAntiAliasing() )
1402 useDrawThemeText
= false ;
1407 m_macFormerAliasState
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
);
1408 SetAntiAliasedTextEnabled(true, 8);
1409 m_macAliasWasEnabled
= true ;
1412 ::GetFontInfo( &fi
) ;
1414 if ( !useDrawThemeText
)
1417 ::MoveTo( xx
, yy
);
1418 if ( m_backgroundMode
== wxTRANSPARENT
)
1420 ::TextMode( srcOr
) ;
1424 ::TextMode( srcCopy
) ;
1426 int length
= strtext
.Length() ;
1434 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1436 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1438 if ( useDrawThemeText
)
1440 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1441 wxMacCFStringHolder
mString( linetext
) ;
1442 if ( m_backgroundMode
!= wxTRANSPARENT
)
1444 Point bounds
={0,0} ;
1445 Rect background
= frame
;
1447 ::GetThemeTextDimensions( mString
,
1448 kThemeCurrentPortFont
,
1453 background
.right
= background
.left
+ bounds
.h
;
1454 background
.bottom
= background
.top
+ bounds
.v
;
1455 ::EraseRect( &background
) ;
1457 ::DrawThemeTextBox( mString
,
1458 kThemeCurrentPortFont
,
1469 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1470 ::DrawText( text
, 0 , strlen(text
) ) ;
1472 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1478 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1480 if ( useDrawThemeText
)
1482 Rect frame
= { yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) ,xx
, yy
+ (line
+1)*(fi
.descent
+ fi
.ascent
+ fi
.leading
) , xx
+ 10000 } ;
1483 wxMacCFStringHolder
mString( linetext
) ;
1485 if ( m_backgroundMode
!= wxTRANSPARENT
)
1487 Point bounds
={0,0} ;
1488 Rect background
= frame
;
1490 ::GetThemeTextDimensions( mString
,
1491 kThemeCurrentPortFont
,
1496 background
.right
= background
.left
+ bounds
.h
;
1497 background
.bottom
= background
.top
+ bounds
.v
;
1498 ::EraseRect( &background
) ;
1500 ::DrawThemeTextBox( mString
,
1501 kThemeCurrentPortFont
,
1511 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1512 ::DrawText( text
, 0 , strlen(text
) ) ;
1515 ::TextMode( srcOr
) ;
1518 bool wxDC::CanGetTextExtent() const
1520 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1524 void wxDC::DoGetTextExtent( const wxString
&strtext
, wxCoord
*width
, wxCoord
*height
,
1525 wxCoord
*descent
, wxCoord
*externalLeading
,
1526 wxFont
*theFont
) const
1528 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1529 wxMacPortSetter
helper(this) ;
1530 wxFont formerFont
= m_font
;
1533 // work around the constness
1534 *((wxFont
*)(&m_font
)) = *theFont
;
1538 ::GetFontInfo( &fi
) ;
1540 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1541 if ( IsKindOf(CLASSINFO( wxPrinterDC
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1542 useGetThemeText
= false ;
1545 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1547 *descent
=YDEV2LOGREL( fi
.descent
);
1548 if ( externalLeading
)
1549 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1550 int length
= strtext
.Length() ;
1552 const char *text = NULL ;
1554 if ( wxApp::s_macDefaultEncodingIsPC )
1556 macText = wxMacMakeMacStringFromPC( string ) ;
1558 length = macText.Length() ;
1563 length = string.Length() ;
1574 if( strtext
[i
] == 13 || strtext
[i
] == 10)
1576 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1578 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1580 if ( useGetThemeText
)
1582 Point bounds
={0,0} ;
1584 wxMacCFStringHolder
mString( linetext
) ;
1585 ::GetThemeTextDimensions( mString
,
1586 kThemeCurrentPortFont
,
1591 curwidth
= bounds
.h
;
1596 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1597 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1599 if ( curwidth
> *width
)
1600 *width
= XDEV2LOGREL( curwidth
) ;
1606 wxString linetext
= strtext
.Mid( laststop
, i
- laststop
) ;
1608 if ( useGetThemeText
)
1610 Point bounds
={0,0} ;
1612 wxMacCFStringHolder
mString( linetext
) ;
1613 ::GetThemeTextDimensions( mString
,
1614 kThemeCurrentPortFont
,
1619 curwidth
= bounds
.h
;
1624 wxCharBuffer text
= wxMacStringToCString(linetext
) ;
1625 curwidth
= ::TextWidth( text
, 0 , strlen(text
) ) ;
1627 if ( curwidth
> *width
)
1628 *width
= XDEV2LOGREL( curwidth
) ;
1632 // work around the constness
1633 *((wxFont
*)(&m_font
)) = formerFont
;
1634 m_macFontInstalled
= false ;
1638 wxCoord
wxDC::GetCharWidth(void) const
1640 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1641 wxMacPortSetter
helper(this) ;
1645 bool useGetThemeText
= ( GetThemeTextDimensions
!= (void*) kUnresolvedCFragSymbolAddress
) ;
1646 if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() )
1647 useGetThemeText
= false ;
1651 if ( useGetThemeText
)
1653 Point bounds
={0,0} ;
1655 CFStringRef mString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
, 1 , CFStringGetSystemEncoding(), false ) ;
1656 ::GetThemeTextDimensions( mString
,
1657 kThemeCurrentPortFont
,
1662 CFRelease( mString
) ;
1668 width
= ::TextWidth( text
, 0 , 1 ) ;
1670 return YDEV2LOGREL(width
) ;
1673 wxCoord
wxDC::GetCharHeight(void) const
1675 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1676 wxMacPortSetter
helper(this) ;
1679 ::GetFontInfo( &fi
) ;
1680 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1683 void wxDC::Clear(void)
1685 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1686 wxMacPortSetter
helper(this) ;
1687 Rect rect
= { -31000 , -31000 , 31000 , 31000 } ;
1688 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1691 //MacInstallBrush() ;
1692 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1693 ::EraseRect( &rect
) ;
1697 void wxDC::MacInstallFont() const
1699 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1700 // if ( m_macFontInstalled )
1702 Pattern blackColor
;
1703 MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ;
1704 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1707 ::TextFont( font
->m_macFontNum
) ;
1708 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1709 ::TextFace( font
->m_macFontStyle
) ;
1710 m_macFontInstalled
= true ;
1711 m_macBrushInstalled
= false ;
1712 m_macPenInstalled
= false ;
1713 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1714 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1715 ::RGBForeColor( &forecolor
);
1716 ::RGBBackColor( &backcolor
);
1720 FontFamilyID fontId
;
1724 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
1725 GetFNum( fontName
, &fontId
);
1726 ::TextFont( fontId
) ;
1727 ::TextSize( short(m_scaleY
* fontSize
) ) ;
1728 ::TextFace( fontStyle
) ;
1729 // todo reset after spacing changes - or store the current spacing somewhere
1730 m_macFontInstalled
= true ;
1731 m_macBrushInstalled
= false ;
1732 m_macPenInstalled
= false ;
1733 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1734 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1735 ::RGBForeColor( &forecolor
);
1736 ::RGBBackColor( &backcolor
);
1738 short mode
= patCopy
;
1740 switch( m_logicalFunction
)
1745 case wxINVERT
: // NOT dst
1746 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1749 case wxXOR
: // src XOR dst
1752 case wxOR_REVERSE
: // src OR (NOT dst)
1755 case wxSRC_INVERT
: // (NOT src)
1758 case wxAND
: // src AND dst
1763 case wxAND_REVERSE
:// src AND (NOT dst)
1764 case wxAND_INVERT
: // (NOT src) AND dst
1765 case wxNO_OP
: // dst
1766 case wxNOR
: // (NOT src) AND (NOT dst)
1767 case wxEQUIV
: // (NOT src) XOR dst
1768 case wxOR_INVERT
: // (NOT src) OR dst
1769 case wxNAND
: // (NOT src) OR (NOT dst)
1770 case wxOR
: // src OR dst
1772 // case wxSRC_OR: // source _bitmap_ OR destination
1773 // case wxSRC_AND: // source _bitmap_ AND destination
1777 OSStatus status
= noErr
;
1778 Fixed atsuSize
= IntToFixed( int(m_scaleY
* font
->m_macFontSize
) ) ;
1779 Style qdStyle
= font
->m_macFontStyle
;
1780 ATSUFontID atsuFont
= font
->m_macATSUFontID
;
1781 status
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ;
1782 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") ) ;
1783 ATSUAttributeTag atsuTags
[] =
1788 // kATSUBaselineClassTag ,
1789 kATSUVerticalCharacterTag
,
1790 kATSUQDBoldfaceTag
,
1792 kATSUQDUnderlineTag
,
1793 kATSUQDCondensedTag
,
1794 kATSUQDExtendedTag
,
1796 ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1798 sizeof( ATSUFontID
) ,
1800 // sizeof( RGBColor ) ,
1801 // sizeof( BslnBaselineClass ) ,
1802 sizeof( ATSUVerticalCharacterType
),
1809 Boolean kTrue
= true ;
1810 Boolean kFalse
= false ;
1811 BslnBaselineClass kBaselineDefault
= kBSLNHangingBaseline
;
1812 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
1813 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] =
1817 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1818 // &kBaselineDefault ,
1820 (qdStyle
& bold
) ? &kTrue
: &kFalse
,
1821 (qdStyle
& italic
) ? &kTrue
: &kFalse
,
1822 (qdStyle
& underline
) ? &kTrue
: &kFalse
,
1823 (qdStyle
& condense
) ? &kTrue
: &kFalse
,
1824 (qdStyle
& extend
) ? &kTrue
: &kFalse
,
1826 status
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
) ,
1827 atsuTags
, atsuSizes
, atsuValues
);
1828 wxASSERT_MSG( status
== noErr
, wxT("couldn't set create ATSU style") ) ;
1831 Pattern gHatchPatterns
[] =
1833 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1834 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1835 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1836 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1837 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1838 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1839 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
1842 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1847 case wxBDIAGONAL_HATCH
:
1850 case wxFDIAGONAL_HATCH
:
1856 case wxHORIZONTAL_HATCH
:
1859 case wxVERTICAL_HATCH
:
1862 case wxCROSSDIAG_HATCH
:
1866 theIndex
= 1; // solid pattern
1869 *pattern
= gHatchPatterns
[theIndex
-1] ;
1872 void wxDC::MacInstallPen() const
1874 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1876 // if ( m_macPenInstalled )
1878 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1879 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1880 ::RGBForeColor( &forecolor
);
1881 ::RGBBackColor( &backcolor
);
1883 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1884 // null means only one pixel, at whatever resolution
1885 if ( penWidth
== 0 )
1887 ::PenSize(penWidth
, penWidth
);
1888 int penStyle
= m_pen
.GetStyle();
1889 if (penStyle
== wxSOLID
)
1891 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1893 else if (IS_HATCH(penStyle
))
1896 wxMacGetHatchPattern(penStyle
, &pat
);
1901 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1905 for ( int i
= 0 ; i
< 8 ; ++i
)
1911 for ( int i
= 0 ; i
< 8 ; ++i
)
1917 for ( int i
= 0 ; i
< 8 ; ++i
)
1923 for ( int i
= 0 ; i
< 8 ; ++i
)
1931 m_pen
.GetDashes(&dash
) ;
1932 // right now we don't allocate larger pixmaps
1934 m_pen
.GetDashes(&dash
) ;
1935 for ( int i
= 0 ; i
< 8 ; ++i
)
1937 pat
.pat
[i
] = dash
[0] ;
1944 short mode
= patCopy
;
1946 switch( m_logicalFunction
)
1948 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1951 case wxINVERT
: // NOT dst
1952 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1955 case wxXOR
: // src XOR dst
1958 case wxOR_REVERSE
: // src OR (NOT dst)
1961 case wxSRC_INVERT
: // (NOT src)
1964 case wxAND
: // src AND dst
1969 case wxAND_REVERSE
:// src AND (NOT dst)
1970 case wxAND_INVERT
: // (NOT src) AND dst
1971 case wxNO_OP
: // dst
1972 case wxNOR
: // (NOT src) AND (NOT dst)
1973 case wxEQUIV
: // (NOT src) XOR dst
1974 case wxOR_INVERT
: // (NOT src) OR dst
1975 case wxNAND
: // (NOT src) OR (NOT dst)
1976 case wxOR
: // src OR dst
1978 // case wxSRC_OR: // source _bitmap_ OR destination
1979 // case wxSRC_AND: // source _bitmap_ AND destination
1983 m_macPenInstalled
= true ;
1984 m_macBrushInstalled
= false ;
1985 m_macFontInstalled
= false ;
1988 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1990 Pattern whiteColor
;
1991 switch( background
.MacGetBrushKind() )
1993 case kwxMacBrushTheme
:
1995 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1998 case kwxMacBrushThemeBackground
:
2001 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
2002 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
2005 case kwxMacBrushColour
:
2007 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
2008 int brushStyle
= background
.GetStyle();
2009 if (brushStyle
== wxSOLID
)
2010 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2011 else if (IS_HATCH(brushStyle
))
2014 wxMacGetHatchPattern(brushStyle
, &pat
);
2019 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
2026 void wxDC::MacInstallBrush() const
2028 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2029 Pattern blackColor
;
2030 // if ( m_macBrushInstalled )
2033 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
2034 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
2035 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
2036 int brushStyle
= m_brush
.GetStyle();
2037 if (brushStyle
== wxSOLID
)
2039 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2041 else if (IS_HATCH(brushStyle
))
2044 wxMacGetHatchPattern(brushStyle
, &pat
);
2047 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
2049 // we force this in order to be compliant with wxMSW
2050 backgroundTransparent
= false ;
2051 // for these the text fore (and back for MASK_OPAQUE) colors are used
2052 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
2053 int width
= bitmap
->GetWidth() ;
2054 int height
= bitmap
->GetHeight() ;
2055 GWorldPtr gw
= NULL
;
2056 if ( m_brush
.GetStyle() == wxSTIPPLE
)
2057 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
2059 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
2060 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
2061 LockPixels( gwpixmaphandle
) ;
2062 bool isMonochrome
= !IsPortColor( gw
) ;
2063 if ( !isMonochrome
)
2065 if ( (**gwpixmaphandle
).pixelSize
== 1 )
2066 isMonochrome
= true ;
2068 if ( isMonochrome
&& width
== 8 && height
== 8 )
2070 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
2071 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
2072 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
2073 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
2074 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
2076 for ( int i
= 0 ; i
< 8 ; ++i
)
2078 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
2080 UnlockPixels( GetGWorldPixMap( gw
) ) ;
2085 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2086 // caching scheme before putting this into production
2089 PixPatHandle pixpat
= NewPixPat() ;
2090 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
2091 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
2092 ((**(**pixpat
).patMap
).bounds
.bottom
-
2093 (**(**pixpat
).patMap
).bounds
.top
);
2094 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
2095 (**pixpat
).patData
= image
;
2098 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
2099 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
2100 if ( ctspec
[0].rgb
.red
== 0x0000 )
2102 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2103 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2107 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
2108 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
2110 ::CTabChanged( ctable
) ;
2112 ::PenPixPat(pixpat
);
2113 m_macForegroundPixMap
= pixpat
;
2115 UnlockPixels( gwpixmaphandle
) ;
2119 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2121 short mode
= patCopy
;
2122 switch( m_logicalFunction
)
2125 if ( backgroundTransparent
)
2130 case wxINVERT
: // NOT dst
2131 if ( !backgroundTransparent
)
2133 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2137 case wxXOR
: // src XOR dst
2140 case wxOR_REVERSE
: // src OR (NOT dst)
2143 case wxSRC_INVERT
: // (NOT src)
2146 case wxAND
: // src AND dst
2151 case wxAND_REVERSE
:// src AND (NOT dst)
2152 case wxAND_INVERT
: // (NOT src) AND dst
2153 case wxNO_OP
: // dst
2154 case wxNOR
: // (NOT src) AND (NOT dst)
2155 case wxEQUIV
: // (NOT src) XOR dst
2156 case wxOR_INVERT
: // (NOT src) OR dst
2157 case wxNAND
: // (NOT src) OR (NOT dst)
2158 case wxOR
: // src OR dst
2160 // case wxSRC_OR: // source _bitmap_ OR destination
2161 // case wxSRC_AND: // source _bitmap_ AND destination
2165 m_macBrushInstalled
= true ;
2166 m_macPenInstalled
= false ;
2167 m_macFontInstalled
= false ;
2170 // ---------------------------------------------------------------------------
2171 // coordinates transformations
2172 // ---------------------------------------------------------------------------
2174 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2176 return ((wxDC
*)this)->XDEV2LOG(x
);
2179 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2181 return ((wxDC
*)this)->YDEV2LOG(y
);
2184 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2186 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2189 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2191 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2194 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2196 return ((wxDC
*)this)->XLOG2DEV(x
);
2199 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2201 return ((wxDC
*)this)->YLOG2DEV(y
);
2204 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2206 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2209 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2211 return ((wxDC
*)this)->YLOG2DEVREL(y
);