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"
23 #include "wx/mac/private.h"
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define mm2inches 0.0393700787402
38 #define inches2mm 25.4
39 #define mm2twips 56.6929133859
40 #define twips2mm 0.0176388888889
41 #define mm2pt 2.83464566929
42 #define pt2mm 0.352777777778
44 const double M_PI
= 3.14159265358979 ;
46 const double RAD2DEG
= 180.0 / M_PI
;
47 const short kEmulatedMode
= -1 ;
48 const short kUnsupportedMode
= -2 ;
50 #define wxMAC_EXPERIMENTAL_PATTERN 0
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
57 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
58 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 // this function emulates all wx colour manipulations, used to verify the implementation
65 // by setting the mode in the blitting functions to kEmulatedMode
67 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
) ;
68 void wxMacCalculateColour( int logical_func
, const RGBColor
&srcColor
, RGBColor
&dstColor
)
70 switch ( logical_func
)
72 case wxAND
: // src AND dst
73 dstColor
.red
= dstColor
.red
& srcColor
.red
;
74 dstColor
.green
= dstColor
.green
& srcColor
.green
;
75 dstColor
.blue
= dstColor
.blue
& srcColor
.blue
;
77 case wxAND_INVERT
: // (NOT src) AND dst
78 dstColor
.red
= dstColor
.red
& ~srcColor
.red
;
79 dstColor
.green
= dstColor
.green
& ~srcColor
.green
;
80 dstColor
.blue
= dstColor
.blue
& ~srcColor
.blue
;
82 case wxAND_REVERSE
:// src AND (NOT dst)
83 dstColor
.red
= ~dstColor
.red
& srcColor
.red
;
84 dstColor
.green
= ~dstColor
.green
& srcColor
.green
;
85 dstColor
.blue
= ~dstColor
.blue
& srcColor
.blue
;
93 dstColor
.red
= srcColor
.red
;
94 dstColor
.green
= srcColor
.green
;
95 dstColor
.blue
= srcColor
.blue
;
97 case wxEQUIV
: // (NOT src) XOR dst
98 dstColor
.red
= dstColor
.red
^ ~srcColor
.red
;
99 dstColor
.green
= dstColor
.green
^ ~srcColor
.green
;
100 dstColor
.blue
= dstColor
.blue
^ ~srcColor
.blue
;
102 case wxINVERT
: // NOT dst
103 dstColor
.red
= ~dstColor
.red
;
104 dstColor
.green
= ~dstColor
.green
;
105 dstColor
.blue
= ~dstColor
.blue
;
107 case wxNAND
: // (NOT src) OR (NOT dst)
108 dstColor
.red
= ~dstColor
.red
| ~srcColor
.red
;
109 dstColor
.green
= ~dstColor
.green
| ~srcColor
.green
;
110 dstColor
.blue
= ~dstColor
.blue
| ~srcColor
.blue
;
112 case wxNOR
: // (NOT src) AND (NOT dst)
113 dstColor
.red
= ~dstColor
.red
& ~srcColor
.red
;
114 dstColor
.green
= ~dstColor
.green
& ~srcColor
.green
;
115 dstColor
.blue
= ~dstColor
.blue
& ~srcColor
.blue
;
119 case wxOR
: // src OR dst
120 dstColor
.red
= dstColor
.red
| srcColor
.red
;
121 dstColor
.green
= dstColor
.green
| srcColor
.green
;
122 dstColor
.blue
= dstColor
.blue
| srcColor
.blue
;
124 case wxOR_INVERT
: // (NOT src) OR dst
125 dstColor
.red
= dstColor
.red
| ~srcColor
.red
;
126 dstColor
.green
= dstColor
.green
| ~srcColor
.green
;
127 dstColor
.blue
= dstColor
.blue
| ~srcColor
.blue
;
129 case wxOR_REVERSE
: // src OR (NOT dst)
130 dstColor
.red
= ~dstColor
.red
| srcColor
.red
;
131 dstColor
.green
= ~dstColor
.green
| srcColor
.green
;
132 dstColor
.blue
= ~dstColor
.blue
| srcColor
.blue
;
135 dstColor
.red
= 0xFFFF ;
136 dstColor
.green
= 0xFFFF ;
137 dstColor
.blue
= 0xFFFF ;
139 case wxSRC_INVERT
: // (NOT src)
140 dstColor
.red
= ~srcColor
.red
;
141 dstColor
.green
= ~srcColor
.green
;
142 dstColor
.blue
= ~srcColor
.blue
;
144 case wxXOR
: // src XOR dst
145 dstColor
.red
= dstColor
.red
^ srcColor
.red
;
146 dstColor
.green
= dstColor
.green
^ srcColor
.green
;
147 dstColor
.blue
= dstColor
.blue
^ srcColor
.blue
;
158 m_mm_to_pix_x
= mm2pt
;
159 m_mm_to_pix_y
= mm2pt
;
161 m_internalDeviceOriginX
= 0;
162 m_internalDeviceOriginY
= 0;
163 m_externalDeviceOriginX
= 0;
164 m_externalDeviceOriginY
= 0;
166 m_logicalScaleX
= 1.0;
167 m_logicalScaleY
= 1.0;
173 m_needComputeScaleX
= FALSE
;
174 m_needComputeScaleY
= FALSE
;
180 m_macFontInstalled
= false ;
181 m_macBrushInstalled
= false ;
182 m_macPenInstalled
= false ;
184 m_macLocalOrigin
.x
= m_macLocalOrigin
.y
= 0 ;
185 m_macBoundaryClipRgn
= NewRgn() ;
186 m_macCurrentClipRgn
= NewRgn() ;
188 SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
189 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, -32000 , -32000 , 32000 , 32000 ) ;
191 m_pen
= *wxBLACK_PEN
;
192 m_font
= *wxNORMAL_FONT
;
193 m_brush
= *wxWHITE_BRUSH
;
195 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
196 m_ph( (GrafPtr
) dc
->m_macPort
)
198 wxASSERT( dc
->Ok() ) ;
200 dc
->MacSetupPort(&m_ph
) ;
203 wxMacPortSetter::~wxMacPortSetter()
209 DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn
) ;
210 DisposeRgn( (RgnHandle
) m_macCurrentClipRgn
) ;
212 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const
214 SetClip( (RgnHandle
) m_macCurrentClipRgn
);
216 m_macFontInstalled
= false ;
217 m_macBrushInstalled
= false ;
218 m_macPenInstalled
= false ;
221 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
223 wxCHECK_RET( Ok(), wxT("invalid window dc") );
225 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
227 wxMacPortSetter
helper(this) ;
229 wxCoord xx
= XLOG2DEVMAC(x
);
230 wxCoord yy
= YLOG2DEVMAC(y
);
231 wxCoord w
= bmp
.GetWidth();
232 wxCoord h
= bmp
.GetHeight();
233 wxCoord ww
= XLOG2DEVREL(w
);
234 wxCoord hh
= YLOG2DEVREL(h
);
236 // Set up drawing mode
237 short mode
= (m_logicalFunction
== wxCOPY
? srcCopy
:
238 //m_logicalFunction == wxCLEAR ? WHITENESS :
239 //m_logicalFunction == wxSET ? BLACKNESS :
240 m_logicalFunction
== wxINVERT
? hilite
:
241 //m_logicalFunction == wxAND ? MERGECOPY :
242 m_logicalFunction
== wxOR
? srcOr
:
243 m_logicalFunction
== wxSRC_INVERT
? notSrcCopy
:
244 m_logicalFunction
== wxXOR
? srcXor
:
245 m_logicalFunction
== wxOR_REVERSE
? notSrcOr
:
246 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
247 //m_logicalFunction == wxSRC_OR ? srcOr :
248 //m_logicalFunction == wxSRC_AND ? SRCAND :
251 if ( bmp
.GetBitmapType() == kMacBitmapTypePict
) {
252 Rect bitmaprect
= { 0 , 0 , hh
, ww
};
253 ::OffsetRect( &bitmaprect
, xx
, yy
) ;
254 ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect
) ;
256 else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld
)
258 GWorldPtr bmapworld
= MAC_WXHBITMAP( bmp
.GetHBITMAP() );
259 PixMapHandle bmappixels
;
261 // Set foreground and background colours (for bitmaps depth = 1)
262 if(bmp
.GetDepth() == 1)
264 RGBColor fore
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel());
265 RGBColor back
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel());
271 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
272 RGBColor black
= { 0,0,0} ;
273 RGBForeColor( &black
) ;
274 RGBBackColor( &white
) ;
277 bmappixels
= GetGWorldPixMap( bmapworld
) ;
279 wxCHECK_RET(LockPixels(bmappixels
),
280 wxT("DoDrawBitmap: Unable to lock pixels"));
282 Rect source
= { 0, 0, h
, w
};
283 Rect dest
= { yy
, xx
, yy
+ hh
, xx
+ ww
};
285 if ( useMask
&& bmp
.GetMask() )
287 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))))
291 GetPortBitMapForCopyBits(bmapworld
),
292 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())),
293 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
294 &source
, &source
, &dest
, mode
, NULL
296 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())));
300 CopyBits( GetPortBitMapForCopyBits( bmapworld
),
301 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ),
302 &source
, &dest
, mode
, NULL
) ;
304 UnlockPixels( bmappixels
) ;
306 else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon
)
308 Rect bitmaprect
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ;
309 OffsetRect( &bitmaprect
, xx
, yy
) ;
310 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, MAC_WXHICON(bmp
.GetHICON()) ) ;
312 m_macPenInstalled
= false ;
313 m_macBrushInstalled
= false ;
314 m_macFontInstalled
= false ;
318 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
320 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
322 wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
324 DoDrawBitmap( icon
, x
, y
, icon
.GetMask() != NULL
) ;
326 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
328 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
329 wxCoord xx
, yy
, ww
, hh
;
333 ww
= XLOG2DEVREL(width
);
334 hh
= YLOG2DEVREL(height
);
336 SetRectRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
, yy
, xx
+ ww
, yy
+ hh
) ;
337 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
341 m_clipX1
= wxMax( m_clipX1
, xx
);
342 m_clipY1
= wxMax( m_clipY1
, yy
);
343 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
344 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
356 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
358 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
360 wxMacPortSetter
helper(this) ;
363 DestroyClippingRegion();
368 region
.GetBox( x
, y
, w
, h
);
369 wxCoord xx
, yy
, ww
, hh
;
376 // if we have a scaling that we cannot map onto native regions
377 // we must use the box
379 if ( ww
!= w
|| hh
!= h
)
381 wxDC::DoSetClippingRegion( x
, y
, w
, h
);
385 CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn
) ;
386 if ( xx
!= x
|| yy
!= y
)
388 OffsetRgn( (RgnHandle
) m_macCurrentClipRgn
, xx
- x
, yy
- y
) ;
390 SectRgn( (RgnHandle
) m_macCurrentClipRgn
, (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
393 m_clipX1
= wxMax( m_clipX1
, xx
);
394 m_clipY1
= wxMax( m_clipY1
, yy
);
395 m_clipX2
= wxMin( m_clipX2
, (xx
+ ww
));
396 m_clipY2
= wxMin( m_clipY2
, (yy
+ hh
));
410 void wxDC::DestroyClippingRegion()
412 wxMacPortSetter
helper(this) ;
413 CopyRgn( (RgnHandle
) m_macBoundaryClipRgn
, (RgnHandle
) m_macCurrentClipRgn
) ;
416 void wxDC::DoGetSize( int* width
, int* height
) const
418 *width
= m_maxX
-m_minX
;
419 *height
= m_maxY
-m_minY
;
421 void wxDC::DoGetSizeMM( int* width
, int* height
) const
426 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
427 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
429 void wxDC::SetTextForeground( const wxColour
&col
)
431 wxCHECK_RET(Ok(), wxT("Invalid DC"));
432 m_textForegroundColour
= col
;
433 m_macFontInstalled
= false ;
435 void wxDC::SetTextBackground( const wxColour
&col
)
437 wxCHECK_RET(Ok(), wxT("Invalid DC"));
438 m_textBackgroundColour
= col
;
439 m_macFontInstalled
= false ;
441 void wxDC::SetMapMode( int mode
)
446 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
449 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
452 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
455 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
459 SetLogicalScale( 1.0, 1.0 );
462 if (mode
!= wxMM_TEXT
)
464 m_needComputeScaleX
= TRUE
;
465 m_needComputeScaleY
= TRUE
;
468 void wxDC::SetUserScale( double x
, double y
)
470 // allow negative ? -> no
473 ComputeScaleAndOrigin();
475 void wxDC::SetLogicalScale( double x
, double y
)
480 ComputeScaleAndOrigin();
482 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
484 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
485 m_logicalOriginY
= y
* m_signY
;
486 ComputeScaleAndOrigin();
488 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
490 m_externalDeviceOriginX
= x
;
491 m_externalDeviceOriginY
= y
;
492 ComputeScaleAndOrigin();
496 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
498 m_internalDeviceOriginX
= x
;
499 m_internalDeviceOriginY
= y
;
500 ComputeScaleAndOrigin();
502 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
504 if (x
) *x
= m_internalDeviceOriginX
;
505 if (y
) *y
= m_internalDeviceOriginY
;
508 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
510 m_signX
= (xLeftRight
? 1 : -1);
511 m_signY
= (yBottomUp
? -1 : 1);
512 ComputeScaleAndOrigin();
515 wxSize
wxDC::GetPPI() const
517 return wxSize(72, 72);
520 int wxDC::GetDepth() const
522 return wxDisplayDepth() ;
525 void wxDC::ComputeScaleAndOrigin()
527 // CMB: copy scale to see if it changes
528 double origScaleX
= m_scaleX
;
529 double origScaleY
= m_scaleY
;
531 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
532 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
534 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
535 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
537 // CMB: if scale has changed call SetPen to recalulate the line width
538 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
540 // this is a bit artificial, but we need to force wxDC to think
541 // the pen has changed
542 wxPen
* pen
= & GetPen();
548 void wxDC::SetPalette( const wxPalette
& palette
)
552 void wxDC::SetBackgroundMode( int mode
)
554 m_backgroundMode
= mode
;
557 void wxDC::SetFont( const wxFont
&font
)
560 m_macFontInstalled
= false ;
563 void wxDC::SetPen( const wxPen
&pen
)
570 m_macPenInstalled
= false ;
573 void wxDC::SetBrush( const wxBrush
&brush
)
575 if (m_brush
== brush
)
579 m_macBrushInstalled
= false ;
582 void wxDC::SetBackground( const wxBrush
&brush
)
584 if (m_backgroundBrush
== brush
)
587 m_backgroundBrush
= brush
;
589 if (!m_backgroundBrush
.Ok())
591 m_macBrushInstalled
= false ;
594 void wxDC::SetLogicalFunction( int function
)
596 if (m_logicalFunction
== function
)
599 m_logicalFunction
= function
;
600 m_macFontInstalled
= false ;
601 m_macBrushInstalled
= false ;
602 m_macPenInstalled
= false ;
605 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
610 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
612 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
613 wxMacPortSetter
helper(this) ;
617 GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour
);
619 // Convert from Mac colour to wx
620 col
->Set( colour
.red
>> 8,
627 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
629 wxCHECK_RET(Ok(), wxT("Invalid DC"));
631 wxMacPortSetter
helper(this) ;
633 if (m_pen
.GetStyle() != wxTRANSPARENT
)
636 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
637 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2;
639 wxCoord xx1
= XLOG2DEVMAC(x1
) - offset
;
640 wxCoord yy1
= YLOG2DEVMAC(y1
) - offset
;
641 wxCoord xx2
= XLOG2DEVMAC(x2
) - offset
;
642 wxCoord yy2
= YLOG2DEVMAC(y2
) - offset
;
644 if ((m_pen
.GetCap() == wxCAP_ROUND
) &&
645 (m_pen
.GetWidth() <= 1))
647 // Implement LAST_NOT for MAC at least for
648 // orthogonal lines. RR.
670 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
672 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
674 if (m_pen
.GetStyle() != wxTRANSPARENT
)
679 wxCoord xx
= XLOG2DEVMAC(x
);
680 wxCoord yy
= YLOG2DEVMAC(y
);
683 ::MoveTo( XLOG2DEVMAC(0), yy
);
684 ::LineTo( XLOG2DEVMAC(w
), yy
);
685 ::MoveTo( xx
, YLOG2DEVMAC(0) );
686 ::LineTo( xx
, YLOG2DEVMAC(h
) );
691 * To draw arcs properly the angles need to be converted from the WX style:
692 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
693 * a normal axis on paper).
696 * Angles start on the +ve y axis and go clockwise.
697 * To achive this I work out which quadrant the angle lies in then map this to
698 * the equivalent quadrant on the Mac. (Sin and Cos values reveal which
699 * quadrant you are in).
701 static double wxConvertWXangleToMACangle(double angle
)
705 sin_a
= sin(angle
/ RAD2DEG
);
706 cos_a
= cos(angle
/ RAD2DEG
);
708 if( (sin_a
>= 0.0) && (cos_a
>= 0.0) ) {
709 angle
= acos(sin_a
) * RAD2DEG
;
711 else if( (sin_a
>= 0.0) && (cos_a
<= 0.0) ) {
713 angle
= acos(sin_a
) * RAD2DEG
+ 180;
715 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) ) {
720 angle
= acos(sin_a
) * RAD2DEG
+ 180;
725 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
726 wxCoord x2
, wxCoord y2
,
727 wxCoord xc
, wxCoord yc
)
729 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
731 wxCoord xx1
= XLOG2DEVMAC(x1
);
732 wxCoord yy1
= YLOG2DEVMAC(y1
);
733 wxCoord xx2
= XLOG2DEVMAC(x2
);
734 wxCoord yy2
= YLOG2DEVMAC(y2
);
735 wxCoord xxc
= XLOG2DEVMAC(xc
);
736 wxCoord yyc
= YLOG2DEVMAC(yc
);
737 double dx
= xx1
- xxc
;
738 double dy
= yy1
- yyc
;
739 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
740 wxCoord rad
= (wxCoord
)radius
;
741 double radius1
, radius2
;
743 if (xx1
== xx2
&& yy1
== yy2
)
748 else if (radius
== 0.0)
750 radius1
= radius2
= 0.0;
754 radius1
= (xx1
- xxc
== 0) ?
755 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
756 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
757 radius2
= (xx2
- xxc
== 0) ?
758 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
759 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
761 wxCoord alpha2
= wxCoord(radius2
- radius1
);
762 wxCoord alpha1
= wxCoord(wxConvertWXangleToMACangle(radius1
));
763 if( (xx1
> xx2
) || (yy1
> yy2
) ) {
767 Rect r
= { yyc
- rad
, xxc
- rad
, yyc
+ rad
, xxc
+ rad
};
769 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
771 PaintArc(&r
, alpha1
, alpha2
);
773 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
775 FrameArc(&r
, alpha1
, alpha2
);
779 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
780 double sa
, double ea
)
782 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
785 double angle
= sa
- ea
; // Order important Mac in opposite direction to wx
787 wxCoord xx
= XLOG2DEVMAC(x
);
788 wxCoord yy
= YLOG2DEVMAC(y
);
789 wxCoord ww
= m_signX
* XLOG2DEVREL(w
);
790 wxCoord hh
= m_signY
* YLOG2DEVREL(h
);
792 // handle -ve width and/or height
793 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
794 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
796 sa
= wxConvertWXangleToMACangle(sa
);
803 if(m_brush
.GetStyle() != wxTRANSPARENT
) {
805 PaintArc(&r
, (short)sa
, (short)angle
);
807 if(m_pen
.GetStyle() != wxTRANSPARENT
) {
809 FrameArc(&r
, (short)sa
, (short)angle
);
813 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
815 wxCHECK_RET(Ok(), wxT("Invalid DC"));
817 wxMacPortSetter
helper(this) ;
819 if (m_pen
.GetStyle() != wxTRANSPARENT
)
822 wxCoord xx1
= XLOG2DEVMAC(x
);
823 wxCoord yy1
= YLOG2DEVMAC(y
);
826 ::LineTo(xx1
+1, yy1
+1);
830 void wxDC::DoDrawLines(int n
, wxPoint points
[],
831 wxCoord xoffset
, wxCoord yoffset
)
833 wxCHECK_RET(Ok(), wxT("Invalid DC"));
834 wxMacPortSetter
helper(this) ;
836 if (m_pen
.GetStyle() == wxTRANSPARENT
)
841 wxCoord offset
= ( (m_pen
.GetWidth() == 0 ? 1 :
842 m_pen
.GetWidth() ) * (wxCoord
)m_scaleX
- 1) / 2 ;
844 wxCoord x1
, x2
, y1
, y2
;
845 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
846 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
847 ::MoveTo(x1
- offset
, y1
- offset
);
849 for (int i
= 0; i
< n
-1; i
++)
851 x2
= XLOG2DEVMAC(points
[i
+1].x
+ xoffset
);
852 y2
= YLOG2DEVMAC(points
[i
+1].y
+ yoffset
);
853 ::LineTo( x2
- offset
, y2
- offset
);
857 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
858 wxCoord xoffset
, wxCoord yoffset
,
861 wxCHECK_RET(Ok(), wxT("Invalid DC"));
862 wxMacPortSetter
helper(this) ;
864 wxCoord x1
, x2
, y1
, y2
;
866 if ( m_brush
.GetStyle() == wxTRANSPARENT
&& m_pen
.GetStyle() == wxTRANSPARENT
)
869 PolyHandle polygon
= OpenPoly();
871 x1
= XLOG2DEVMAC(points
[0].x
+ xoffset
);
872 y1
= YLOG2DEVMAC(points
[0].y
+ yoffset
);
875 for (int i
= 1; i
< n
; i
++)
877 x2
= XLOG2DEVMAC(points
[i
].x
+ xoffset
);
878 y2
= YLOG2DEVMAC(points
[i
].y
+ yoffset
);
882 // close the polyline if necessary
883 if ( x1
!= x2
|| y1
!= y2
)
890 if (m_brush
.GetStyle() != wxTRANSPARENT
)
894 ::PaintPoly( polygon
);
898 if (m_pen
.GetStyle() != wxTRANSPARENT
)
902 ::FramePoly( polygon
) ;
908 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
910 wxCHECK_RET(Ok(), wxT("Invalid DC"));
911 wxMacPortSetter
helper(this) ;
913 wxCoord xx
= XLOG2DEVMAC(x
);
914 wxCoord yy
= YLOG2DEVMAC(y
);
915 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
916 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
918 // CMB: draw nothing if transformed w or h is 0
919 if (ww
== 0 || hh
== 0)
922 // CMB: handle -ve width and/or height
935 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
937 if (m_brush
.GetStyle() != wxTRANSPARENT
)
940 ::PaintRect( &rect
) ;
943 if (m_pen
.GetStyle() != wxTRANSPARENT
)
946 ::FrameRect( &rect
) ;
950 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
951 wxCoord width
, wxCoord height
,
954 wxCHECK_RET(Ok(), wxT("Invalid DC"));
955 wxMacPortSetter
helper(this) ;
958 radius
= - radius
* ((width
< height
) ? width
: height
);
960 wxCoord xx
= XLOG2DEVMAC(x
);
961 wxCoord yy
= YLOG2DEVMAC(y
);
962 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
963 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
965 // CMB: draw nothing if transformed w or h is 0
966 if (ww
== 0 || hh
== 0)
969 // CMB: handle -ve width and/or height
982 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
984 if (m_brush
.GetStyle() != wxTRANSPARENT
)
987 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
990 if (m_pen
.GetStyle() != wxTRANSPARENT
)
993 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
997 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
999 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1000 wxMacPortSetter
helper(this) ;
1002 wxCoord xx
= XLOG2DEVMAC(x
);
1003 wxCoord yy
= YLOG2DEVMAC(y
);
1004 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
1005 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
1007 // CMB: draw nothing if transformed w or h is 0
1008 if (ww
== 0 || hh
== 0)
1011 // CMB: handle -ve width and/or height
1024 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
1026 if (m_brush
.GetStyle() != wxTRANSPARENT
)
1029 ::PaintOval( &rect
) ;
1032 if (m_pen
.GetStyle() != wxTRANSPARENT
)
1035 ::FrameOval( &rect
) ;
1041 bool wxDC::CanDrawBitmap(void) const
1047 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1048 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1049 wxCoord xsrcMask
, wxCoord ysrcMask
)
1051 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1052 wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1054 if ( logical_func
== wxNO_OP
)
1057 if (xsrcMask
== -1 && ysrcMask
== -1)
1059 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1062 // correct the parameter in case this dc does not have a mask at all
1064 if ( useMask
&& !source
->m_macMask
)
1067 Rect srcrect
, dstrect
;
1068 srcrect
.top
= source
->YLOG2DEVMAC(ysrc
) ;
1069 srcrect
.left
= source
->XLOG2DEVMAC(xsrc
) ;
1070 srcrect
.right
= source
->XLOG2DEVMAC(xsrc
+ width
) ;
1071 srcrect
.bottom
= source
->YLOG2DEVMAC(ysrc
+ height
) ;
1072 dstrect
.top
= YLOG2DEVMAC(ydest
) ;
1073 dstrect
.left
= XLOG2DEVMAC(xdest
) ;
1074 dstrect
.bottom
= YLOG2DEVMAC(ydest
+ height
) ;
1075 dstrect
.right
= XLOG2DEVMAC(xdest
+ width
) ;
1077 short mode
= kUnsupportedMode
;
1078 bool invertDestinationFirst
= false ;
1079 switch ( logical_func
)
1081 case wxAND
: // src AND dst
1082 mode
= srcOr
; // ok
1084 case wxAND_INVERT
: // (NOT src) AND dst
1085 mode
= notSrcOr
; // ok
1087 case wxAND_REVERSE
:// src AND (NOT dst)
1088 invertDestinationFirst
= true ;
1092 mode
= kEmulatedMode
;
1095 mode
= srcCopy
; // ok
1097 case wxEQUIV
: // (NOT src) XOR dst
1098 mode
= srcXor
; // ok
1100 case wxINVERT
: // NOT dst
1101 mode
= kEmulatedMode
; //or hilite ;
1103 case wxNAND
: // (NOT src) OR (NOT dst)
1104 invertDestinationFirst
= true ;
1107 case wxNOR
: // (NOT src) AND (NOT dst)
1108 invertDestinationFirst
= true ;
1111 case wxNO_OP
: // dst
1112 mode
= kEmulatedMode
; // this has already been handled upon entry
1114 case wxOR
: // src OR dst
1117 case wxOR_INVERT
: // (NOT src) OR dst
1120 case wxOR_REVERSE
: // src OR (NOT dst)
1121 invertDestinationFirst
= true ;
1125 mode
= kEmulatedMode
;
1127 case wxSRC_INVERT
: // (NOT src)
1128 mode
= notSrcCopy
; // ok
1130 case wxXOR
: // src XOR dst
1131 mode
= notSrcXor
; // ok
1139 if ( mode
== kUnsupportedMode
)
1141 wxFAIL_MSG("unsupported blitting mode" )
1145 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
1146 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
1147 if ( LockPixels(bmappixels
) )
1149 wxMacPortSetter
helper(this) ;
1150 RGBColor tempColor
;
1152 if ( source
->GetDepth() == 1 )
1154 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ;
1155 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ;
1159 // the modes need this, otherwise we'll end up having really nice colors...
1160 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
1161 RGBColor black
= { 0,0,0} ;
1162 RGBForeColor( &black
) ;
1163 RGBBackColor( &white
) ;
1166 if ( useMask
&& source
->m_macMask
)
1168 if ( mode
== srcCopy
)
1170 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) )
1172 CopyMask( GetPortBitMapForCopyBits( sourcePort
) ,
1173 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) ,
1174 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1175 &srcrect
, &srcrect
, &dstrect
) ;
1176 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1181 RgnHandle clipRgn
= NewRgn() ;
1182 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1183 BitMapToRegion( clipRgn
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1184 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ;
1185 OffsetRgn( clipRgn
, -srcrect
.left
+ dstrect
.left
, -srcrect
.top
+ dstrect
.top
) ;
1186 if ( mode
== kEmulatedMode
)
1189 ::PenPat(GetQDGlobalsBlack(&pat
));
1190 if ( logical_func
== wxSET
)
1192 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1193 ::RGBForeColor( &col
) ;
1194 ::PaintRgn( clipRgn
) ;
1196 else if ( logical_func
== wxCLEAR
)
1198 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1199 ::RGBForeColor( &col
) ;
1200 ::PaintRgn( clipRgn
) ;
1202 else if ( logical_func
== wxINVERT
)
1204 MacInvertRgn( clipRgn
) ;
1208 for ( int y
= 0 ; y
< srcrect
.right
- srcrect
.left
; ++y
)
1210 for ( int x
= 0 ; x
< srcrect
.bottom
- srcrect
.top
; ++x
)
1212 Point dstPoint
= { dstrect
.top
+ y
, dstrect
.left
+ x
} ;
1213 Point srcPoint
= { srcrect
.top
+ y
, srcrect
.left
+ x
} ;
1214 if ( PtInRgn( dstPoint
, clipRgn
) )
1219 SetPort( (GrafPtr
) sourcePort
) ;
1220 GetCPixel( srcPoint
.h
, srcPoint
.v
, &srcColor
) ;
1221 SetPort( (GrafPtr
) m_macPort
) ;
1222 GetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1224 wxMacCalculateColour( logical_func
, srcColor
, dstColor
) ;
1225 SetCPixel( dstPoint
.h
, dstPoint
.v
, &dstColor
) ;
1229 // wxFAIL_MSG("unimplemented emulated mode") ;
1234 if ( invertDestinationFirst
)
1236 MacInvertRgn( clipRgn
) ;
1238 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1239 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1240 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1242 DisposeRgn( clipRgn
) ;
1247 if ( mode
== kEmulatedMode
)
1249 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1250 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1251 &srcrect
, &dstrect
, mode
, NULL
) ;
1256 ::PenPat(GetQDGlobalsBlack(&pat
));
1257 if ( logical_func
== wxSET
)
1259 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1260 ::RGBForeColor( &col
) ;
1264 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1265 ::RGBForeColor( &col
) ;
1267 ::PaintRect( &dstrect
) ;
1270 UnlockPixels( bmappixels
) ;
1273 m_macPenInstalled
= false ;
1274 m_macBrushInstalled
= false ;
1275 m_macFontInstalled
= false ;
1280 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1283 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1287 DrawText(text
, x
, y
);
1293 // the size of the text
1295 GetTextExtent(text
, &w
, &h
);
1297 // draw the string normally
1300 dc
.SelectObject(src
);
1301 dc
.SetFont(GetFont());
1302 dc
.SetBackground(*wxWHITE_BRUSH
);
1303 dc
.SetBrush(*wxBLACK_BRUSH
);
1305 dc
.DrawText(text
, 0, 0);
1306 dc
.SetFont(wxNullFont
);
1307 dc
.SelectObject(wxNullBitmap
);
1309 wxMacPortSetter
helper(this) ;
1311 // Calculate the size of the rotated bounding box.
1312 double rad
= DegToRad(angle
);
1313 double dx
= cos(rad
);
1314 double dy
= sin(rad
);
1316 // the rectngle vertices are counted clockwise with the first one being at
1317 // (0, 0) (or, rather, at (x, y))
1319 double y2
= -w
* dy
; // y axis points to the bottom, hence minus
1322 double x3
= x4
+ x2
;
1323 double y3
= y4
+ y2
;
1326 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5);
1327 wxCoord maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5);
1328 wxCoord minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5);
1329 wxCoord minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1331 // prepare to blit-with-rotate the bitmap to the DC
1334 RGBColor colText
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() );
1335 RGBColor colBack
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel() );
1337 unsigned char *data
= image
.GetData();
1340 double r
, angleOrig
;
1343 // paint pixel by pixel
1344 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1346 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1348 // transform source coords to dest coords
1349 r
= sqrt( (double)(srcX
* srcX
+ srcY
* srcY
) );
1350 angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1351 dstX
= (wxCoord
)(r
* cos(angleOrig
) + 0.5);
1352 dstY
= (wxCoord
)(r
* sin(angleOrig
) + 0.5);
1355 textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1356 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1358 SetCPixel(XLOG2DEVMAC(x
+ dstX
), YLOG2DEVMAC(y
+ dstY
),
1359 textPixel
? &colText
: &colBack
);
1364 // it would be better to draw with non underlined font and draw the line
1365 // manually here (it would be more straight...)
1367 if ( m_font
.GetUnderlined() )
1369 ::MoveTo(XLOG2DEVMAC(x
+ x4
), YLOG2DEVMAC(y
+ y4
+ font
->descent
));
1370 ::LineTo(XLOG2DEVMAC(x
+ x3
), YLOG2DEVMAC(y
+ y3
+ font
->descent
));
1374 // update the bounding box
1375 CalcBoundingBox(x
+ minX
, y
+ minY
);
1376 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1378 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1380 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1381 wxMacPortSetter
helper(this) ;
1383 long xx
= XLOG2DEVMAC(x
);
1384 long yy
= YLOG2DEVMAC(y
);
1386 // if (m_pen.GetStyle() != wxTRANSPARENT)
1390 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1392 ::ClipRect( &clip ) ;
1396 ::GetFontInfo( &fi
) ;
1399 ::MoveTo( xx
, yy
);
1400 if ( m_backgroundMode
== wxTRANSPARENT
)
1402 ::TextMode( srcOr
) ;
1406 ::TextMode( srcCopy
) ;
1409 const char *text
= NULL
;
1413 if ( wxApp::s_macDefaultEncodingIsPC
)
1415 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1417 length
= macText
.Length() ;
1422 length
= strtext
.Length() ;
1431 if( text
[i
] == 13 || text
[i
] == 10)
1433 ::DrawText( text
, laststop
, i
- laststop
) ;
1435 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1441 ::DrawText( text
, laststop
, i
- laststop
) ;
1442 ::TextMode( srcOr
) ;
1446 bool wxDC::CanGetTextExtent() const
1448 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1453 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1454 wxCoord
*descent
, wxCoord
*externalLeading
,
1455 wxFont
*theFont
) const
1457 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1458 wxMacPortSetter
helper(this) ;
1460 wxFont formerFont
= m_font
;
1464 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1468 ::TextFont( font
->m_macFontNum
) ;
1469 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1470 ::TextFace( font
->m_macFontStyle
) ;
1479 ::GetFontInfo( &fi
) ;
1482 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1484 *descent
=YDEV2LOGREL( fi
.descent
);
1485 if ( externalLeading
)
1486 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1488 const char *text
= NULL
;
1491 if ( wxApp::s_macDefaultEncodingIsPC
)
1493 macText
= wxMacMakeMacStringFromPC( string
) ;
1495 length
= macText
.Length() ;
1500 length
= string
.Length() ;
1512 if( text
[i
] == 13 || text
[i
] == 10)
1515 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1516 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1517 if ( curwidth
> *width
)
1518 *width
= XDEV2LOGREL( curwidth
) ;
1524 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1525 if ( curwidth
> *width
)
1526 *width
= XDEV2LOGREL( curwidth
) ;
1531 m_macFontInstalled
= false ;
1535 wxCoord
wxDC::GetCharWidth(void) const
1537 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1539 wxMacPortSetter
helper(this) ;
1543 int width
= ::TextWidth( "n" , 0 , 1 ) ;
1545 return YDEV2LOGREL(width
) ;
1548 wxCoord
wxDC::GetCharHeight(void) const
1550 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1552 wxMacPortSetter
helper(this) ;
1557 ::GetFontInfo( &fi
) ;
1559 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1562 void wxDC::Clear(void)
1564 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1565 wxMacPortSetter
helper(this) ;
1566 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1568 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1570 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1572 ::EraseRect( &rect
) ;
1576 void wxDC::MacInstallFont() const
1578 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1579 // if ( m_macFontInstalled )
1581 Pattern blackColor
;
1583 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1587 ::TextFont( font
->m_macFontNum
) ;
1588 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1589 ::TextFace( font
->m_macFontStyle
) ;
1591 m_macFontInstalled
= true ;
1592 m_macBrushInstalled
= false ;
1593 m_macPenInstalled
= false ;
1595 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1596 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1597 ::RGBForeColor( &forecolor
);
1598 ::RGBBackColor( &backcolor
);
1604 GetFNum( "\pGeneva" , &fontnum
) ;
1605 ::TextFont( fontnum
) ;
1606 ::TextSize( short(m_scaleY
* 10) ) ;
1609 // todo reset after spacing changes - or store the current spacing somewhere
1611 m_macFontInstalled
= true ;
1612 m_macBrushInstalled
= false ;
1613 m_macPenInstalled
= false ;
1615 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1616 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1617 ::RGBForeColor( &forecolor
);
1618 ::RGBBackColor( &backcolor
);
1621 short mode
= patCopy
;
1625 switch( m_logicalFunction
)
1630 case wxINVERT
: // NOT dst
1631 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1634 case wxXOR
: // src XOR dst
1637 case wxOR_REVERSE
: // src OR (NOT dst)
1640 case wxSRC_INVERT
: // (NOT src)
1647 case wxAND_REVERSE
:// src AND (NOT dst)
1648 case wxAND
: // src AND dst
1649 case wxAND_INVERT
: // (NOT src) AND dst
1650 case wxNO_OP
: // dst
1651 case wxNOR
: // (NOT src) AND (NOT dst)
1652 case wxEQUIV
: // (NOT src) XOR dst
1653 case wxOR_INVERT
: // (NOT src) OR dst
1654 case wxNAND
: // (NOT src) OR (NOT dst)
1655 case wxOR
: // src OR dst
1657 // case wxSRC_OR: // source _bitmap_ OR destination
1658 // case wxSRC_AND: // source _bitmap_ AND destination
1664 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1666 // we have our own pattern list now
1667 int thePatListID
= 128;
1671 case wxBDIAGONAL_HATCH
:
1674 case wxFDIAGONAL_HATCH
:
1680 case wxHORIZONTAL_HATCH
:
1683 case wxVERTICAL_HATCH
:
1686 case wxCROSSDIAG_HATCH
:
1690 theIndex
= 1; // solid pattern
1693 GetIndPattern( pattern
, thePatListID
, theIndex
);
1696 void wxDC::MacInstallPen() const
1698 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1702 // if ( m_macPenInstalled )
1705 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1706 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1707 ::RGBForeColor( &forecolor
);
1708 ::RGBBackColor( &backcolor
);
1711 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1713 // null means only one pixel, at whatever resolution
1714 if ( penWidth
== 0 )
1716 ::PenSize(penWidth
, penWidth
);
1718 int penStyle
= m_pen
.GetStyle();
1720 if (penStyle
== wxSOLID
)
1722 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1724 else if (IS_HATCH(penStyle
))
1727 wxMacGetHatchPattern(penStyle
, &pat
);
1732 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1736 for ( int i
= 0 ; i
< 8 ; ++i
)
1742 for ( int i
= 0 ; i
< 8 ; ++i
)
1748 for ( int i
= 0 ; i
< 8 ; ++i
)
1754 for ( int i
= 0 ; i
< 8 ; ++i
)
1762 int number
= m_pen
.GetDashes(&dash
) ;
1763 // right now we don't allocate larger pixmaps
1764 for ( int i
= 0 ; i
< 8 ; ++i
)
1766 pat
.pat
[i
] = dash
[0] ;
1774 short mode
= patCopy
;
1778 switch( m_logicalFunction
)
1780 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1783 case wxINVERT
: // NOT dst
1784 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1787 case wxXOR
: // src XOR dst
1790 case wxOR_REVERSE
: // src OR (NOT dst)
1793 case wxSRC_INVERT
: // (NOT src)
1800 case wxAND_REVERSE
:// src AND (NOT dst)
1801 case wxAND
: // src AND dst
1802 case wxAND_INVERT
: // (NOT src) AND dst
1803 case wxNO_OP
: // dst
1804 case wxNOR
: // (NOT src) AND (NOT dst)
1805 case wxEQUIV
: // (NOT src) XOR dst
1806 case wxOR_INVERT
: // (NOT src) OR dst
1807 case wxNAND
: // (NOT src) OR (NOT dst)
1808 case wxOR
: // src OR dst
1810 // case wxSRC_OR: // source _bitmap_ OR destination
1811 // case wxSRC_AND: // source _bitmap_ AND destination
1815 m_macPenInstalled
= true ;
1816 m_macBrushInstalled
= false ;
1817 m_macFontInstalled
= false ;
1820 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1822 Pattern whiteColor
;
1823 switch( background
.MacGetBrushKind() )
1825 case kwxMacBrushTheme
:
1827 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1830 case kwxMacBrushThemeBackground
:
1833 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1834 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1837 case kwxMacBrushColour
:
1839 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1840 int brushStyle
= background
.GetStyle();
1841 if (brushStyle
== wxSOLID
)
1842 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1843 else if (IS_HATCH(brushStyle
))
1846 wxMacGetHatchPattern(brushStyle
, &pat
);
1851 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1858 void wxDC::MacInstallBrush() const
1860 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1862 Pattern blackColor
;
1863 // if ( m_macBrushInstalled )
1868 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1870 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1872 int brushStyle
= m_brush
.GetStyle();
1873 if (brushStyle
== wxSOLID
)
1874 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1875 else if (IS_HATCH(brushStyle
))
1878 wxMacGetHatchPattern(brushStyle
, &pat
);
1881 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1883 // we force this in order to be compliant with wxMSW
1884 backgroundTransparent
= false ;
1885 // for these the text fore (and back for MASK_OPAQUE) colors are used
1886 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1887 int width
= bitmap
->GetWidth() ;
1888 int height
= bitmap
->GetHeight() ;
1889 GWorldPtr gw
= NULL
;
1891 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1892 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1894 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1896 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
1897 LockPixels( gwpixmaphandle
) ;
1899 bool isMonochrome
= !IsPortColor( gw
) ;
1901 if ( !isMonochrome
)
1903 if ( (**gwpixmaphandle
).pixelSize
== 1 )
1904 isMonochrome
= true ;
1910 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
1912 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
1913 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
1914 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
1916 if( width
== 8 && height
== 8 )
1919 for ( int i
= 0 ; i
< 8 ; ++i
)
1921 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
1923 UnlockPixels( GetGWorldPixMap( gw
) ) ;
1928 #if wxMAC_EXPERIMENTAL_PATTERN
1929 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
1930 // caching scheme before putting this into production
1933 PixPatHandle pixpat
= NewPixPat() ;
1935 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
1936 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
1937 ((**(**pixpat
).patMap
).bounds
.bottom
-
1938 (**(**pixpat
).patMap
).bounds
.top
);
1940 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
1941 (**pixpat
).patData
= image
;
1942 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
1943 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
1944 if ( ctspec
[0].rgb
.red
== 0x0000 )
1946 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1947 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1951 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1952 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1954 ::CTabChanged( ctable
) ;
1955 ::PenPixPat(pixpat
);
1962 UnlockPixels( gwpixmaphandle
) ;
1966 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1969 if ( !backgroundTransparent
)
1970 ::RGBBackColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ) ;
1972 short mode
= patCopy
;
1973 switch( m_logicalFunction
)
1976 if ( backgroundTransparent
)
1981 case wxINVERT
: // NOT dst
1982 if ( !backgroundTransparent
)
1984 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1988 case wxXOR
: // src XOR dst
1991 case wxOR_REVERSE
: // src OR (NOT dst)
1994 case wxSRC_INVERT
: // (NOT src)
2001 case wxAND_REVERSE
:// src AND (NOT dst)
2002 case wxAND
: // src AND dst
2003 case wxAND_INVERT
: // (NOT src) AND dst
2004 case wxNO_OP
: // dst
2005 case wxNOR
: // (NOT src) AND (NOT dst)
2006 case wxEQUIV
: // (NOT src) XOR dst
2007 case wxOR_INVERT
: // (NOT src) OR dst
2008 case wxNAND
: // (NOT src) OR (NOT dst)
2009 case wxOR
: // src OR dst
2011 // case wxSRC_OR: // source _bitmap_ OR destination
2012 // case wxSRC_AND: // source _bitmap_ AND destination
2016 m_macBrushInstalled
= true ;
2017 m_macPenInstalled
= false ;
2018 m_macFontInstalled
= false ;
2021 // ---------------------------------------------------------------------------
2022 // coordinates transformations
2023 // ---------------------------------------------------------------------------
2026 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2028 return ((wxDC
*)this)->XDEV2LOG(x
);
2031 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2033 return ((wxDC
*)this)->YDEV2LOG(y
);
2036 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2038 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2041 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2043 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2046 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2048 return ((wxDC
*)this)->XLOG2DEV(x
);
2051 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2053 return ((wxDC
*)this)->YLOG2DEV(y
);
2056 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2058 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2061 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2063 return ((wxDC
*)this)->YLOG2DEVREL(y
);