1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 #define mm2inches 0.0393700787402
33 #define inches2mm 25.4
34 #define mm2twips 56.6929133859
35 #define twips2mm 0.0176388888889
36 #define mm2pt 2.83464566929
37 #define pt2mm 0.352777777778
39 long wxDC::m_macCurrentPortId
= 1 ;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
48 // m_optimize = FALSE;
49 // m_autoSetting = FALSE;
53 m_mm_to_pix_x
= mm2pt
;
54 m_mm_to_pix_y
= mm2pt
;
60 m_internalDeviceOriginX
= 0;
61 m_internalDeviceOriginY
= 0;
62 m_externalDeviceOriginX
= 0;
63 m_externalDeviceOriginY
= 0;
65 m_logicalScaleX
= 1.0;
66 m_logicalScaleY
= 1.0;
72 m_mappingMode
= wxMM_TEXT
;
73 m_needComputeScaleX
= FALSE
;
74 m_needComputeScaleY
= FALSE
;
76 m_signX
= 1; // default x-axis left to right
77 m_signY
= 1; // default y-axis top down
79 m_maxX
= m_maxY
= -100000;
80 m_minY
= m_minY
= 100000;
82 m_logicalFunction
= wxCOPY
;
83 // m_textAlignment = wxALIGN_TOP_LEFT;
84 m_backgroundMode
= wxTRANSPARENT
;
86 m_textForegroundColour
= *wxBLACK
;
87 m_textBackgroundColour
= *wxWHITE
;
89 m_font
= *wxNORMAL_FONT
;
90 m_brush
= *wxTRANSPARENT_BRUSH
;
91 m_backgroundBrush
= *wxWHITE_BRUSH
;
93 // m_palette = wxAPP_COLOURMAP;
98 m_macFontInstalled
= false ;
99 m_macBrushInstalled
= false ;
100 m_macPenInstalled
= false ;
103 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
104 m_macClipRect
.left
= -32000 ;
105 m_macClipRect
.top
= -32000 ;
106 m_macClipRect
.right
= 32000 ;
107 m_macClipRect
.bottom
= 32000 ;
108 ::GetPort( &m_macOrigPort
) ;
113 if ( !m_macPortHelper
.IsCleared() )
117 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
124 ::SetPort( m_macPort ) ;
125 ::SetOrigin( 0 , 0 ) ;
126 ::ClipRect( &m_macPort->portRect ) ;
128 ::SetPort( m_macOrigPort ) ;
131 ++m_macCurrentPortId
;
134 void wxDC::MacSetupPort() const
136 AGAPortHelper
* help
= (AGAPortHelper
*) &m_macPortHelper
;
137 help
->Setup( m_macPort
) ;
138 m_macPortId
= ++m_macCurrentPortId
;
139 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
140 ::ClipRect(&m_macClipRect
);
142 m_macFontInstalled
= false ;
143 m_macBrushInstalled
= false ;
144 m_macPenInstalled
= false ;
147 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
155 long xx1
= XLOG2DEV(x
);
156 long yy1
= YLOG2DEV(y
);
159 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
163 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
165 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
166 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
167 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
169 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
171 if ( bmap
->m_hBitmap
)
173 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
174 PixMapHandle bmappixels
;
175 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
176 RGBColor black
= { 0,0,0} ;
177 RGBForeColor( &black
) ;
178 RGBBackColor( &white
) ;
180 bmappixels
= GetGWorldPixMap( bmapworld
) ;
181 if ( LockPixels(bmappixels
) )
186 source
.right
= bmap
->m_width
;
187 source
.bottom
= bmap
->m_height
;
188 dest
.top
= YLOG2DEV(y
) ;
189 dest
.left
= XLOG2DEV(x
) ;
190 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
191 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
193 if ( useMask
&& bmp
.GetMask() )
195 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
197 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
198 GetPortBitMapForCopyBits( m_macPort
) ,
199 &source
, &source
, &dest
) ;
200 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
204 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
205 &source
, &dest
, srcCopy
, NULL
) ;
207 UnlockPixels( bmappixels
) ;
209 m_macPenInstalled
= false ;
210 m_macBrushInstalled
= false ;
211 m_macFontInstalled
= false ;
218 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
224 long xx1
= XLOG2DEV(x
);
225 long yy1
= YLOG2DEV(y
);
228 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
230 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
232 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
233 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
234 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
239 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
244 m_clipX1
= wxMax( m_clipX1
, x
) ;
245 m_clipY1
= wxMax( m_clipY1
,y
);
246 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
247 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
255 m_clipX2
= x
+ width
;
256 m_clipY2
= y
+ height
;
259 long x1
= XLOG2DEV(m_clipX1
);
260 long y1
= YLOG2DEV(m_clipY1
);
261 long x2
= XLOG2DEV(m_clipX2
);
262 long y2
= YLOG2DEV(m_clipY2
);
264 Rect clip
= { y1
, x1
, y2
, x2
} ;
266 ::ClipRect( &clip
) ;
270 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
272 wxCHECK_RET( Ok(), wxT("invalid window dc") );
277 DestroyClippingRegion();
281 wxCoord xx
, yy
, ww
, hh
;
282 region
.GetBox( xx
, yy
, ww
, hh
);
283 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
286 void wxDC::DestroyClippingRegion(void)
290 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
291 ::ClipRect(&m_macClipRect
);
294 void wxDC::DoGetSize( int* width
, int* height
) const
296 *width
= m_maxX
-m_minX
;
297 *height
= m_maxY
-m_minY
;
300 void wxDC::DoGetSizeMM( int* width
, int* height
) const
305 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
306 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
309 void wxDC::SetTextForeground( const wxColour
&col
)
312 m_textForegroundColour
= col
;
313 m_macFontInstalled
= false ;
316 void wxDC::SetTextBackground( const wxColour
&col
)
319 m_textBackgroundColour
= col
;
320 m_macFontInstalled
= false ;
323 void wxDC::SetMapMode( int mode
)
328 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
331 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
334 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
337 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
341 SetLogicalScale( 1.0, 1.0 );
344 if (mode
!= wxMM_TEXT
)
346 m_needComputeScaleX
= TRUE
;
347 m_needComputeScaleY
= TRUE
;
351 void wxDC::SetUserScale( double x
, double y
)
353 // allow negative ? -> no
356 ComputeScaleAndOrigin();
359 void wxDC::SetLogicalScale( double x
, double y
)
364 ComputeScaleAndOrigin();
367 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
369 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
370 m_logicalOriginY
= y
* m_signY
;
371 ComputeScaleAndOrigin();
374 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
376 m_externalDeviceOriginX
= x
;
377 m_externalDeviceOriginY
= y
;
378 ComputeScaleAndOrigin();
381 void wxDC::SetInternalDeviceOrigin( long x, long y )
383 m_internalDeviceOriginX = x;
384 m_internalDeviceOriginY = y;
385 ComputeScaleAndOrigin();
388 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
390 if (x) *x = m_internalDeviceOriginX;
391 if (y) *y = m_internalDeviceOriginY;
394 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
396 m_signX
= (xLeftRight
? 1 : -1);
397 m_signY
= (yBottomUp
? -1 : 1);
398 ComputeScaleAndOrigin();
402 void wxDC::CalcBoundingBox( long x, long y )
404 if (x < m_minX) m_minX = x;
405 if (y < m_minY) m_minY = y;
406 if (x > m_maxX) m_maxX = x;
407 if (y > m_maxY) m_maxY = y;
410 wxSize
wxDC::GetPPI() const
412 return wxSize(72, 72);
415 int wxDC::GetDepth() const
417 return wxDisplayDepth() ;
420 void wxDC::ComputeScaleAndOrigin(void)
422 // CMB: copy scale to see if it changes
423 double origScaleX
= m_scaleX
;
424 double origScaleY
= m_scaleY
;
426 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
427 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
429 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
430 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
432 // CMB: if scale has changed call SetPen to recalulate the line width
433 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
435 // this is a bit artificial, but we need to force wxDC to think
436 // the pen has changed
437 wxPen
* pen
= & GetPen();
444 void wxDC::SetPalette( const wxPalette
& palette
)
448 void wxDC::SetBackgroundMode( int mode
)
450 m_backgroundMode
= mode
;
453 void wxDC::SetFont( const wxFont
&font
)
461 m_macFontInstalled
= false ;
464 void wxDC::SetPen( const wxPen
&pen
)
479 m_macPenInstalled
= false ;
482 void wxDC::SetBrush( const wxBrush
&brush
)
488 if (m_brush
== brush
)
492 m_macBrushInstalled
= false ;
495 void wxDC::SetBackground( const wxBrush
&brush
)
501 if (m_backgroundBrush
== brush
)
504 m_backgroundBrush
= brush
;
506 if (!m_backgroundBrush
.Ok())
508 m_macBrushInstalled
= false ;
511 void wxDC::SetLogicalFunction( int function
)
513 if (m_logicalFunction
== function
)
516 m_logicalFunction
= function
;
517 m_macFontInstalled
= false ;
518 m_macBrushInstalled
= false ;
519 m_macPenInstalled
= false ;
522 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
527 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
532 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
539 if (m_pen
.GetStyle() != wxTRANSPARENT
)
542 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
543 long xx1
= XLOG2DEV(x1
);
544 long yy1
= YLOG2DEV(y1
);
545 long xx2
= XLOG2DEV(x2
);
546 long yy2
= YLOG2DEV(y2
);
548 ::MoveTo(xx1
- offset
,yy1
- offset
);
549 ::LineTo(xx2
- offset
, yy2
- offset
);
553 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
557 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
558 wxCoord x2
, wxCoord y2
,
559 wxCoord xc
, wxCoord yc
)
563 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
564 double sa
, double ea
)
568 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
575 if (m_pen
.GetStyle() != wxTRANSPARENT
)
578 long xx1
= XLOG2DEV(x
);
579 long yy1
= YLOG2DEV(y
);
582 ::LineTo(xx1
+1, yy1
+1);
586 void wxDC::DoDrawLines(int n
, wxPoint points
[],
587 wxCoord xoffset
, wxCoord yoffset
)
593 if (m_pen
.GetStyle() == wxTRANSPARENT
)
598 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
599 long x1
, x2
, y1
, y2
;
600 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
601 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
602 ::MoveTo(x1
- offset
,y1
- offset
);
604 for (int i
= 0; i
< n
-1; i
++)
606 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
607 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
608 ::LineTo(x2
- offset
, y2
- offset
);
612 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
613 wxCoord xoffset
, wxCoord yoffset
,
620 PolyHandle polygon
= OpenPoly() ;
621 long x1
, x2
, y1
, y2
;
622 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
623 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
626 for (int i
= 0; i
< n
-1; i
++)
628 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
629 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
634 if (m_brush
.GetStyle() != wxTRANSPARENT
)
637 ::PaintPoly( polygon
) ;
640 if (m_pen
.GetStyle() != wxTRANSPARENT
)
643 ::FramePoly( polygon
) ;
645 KillPoly( polygon
) ;
648 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
654 long xx
= XLOG2DEV(x
);
655 long yy
= YLOG2DEV(y
);
656 long ww
= m_signX
* XLOG2DEVREL(width
);
657 long hh
= m_signY
* YLOG2DEVREL(height
);
659 // CMB: draw nothing if transformed w or h is 0
660 if (ww
== 0 || hh
== 0)
663 // CMB: handle -ve width and/or height
676 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
678 if (m_brush
.GetStyle() != wxTRANSPARENT
)
681 ::PaintRect( &rect
) ;
684 if (m_pen
.GetStyle() != wxTRANSPARENT
)
687 ::FrameRect( &rect
) ;
691 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
692 wxCoord width
, wxCoord height
,
700 radius
= - radius
* ((width
< height
) ? width
: height
);
702 long xx
= XLOG2DEV(x
);
703 long yy
= YLOG2DEV(y
);
704 long ww
= m_signX
* XLOG2DEVREL(width
);
705 long hh
= m_signY
* YLOG2DEVREL(height
);
707 // CMB: draw nothing if transformed w or h is 0
708 if (ww
== 0 || hh
== 0)
711 // CMB: handle -ve width and/or height
724 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
726 if (m_brush
.GetStyle() != wxTRANSPARENT
)
729 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
732 if (m_pen
.GetStyle() != wxTRANSPARENT
)
735 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
739 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
745 long xx
= XLOG2DEV(x
);
746 long yy
= YLOG2DEV(y
);
747 long ww
= m_signX
* XLOG2DEVREL(width
);
748 long hh
= m_signY
* YLOG2DEVREL(height
);
750 // CMB: draw nothing if transformed w or h is 0
751 if (ww
== 0 || hh
== 0)
754 // CMB: handle -ve width and/or height
767 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
769 if (m_brush
.GetStyle() != wxTRANSPARENT
)
772 ::PaintOval( &rect
) ;
775 if (m_pen
.GetStyle() != wxTRANSPARENT
)
778 ::FrameOval( &rect
) ;
782 // ----------------------------------- spline code ----------------------------------------
784 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
785 double a3
, double b3
, double a4
, double b4
);
786 static void wx_clear_stack(void);
787 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
788 double *y3
, double *x4
, double *y4
);
789 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
790 double x4
, double y4
);
791 static bool wx_spline_add_point(double x
, double y
);
792 static void wx_spline_draw_point_array(wxDC
*dc
);
794 static wxList wx_spline_point_list
;
796 #define half(z1, z2) ((z1+z2)/2.0)
799 /* iterative version */
801 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
804 register double xmid
, ymid
;
805 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
808 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
810 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
811 xmid
= (double)half(x2
, x3
);
812 ymid
= (double)half(y2
, y3
);
813 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
814 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
815 wx_spline_add_point( x1
, y1
);
816 wx_spline_add_point( xmid
, ymid
);
818 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
819 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
820 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
821 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
826 /* utilities used by spline drawing routines */
828 typedef struct wx_spline_stack_struct
{
829 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
832 #define SPLINE_STACK_DEPTH 20
833 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
834 static Stack
*wx_stack_top
;
835 static int wx_stack_count
;
837 static void wx_clear_stack(void)
839 wx_stack_top
= wx_spline_stack
;
843 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
845 wx_stack_top
->x1
= x1
;
846 wx_stack_top
->y1
= y1
;
847 wx_stack_top
->x2
= x2
;
848 wx_stack_top
->y2
= y2
;
849 wx_stack_top
->x3
= x3
;
850 wx_stack_top
->y3
= y3
;
851 wx_stack_top
->x4
= x4
;
852 wx_stack_top
->y4
= y4
;
857 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
858 double *x3
, double *y3
, double *x4
, double *y4
)
860 if (wx_stack_count
== 0)
864 *x1
= wx_stack_top
->x1
;
865 *y1
= wx_stack_top
->y1
;
866 *x2
= wx_stack_top
->x2
;
867 *y2
= wx_stack_top
->y2
;
868 *x3
= wx_stack_top
->x3
;
869 *y3
= wx_stack_top
->y3
;
870 *x4
= wx_stack_top
->x4
;
871 *y4
= wx_stack_top
->y4
;
875 static bool wx_spline_add_point(double x
, double y
)
877 wxPoint
*point
= new wxPoint
;
880 wx_spline_point_list
.Append((wxObject
*)point
);
884 static void wx_spline_draw_point_array(wxDC
*dc
)
886 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
887 wxNode
*node
= wx_spline_point_list
.First();
890 wxPoint
*point
= (wxPoint
*)node
->Data();
893 node
= wx_spline_point_list
.First();
897 void wxDC::DoDrawSpline(wxList
*points
)
900 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
901 double x1
, y1
, x2
, y2
;
903 wxNode
*node
= points
->First();
904 p
= (wxPoint
*)node
->Data();
910 p
= (wxPoint
*)node
->Data();
914 cx1
= (double)((x1
+ x2
) / 2);
915 cy1
= (double)((y1
+ y2
) / 2);
916 cx2
= (double)((cx1
+ x2
) / 2);
917 cy2
= (double)((cy1
+ y2
) / 2);
919 wx_spline_add_point(x1
, y1
);
921 while ((node
= node
->Next()) != NULL
)
923 p
= (wxPoint
*)node
->Data();
928 cx4
= (double)(x1
+ x2
) / 2;
929 cy4
= (double)(y1
+ y2
) / 2;
930 cx3
= (double)(x1
+ cx4
) / 2;
931 cy3
= (double)(y1
+ cy4
) / 2;
933 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
937 cx2
= (double)(cx1
+ x2
) / 2;
938 cy2
= (double)(cy1
+ y2
) / 2;
941 wx_spline_add_point( cx1
, cy1
);
942 wx_spline_add_point( x2
, y2
);
944 wx_spline_draw_point_array( this );
949 bool wxDC::CanDrawBitmap(void) const
955 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
956 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
958 if (!Ok()) return FALSE
;
961 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
962 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
963 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
964 RGBColor black
= { 0,0,0} ;
965 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
966 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
967 RGBForeColor( &forecolor
) ;
968 RGBBackColor( &backcolor
) ;
970 if ( LockPixels(bmappixels
) )
972 Rect srcrect
, dstrect
;
973 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
974 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
975 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
976 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
977 dstrect
.top
= YLOG2DEV(ydest
) ;
978 dstrect
.left
= XLOG2DEV(xdest
) ;
979 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
980 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
982 short mode
= (logical_func
== wxCOPY
? srcCopy
:
983 // logical_func == wxCLEAR ? WHITENESS :
984 // logical_func == wxSET ? BLACKNESS :
985 logical_func
== wxINVERT
? hilite
:
986 // logical_func == wxAND ? MERGECOPY :
987 logical_func
== wxOR
? srcOr
:
988 logical_func
== wxSRC_INVERT
? notSrcCopy
:
989 logical_func
== wxXOR
? srcXor
:
990 // logical_func == wxOR_REVERSE ? MERGEPAINT :
991 // logical_func == wxAND_REVERSE ? SRCERASE :
992 // logical_func == wxSRC_OR ? srcOr :
993 // logical_func == wxSRC_AND ? SRCAND :
996 if ( useMask
&& source
->m_macMask
)
998 wxASSERT( mode
== srcCopy
) ;
999 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
1001 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
1002 GetPortBitMapForCopyBits( m_macPort
) ,
1003 &srcrect
, &srcrect
, &dstrect
) ;
1004 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
1009 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
1010 &srcrect
, &dstrect
, mode
, NULL
) ;
1012 UnlockPixels( bmappixels
) ;
1015 m_macPenInstalled
= false ;
1016 m_macBrushInstalled
= false ;
1017 m_macFontInstalled
= false ;
1022 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1026 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1032 long xx
= XLOG2DEV(x
);
1033 long yy
= YLOG2DEV(y
);
1035 // if (m_pen.GetStyle() != wxTRANSPARENT)
1039 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1041 ::ClipRect( &clip ) ;
1045 ::GetFontInfo( &fi
) ;
1048 ::MoveTo( xx
, yy
);
1049 if ( m_backgroundMode
== wxTRANSPARENT
)
1051 ::TextMode( srcOr
) ;
1055 ::TextMode( srcCopy
) ;
1058 const char *text
= NULL
;
1062 if ( wxApp::s_macDefaultEncodingIsPC
)
1064 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1066 length
= macText
.Length() ;
1071 length
= strtext
.Length() ;
1080 if( text
[i
] == 13 || text
[i
] == 10)
1082 ::DrawText( text
, laststop
, i
- laststop
) ;
1084 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1090 ::DrawText( text
, laststop
, i
- laststop
) ;
1091 ::TextMode( srcOr
) ;
1095 bool wxDC::CanGetTextExtent(void) const
1103 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1104 wxCoord
*descent
, wxCoord
*externalLeading
,
1105 wxFont
*theFont
) const
1112 wxFont formerFont
= m_font
;
1116 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1120 ::TextFont( font
->m_macFontNum
) ;
1121 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1122 ::TextFace( font
->m_macFontStyle
) ;
1131 ::GetFontInfo( &fi
) ;
1134 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1136 *descent
=YDEV2LOGREL( fi
.descent
);
1137 if ( externalLeading
)
1138 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1140 const char *text
= NULL
;
1143 if ( wxApp::s_macDefaultEncodingIsPC
)
1145 macText
= wxMacMakeMacStringFromPC( string
) ;
1147 length
= macText
.Length() ;
1152 length
= string
.Length() ;
1164 if( text
[i
] == 13 || text
[i
] == 10)
1167 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1168 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1169 if ( curwidth
> *width
)
1170 *width
= XDEV2LOGREL( curwidth
) ;
1176 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1177 if ( curwidth
> *width
)
1178 *width
= XDEV2LOGREL( curwidth
) ;
1183 m_macFontInstalled
= false ;
1187 wxCoord
wxDC::GetCharWidth(void) const
1197 ::GetFontInfo( &fi
) ;
1199 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1202 wxCoord
wxDC::GetCharHeight(void) const
1212 ::GetFontInfo( &fi
) ;
1214 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1217 void wxDC::Clear(void)
1222 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1224 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1227 ::EraseRect( &rect
) ;
1231 void wxDC::MacInstallFont() const
1237 if ( m_macFontInstalled
)
1239 Pattern blackColor
;
1241 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1245 ::TextFont( font
->m_macFontNum
) ;
1246 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1247 ::TextFace( font
->m_macFontStyle
) ;
1249 m_macFontInstalled
= true ;
1250 m_macBrushInstalled
= false ;
1251 m_macPenInstalled
= false ;
1253 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1254 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1255 ::RGBForeColor( &forecolor
);
1256 ::RGBBackColor( &backcolor
);
1262 GetFNum( "\pGeneva" , &fontnum
) ;
1263 ::TextFont( fontnum
) ;
1264 ::TextSize( short(m_scaleY
* 10) ) ;
1267 // todo reset after spacing changes - or store the current spacing somewhere
1269 m_macFontInstalled
= true ;
1270 m_macBrushInstalled
= false ;
1271 m_macPenInstalled
= false ;
1273 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1274 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1275 ::RGBForeColor( &forecolor
);
1276 ::RGBBackColor( &backcolor
);
1279 short mode
= patCopy
;
1283 switch( m_logicalFunction
)
1288 case wxINVERT
: // NOT dst
1289 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1292 case wxXOR
: // src XOR dst
1295 case wxOR_REVERSE
: // src OR (NOT dst)
1298 case wxSRC_INVERT
: // (NOT src)
1305 case wxAND_REVERSE
:// src AND (NOT dst)
1306 case wxAND
: // src AND dst
1307 case wxAND_INVERT
: // (NOT src) AND dst
1308 case wxNO_OP
: // dst
1309 case wxNOR
: // (NOT src) AND (NOT dst)
1310 case wxEQUIV
: // (NOT src) XOR dst
1311 case wxOR_INVERT
: // (NOT src) OR dst
1312 case wxNAND
: // (NOT src) OR (NOT dst)
1313 case wxOR
: // src OR dst
1315 // case wxSRC_OR: // source _bitmap_ OR destination
1316 // case wxSRC_AND: // source _bitmap_ AND destination
1322 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1324 int thePatListID
= sysPatListID
;
1328 case wxBDIAGONAL_HATCH
:
1329 theIndex
= 34; // WCH: this is not good
1331 case wxFDIAGONAL_HATCH
:
1337 case wxHORIZONTAL_HATCH
:
1340 case wxVERTICAL_HATCH
:
1343 case wxCROSSDIAG_HATCH
:
1344 theIndex
= 4; // WCH: this is not good
1347 theIndex
= 1; // solid pattern
1350 GetIndPattern( pattern
, thePatListID
, theIndex
);
1353 void wxDC::MacInstallPen() const
1361 if ( m_macPenInstalled
)
1364 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1365 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1366 ::RGBForeColor( &forecolor
);
1367 ::RGBBackColor( &backcolor
);
1370 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1372 // null means only one pixel, at whatever resolution
1373 if ( penWidth
== 0 )
1375 ::PenSize(penWidth
, penWidth
);
1377 int penStyle
= m_pen
.GetStyle();
1379 if (penStyle
== wxSOLID
)
1381 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1383 else if (IS_HATCH(penStyle
))
1386 wxMacGetHatchPattern(penStyle
, &pat
);
1391 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1394 short mode
= patCopy
;
1398 switch( m_logicalFunction
)
1403 case wxINVERT
: // NOT dst
1404 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1407 case wxXOR
: // src XOR dst
1410 case wxOR_REVERSE
: // src OR (NOT dst)
1413 case wxSRC_INVERT
: // (NOT src)
1420 case wxAND_REVERSE
:// src AND (NOT dst)
1421 case wxAND
: // src AND dst
1422 case wxAND_INVERT
: // (NOT src) AND dst
1423 case wxNO_OP
: // dst
1424 case wxNOR
: // (NOT src) AND (NOT dst)
1425 case wxEQUIV
: // (NOT src) XOR dst
1426 case wxOR_INVERT
: // (NOT src) OR dst
1427 case wxNAND
: // (NOT src) OR (NOT dst)
1428 case wxOR
: // src OR dst
1430 // case wxSRC_OR: // source _bitmap_ OR destination
1431 // case wxSRC_AND: // source _bitmap_ AND destination
1435 m_macPenInstalled
= true ;
1436 m_macBrushInstalled
= false ;
1437 m_macFontInstalled
= false ;
1440 void wxDC::MacInstallBrush() const
1445 Pattern blackColor
, whiteColor
;
1446 if ( m_macBrushInstalled
)
1451 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1452 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1453 ::RGBForeColor( &forecolor
);
1454 ::RGBBackColor( &backcolor
);
1456 int brushStyle
= m_brush
.GetStyle();
1457 if (brushStyle
== wxSOLID
)
1458 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1459 else if (IS_HATCH(brushStyle
))
1462 wxMacGetHatchPattern(brushStyle
, &pat
);
1467 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1473 brushStyle
= m_backgroundBrush
.GetStyle();
1474 if (brushStyle
== wxSOLID
)
1475 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1476 else if (IS_HATCH(brushStyle
))
1479 wxMacGetHatchPattern(brushStyle
, &pat
);
1484 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1487 short mode
= patCopy
;
1491 switch( m_logicalFunction
)
1496 case wxINVERT
: // NOT dst
1497 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1500 case wxXOR
: // src XOR dst
1503 case wxOR_REVERSE
: // src OR (NOT dst)
1506 case wxSRC_INVERT
: // (NOT src)
1513 case wxAND_REVERSE
:// src AND (NOT dst)
1514 case wxAND
: // src AND dst
1515 case wxAND_INVERT
: // (NOT src) AND dst
1516 case wxNO_OP
: // dst
1517 case wxNOR
: // (NOT src) AND (NOT dst)
1518 case wxEQUIV
: // (NOT src) XOR dst
1519 case wxOR_INVERT
: // (NOT src) OR dst
1520 case wxNAND
: // (NOT src) OR (NOT dst)
1521 case wxOR
: // src OR dst
1523 // case wxSRC_OR: // source _bitmap_ OR destination
1524 // case wxSRC_AND: // source _bitmap_ AND destination
1528 m_macBrushInstalled
= true ;
1529 m_macPenInstalled
= false ;
1530 m_macFontInstalled
= false ;
1533 // ---------------------------------------------------------------------------
1534 // coordinates transformations
1535 // ---------------------------------------------------------------------------
1538 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1540 return ((wxDC
*)this)->XDEV2LOG(x
);
1543 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1545 return ((wxDC
*)this)->YDEV2LOG(y
);
1548 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1550 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1553 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1555 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1558 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1560 return ((wxDC
*)this)->XLOG2DEV(x
);
1563 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1565 return ((wxDC
*)this)->YLOG2DEV(y
);
1568 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1570 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1573 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1575 return ((wxDC
*)this)->YLOG2DEVREL(y
);