1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
19 #include "wx/dcmemory.h"
20 #include "wx/region.h"
29 #include "wx/mac/private.h"
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 #define mm2inches 0.0393700787402
41 #define inches2mm 25.4
42 #define mm2twips 56.6929133859
43 #define twips2mm 0.0176388888889
44 #define mm2pt 2.83464566929
45 #define pt2mm 0.352777777778
47 const double M_PI
= 3.14159265358979 ;
49 const double RAD2DEG
= 180.0 / M_PI
;
50 const short kEmulatedMode
= -1 ;
51 const short kUnsupportedMode
= -2 ;
53 #define wxMAC_EXPERIMENTAL_PATTERN 0
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
60 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
61 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 // this function emulates all wx colour manipulations, used to verify the implementation
68 // by setting the mode in the blitting functions to kEmulatedMode
70 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
71 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
73 switch ( logical_func
)
75 case wxAND
: // src AND dst
76 dstColor
.red
= dstColor
.red
& srcColor
.red
;
77 dstColor
.green
= dstColor
.green
& srcColor
.green
;
78 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
80 case wxAND_INVERT
: // (NOT src) AND dst
81 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
82 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
83 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
85 case wxAND_REVERSE
:// src AND (NOT dst)
86 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
87 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
88 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
96 dstColor
.red
= srcColor
.red
;
97 dstColor
.green
= srcColor
.green
;
98 dstColor
.blue
= srcColor
.blue
;
100 case wxEQUIV
: // (NOT src) XOR dst
101 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
102 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
103 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
105 case wxINVERT
: // NOT dst
106 dstColor
.red
= ~dstColor
.red
;
107 dstColor
.green
= ~dstColor
.green
;
108 dstColor
.blue
= ~dstColor
.blue
;
110 case wxNAND
: // (NOT src) OR (NOT dst)
111 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
112 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
113 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
115 case wxNOR
: // (NOT src) AND (NOT dst)
116 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
117 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
118 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
122 case wxOR
: // src OR dst
123 dstColor
.red
= dstColor
.red
| srcColor
.red
;
124 dstColor
.green
= dstColor
.green
| srcColor
.green
;
125 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
127 case wxOR_INVERT
: // (NOT src) OR dst
128 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
129 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
130 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
132 case wxOR_REVERSE
: // src OR (NOT dst)
133 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
134 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
135 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
138 dstColor
.red
= 0xFFFF ;
139 dstColor
.green
= 0xFFFF ;
140 dstColor
.blue
= 0xFFFF ;
142 case wxSRC_INVERT
: // (NOT src)
143 dstColor
.red
= ~srcColor
.red
;
144 dstColor
.green
= ~srcColor
.green
;
145 dstColor
.blue
= ~srcColor
.blue
;
147 case wxXOR
: // src XOR dst
148 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
149 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
150 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
161 m_mm_to_pix_x
= mm2pt
;
162 m_mm_to_pix_y
= mm2pt
;
164 m_internalDeviceOriginX
= 0;
165 m_internalDeviceOriginY
= 0;
166 m_externalDeviceOriginX
= 0;
167 m_externalDeviceOriginY
= 0;
169 m_logicalScaleX
= 1.0;
170 m_logicalScaleY
= 1.0;
176 m_needComputeScaleX
= FALSE
;
177 m_needComputeScaleY
= FALSE
;
183 m_macFontInstalled
= false ;
184 m_macBrushInstalled
= false ;
185 m_macPenInstalled
= false ;
187 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
188 m_macBoundaryClipRgn
= NewRgn() ;
189 m_macCurrentClipRgn
= NewRgn() ;
191 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
192 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
194 m_pen
= *wxBLACK_PEN
;
195 m_font
= *wxNORMAL_FONT
;
196 m_brush
= *wxWHITE_BRUSH
;
198 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
199 m_ph( (GrafPtr
) dc
->m_macPort
)
201 wxASSERT( dc
->Ok() ) ;
203 dc
->MacSetupPort(&m_ph
) ;
206 wxMacPortSetter::~wxMacPortSetter()
212 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
213 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
215 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
217 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
219 m_macFontInstalled
= false ;
220 m_macBrushInstalled
= false ;
221 m_macPenInstalled
= false ;
224 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
226 wxCHECK_RET( Ok(), wxT("invalid window dc") );
228 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
230 wxMacPortSetter
helper(this) ;
232 wxCoord xx
= XLOG2DEVMAC(x
);
233 wxCoord yy
= YLOG2DEVMAC(y
);
234 wxCoord w
= bmp
.GetWidth();
235 wxCoord h
= bmp
.GetHeight();
236 wxCoord ww
= XLOG2DEVREL(w
);
237 wxCoord hh
= YLOG2DEVREL(h
);
239 // Set up drawing mode
240 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
241 //m_logicalFunction == wxCLEAR ? WHITENESS :
242 //m_logicalFunction == wxSET ? BLACKNESS :
243 m_logicalFunction
== wxINVERT
? hilite
:
244 //m_logicalFunction == wxAND ? MERGECOPY :
245 m_logicalFunction
== wxOR
? srcOr
:
246 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
247 m_logicalFunction
== wxXOR
? srcXor
:
248 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
249 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
250 //m_logicalFunction == wxSRC_OR ? srcOr :
251 //m_logicalFunction == wxSRC_AND ? SRCAND :
254 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
255 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
256 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
257 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
259 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
261 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
262 PixMapHandle bmappixels
;
264 // Set foreground and background colours (for bitmaps depth = 1)
265 if(bmp
.GetDepth() == 1)
267 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
268 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
274 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
275 RGBColor black
= { 0,0,0} ;
276 RGBForeColor( &black
) ;
277 RGBBackColor( &white
) ;
280 bmappixels
= GetGWorldPixMap( bmapworld
) ;
282 wxCHECK_RET(LockPixels(bmappixels
),
283 wxT("DoDrawBitmap: Unable to lock pixels"));
285 Rect source
= { 0, 0, h
, w
};
286 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
288 if ( useMask
&& bmp
.GetMask() )
290 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
294 GetPortBitMapForCopyBits(bmapworld
),
295 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
296 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
297 &source
, &source
, &dest
, mode
, NULL
299 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
303 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
304 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
305 &source
, &dest
, mode
, NULL
) ;
307 UnlockPixels( bmappixels
) ;
309 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
311 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
312 OffsetRect( &bitmaprect
, xx
, yy
) ;
313 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
315 m_macPenInstalled
= false ;
316 m_macBrushInstalled
= false ;
317 m_macFontInstalled
= false ;
321 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
323 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
325 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
327 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
329 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
331 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
332 wxCoord xx
, yy
, ww
, hh
;
336 ww
= XLOG2DEVREL(width
);
337 hh
= YLOG2DEVREL(height
);
339 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
340 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
344 m_clipX1
= wxMax( m_clipX1
, xx
);
345 m_clipY1
= wxMax( m_clipY1
, yy
);
346 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
347 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
359 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
361 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
363 wxMacPortSetter
helper(this) ;
366 DestroyClippingRegion();
371 region
.GetBox( x
, y
, w
, h
);
372 wxCoord xx
, yy
, ww
, hh
;
379 // if we have a scaling that we cannot map onto native regions
380 // we must use the box
382 if ( ww
!= w
|| hh
!= h
)
384 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
388 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
389 if ( xx
!= x
|| yy
!= y
)
391 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
393 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
396 m_clipX1
= wxMax( m_clipX1
, xx
);
397 m_clipY1
= wxMax( m_clipY1
, yy
);
398 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
399 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
413 void wxDC::DestroyClippingRegion()
415 wxMacPortSetter
helper(this) ;
416 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
419 void wxDC::DoGetSize( int* width
, int* height
) const
421 *width
= m_maxX
-m_minX
;
422 *height
= m_maxY
-m_minY
;
424 void wxDC::DoGetSizeMM( int* width
, int* height
) const
429 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
430 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
432 void wxDC::SetTextForeground( const wxColour
&col
)
434 wxCHECK_RET(Ok(), wxT("Invalid DC"));
435 m_textForegroundColour
= col
;
436 m_macFontInstalled
= false ;
438 void wxDC::SetTextBackground( const wxColour
&col
)
440 wxCHECK_RET(Ok(), wxT("Invalid DC"));
441 m_textBackgroundColour
= col
;
442 m_macFontInstalled
= false ;
444 void wxDC::SetMapMode( int mode
)
449 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
452 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
455 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
458 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
462 SetLogicalScale( 1.0, 1.0 );
465 if (mode
!= wxMM_TEXT
)
467 m_needComputeScaleX
= TRUE
;
468 m_needComputeScaleY
= TRUE
;
471 void wxDC::SetUserScale( double x
, double y
)
473 // allow negative ? -> no
476 ComputeScaleAndOrigin();
478 void wxDC::SetLogicalScale( double x
, double y
)
483 ComputeScaleAndOrigin();
485 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
487 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
488 m_logicalOriginY
= y
* m_signY
;
489 ComputeScaleAndOrigin();
491 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
493 m_externalDeviceOriginX
= x
;
494 m_externalDeviceOriginY
= y
;
495 ComputeScaleAndOrigin();
499 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
501 m_internalDeviceOriginX
= x
;
502 m_internalDeviceOriginY
= y
;
503 ComputeScaleAndOrigin();
505 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
507 if (x
) *x
= m_internalDeviceOriginX
;
508 if (y
) *y
= m_internalDeviceOriginY
;
511 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
513 m_signX
= (xLeftRight
? 1 : -1);
514 m_signY
= (yBottomUp
? -1 : 1);
515 ComputeScaleAndOrigin();
518 wxSize
wxDC::GetPPI() const
520 return wxSize(72, 72);
523 int wxDC::GetDepth() const
525 return wxDisplayDepth() ;
528 void wxDC::ComputeScaleAndOrigin()
530 // CMB: copy scale to see if it changes
531 double origScaleX
= m_scaleX
;
532 double origScaleY
= m_scaleY
;
534 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
535 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
537 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
538 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
540 // CMB: if scale has changed call SetPen to recalulate the line width
541 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
543 // this is a bit artificial, but we need to force wxDC to think
544 // the pen has changed
545 wxPen
* pen
= & GetPen();
551 void wxDC::SetPalette( const wxPalette
& palette
)
555 void wxDC::SetBackgroundMode( int mode
)
557 m_backgroundMode
= mode
;
560 void wxDC::SetFont( const wxFont
&font
)
563 m_macFontInstalled
= false ;
566 void wxDC::SetPen( const wxPen
&pen
)
573 m_macPenInstalled
= false ;
576 void wxDC::SetBrush( const wxBrush
&brush
)
578 if (m_brush
== brush
)
582 m_macBrushInstalled
= false ;
585 void wxDC::SetBackground( const wxBrush
&brush
)
587 if (m_backgroundBrush
== brush
)
590 m_backgroundBrush
= brush
;
592 if (!m_backgroundBrush
.Ok())
594 m_macBrushInstalled
= false ;
597 void wxDC::SetLogicalFunction( int function
)
599 if (m_logicalFunction
== function
)
602 m_logicalFunction
= function
;
603 m_macFontInstalled
= false ;
604 m_macBrushInstalled
= false ;
605 m_macPenInstalled
= false ;
608 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
613 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
615 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
616 wxMacPortSetter
helper(this) ;
620 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
622 // Convert from Mac colour to wx
623 col
->Set( colour
.red
>> 8,
630 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
632 wxCHECK_RET(Ok(), wxT("Invalid DC"));
634 wxMacPortSetter
helper(this) ;
636 if (m_pen
.GetStyle() != wxTRANSPARENT
)
639 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
640 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
642 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
643 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
644 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
645 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
647 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
648 (m_pen
.GetWidth() <= 1))
650 // Implement LAST_NOT for MAC at least for
651 // orthogonal lines. RR.
673 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
675 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
677 if (m_pen
.GetStyle() != wxTRANSPARENT
)
682 wxCoord xx
= XLOG2DEVMAC(x
);
683 wxCoord yy
= YLOG2DEVMAC(y
);
686 ::MoveTo( XLOG2DEVMAC(0), yy
);
687 ::LineTo( XLOG2DEVMAC(w
), yy
);
688 ::MoveTo( xx
, YLOG2DEVMAC(0) );
689 ::LineTo( xx
, YLOG2DEVMAC(h
) );
694 * To draw arcs properly the angles need to be converted from the WX style:
695 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
696 * a normal axis on paper).
699 * Angles start on the +ve y axis and go clockwise.
700 * To achive this I work out which quadrant the angle lies in then map this to
701 * the equivalent quadrant on the Mac. (Sin and Cos values reveal which
702 * quadrant you are in).
704 static double wxConvertWXangleToMACangle(double angle
)
708 sin_a
= sin(angle
/ RAD2DEG
);
709 cos_a
= cos(angle
/ RAD2DEG
);
711 if( (sin_a
>= 0.0) && (cos_a
>= 0.0) ) {
712 angle
= acos(sin_a
) * RAD2DEG
;
714 else if( (sin_a
>= 0.0) && (cos_a
<= 0.0) ) {
716 angle
= acos(sin_a
) * RAD2DEG
+ 180;
718 else if( (sin_a
<= 0.0) && (cos_a
>= 0.0) ) {
719 angle
= acos(sin_a
) * RAD2DEG
+ 180;
721 else if( (sin_a
< 0.0) && (cos_a
< 0.0) ) {
723 angle
= acos(sin_a
) * RAD2DEG
+ 180;
728 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
729 wxCoord x2
, wxCoord y2
,
730 wxCoord xc
, wxCoord yc
)
732 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
734 wxCoord xx1
= XLOG2DEVMAC(x1
);
735 wxCoord yy1
= YLOG2DEVMAC(y1
);
736 wxCoord xx2
= XLOG2DEVMAC(x2
);
737 wxCoord yy2
= YLOG2DEVMAC(y2
);
738 wxCoord xxc
= XLOG2DEVMAC(xc
);
739 wxCoord yyc
= YLOG2DEVMAC(yc
);
740 double dx
= xx1
- xxc
;
741 double dy
= yy1
- yyc
;
742 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
743 wxCoord rad
= (wxCoord
)radius
;
744 double radius1
, radius2
;
746 if (xx1
== xx2
&& yy1
== yy2
)
751 else if (radius
== 0.0)
753 radius1
= radius2
= 0.0;
757 radius1
= (xx1
- xxc
== 0) ?
758 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
759 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
760 radius2
= (xx2
- xxc
== 0) ?
761 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
762 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
764 wxCoord alpha2
= wxCoord(radius2
- radius1
);
765 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
766 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
770 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
772 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
774 PaintArc(&r
, alpha1
, alpha2
);
776 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
778 FrameArc(&r
, alpha1
, alpha2
);
782 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
783 double sa
, double ea
)
785 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
788 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
790 wxCoord xx
= XLOG2DEVMAC(x
);
791 wxCoord yy
= YLOG2DEVMAC(y
);
792 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
793 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
795 // handle -ve width and/or height
796 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
797 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
799 sa
= wxConvertWXangleToMACangle(sa
);
806 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
808 PaintArc(&r
, (short)sa
, (short)angle
);
810 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
812 FrameArc(&r
, (short)sa
, (short)angle
);
816 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
818 wxCHECK_RET(Ok(), wxT("Invalid DC"));
820 wxMacPortSetter
helper(this) ;
822 if (m_pen
.GetStyle() != wxTRANSPARENT
)
825 wxCoord xx1
= XLOG2DEVMAC(x
);
826 wxCoord yy1
= YLOG2DEVMAC(y
);
829 ::LineTo(xx1
+1, yy1
+1);
833 void wxDC::DoDrawLines(int n
, wxPoint points
[],
834 wxCoord xoffset
, wxCoord yoffset
)
836 wxCHECK_RET(Ok(), wxT("Invalid DC"));
837 wxMacPortSetter
helper(this) ;
839 if (m_pen
.GetStyle() == wxTRANSPARENT
)
844 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
845 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
847 wxCoord x1
, x2
, y1
, y2
;
848 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
849 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
850 ::MoveTo(x1
- offset
, y1
- offset
);
852 for (int i
= 0; i
< n
-1; i
++)
854 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
855 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
856 ::LineTo( x2
- offset
, y2
- offset
);
860 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
861 wxCoord xoffset
, wxCoord yoffset
,
864 wxCHECK_RET(Ok(), wxT("Invalid DC"));
865 wxMacPortSetter
helper(this) ;
867 wxCoord x1
, x2
, y1
, y2
;
869 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
872 PolyHandle polygon
= OpenPoly();
874 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
875 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
878 for (int i
= 1; i
< n
; i
++)
880 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
881 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
885 // close the polyline if necessary
886 if ( x1
!= x2
|| y1
!= y2
)
893 if (m_brush
.GetStyle() != wxTRANSPARENT
)
897 ::PaintPoly( polygon
);
901 if (m_pen
.GetStyle() != wxTRANSPARENT
)
905 ::FramePoly( polygon
) ;
911 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
913 wxCHECK_RET(Ok(), wxT("Invalid DC"));
914 wxMacPortSetter
helper(this) ;
916 wxCoord xx
= XLOG2DEVMAC(x
);
917 wxCoord yy
= YLOG2DEVMAC(y
);
918 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
919 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
921 // CMB: draw nothing if transformed w or h is 0
922 if (ww
== 0 || hh
== 0)
925 // CMB: handle -ve width and/or height
938 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
940 if (m_brush
.GetStyle() != wxTRANSPARENT
)
943 ::PaintRect( &rect
) ;
946 if (m_pen
.GetStyle() != wxTRANSPARENT
)
949 ::FrameRect( &rect
) ;
953 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
954 wxCoord width
, wxCoord height
,
957 wxCHECK_RET(Ok(), wxT("Invalid DC"));
958 wxMacPortSetter
helper(this) ;
961 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
);
968 // CMB: draw nothing if transformed w or h is 0
969 if (ww
== 0 || hh
== 0)
972 // CMB: handle -ve width and/or height
985 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
987 if (m_brush
.GetStyle() != wxTRANSPARENT
)
990 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
993 if (m_pen
.GetStyle() != wxTRANSPARENT
)
996 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
1000 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1002 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1003 wxMacPortSetter
helper(this) ;
1005 wxCoord xx
= XLOG2DEVMAC(x
);
1006 wxCoord yy
= YLOG2DEVMAC(y
);
1007 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1008 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1010 // CMB: draw nothing if transformed w or h is 0
1011 if (ww
== 0 || hh
== 0)
1014 // CMB: handle -ve width and/or height
1027 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1029 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1032 ::PaintOval( &rect
) ;
1035 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1038 ::FrameOval( &rect
) ;
1044 bool wxDC::CanDrawBitmap(void) const
1050 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1051 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1052 wxCoord xsrcMask
, wxCoord ysrcMask
)
1054 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1055 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1057 if ( logical_func
== wxNO_OP
)
1060 if (xsrcMask
== -1 && ysrcMask
== -1)
1062 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1065 // correct the parameter in case this dc does not have a mask at all
1067 if ( useMask
&& !source
->m_macMask
)
1070 Rect srcrect
, dstrect
;
1071 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1072 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1073 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1074 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1075 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1076 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1077 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1078 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1080 short mode
= kUnsupportedMode
;
1081 bool invertDestinationFirst
= false ;
1082 switch ( logical_func
)
1084 case wxAND
: // src AND dst
1085 mode
= srcOr
; // ok
1087 case wxAND_INVERT
: // (NOT src) AND dst
1088 mode
= notSrcOr
; // ok
1090 case wxAND_REVERSE
:// src AND (NOT dst)
1091 invertDestinationFirst
= true ;
1095 mode
= kEmulatedMode
;
1098 mode
= srcCopy
; // ok
1100 case wxEQUIV
: // (NOT src) XOR dst
1101 mode
= srcXor
; // ok
1103 case wxINVERT
: // NOT dst
1104 mode
= kEmulatedMode
; //or hilite ;
1106 case wxNAND
: // (NOT src) OR (NOT dst)
1107 invertDestinationFirst
= true ;
1110 case wxNOR
: // (NOT src) AND (NOT dst)
1111 invertDestinationFirst
= true ;
1114 case wxNO_OP
: // dst
1115 mode
= kEmulatedMode
; // this has already been handled upon entry
1117 case wxOR
: // src OR dst
1120 case wxOR_INVERT
: // (NOT src) OR dst
1123 case wxOR_REVERSE
: // src OR (NOT dst)
1124 invertDestinationFirst
= true ;
1128 mode
= kEmulatedMode
;
1130 case wxSRC_INVERT
: // (NOT src)
1131 mode
= notSrcCopy
; // ok
1133 case wxXOR
: // src XOR dst
1134 mode
= notSrcXor
; // ok
1142 if ( mode
== kUnsupportedMode
)
1144 wxFAIL_MSG("unsupported blitting mode" )
1148 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1149 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1150 if ( LockPixels(bmappixels
) )
1152 wxMacPortSetter
helper(this) ;
1153 RGBColor tempColor
;
1155 if ( source
->GetDepth() == 1 )
1157 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1158 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1162 // the modes need this, otherwise we'll end up having really nice colors...
1163 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1164 RGBColor black
= { 0,0,0} ;
1165 RGBForeColor( &black
) ;
1166 RGBBackColor( &white
) ;
1169 if ( useMask
&& source
->m_macMask
)
1171 if ( mode
== srcCopy
)
1173 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1175 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1176 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1177 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1178 &srcrect
, &srcrect
, &dstrect
) ;
1179 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1184 RgnHandle clipRgn
= NewRgn() ;
1185 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1186 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1187 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1188 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1189 if ( mode
== kEmulatedMode
)
1192 ::PenPat(GetQDGlobalsBlack(&pat
));
1193 if ( logical_func
== wxSET
)
1195 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1196 ::RGBForeColor( &col
) ;
1197 ::PaintRgn( clipRgn
) ;
1199 else if ( logical_func
== wxCLEAR
)
1201 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1202 ::RGBForeColor( &col
) ;
1203 ::PaintRgn( clipRgn
) ;
1205 else if ( logical_func
== wxINVERT
)
1207 MacInvertRgn( clipRgn
) ;
1211 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1213 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1215 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1216 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1217 if ( PtInRgn( dstPoint
, clipRgn
) )
1222 SetPort( (GrafPtr
) sourcePort
) ;
1223 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1224 SetPort( (GrafPtr
) m_macPort
) ;
1225 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1227 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1228 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1236 if ( invertDestinationFirst
)
1238 MacInvertRgn( clipRgn
) ;
1240 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1241 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1242 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1244 DisposeRgn( clipRgn
) ;
1249 RgnHandle clipRgn
= NewRgn() ;
1250 SetRectRgn( clipRgn
, dstrect
.left
, dstrect
.top
, dstrect
.right
, dstrect
.bottom
) ;
1251 if ( mode
== kEmulatedMode
)
1254 ::PenPat(GetQDGlobalsBlack(&pat
));
1255 if ( logical_func
== wxSET
)
1257 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1258 ::RGBForeColor( &col
) ;
1259 ::PaintRgn( clipRgn
) ;
1261 else if ( logical_func
== wxCLEAR
)
1263 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1264 ::RGBForeColor( &col
) ;
1265 ::PaintRgn( clipRgn
) ;
1267 else if ( logical_func
== wxINVERT
)
1269 MacInvertRgn( clipRgn
) ;
1273 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1275 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1277 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1278 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1284 SetPort( (GrafPtr
) sourcePort
) ;
1285 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1286 SetPort( (GrafPtr
) m_macPort
) ;
1287 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1289 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1290 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1299 if ( invertDestinationFirst
)
1301 MacInvertRgn( clipRgn
) ;
1303 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1304 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1305 &srcrect
, &dstrect
, mode
, NULL
) ;
1307 DisposeRgn( clipRgn
) ;
1309 UnlockPixels( bmappixels
) ;
1312 m_macPenInstalled
= false ;
1313 m_macBrushInstalled
= false ;
1314 m_macFontInstalled
= false ;
1319 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1322 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1326 DrawText(text
, x
, y
);
1332 // the size of the text
1334 GetTextExtent(text
, &w
, &h
);
1336 // draw the string normally
1339 dc
.SelectObject(src
);
1340 dc
.SetFont(GetFont());
1341 dc
.SetBackground(*wxWHITE_BRUSH
);
1342 dc
.SetBrush(*wxBLACK_BRUSH
);
1344 dc
.DrawText(text
, 0, 0);
1345 dc
.SetFont(wxNullFont
);
1346 dc
.SelectObject(wxNullBitmap
);
1348 wxMacPortSetter
helper(this) ;
1350 // Calculate the size of the rotated bounding box.
1351 double rad
= DegToRad(angle
);
1352 double dx
= cos(rad
);
1353 double dy
= sin(rad
);
1355 // the rectngle vertices are counted clockwise with the first one being at
1356 // (0, 0) (or, rather, at (x, y))
1358 double y2
= -w
* dy
; // y axis points to the bottom, hence minus
1361 double x3
= x4
+ x2
;
1362 double y3
= y4
+ y2
;
1365 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5);
1366 wxCoord maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5);
1367 wxCoord minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5);
1368 wxCoord minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1370 // prepare to blit-with-rotate the bitmap to the DC
1373 RGBColor colText
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() );
1374 RGBColor colBack
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel() );
1376 unsigned char *data
= image
.GetData();
1379 double r
, angleOrig
;
1382 // paint pixel by pixel
1383 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1385 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1387 // transform source coords to dest coords
1388 r
= sqrt( (double)(srcX
* srcX
+ srcY
* srcY
) );
1389 angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1390 dstX
= (wxCoord
)(r
* cos(angleOrig
) + 0.5);
1391 dstY
= (wxCoord
)(r
* sin(angleOrig
) + 0.5);
1394 textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1395 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1397 SetCPixel(XLOG2DEVMAC(x
+ dstX
), YLOG2DEVMAC(y
+ dstY
),
1398 textPixel
? &colText
: &colBack
);
1403 // it would be better to draw with non underlined font and draw the line
1404 // manually here (it would be more straight...)
1406 if ( m_font
.GetUnderlined() )
1408 ::MoveTo(XLOG2DEVMAC(x
+ x4
), YLOG2DEVMAC(y
+ y4
+ font
->descent
));
1409 ::LineTo(XLOG2DEVMAC(x
+ x3
), YLOG2DEVMAC(y
+ y3
+ font
->descent
));
1413 // update the bounding box
1414 CalcBoundingBox(x
+ minX
, y
+ minY
);
1415 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1417 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1419 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1420 wxMacPortSetter
helper(this) ;
1422 long xx
= XLOG2DEVMAC(x
);
1423 long yy
= YLOG2DEVMAC(y
);
1425 // if (m_pen.GetStyle() != wxTRANSPARENT)
1429 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1431 ::ClipRect( &clip ) ;
1435 ::GetFontInfo( &fi
) ;
1438 ::MoveTo( xx
, yy
);
1439 if ( m_backgroundMode
== wxTRANSPARENT
)
1441 ::TextMode( srcOr
) ;
1445 ::TextMode( srcCopy
) ;
1448 const char *text
= NULL
;
1452 if ( wxApp::s_macDefaultEncodingIsPC
)
1454 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1456 length
= macText
.Length() ;
1461 length
= strtext
.Length() ;
1470 if( text
[i
] == 13 || text
[i
] == 10)
1472 ::DrawText( text
, laststop
, i
- laststop
) ;
1474 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1480 ::DrawText( text
, laststop
, i
- laststop
) ;
1481 ::TextMode( srcOr
) ;
1485 bool wxDC::CanGetTextExtent() const
1487 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1492 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1493 wxCoord
*descent
, wxCoord
*externalLeading
,
1494 wxFont
*theFont
) const
1496 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1497 wxMacPortSetter
helper(this) ;
1499 wxFont formerFont
= m_font
;
1503 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1507 ::TextFont( font
->m_macFontNum
) ;
1508 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1509 ::TextFace( font
->m_macFontStyle
) ;
1518 ::GetFontInfo( &fi
) ;
1521 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1523 *descent
=YDEV2LOGREL( fi
.descent
);
1524 if ( externalLeading
)
1525 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1527 const char *text
= NULL
;
1530 if ( wxApp::s_macDefaultEncodingIsPC
)
1532 macText
= wxMacMakeMacStringFromPC( string
) ;
1534 length
= macText
.Length() ;
1539 length
= string
.Length() ;
1551 if( text
[i
] == 13 || text
[i
] == 10)
1554 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1555 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1556 if ( curwidth
> *width
)
1557 *width
= XDEV2LOGREL( curwidth
) ;
1563 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1564 if ( curwidth
> *width
)
1565 *width
= XDEV2LOGREL( curwidth
) ;
1570 m_macFontInstalled
= false ;
1574 wxCoord
wxDC::GetCharWidth(void) const
1576 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1578 wxMacPortSetter
helper(this) ;
1582 int width
= ::TextWidth( "n" , 0 , 1 ) ;
1584 return YDEV2LOGREL(width
) ;
1587 wxCoord
wxDC::GetCharHeight(void) const
1589 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1591 wxMacPortSetter
helper(this) ;
1596 ::GetFontInfo( &fi
) ;
1598 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1601 void wxDC::Clear(void)
1603 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1604 wxMacPortSetter
helper(this) ;
1605 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1607 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1609 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1611 ::EraseRect( &rect
) ;
1615 void wxDC::MacInstallFont() const
1617 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1618 // if ( m_macFontInstalled )
1620 Pattern blackColor
;
1622 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1626 ::TextFont( font
->m_macFontNum
) ;
1627 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1628 ::TextFace( font
->m_macFontStyle
) ;
1630 m_macFontInstalled
= true ;
1631 m_macBrushInstalled
= false ;
1632 m_macPenInstalled
= false ;
1634 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1635 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1636 ::RGBForeColor( &forecolor
);
1637 ::RGBBackColor( &backcolor
);
1643 GetFNum( "\pGeneva" , &fontnum
) ;
1644 ::TextFont( fontnum
) ;
1645 ::TextSize( short(m_scaleY
* 10) ) ;
1648 // todo reset after spacing changes - or store the current spacing somewhere
1650 m_macFontInstalled
= true ;
1651 m_macBrushInstalled
= false ;
1652 m_macPenInstalled
= false ;
1654 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1655 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1656 ::RGBForeColor( &forecolor
);
1657 ::RGBBackColor( &backcolor
);
1660 short mode
= patCopy
;
1664 switch( m_logicalFunction
)
1669 case wxINVERT
: // NOT dst
1670 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1673 case wxXOR
: // src XOR dst
1676 case wxOR_REVERSE
: // src OR (NOT dst)
1679 case wxSRC_INVERT
: // (NOT src)
1686 case wxAND_REVERSE
:// src AND (NOT dst)
1687 case wxAND
: // src AND dst
1688 case wxAND_INVERT
: // (NOT src) AND dst
1689 case wxNO_OP
: // dst
1690 case wxNOR
: // (NOT src) AND (NOT dst)
1691 case wxEQUIV
: // (NOT src) XOR dst
1692 case wxOR_INVERT
: // (NOT src) OR dst
1693 case wxNAND
: // (NOT src) OR (NOT dst)
1694 case wxOR
: // src OR dst
1696 // case wxSRC_OR: // source _bitmap_ OR destination
1697 // case wxSRC_AND: // source _bitmap_ AND destination
1703 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1705 // we have our own pattern list now
1706 int thePatListID
= 128;
1710 case wxBDIAGONAL_HATCH
:
1713 case wxFDIAGONAL_HATCH
:
1719 case wxHORIZONTAL_HATCH
:
1722 case wxVERTICAL_HATCH
:
1725 case wxCROSSDIAG_HATCH
:
1729 theIndex
= 1; // solid pattern
1732 GetIndPattern( pattern
, thePatListID
, theIndex
);
1735 void wxDC::MacInstallPen() const
1737 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1741 // if ( m_macPenInstalled )
1744 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1745 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1746 ::RGBForeColor( &forecolor
);
1747 ::RGBBackColor( &backcolor
);
1750 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1752 // null means only one pixel, at whatever resolution
1753 if ( penWidth
== 0 )
1755 ::PenSize(penWidth
, penWidth
);
1757 int penStyle
= m_pen
.GetStyle();
1759 if (penStyle
== wxSOLID
)
1761 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1763 else if (IS_HATCH(penStyle
))
1766 wxMacGetHatchPattern(penStyle
, &pat
);
1771 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1775 for ( int i
= 0 ; i
< 8 ; ++i
)
1781 for ( int i
= 0 ; i
< 8 ; ++i
)
1787 for ( int i
= 0 ; i
< 8 ; ++i
)
1793 for ( int i
= 0 ; i
< 8 ; ++i
)
1801 int number
= m_pen
.GetDashes(&dash
) ;
1802 // right now we don't allocate larger pixmaps
1803 for ( int i
= 0 ; i
< 8 ; ++i
)
1805 pat
.pat
[i
] = dash
[0] ;
1813 short mode
= patCopy
;
1817 switch( m_logicalFunction
)
1819 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1822 case wxINVERT
: // NOT dst
1823 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1826 case wxXOR
: // src XOR dst
1829 case wxOR_REVERSE
: // src OR (NOT dst)
1832 case wxSRC_INVERT
: // (NOT src)
1839 case wxAND_REVERSE
:// src AND (NOT dst)
1840 case wxAND
: // src AND dst
1841 case wxAND_INVERT
: // (NOT src) AND dst
1842 case wxNO_OP
: // dst
1843 case wxNOR
: // (NOT src) AND (NOT dst)
1844 case wxEQUIV
: // (NOT src) XOR dst
1845 case wxOR_INVERT
: // (NOT src) OR dst
1846 case wxNAND
: // (NOT src) OR (NOT dst)
1847 case wxOR
: // src OR dst
1849 // case wxSRC_OR: // source _bitmap_ OR destination
1850 // case wxSRC_AND: // source _bitmap_ AND destination
1854 m_macPenInstalled
= true ;
1855 m_macBrushInstalled
= false ;
1856 m_macFontInstalled
= false ;
1859 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1861 Pattern whiteColor
;
1862 switch( background
.MacGetBrushKind() )
1864 case kwxMacBrushTheme
:
1866 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1869 case kwxMacBrushThemeBackground
:
1872 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1873 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1876 case kwxMacBrushColour
:
1878 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1879 int brushStyle
= background
.GetStyle();
1880 if (brushStyle
== wxSOLID
)
1881 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1882 else if (IS_HATCH(brushStyle
))
1885 wxMacGetHatchPattern(brushStyle
, &pat
);
1890 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1897 void wxDC::MacInstallBrush() const
1899 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1901 Pattern blackColor
;
1902 // if ( m_macBrushInstalled )
1907 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1909 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1910 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) );
1912 int brushStyle
= m_brush
.GetStyle();
1913 if (brushStyle
== wxSOLID
)
1915 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1917 else if (IS_HATCH(brushStyle
))
1920 wxMacGetHatchPattern(brushStyle
, &pat
);
1923 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1925 // we force this in order to be compliant with wxMSW
1926 backgroundTransparent
= false ;
1927 // for these the text fore (and back for MASK_OPAQUE) colors are used
1928 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1929 int width
= bitmap
->GetWidth() ;
1930 int height
= bitmap
->GetHeight() ;
1931 GWorldPtr gw
= NULL
;
1933 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1934 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1936 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1938 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
1939 LockPixels( gwpixmaphandle
) ;
1941 bool isMonochrome
= !IsPortColor( gw
) ;
1943 if ( !isMonochrome
)
1945 if ( (**gwpixmaphandle
).pixelSize
== 1 )
1946 isMonochrome
= true ;
1952 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
1953 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) );
1955 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
1956 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
1957 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
1959 if( width
== 8 && height
== 8 )
1962 for ( int i
= 0 ; i
< 8 ; ++i
)
1964 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
1966 UnlockPixels( GetGWorldPixMap( gw
) ) ;
1971 #if wxMAC_EXPERIMENTAL_PATTERN
1972 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
1973 // caching scheme before putting this into production
1976 PixPatHandle pixpat
= NewPixPat() ;
1978 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
1979 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
1980 ((**(**pixpat
).patMap
).bounds
.bottom
-
1981 (**(**pixpat
).patMap
).bounds
.top
);
1983 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
1984 (**pixpat
).patData
= image
;
1985 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
1986 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
1987 if ( ctspec
[0].rgb
.red
== 0x0000 )
1989 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1990 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1994 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1995 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1997 ::CTabChanged( ctable
) ;
1998 ::PenPixPat(pixpat
);
2005 UnlockPixels( gwpixmaphandle
) ;
2009 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2012 short mode
= patCopy
;
2013 switch( m_logicalFunction
)
2016 if ( backgroundTransparent
)
2021 case wxINVERT
: // NOT dst
2022 if ( !backgroundTransparent
)
2024 ::PenPat(GetQDGlobalsBlack(&blackColor
));
2028 case wxXOR
: // src XOR dst
2031 case wxOR_REVERSE
: // src OR (NOT dst)
2034 case wxSRC_INVERT
: // (NOT src)
2041 case wxAND_REVERSE
:// src AND (NOT dst)
2042 case wxAND
: // src AND dst
2043 case wxAND_INVERT
: // (NOT src) AND dst
2044 case wxNO_OP
: // dst
2045 case wxNOR
: // (NOT src) AND (NOT dst)
2046 case wxEQUIV
: // (NOT src) XOR dst
2047 case wxOR_INVERT
: // (NOT src) OR dst
2048 case wxNAND
: // (NOT src) OR (NOT dst)
2049 case wxOR
: // src OR dst
2051 // case wxSRC_OR: // source _bitmap_ OR destination
2052 // case wxSRC_AND: // source _bitmap_ AND destination
2056 m_macBrushInstalled
= true ;
2057 m_macPenInstalled
= false ;
2058 m_macFontInstalled
= false ;
2061 // ---------------------------------------------------------------------------
2062 // coordinates transformations
2063 // ---------------------------------------------------------------------------
2066 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2068 return ((wxDC
*)this)->XDEV2LOG(x
);
2071 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2073 return ((wxDC
*)this)->YDEV2LOG(y
);
2076 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2078 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2081 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2083 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2086 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2088 return ((wxDC
*)this)->XLOG2DEV(x
);
2091 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2093 return ((wxDC
*)this)->YLOG2DEV(y
);
2096 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2098 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2101 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2103 return ((wxDC
*)this)->YLOG2DEVREL(y
);