1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
17 #include "wx/mac/uma.h"
23 #if !USE_SHARED_LIBRARY
24 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 #define mm2inches 0.0393700787402
32 #define inches2mm 25.4
33 #define mm2twips 56.6929133859
34 #define twips2mm 0.0176388888889
35 #define mm2pt 2.83464566929
36 #define pt2mm 0.352777777778
38 long wxDC::m_macCurrentPortId
= 1 ;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
48 m_autoSetting
= FALSE
;
52 m_mm_to_pix_x
= mm2pt
;
53 m_mm_to_pix_y
= mm2pt
;
59 m_internalDeviceOriginX
= 0;
60 m_internalDeviceOriginY
= 0;
61 m_externalDeviceOriginX
= 0;
62 m_externalDeviceOriginY
= 0;
64 m_logicalScaleX
= 1.0;
65 m_logicalScaleY
= 1.0;
71 m_mappingMode
= wxMM_TEXT
;
72 m_needComputeScaleX
= FALSE
;
73 m_needComputeScaleY
= FALSE
;
75 m_signX
= 1; // default x-axis left to right
76 m_signY
= 1; // default y-axis top down
78 m_maxX
= m_maxY
= -100000;
79 m_minY
= m_minY
= 100000;
81 m_logicalFunction
= wxCOPY
;
82 // m_textAlignment = wxALIGN_TOP_LEFT;
83 m_backgroundMode
= wxTRANSPARENT
;
85 m_textForegroundColour
= *wxBLACK
;
86 m_textBackgroundColour
= *wxWHITE
;
88 m_font
= *wxNORMAL_FONT
;
89 m_brush
= *wxTRANSPARENT_BRUSH
;
90 m_backgroundBrush
= *wxWHITE_BRUSH
;
92 // m_palette = wxAPP_COLOURMAP;
97 m_macFontInstalled
= false ;
98 m_macBrushInstalled
= false ;
99 m_macPenInstalled
= false ;
102 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
103 m_macClipRect
.left
= -32000 ;
104 m_macClipRect
.top
= -32000 ;
105 m_macClipRect
.right
= 32000 ;
106 m_macClipRect
.bottom
= 32000 ;
107 ::GetPort( &m_macOrigPort
) ;
112 if ( !m_macPortHelper
.IsCleared() )
116 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
123 ::SetPort( m_macPort ) ;
124 ::SetOrigin( 0 , 0 ) ;
125 ::ClipRect( &m_macPort->portRect ) ;
127 ::SetPort( m_macOrigPort ) ;
130 ++m_macCurrentPortId
;
133 void wxDC::MacSetupPort() const
135 AGAPortHelper
* help
= (AGAPortHelper
*) &m_macPortHelper
;
136 help
->Setup( m_macPort
) ;
137 m_macPortId
= ++m_macCurrentPortId
;
138 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
139 ::ClipRect(&m_macClipRect
);
141 m_macFontInstalled
= false ;
142 m_macBrushInstalled
= false ;
143 m_macPenInstalled
= false ;
146 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
154 long xx1
= XLOG2DEV(x
);
155 long yy1
= YLOG2DEV(y
);
158 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
162 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
164 Rect bitmaprect
= { 0 , 0 , bmap
->m_height
* scale
, bmap
->m_width
* scale
} ;
165 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
166 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
168 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
170 if ( bmap
->m_hBitmap
)
172 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
173 PixMapHandle bmappixels
;
174 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
175 RGBColor black
= { 0,0,0} ;
176 RGBForeColor( &black
) ;
177 RGBBackColor( &white
) ;
179 bmappixels
= GetGWorldPixMap( bmapworld
) ;
180 if ( LockPixels(bmappixels
) )
185 source
.right
= bmap
->m_width
;
186 source
.bottom
= bmap
->m_height
;
187 dest
.top
= YLOG2DEV(y
) ;
188 dest
.left
= XLOG2DEV(x
) ;
189 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
190 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
192 if ( useMask
&& bmp
.GetMask() )
194 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
196 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
197 GetPortBitMapForCopyBits( m_macPort
) ,
198 &source
, &source
, &dest
) ;
199 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
203 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
204 &source
, &dest
, srcCopy
, NULL
) ;
206 UnlockPixels( bmappixels
) ;
208 m_macPenInstalled
= false ;
209 m_macBrushInstalled
= false ;
210 m_macFontInstalled
= false ;
217 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
223 long xx1
= XLOG2DEV(x
);
224 long yy1
= YLOG2DEV(y
);
227 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
229 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
231 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
232 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
233 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
238 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
243 m_clipX1
= wxMax( m_clipX1
, x
) ;
244 m_clipY1
= wxMax( m_clipY1
,y
);
245 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
246 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
254 m_clipX2
= x
+ width
;
255 m_clipY2
= y
+ height
;
258 long x1
= XLOG2DEV(m_clipX1
);
259 long y1
= YLOG2DEV(m_clipY1
);
260 long x2
= XLOG2DEV(m_clipX2
);
261 long y2
= YLOG2DEV(m_clipY2
);
263 Rect clip
= { y1
, x1
, y2
, x2
} ;
265 ::ClipRect( &clip
) ;
269 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
271 wxCHECK_RET( Ok(), wxT("invalid window dc") );
276 DestroyClippingRegion();
280 wxCoord xx
, yy
, ww
, hh
;
281 region
.GetBox( xx
, yy
, ww
, hh
);
282 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
285 void wxDC::DestroyClippingRegion(void)
289 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
290 ::ClipRect(&m_macClipRect
);
293 void wxDC::DoGetSize( int* width
, int* height
) const
295 *width
= m_maxX
-m_minX
;
296 *height
= m_maxY
-m_minY
;
299 void wxDC::DoGetSizeMM( int* width
, int* height
) const
304 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
305 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
308 void wxDC::SetTextForeground( const wxColour
&col
)
311 m_textForegroundColour
= col
;
312 m_macFontInstalled
= false ;
315 void wxDC::SetTextBackground( const wxColour
&col
)
318 m_textBackgroundColour
= col
;
319 m_macFontInstalled
= false ;
322 void wxDC::SetMapMode( int mode
)
327 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
330 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
333 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
336 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
340 SetLogicalScale( 1.0, 1.0 );
343 if (mode
!= wxMM_TEXT
)
345 m_needComputeScaleX
= TRUE
;
346 m_needComputeScaleY
= TRUE
;
350 void wxDC::SetUserScale( double x
, double y
)
352 // allow negative ? -> no
355 ComputeScaleAndOrigin();
358 void wxDC::SetLogicalScale( double x
, double y
)
363 ComputeScaleAndOrigin();
366 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
368 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
369 m_logicalOriginY
= y
* m_signY
;
370 ComputeScaleAndOrigin();
373 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
375 m_externalDeviceOriginX
= x
;
376 m_externalDeviceOriginY
= y
;
377 ComputeScaleAndOrigin();
380 void wxDC::SetInternalDeviceOrigin( long x, long y )
382 m_internalDeviceOriginX = x;
383 m_internalDeviceOriginY = y;
384 ComputeScaleAndOrigin();
387 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
389 if (x) *x = m_internalDeviceOriginX;
390 if (y) *y = m_internalDeviceOriginY;
393 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
395 m_signX
= (xLeftRight
? 1 : -1);
396 m_signY
= (yBottomUp
? -1 : 1);
397 ComputeScaleAndOrigin();
401 void wxDC::CalcBoundingBox( long x, long y )
403 if (x < m_minX) m_minX = x;
404 if (y < m_minY) m_minY = y;
405 if (x > m_maxX) m_maxX = x;
406 if (y > m_maxY) m_maxY = y;
409 wxSize
wxDC::GetPPI() const
411 return wxSize(72, 72);
414 int wxDC::GetDepth() const
416 return wxDisplayDepth() ;
419 void wxDC::ComputeScaleAndOrigin(void)
421 // CMB: copy scale to see if it changes
422 double origScaleX
= m_scaleX
;
423 double origScaleY
= m_scaleY
;
425 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
426 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
428 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
429 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
431 // CMB: if scale has changed call SetPen to recalulate the line width
432 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
434 // this is a bit artificial, but we need to force wxDC to think
435 // the pen has changed
436 wxPen
* pen
= & GetPen();
443 void wxDC::SetPalette( const wxPalette
& palette
)
447 void wxDC::SetBackgroundMode( int mode
)
449 m_backgroundMode
= mode
;
452 void wxDC::SetFont( const wxFont
&font
)
460 m_macFontInstalled
= false ;
463 void wxDC::SetPen( const wxPen
&pen
)
478 m_macPenInstalled
= false ;
481 void wxDC::SetBrush( const wxBrush
&brush
)
487 if (m_brush
== brush
)
491 m_macBrushInstalled
= false ;
494 void wxDC::SetBackground( const wxBrush
&brush
)
500 if (m_backgroundBrush
== brush
)
503 m_backgroundBrush
= brush
;
505 if (!m_backgroundBrush
.Ok())
507 m_macBrushInstalled
= false ;
510 void wxDC::SetLogicalFunction( int function
)
512 if (m_logicalFunction
== function
)
515 m_logicalFunction
= function
;
516 m_macFontInstalled
= false ;
517 m_macBrushInstalled
= false ;
518 m_macPenInstalled
= false ;
521 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
526 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
531 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
538 if (m_pen
.GetStyle() != wxTRANSPARENT
)
541 int offset
= (m_pen
.GetWidth() - 1) / 2 ;
542 long xx1
= XLOG2DEV(x1
);
543 long yy1
= YLOG2DEV(y1
);
544 long xx2
= XLOG2DEV(x2
);
545 long yy2
= YLOG2DEV(y2
);
547 ::MoveTo(xx1
- offset
,yy1
- offset
);
548 ::LineTo(xx2
- offset
, yy2
- offset
);
552 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
556 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
557 wxCoord x2
, wxCoord y2
,
558 wxCoord xc
, wxCoord yc
)
562 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
563 double sa
, double ea
)
567 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
574 if (m_pen
.GetStyle() != wxTRANSPARENT
)
577 long xx1
= XLOG2DEV(x
);
578 long yy1
= YLOG2DEV(y
);
581 ::LineTo(xx1
+1, yy1
+1);
585 void wxDC::DoDrawLines(int n
, wxPoint points
[],
586 wxCoord xoffset
, wxCoord yoffset
)
592 if (m_pen
.GetStyle() == wxTRANSPARENT
)
597 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
598 long x1
, x2
, y1
, y2
;
599 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
600 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
601 ::MoveTo(x1
- offset
,y1
- offset
);
603 for (int i
= 0; i
< n
-1; i
++)
605 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
606 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
607 ::LineTo(x2
- offset
, y2
- offset
);
611 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
612 wxCoord xoffset
, wxCoord yoffset
,
619 PolyHandle polygon
= OpenPoly() ;
620 long x1
, x2
, y1
, y2
;
621 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
622 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
625 for (int i
= 0; i
< n
-1; i
++)
627 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
628 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
633 if (m_brush
.GetStyle() != wxTRANSPARENT
)
636 ::PaintPoly( polygon
) ;
639 if (m_pen
.GetStyle() != wxTRANSPARENT
)
642 ::FramePoly( polygon
) ;
644 KillPoly( polygon
) ;
647 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
653 long xx
= XLOG2DEV(x
);
654 long yy
= YLOG2DEV(y
);
655 long ww
= m_signX
* XLOG2DEVREL(width
);
656 long hh
= m_signY
* YLOG2DEVREL(height
);
658 // CMB: draw nothing if transformed w or h is 0
659 if (ww
== 0 || hh
== 0)
662 // CMB: handle -ve width and/or height
675 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
677 if (m_brush
.GetStyle() != wxTRANSPARENT
)
680 ::PaintRect( &rect
) ;
683 if (m_pen
.GetStyle() != wxTRANSPARENT
)
686 ::FrameRect( &rect
) ;
690 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
691 wxCoord width
, wxCoord height
,
699 radius
= - radius
* ((width
< height
) ? width
: height
);
701 long xx
= XLOG2DEV(x
);
702 long yy
= YLOG2DEV(y
);
703 long ww
= m_signX
* XLOG2DEVREL(width
);
704 long hh
= m_signY
* YLOG2DEVREL(height
);
706 // CMB: draw nothing if transformed w or h is 0
707 if (ww
== 0 || hh
== 0)
710 // CMB: handle -ve width and/or height
723 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
725 if (m_brush
.GetStyle() != wxTRANSPARENT
)
728 ::PaintRoundRect( &rect
, radius
* 2 , radius
* 2 ) ;
731 if (m_pen
.GetStyle() != wxTRANSPARENT
)
734 ::FrameRoundRect( &rect
, radius
* 2 , radius
* 2 ) ;
738 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
744 long xx
= XLOG2DEV(x
);
745 long yy
= YLOG2DEV(y
);
746 long ww
= m_signX
* XLOG2DEVREL(width
);
747 long hh
= m_signY
* YLOG2DEVREL(height
);
749 // CMB: draw nothing if transformed w or h is 0
750 if (ww
== 0 || hh
== 0)
753 // CMB: handle -ve width and/or height
766 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
768 if (m_brush
.GetStyle() != wxTRANSPARENT
)
771 ::PaintOval( &rect
) ;
774 if (m_pen
.GetStyle() != wxTRANSPARENT
)
777 ::FrameOval( &rect
) ;
781 // ----------------------------------- spline code ----------------------------------------
783 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
784 double a3
, double b3
, double a4
, double b4
);
785 static void wx_clear_stack(void);
786 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
787 double *y3
, double *x4
, double *y4
);
788 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
789 double x4
, double y4
);
790 static bool wx_spline_add_point(double x
, double y
);
791 static void wx_spline_draw_point_array(wxDC
*dc
);
793 static wxList wx_spline_point_list
;
795 #define half(z1, z2) ((z1+z2)/2.0)
798 /* iterative version */
800 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
803 register double xmid
, ymid
;
804 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
807 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
809 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
810 xmid
= (double)half(x2
, x3
);
811 ymid
= (double)half(y2
, y3
);
812 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
813 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
814 wx_spline_add_point( x1
, y1
);
815 wx_spline_add_point( xmid
, ymid
);
817 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
818 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
819 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
820 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
825 /* utilities used by spline drawing routines */
827 typedef struct wx_spline_stack_struct
{
828 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
831 #define SPLINE_STACK_DEPTH 20
832 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
833 static Stack
*wx_stack_top
;
834 static int wx_stack_count
;
836 static void wx_clear_stack(void)
838 wx_stack_top
= wx_spline_stack
;
842 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
844 wx_stack_top
->x1
= x1
;
845 wx_stack_top
->y1
= y1
;
846 wx_stack_top
->x2
= x2
;
847 wx_stack_top
->y2
= y2
;
848 wx_stack_top
->x3
= x3
;
849 wx_stack_top
->y3
= y3
;
850 wx_stack_top
->x4
= x4
;
851 wx_stack_top
->y4
= y4
;
856 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
857 double *x3
, double *y3
, double *x4
, double *y4
)
859 if (wx_stack_count
== 0)
863 *x1
= wx_stack_top
->x1
;
864 *y1
= wx_stack_top
->y1
;
865 *x2
= wx_stack_top
->x2
;
866 *y2
= wx_stack_top
->y2
;
867 *x3
= wx_stack_top
->x3
;
868 *y3
= wx_stack_top
->y3
;
869 *x4
= wx_stack_top
->x4
;
870 *y4
= wx_stack_top
->y4
;
874 static bool wx_spline_add_point(double x
, double y
)
876 wxPoint
*point
= new wxPoint
;
879 wx_spline_point_list
.Append((wxObject
*)point
);
883 static void wx_spline_draw_point_array(wxDC
*dc
)
885 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
886 wxNode
*node
= wx_spline_point_list
.First();
889 wxPoint
*point
= (wxPoint
*)node
->Data();
892 node
= wx_spline_point_list
.First();
896 void wxDC::DoDrawSpline(wxList
*points
)
899 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
900 double x1
, y1
, x2
, y2
;
902 wxNode
*node
= points
->First();
903 p
= (wxPoint
*)node
->Data();
909 p
= (wxPoint
*)node
->Data();
913 cx1
= (double)((x1
+ x2
) / 2);
914 cy1
= (double)((y1
+ y2
) / 2);
915 cx2
= (double)((cx1
+ x2
) / 2);
916 cy2
= (double)((cy1
+ y2
) / 2);
918 wx_spline_add_point(x1
, y1
);
920 while ((node
= node
->Next()) != NULL
)
922 p
= (wxPoint
*)node
->Data();
927 cx4
= (double)(x1
+ x2
) / 2;
928 cy4
= (double)(y1
+ y2
) / 2;
929 cx3
= (double)(x1
+ cx4
) / 2;
930 cy3
= (double)(y1
+ cy4
) / 2;
932 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
936 cx2
= (double)(cx1
+ x2
) / 2;
937 cy2
= (double)(cy1
+ y2
) / 2;
940 wx_spline_add_point( cx1
, cy1
);
941 wx_spline_add_point( x2
, y2
);
943 wx_spline_draw_point_array( this );
948 bool wxDC::CanDrawBitmap(void) const
954 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
955 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
957 if (!Ok()) return FALSE
;
960 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
961 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
962 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
963 RGBColor black
= { 0,0,0} ;
964 RGBForeColor( &m_textForegroundColour
.GetPixel() ) ;
965 RGBBackColor( &m_textBackgroundColour
.GetPixel() ) ;
967 if ( LockPixels(bmappixels
) )
969 Rect srcrect
, dstrect
;
970 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
971 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
972 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
973 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
974 dstrect
.top
= YLOG2DEV(ydest
) ;
975 dstrect
.left
= XLOG2DEV(xdest
) ;
976 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
977 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
979 short mode
= (logical_func
== wxCOPY
? srcCopy
:
980 // logical_func == wxCLEAR ? WHITENESS :
981 // logical_func == wxSET ? BLACKNESS :
982 logical_func
== wxINVERT
? hilite
:
983 // logical_func == wxAND ? MERGECOPY :
984 logical_func
== wxOR
? srcOr
:
985 logical_func
== wxSRC_INVERT
? notSrcCopy
:
986 logical_func
== wxXOR
? srcXor
:
987 // logical_func == wxOR_REVERSE ? MERGEPAINT :
988 // logical_func == wxAND_REVERSE ? SRCERASE :
989 // logical_func == wxSRC_OR ? srcOr :
990 // logical_func == wxSRC_AND ? SRCAND :
993 if ( useMask
&& source
->m_macMask
)
995 wxASSERT( mode
== srcCopy
) ;
996 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
998 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
999 GetPortBitMapForCopyBits( m_macPort
) ,
1000 &srcrect
, &srcrect
, &dstrect
) ;
1001 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
1006 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
1007 &srcrect
, &dstrect
, mode
, NULL
) ;
1009 UnlockPixels( bmappixels
) ;
1012 m_macPenInstalled
= false ;
1013 m_macBrushInstalled
= false ;
1014 m_macFontInstalled
= false ;
1019 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1023 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1029 long xx
= XLOG2DEV(x
);
1030 long yy
= YLOG2DEV(y
);
1032 // if (m_pen.GetStyle() != wxTRANSPARENT)
1036 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1038 ::ClipRect( &clip ) ;
1042 ::GetFontInfo( &fi
) ;
1045 ::MoveTo( xx
, yy
);
1046 if ( m_backgroundMode
== wxTRANSPARENT
)
1048 ::TextMode( srcOr
) ;
1052 ::TextMode( srcCopy
) ;
1055 const char *text
= NULL
;
1059 if ( wxApp::s_macDefaultEncodingIsPC
)
1061 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1063 length
= macText
.Length() ;
1068 length
= strtext
.Length() ;
1077 if( text
[i
] == 13 || text
[i
] == 10)
1079 ::DrawText( text
, laststop
, i
- laststop
) ;
1081 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1087 ::DrawText( text
, laststop
, i
- laststop
) ;
1088 ::TextMode( srcOr
) ;
1092 bool wxDC::CanGetTextExtent(void) const
1100 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1101 wxCoord
*descent
, wxCoord
*externalLeading
,
1102 wxFont
*theFont
) const
1109 wxFont formerFont
= m_font
;
1113 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1117 ::TextFont( font
->m_macFontNum
) ;
1118 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1119 ::TextFace( font
->m_macFontStyle
) ;
1128 ::GetFontInfo( &fi
) ;
1131 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1133 *descent
=YDEV2LOGREL( fi
.descent
);
1134 if ( externalLeading
)
1135 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1137 const char *text
= NULL
;
1140 if ( wxApp::s_macDefaultEncodingIsPC
)
1142 macText
= wxMacMakeMacStringFromPC( string
) ;
1144 length
= macText
.Length() ;
1149 length
= string
.Length() ;
1161 if( text
[i
] == 13 || text
[i
] == 10)
1164 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1165 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1166 if ( curwidth
> *width
)
1167 *width
= XDEV2LOGREL( curwidth
) ;
1173 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1174 if ( curwidth
> *width
)
1175 *width
= XDEV2LOGREL( curwidth
) ;
1180 m_macFontInstalled
= false ;
1184 wxCoord
wxDC::GetCharWidth(void) const
1194 ::GetFontInfo( &fi
) ;
1196 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1199 wxCoord
wxDC::GetCharHeight(void) const
1209 ::GetFontInfo( &fi
) ;
1211 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1214 void wxDC::Clear(void)
1219 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1221 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1224 ::EraseRect( &rect
) ;
1228 void wxDC::MacInstallFont() const
1234 if ( m_macFontInstalled
)
1236 Pattern blackColor
;
1238 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1242 ::TextFont( font
->m_macFontNum
) ;
1243 ::TextSize( m_scaleY
* font
->m_macFontSize
) ;
1244 ::TextFace( font
->m_macFontStyle
) ;
1246 m_macFontInstalled
= true ;
1247 m_macBrushInstalled
= false ;
1248 m_macPenInstalled
= false ;
1250 ::RGBForeColor(&m_textForegroundColour
.GetPixel() );
1251 ::RGBBackColor(&m_textBackgroundColour
.GetPixel() );
1257 GetFNum( "\pGeneva" , &fontnum
) ;
1258 ::TextFont( fontnum
) ;
1259 ::TextSize( m_scaleY
* 10 ) ;
1262 // todo reset after spacing changes - or store the current spacing somewhere
1264 m_macFontInstalled
= true ;
1265 m_macBrushInstalled
= false ;
1266 m_macPenInstalled
= false ;
1267 ::RGBForeColor( &(m_textForegroundColour
.GetPixel()) );
1268 ::RGBBackColor(&m_textBackgroundColour
.GetPixel() );
1272 short mode
= patCopy
;
1276 switch( m_logicalFunction
)
1281 case wxINVERT
: // NOT dst
1282 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1285 case wxXOR
: // src XOR dst
1288 case wxOR_REVERSE
: // src OR (NOT dst)
1291 case wxSRC_INVERT
: // (NOT src)
1298 case wxAND_REVERSE
:// src AND (NOT dst)
1299 case wxAND
: // src AND dst
1300 case wxAND_INVERT
: // (NOT src) AND dst
1301 case wxNO_OP
: // dst
1302 case wxNOR
: // (NOT src) AND (NOT dst)
1303 case wxEQUIV
: // (NOT src) XOR dst
1304 case wxOR_INVERT
: // (NOT src) OR dst
1305 case wxNAND
: // (NOT src) OR (NOT dst)
1306 case wxOR
: // src OR dst
1308 // case wxSRC_OR: // source _bitmap_ OR destination
1309 // case wxSRC_AND: // source _bitmap_ AND destination
1315 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1317 int thePatListID
= sysPatListID
;
1321 case wxBDIAGONAL_HATCH
:
1322 theIndex
= 34; // WCH: this is not good
1324 case wxFDIAGONAL_HATCH
:
1330 case wxHORIZONTAL_HATCH
:
1333 case wxVERTICAL_HATCH
:
1336 case wxCROSSDIAG_HATCH
:
1337 theIndex
= 4; // WCH: this is not good
1340 theIndex
= 1; // solid pattern
1343 GetIndPattern( pattern
, thePatListID
, theIndex
);
1346 void wxDC::MacInstallPen() const
1354 if ( m_macPenInstalled
)
1357 ::RGBForeColor(&m_pen
.GetColour().GetPixel() );
1358 ::RGBBackColor(&m_backgroundBrush
.GetColour().GetPixel() );
1361 int penWidth
= m_pen
.GetWidth();
1362 ::PenSize(penWidth
, penWidth
);
1364 int penStyle
= m_pen
.GetStyle();
1366 if (penStyle
== wxSOLID
)
1367 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1368 else if (IS_HATCH(penStyle
))
1371 wxMacGetHatchPattern(penStyle
, &pat
);
1376 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1379 short mode
= patCopy
;
1383 switch( m_logicalFunction
)
1388 case wxINVERT
: // NOT dst
1389 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1392 case wxXOR
: // src XOR dst
1395 case wxOR_REVERSE
: // src OR (NOT dst)
1398 case wxSRC_INVERT
: // (NOT src)
1405 case wxAND_REVERSE
:// src AND (NOT dst)
1406 case wxAND
: // src AND dst
1407 case wxAND_INVERT
: // (NOT src) AND dst
1408 case wxNO_OP
: // dst
1409 case wxNOR
: // (NOT src) AND (NOT dst)
1410 case wxEQUIV
: // (NOT src) XOR dst
1411 case wxOR_INVERT
: // (NOT src) OR dst
1412 case wxNAND
: // (NOT src) OR (NOT dst)
1413 case wxOR
: // src OR dst
1415 // case wxSRC_OR: // source _bitmap_ OR destination
1416 // case wxSRC_AND: // source _bitmap_ AND destination
1420 m_macPenInstalled
= true ;
1421 m_macBrushInstalled
= false ;
1422 m_macFontInstalled
= false ;
1425 void wxDC::MacInstallBrush() const
1430 Pattern blackColor
, whiteColor
;
1431 if ( m_macBrushInstalled
)
1436 ::RGBForeColor(&m_brush
.GetColour().GetPixel() );
1437 ::RGBBackColor(&m_backgroundBrush
.GetColour().GetPixel() );
1439 int brushStyle
= m_brush
.GetStyle();
1440 if (brushStyle
== wxSOLID
)
1441 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1442 else if (IS_HATCH(brushStyle
))
1445 wxMacGetHatchPattern(brushStyle
, &pat
);
1450 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1456 brushStyle
= m_backgroundBrush
.GetStyle();
1457 if (brushStyle
== wxSOLID
)
1458 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1459 else if (IS_HATCH(brushStyle
))
1462 wxMacGetHatchPattern(brushStyle
, &pat
);
1467 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1470 short mode
= patCopy
;
1474 switch( m_logicalFunction
)
1479 case wxINVERT
: // NOT dst
1480 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1483 case wxXOR
: // src XOR dst
1486 case wxOR_REVERSE
: // src OR (NOT dst)
1489 case wxSRC_INVERT
: // (NOT src)
1496 case wxAND_REVERSE
:// src AND (NOT dst)
1497 case wxAND
: // src AND dst
1498 case wxAND_INVERT
: // (NOT src) AND dst
1499 case wxNO_OP
: // dst
1500 case wxNOR
: // (NOT src) AND (NOT dst)
1501 case wxEQUIV
: // (NOT src) XOR dst
1502 case wxOR_INVERT
: // (NOT src) OR dst
1503 case wxNAND
: // (NOT src) OR (NOT dst)
1504 case wxOR
: // src OR dst
1506 // case wxSRC_OR: // source _bitmap_ OR destination
1507 // case wxSRC_AND: // source _bitmap_ AND destination
1511 m_macBrushInstalled
= true ;
1512 m_macPenInstalled
= false ;
1513 m_macFontInstalled
= false ;
1516 // ---------------------------------------------------------------------------
1517 // coordinates transformations
1518 // ---------------------------------------------------------------------------
1521 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1523 return ((wxDC
*)this)->XDEV2LOG(x
);
1526 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1528 return ((wxDC
*)this)->YDEV2LOG(y
);
1531 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1533 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1536 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1538 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1541 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1543 return ((wxDC
*)this)->XLOG2DEV(x
);
1546 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1548 return ((wxDC
*)this)->YLOG2DEV(y
);
1551 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1553 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1556 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1558 return ((wxDC
*)this)->YLOG2DEVREL(y
);