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
) ;
1232 // wxFAIL_MSG("unimplemented emulated mode") ;
1237 if ( invertDestinationFirst
)
1239 MacInvertRgn( clipRgn
) ;
1241 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1242 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1243 &srcrect
, &dstrect
, mode
, clipRgn
) ;
1245 DisposeRgn( clipRgn
) ;
1250 if ( mode
== kEmulatedMode
)
1252 CopyBits( GetPortBitMapForCopyBits( sourcePort
) ,
1253 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) ,
1254 &srcrect
, &dstrect
, mode
, NULL
) ;
1259 ::PenPat(GetQDGlobalsBlack(&pat
));
1260 if ( logical_func
== wxSET
)
1262 RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1263 ::RGBForeColor( &col
) ;
1267 RGBColor col
= { 0x0000, 0x0000, 0x0000 } ;
1268 ::RGBForeColor( &col
) ;
1270 ::PaintRect( &dstrect
) ;
1273 UnlockPixels( bmappixels
) ;
1276 m_macPenInstalled
= false ;
1277 m_macBrushInstalled
= false ;
1278 m_macFontInstalled
= false ;
1283 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1286 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1290 DrawText(text
, x
, y
);
1296 // the size of the text
1298 GetTextExtent(text
, &w
, &h
);
1300 // draw the string normally
1303 dc
.SelectObject(src
);
1304 dc
.SetFont(GetFont());
1305 dc
.SetBackground(*wxWHITE_BRUSH
);
1306 dc
.SetBrush(*wxBLACK_BRUSH
);
1308 dc
.DrawText(text
, 0, 0);
1309 dc
.SetFont(wxNullFont
);
1310 dc
.SelectObject(wxNullBitmap
);
1312 wxMacPortSetter
helper(this) ;
1314 // Calculate the size of the rotated bounding box.
1315 double rad
= DegToRad(angle
);
1316 double dx
= cos(rad
);
1317 double dy
= sin(rad
);
1319 // the rectngle vertices are counted clockwise with the first one being at
1320 // (0, 0) (or, rather, at (x, y))
1322 double y2
= -w
* dy
; // y axis points to the bottom, hence minus
1325 double x3
= x4
+ x2
;
1326 double y3
= y4
+ y2
;
1329 wxCoord maxX
= (wxCoord
)(dmax(x2
, dmax(x3
, x4
)) + 0.5);
1330 wxCoord maxY
= (wxCoord
)(dmax(y2
, dmax(y3
, y4
)) + 0.5);
1331 wxCoord minX
= (wxCoord
)(dmin(x2
, dmin(x3
, x4
)) - 0.5);
1332 wxCoord minY
= (wxCoord
)(dmin(y2
, dmin(y3
, y4
)) - 0.5);
1334 // prepare to blit-with-rotate the bitmap to the DC
1337 RGBColor colText
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel() );
1338 RGBColor colBack
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel() );
1340 unsigned char *data
= image
.GetData();
1343 double r
, angleOrig
;
1346 // paint pixel by pixel
1347 for ( wxCoord srcX
= 0; srcX
< w
; srcX
++ )
1349 for ( wxCoord srcY
= 0; srcY
< h
; srcY
++ )
1351 // transform source coords to dest coords
1352 r
= sqrt( (double)(srcX
* srcX
+ srcY
* srcY
) );
1353 angleOrig
= atan2((double)srcY
, (double)srcX
) - rad
;
1354 dstX
= (wxCoord
)(r
* cos(angleOrig
) + 0.5);
1355 dstY
= (wxCoord
)(r
* sin(angleOrig
) + 0.5);
1358 textPixel
= data
[(srcY
*w
+ srcX
)*3] == 0;
1359 if ( textPixel
|| (m_backgroundMode
== wxSOLID
) )
1361 SetCPixel(XLOG2DEVMAC(x
+ dstX
), YLOG2DEVMAC(y
+ dstY
),
1362 textPixel
? &colText
: &colBack
);
1367 // it would be better to draw with non underlined font and draw the line
1368 // manually here (it would be more straight...)
1370 if ( m_font
.GetUnderlined() )
1372 ::MoveTo(XLOG2DEVMAC(x
+ x4
), YLOG2DEVMAC(y
+ y4
+ font
->descent
));
1373 ::LineTo(XLOG2DEVMAC(x
+ x3
), YLOG2DEVMAC(y
+ y3
+ font
->descent
));
1377 // update the bounding box
1378 CalcBoundingBox(x
+ minX
, y
+ minY
);
1379 CalcBoundingBox(x
+ maxX
, y
+ maxY
);
1381 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1383 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1384 wxMacPortSetter
helper(this) ;
1386 long xx
= XLOG2DEVMAC(x
);
1387 long yy
= YLOG2DEVMAC(y
);
1389 // if (m_pen.GetStyle() != wxTRANSPARENT)
1393 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1395 ::ClipRect( &clip ) ;
1399 ::GetFontInfo( &fi
) ;
1402 ::MoveTo( xx
, yy
);
1403 if ( m_backgroundMode
== wxTRANSPARENT
)
1405 ::TextMode( srcOr
) ;
1409 ::TextMode( srcCopy
) ;
1412 const char *text
= NULL
;
1416 if ( wxApp::s_macDefaultEncodingIsPC
)
1418 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1420 length
= macText
.Length() ;
1425 length
= strtext
.Length() ;
1434 if( text
[i
] == 13 || text
[i
] == 10)
1436 ::DrawText( text
, laststop
, i
- laststop
) ;
1438 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1444 ::DrawText( text
, laststop
, i
- laststop
) ;
1445 ::TextMode( srcOr
) ;
1449 bool wxDC::CanGetTextExtent() const
1451 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1456 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1457 wxCoord
*descent
, wxCoord
*externalLeading
,
1458 wxFont
*theFont
) const
1460 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1461 wxMacPortSetter
helper(this) ;
1463 wxFont formerFont
= m_font
;
1467 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1471 ::TextFont( font
->m_macFontNum
) ;
1472 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1473 ::TextFace( font
->m_macFontStyle
) ;
1482 ::GetFontInfo( &fi
) ;
1485 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1487 *descent
=YDEV2LOGREL( fi
.descent
);
1488 if ( externalLeading
)
1489 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1491 const char *text
= NULL
;
1494 if ( wxApp::s_macDefaultEncodingIsPC
)
1496 macText
= wxMacMakeMacStringFromPC( string
) ;
1498 length
= macText
.Length() ;
1503 length
= string
.Length() ;
1515 if( text
[i
] == 13 || text
[i
] == 10)
1518 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1519 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1520 if ( curwidth
> *width
)
1521 *width
= XDEV2LOGREL( curwidth
) ;
1527 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1528 if ( curwidth
> *width
)
1529 *width
= XDEV2LOGREL( curwidth
) ;
1534 m_macFontInstalled
= false ;
1538 wxCoord
wxDC::GetCharWidth(void) const
1540 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1542 wxMacPortSetter
helper(this) ;
1546 int width
= ::TextWidth( "n" , 0 , 1 ) ;
1548 return YDEV2LOGREL(width
) ;
1551 wxCoord
wxDC::GetCharHeight(void) const
1553 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1555 wxMacPortSetter
helper(this) ;
1560 ::GetFontInfo( &fi
) ;
1562 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1565 void wxDC::Clear(void)
1567 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1568 wxMacPortSetter
helper(this) ;
1569 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1571 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1573 MacSetupBackgroundForCurrentPort( m_backgroundBrush
) ;
1575 ::EraseRect( &rect
) ;
1579 void wxDC::MacInstallFont() const
1581 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1582 // if ( m_macFontInstalled )
1584 Pattern blackColor
;
1586 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1590 ::TextFont( font
->m_macFontNum
) ;
1591 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1592 ::TextFace( font
->m_macFontStyle
) ;
1594 m_macFontInstalled
= true ;
1595 m_macBrushInstalled
= false ;
1596 m_macPenInstalled
= false ;
1598 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1599 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1600 ::RGBForeColor( &forecolor
);
1601 ::RGBBackColor( &backcolor
);
1607 GetFNum( "\pGeneva" , &fontnum
) ;
1608 ::TextFont( fontnum
) ;
1609 ::TextSize( short(m_scaleY
* 10) ) ;
1612 // todo reset after spacing changes - or store the current spacing somewhere
1614 m_macFontInstalled
= true ;
1615 m_macBrushInstalled
= false ;
1616 m_macPenInstalled
= false ;
1618 RGBColor forecolor
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel());
1619 RGBColor backcolor
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel());
1620 ::RGBForeColor( &forecolor
);
1621 ::RGBBackColor( &backcolor
);
1624 short mode
= patCopy
;
1628 switch( m_logicalFunction
)
1633 case wxINVERT
: // NOT dst
1634 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1637 case wxXOR
: // src XOR dst
1640 case wxOR_REVERSE
: // src OR (NOT dst)
1643 case wxSRC_INVERT
: // (NOT src)
1650 case wxAND_REVERSE
:// src AND (NOT dst)
1651 case wxAND
: // src AND dst
1652 case wxAND_INVERT
: // (NOT src) AND dst
1653 case wxNO_OP
: // dst
1654 case wxNOR
: // (NOT src) AND (NOT dst)
1655 case wxEQUIV
: // (NOT src) XOR dst
1656 case wxOR_INVERT
: // (NOT src) OR dst
1657 case wxNAND
: // (NOT src) OR (NOT dst)
1658 case wxOR
: // src OR dst
1660 // case wxSRC_OR: // source _bitmap_ OR destination
1661 // case wxSRC_AND: // source _bitmap_ AND destination
1667 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1669 // we have our own pattern list now
1670 int thePatListID
= 128;
1674 case wxBDIAGONAL_HATCH
:
1677 case wxFDIAGONAL_HATCH
:
1683 case wxHORIZONTAL_HATCH
:
1686 case wxVERTICAL_HATCH
:
1689 case wxCROSSDIAG_HATCH
:
1693 theIndex
= 1; // solid pattern
1696 GetIndPattern( pattern
, thePatListID
, theIndex
);
1699 void wxDC::MacInstallPen() const
1701 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1705 // if ( m_macPenInstalled )
1708 RGBColor forecolor
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel());
1709 RGBColor backcolor
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel());
1710 ::RGBForeColor( &forecolor
);
1711 ::RGBBackColor( &backcolor
);
1714 int penWidth
= m_pen
.GetWidth() * (int) m_scaleX
;
1716 // null means only one pixel, at whatever resolution
1717 if ( penWidth
== 0 )
1719 ::PenSize(penWidth
, penWidth
);
1721 int penStyle
= m_pen
.GetStyle();
1723 if (penStyle
== wxSOLID
)
1725 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1727 else if (IS_HATCH(penStyle
))
1730 wxMacGetHatchPattern(penStyle
, &pat
);
1735 Pattern pat
= *GetQDGlobalsBlack(&blackColor
) ;
1739 for ( int i
= 0 ; i
< 8 ; ++i
)
1745 for ( int i
= 0 ; i
< 8 ; ++i
)
1751 for ( int i
= 0 ; i
< 8 ; ++i
)
1757 for ( int i
= 0 ; i
< 8 ; ++i
)
1765 int number
= m_pen
.GetDashes(&dash
) ;
1766 // right now we don't allocate larger pixmaps
1767 for ( int i
= 0 ; i
< 8 ; ++i
)
1769 pat
.pat
[i
] = dash
[0] ;
1777 short mode
= patCopy
;
1781 switch( m_logicalFunction
)
1783 case wxCOPY
: // only foreground color, leave background (thus not patCopy)
1786 case wxINVERT
: // NOT dst
1787 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1790 case wxXOR
: // src XOR dst
1793 case wxOR_REVERSE
: // src OR (NOT dst)
1796 case wxSRC_INVERT
: // (NOT src)
1803 case wxAND_REVERSE
:// src AND (NOT dst)
1804 case wxAND
: // src AND dst
1805 case wxAND_INVERT
: // (NOT src) AND dst
1806 case wxNO_OP
: // dst
1807 case wxNOR
: // (NOT src) AND (NOT dst)
1808 case wxEQUIV
: // (NOT src) XOR dst
1809 case wxOR_INVERT
: // (NOT src) OR dst
1810 case wxNAND
: // (NOT src) OR (NOT dst)
1811 case wxOR
: // src OR dst
1813 // case wxSRC_OR: // source _bitmap_ OR destination
1814 // case wxSRC_AND: // source _bitmap_ AND destination
1818 m_macPenInstalled
= true ;
1819 m_macBrushInstalled
= false ;
1820 m_macFontInstalled
= false ;
1823 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background
)
1825 Pattern whiteColor
;
1826 switch( background
.MacGetBrushKind() )
1828 case kwxMacBrushTheme
:
1830 ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ;
1833 case kwxMacBrushThemeBackground
:
1836 ThemeBackgroundKind bg
= background
.GetMacThemeBackground( &extent
) ;
1837 ::ApplyThemeBackground( bg
, &extent
,kThemeStateActive
, wxDisplayDepth() , true ) ;
1840 case kwxMacBrushColour
:
1842 ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) );
1843 int brushStyle
= background
.GetStyle();
1844 if (brushStyle
== wxSOLID
)
1845 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1846 else if (IS_HATCH(brushStyle
))
1849 wxMacGetHatchPattern(brushStyle
, &pat
);
1854 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1861 void wxDC::MacInstallBrush() const
1863 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1865 Pattern blackColor
;
1866 // if ( m_macBrushInstalled )
1871 bool backgroundTransparent
= (GetBackgroundMode() == wxTRANSPARENT
) ;
1873 ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) );
1875 int brushStyle
= m_brush
.GetStyle();
1876 if (brushStyle
== wxSOLID
)
1877 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1878 else if (IS_HATCH(brushStyle
))
1881 wxMacGetHatchPattern(brushStyle
, &pat
);
1884 else if ( m_brush
.GetStyle() == wxSTIPPLE
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1886 // we force this in order to be compliant with wxMSW
1887 backgroundTransparent
= false ;
1888 // for these the text fore (and back for MASK_OPAQUE) colors are used
1889 wxBitmap
* bitmap
= m_brush
.GetStipple() ;
1890 int width
= bitmap
->GetWidth() ;
1891 int height
= bitmap
->GetHeight() ;
1892 GWorldPtr gw
= NULL
;
1894 if ( m_brush
.GetStyle() == wxSTIPPLE
)
1895 gw
= MAC_WXHBITMAP(bitmap
->GetHBITMAP()) ;
1897 gw
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ;
1899 PixMapHandle gwpixmaphandle
= GetGWorldPixMap( gw
) ;
1900 LockPixels( gwpixmaphandle
) ;
1902 bool isMonochrome
= !IsPortColor( gw
) ;
1904 if ( !isMonochrome
)
1906 if ( (**gwpixmaphandle
).pixelSize
== 1 )
1907 isMonochrome
= true ;
1913 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) );
1915 BitMap
* gwbitmap
= (BitMap
*) *gwpixmaphandle
; // since the color depth is 1 it is a BitMap
1916 UInt8
*gwbits
= (UInt8
*) gwbitmap
->baseAddr
;
1917 int alignment
= gwbitmap
->rowBytes
& 0x7FFF ;
1919 if( width
== 8 && height
== 8 )
1922 for ( int i
= 0 ; i
< 8 ; ++i
)
1924 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ;
1926 UnlockPixels( GetGWorldPixMap( gw
) ) ;
1931 #if wxMAC_EXPERIMENTAL_PATTERN
1932 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
1933 // caching scheme before putting this into production
1936 PixPatHandle pixpat
= NewPixPat() ;
1938 CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
);
1939 imageSize
= GetPixRowBytes((**pixpat
).patMap
) *
1940 ((**(**pixpat
).patMap
).bounds
.bottom
-
1941 (**(**pixpat
).patMap
).bounds
.top
);
1943 PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize
);
1944 (**pixpat
).patData
= image
;
1945 CTabHandle ctable
= ((**((**pixpat
).patMap
)).pmTable
) ;
1946 ColorSpecPtr ctspec
= (ColorSpecPtr
) &(**ctable
).ctTable
;
1947 if ( ctspec
[0].rgb
.red
== 0x0000 )
1949 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1950 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1954 ctspec
[0].rgb
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ;
1955 ctspec
[1].rgb
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ;
1957 ::CTabChanged( ctable
) ;
1958 ::PenPixPat(pixpat
);
1965 UnlockPixels( gwpixmaphandle
) ;
1969 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1972 if ( !backgroundTransparent
)
1973 ::RGBBackColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ) ;
1975 short mode
= patCopy
;
1976 switch( m_logicalFunction
)
1979 if ( backgroundTransparent
)
1984 case wxINVERT
: // NOT dst
1985 if ( !backgroundTransparent
)
1987 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1991 case wxXOR
: // src XOR dst
1994 case wxOR_REVERSE
: // src OR (NOT dst)
1997 case wxSRC_INVERT
: // (NOT src)
2004 case wxAND_REVERSE
:// src AND (NOT dst)
2005 case wxAND
: // src AND dst
2006 case wxAND_INVERT
: // (NOT src) AND dst
2007 case wxNO_OP
: // dst
2008 case wxNOR
: // (NOT src) AND (NOT dst)
2009 case wxEQUIV
: // (NOT src) XOR dst
2010 case wxOR_INVERT
: // (NOT src) OR dst
2011 case wxNAND
: // (NOT src) OR (NOT dst)
2012 case wxOR
: // src OR dst
2014 // case wxSRC_OR: // source _bitmap_ OR destination
2015 // case wxSRC_AND: // source _bitmap_ AND destination
2019 m_macBrushInstalled
= true ;
2020 m_macPenInstalled
= false ;
2021 m_macFontInstalled
= false ;
2024 // ---------------------------------------------------------------------------
2025 // coordinates transformations
2026 // ---------------------------------------------------------------------------
2029 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
2031 return ((wxDC
*)this)->XDEV2LOG(x
);
2034 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
2036 return ((wxDC
*)this)->YDEV2LOG(y
);
2039 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
2041 return ((wxDC
*)this)->XDEV2LOGREL(x
);
2044 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
2046 return ((wxDC
*)this)->YDEV2LOGREL(y
);
2049 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
2051 return ((wxDC
*)this)->XLOG2DEV(x
);
2054 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
2056 return ((wxDC
*)this)->YLOG2DEV(y
);
2059 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
2061 return ((wxDC
*)this)->XLOG2DEVREL(x
);
2064 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
2066 return ((wxDC
*)this)->YLOG2DEVREL(y
);