1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
17 #include "wx/mac/uma.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 #define mm2inches 0.0393700787402
28 #define inches2mm 25.4
29 #define mm2twips 56.6929133859
30 #define twips2mm 0.0176388888889
31 #define mm2pt 2.83464566929
32 #define pt2mm 0.352777777778
34 long wxDC::m_macCurrentPortId
= 1 ;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
44 m_autoSetting
= FALSE
;
48 m_mm_to_pix_x
= mm2pt
;
49 m_mm_to_pix_y
= mm2pt
;
55 m_internalDeviceOriginX
= 0;
56 m_internalDeviceOriginY
= 0;
57 m_externalDeviceOriginX
= 0;
58 m_externalDeviceOriginY
= 0;
60 m_logicalScaleX
= 1.0;
61 m_logicalScaleY
= 1.0;
67 m_mappingMode
= wxMM_TEXT
;
68 m_needComputeScaleX
= FALSE
;
69 m_needComputeScaleY
= FALSE
;
71 m_signX
= 1; // default x-axis left to right
72 m_signY
= 1; // default y-axis top down
74 m_maxX
= m_maxY
= -100000;
75 m_minY
= m_minY
= 100000;
77 m_logicalFunction
= wxCOPY
;
78 // m_textAlignment = wxALIGN_TOP_LEFT;
79 m_backgroundMode
= wxTRANSPARENT
;
81 m_textForegroundColour
= *wxBLACK
;
82 m_textBackgroundColour
= *wxWHITE
;
84 m_font
= *wxNORMAL_FONT
;
85 m_brush
= *wxTRANSPARENT_BRUSH
;
86 m_backgroundBrush
= *wxWHITE_BRUSH
;
88 // m_palette = wxAPP_COLOURMAP;
93 m_macFontInstalled
= false ;
94 m_macBrushInstalled
= false ;
95 m_macPenInstalled
= false ;
98 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
99 m_macClipRect
.left
= -32000 ;
100 m_macClipRect
.top
= -32000 ;
101 m_macClipRect
.right
= 32000 ;
102 m_macClipRect
.bottom
= 32000 ;
103 ::GetPort( &m_macOrigPort
) ;
108 if ( !m_macPortHelper
.IsCleared() )
112 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
119 ::SetPort( m_macPort ) ;
120 ::SetOrigin( 0 , 0 ) ;
121 ::ClipRect( &m_macPort->portRect ) ;
123 ::SetPort( m_macOrigPort ) ;
126 ++m_macCurrentPortId
;
129 void wxDC::MacSetupPort() const
131 AGAPortHelper
* help
= &m_macPortHelper
;
132 help
->Setup( m_macPort
) ;
133 m_macPortId
= ++m_macCurrentPortId
;
134 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
135 ::ClipRect(&m_macClipRect
);
137 m_macFontInstalled
= false ;
138 m_macBrushInstalled
= false ;
139 m_macPenInstalled
= false ;
142 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
150 long xx1
= XLOG2DEV(x
);
151 long yy1
= YLOG2DEV(y
);
154 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
158 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
160 Rect bitmaprect
= { 0 , 0 , bmap
->m_height
* scale
, bmap
->m_width
* scale
} ;
161 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
162 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
164 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
166 if ( bmap
->m_hBitmap
)
168 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
169 PixMapHandle bmappixels
;
170 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
171 RGBColor black
= { 0,0,0} ;
172 RGBForeColor( &black
) ;
173 RGBBackColor( &white
) ;
175 bmappixels
= GetGWorldPixMap( bmapworld
) ;
176 if ( LockPixels(bmappixels
) )
181 source
.right
= bmap
->m_width
;
182 source
.bottom
= bmap
->m_height
;
183 dest
.top
= YLOG2DEV(y
) ;
184 dest
.left
= XLOG2DEV(x
) ;
185 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
186 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
188 if ( useMask
&& bmp
.GetMask() )
190 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
192 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
193 GetPortBitMapForCopyBits( m_macPort
) ,
194 &source
, &source
, &dest
) ;
195 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
199 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
200 &source
, &dest
, srcCopy
, NULL
) ;
202 UnlockPixels( bmappixels
) ;
204 m_macPenInstalled
= false ;
205 m_macBrushInstalled
= false ;
206 m_macFontInstalled
= false ;
213 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
219 long xx1
= XLOG2DEV(x
);
220 long yy1
= YLOG2DEV(y
);
223 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
225 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
227 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
228 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
229 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
234 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
239 m_clipX1
= wxMax( m_clipX1
, x
) ;
240 m_clipY1
= wxMax( m_clipY1
,y
);
241 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
242 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
250 m_clipX2
= x
+ width
;
251 m_clipY2
= y
+ height
;
254 long x1
= XLOG2DEV(m_clipX1
);
255 long y1
= YLOG2DEV(m_clipY1
);
256 long x2
= XLOG2DEV(m_clipX2
);
257 long y2
= YLOG2DEV(m_clipY2
);
259 Rect clip
= { y1
, x1
, y2
, x2
} ;
261 ::ClipRect( &clip
) ;
265 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
267 wxCHECK_RET( Ok(), wxT("invalid window dc") );
272 DestroyClippingRegion();
276 wxCoord xx
, yy
, ww
, hh
;
277 region
.GetBox( xx
, yy
, ww
, hh
);
278 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
281 void wxDC::DestroyClippingRegion(void)
285 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
286 ::ClipRect(&m_macClipRect
);
289 void wxDC::DoGetSize( int* width
, int* height
) const
291 *width
= m_maxX
-m_minX
;
292 *height
= m_maxY
-m_minY
;
295 void wxDC::DoGetSizeMM( int* width
, int* height
) const
300 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
301 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
304 void wxDC::SetTextForeground( const wxColour
&col
)
307 m_textForegroundColour
= col
;
308 m_macFontInstalled
= false ;
311 void wxDC::SetTextBackground( const wxColour
&col
)
314 m_textBackgroundColour
= col
;
315 m_macFontInstalled
= false ;
318 void wxDC::SetMapMode( int mode
)
323 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
326 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
329 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
332 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
336 SetLogicalScale( 1.0, 1.0 );
339 if (mode
!= wxMM_TEXT
)
341 m_needComputeScaleX
= TRUE
;
342 m_needComputeScaleY
= TRUE
;
346 void wxDC::SetUserScale( double x
, double y
)
348 // allow negative ? -> no
351 ComputeScaleAndOrigin();
354 void wxDC::SetLogicalScale( double x
, double y
)
359 ComputeScaleAndOrigin();
362 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
364 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
365 m_logicalOriginY
= y
* m_signY
;
366 ComputeScaleAndOrigin();
369 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
371 m_externalDeviceOriginX
= x
;
372 m_externalDeviceOriginY
= y
;
373 ComputeScaleAndOrigin();
376 void wxDC::SetInternalDeviceOrigin( long x, long y )
378 m_internalDeviceOriginX = x;
379 m_internalDeviceOriginY = y;
380 ComputeScaleAndOrigin();
383 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
385 if (x) *x = m_internalDeviceOriginX;
386 if (y) *y = m_internalDeviceOriginY;
389 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
391 m_signX
= (xLeftRight
? 1 : -1);
392 m_signY
= (yBottomUp
? -1 : 1);
393 ComputeScaleAndOrigin();
397 void wxDC::CalcBoundingBox( long x, long y )
399 if (x < m_minX) m_minX = x;
400 if (y < m_minY) m_minY = y;
401 if (x > m_maxX) m_maxX = x;
402 if (y > m_maxY) m_maxY = y;
405 wxSize
wxDC::GetPPI() const
407 return wxSize(72, 72);
410 int wxDC::GetDepth() const
412 return wxDisplayDepth() ;
415 void wxDC::ComputeScaleAndOrigin(void)
417 // CMB: copy scale to see if it changes
418 double origScaleX
= m_scaleX
;
419 double origScaleY
= m_scaleY
;
421 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
422 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
424 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
425 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
427 // CMB: if scale has changed call SetPen to recalulate the line width
428 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
430 // TODO : set internal flags for recalc
434 void wxDC::SetPalette( const wxPalette
& palette
)
438 void wxDC::SetBackgroundMode( int mode
)
440 m_backgroundMode
= mode
;
443 void wxDC::SetFont( const wxFont
&font
)
451 m_macFontInstalled
= false ;
454 void wxDC::SetPen( const wxPen
&pen
)
469 m_macPenInstalled
= false ;
472 void wxDC::SetBrush( const wxBrush
&brush
)
478 if (m_brush
== brush
)
482 m_macBrushInstalled
= false ;
485 void wxDC::SetBackground( const wxBrush
&brush
)
491 if (m_backgroundBrush
== brush
)
494 m_backgroundBrush
= brush
;
496 if (!m_backgroundBrush
.Ok())
498 m_macBrushInstalled
= false ;
501 void wxDC::SetLogicalFunction( int function
)
503 if (m_logicalFunction
== function
)
506 m_logicalFunction
= function
;
507 m_macFontInstalled
= false ;
508 m_macBrushInstalled
= false ;
509 m_macPenInstalled
= false ;
512 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
517 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
522 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
529 if (m_pen
.GetStyle() != wxTRANSPARENT
)
532 int offset
= (m_pen
.GetWidth() - 1) / 2 ;
533 long xx1
= XLOG2DEV(x1
);
534 long yy1
= YLOG2DEV(y1
);
535 long xx2
= XLOG2DEV(x2
);
536 long yy2
= YLOG2DEV(y2
);
538 ::MoveTo(xx1
- offset
,yy1
- offset
);
539 ::LineTo(xx2
- offset
, yy2
- offset
);
543 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
547 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
548 wxCoord x2
, wxCoord y2
,
549 wxCoord xc
, wxCoord yc
)
553 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
554 double sa
, double ea
)
558 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
565 if (m_pen
.GetStyle() != wxTRANSPARENT
)
568 long xx1
= XLOG2DEV(x
);
569 long yy1
= YLOG2DEV(y
);
572 ::LineTo(xx1
+1, yy1
+1);
576 void wxDC::DoDrawLines(int n
, wxPoint points
[],
577 wxCoord xoffset
, wxCoord yoffset
)
583 if (m_pen
.GetStyle() == wxTRANSPARENT
)
588 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
589 long x1
, x2
, y1
, y2
;
590 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
591 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
592 ::MoveTo(x1
- offset
,y1
- offset
);
594 for (int i
= 0; i
< n
-1; i
++)
596 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
597 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
598 ::LineTo(x2
- offset
, y2
- offset
);
602 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
603 wxCoord xoffset
, wxCoord yoffset
,
610 PolyHandle polygon
= OpenPoly() ;
611 long x1
, x2
, y1
, y2
;
612 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
613 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
616 for (int i
= 0; i
< n
-1; i
++)
618 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
619 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
624 if (m_brush
.GetStyle() != wxTRANSPARENT
)
627 ::PaintPoly( polygon
) ;
630 if (m_pen
.GetStyle() != wxTRANSPARENT
)
633 ::FramePoly( polygon
) ;
635 KillPoly( polygon
) ;
638 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
644 long xx
= XLOG2DEV(x
);
645 long yy
= YLOG2DEV(y
);
646 long ww
= m_signX
* XLOG2DEVREL(width
);
647 long hh
= m_signY
* YLOG2DEVREL(height
);
649 // CMB: draw nothing if transformed w or h is 0
650 if (ww
== 0 || hh
== 0)
653 // CMB: handle -ve width and/or height
666 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
668 if (m_brush
.GetStyle() != wxTRANSPARENT
)
671 ::PaintRect( &rect
) ;
674 if (m_pen
.GetStyle() != wxTRANSPARENT
)
677 ::FrameRect( &rect
) ;
681 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
682 wxCoord width
, wxCoord height
,
690 radius
= - radius
* ((width
< height
) ? width
: height
);
692 long xx
= XLOG2DEV(x
);
693 long yy
= YLOG2DEV(y
);
694 long ww
= m_signX
* XLOG2DEVREL(width
);
695 long hh
= m_signY
* YLOG2DEVREL(height
);
697 // CMB: draw nothing if transformed w or h is 0
698 if (ww
== 0 || hh
== 0)
701 // CMB: handle -ve width and/or height
714 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
716 if (m_brush
.GetStyle() != wxTRANSPARENT
)
719 ::PaintRoundRect( &rect
, radius
* 2 , radius
* 2 ) ;
722 if (m_pen
.GetStyle() != wxTRANSPARENT
)
725 ::FrameRoundRect( &rect
, radius
* 2 , radius
* 2 ) ;
729 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
735 long xx
= XLOG2DEV(x
);
736 long yy
= YLOG2DEV(y
);
737 long ww
= m_signX
* XLOG2DEVREL(width
);
738 long hh
= m_signY
* YLOG2DEVREL(height
);
740 // CMB: draw nothing if transformed w or h is 0
741 if (ww
== 0 || hh
== 0)
744 // CMB: handle -ve width and/or height
757 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
759 if (m_brush
.GetStyle() != wxTRANSPARENT
)
762 ::PaintOval( &rect
) ;
765 if (m_pen
.GetStyle() != wxTRANSPARENT
)
768 ::FrameOval( &rect
) ;
772 // ----------------------------------- spline code ----------------------------------------
774 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
775 double a3
, double b3
, double a4
, double b4
);
776 static void wx_clear_stack(void);
777 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
778 double *y3
, double *x4
, double *y4
);
779 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
780 double x4
, double y4
);
781 static bool wx_spline_add_point(double x
, double y
);
782 static void wx_spline_draw_point_array(wxDC
*dc
);
784 static wxList wx_spline_point_list
;
786 #define half(z1, z2) ((z1+z2)/2.0)
789 /* iterative version */
791 static void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
794 register double xmid
, ymid
;
795 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
798 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
800 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
801 xmid
= (double)half(x2
, x3
);
802 ymid
= (double)half(y2
, y3
);
803 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
804 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
805 wx_spline_add_point( x1
, y1
);
806 wx_spline_add_point( xmid
, ymid
);
808 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
809 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
810 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
811 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
816 /* utilities used by spline drawing routines */
818 typedef struct wx_spline_stack_struct
{
819 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
822 #define SPLINE_STACK_DEPTH 20
823 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
824 static Stack
*wx_stack_top
;
825 static int wx_stack_count
;
827 static void wx_clear_stack(void)
829 wx_stack_top
= wx_spline_stack
;
833 static void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
835 wx_stack_top
->x1
= x1
;
836 wx_stack_top
->y1
= y1
;
837 wx_stack_top
->x2
= x2
;
838 wx_stack_top
->y2
= y2
;
839 wx_stack_top
->x3
= x3
;
840 wx_stack_top
->y3
= y3
;
841 wx_stack_top
->x4
= x4
;
842 wx_stack_top
->y4
= y4
;
847 static int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
848 double *x3
, double *y3
, double *x4
, double *y4
)
850 if (wx_stack_count
== 0)
854 *x1
= wx_stack_top
->x1
;
855 *y1
= wx_stack_top
->y1
;
856 *x2
= wx_stack_top
->x2
;
857 *y2
= wx_stack_top
->y2
;
858 *x3
= wx_stack_top
->x3
;
859 *y3
= wx_stack_top
->y3
;
860 *x4
= wx_stack_top
->x4
;
861 *y4
= wx_stack_top
->y4
;
865 static bool wx_spline_add_point(double x
, double y
)
867 wxPoint
*point
= new wxPoint
;
870 wx_spline_point_list
.Append((wxObject
*)point
);
874 static void wx_spline_draw_point_array(wxDC
*dc
)
876 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
877 wxNode
*node
= wx_spline_point_list
.First();
880 wxPoint
*point
= (wxPoint
*)node
->Data();
883 node
= wx_spline_point_list
.First();
887 void wxDC::DoDrawSpline(wxList
*points
)
890 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
891 double x1
, y1
, x2
, y2
;
893 wxNode
*node
= points
->First();
894 p
= (wxPoint
*)node
->Data();
900 p
= (wxPoint
*)node
->Data();
904 cx1
= (double)((x1
+ x2
) / 2);
905 cy1
= (double)((y1
+ y2
) / 2);
906 cx2
= (double)((cx1
+ x2
) / 2);
907 cy2
= (double)((cy1
+ y2
) / 2);
909 wx_spline_add_point(x1
, y1
);
911 while ((node
= node
->Next()) != NULL
)
913 p
= (wxPoint
*)node
->Data();
918 cx4
= (double)(x1
+ x2
) / 2;
919 cy4
= (double)(y1
+ y2
) / 2;
920 cx3
= (double)(x1
+ cx4
) / 2;
921 cy3
= (double)(y1
+ cy4
) / 2;
923 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
927 cx2
= (double)(cx1
+ x2
) / 2;
928 cy2
= (double)(cy1
+ y2
) / 2;
931 wx_spline_add_point( cx1
, cy1
);
932 wx_spline_add_point( x2
, y2
);
934 wx_spline_draw_point_array( this );
939 bool wxDC::CanDrawBitmap(void) const
945 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
946 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
948 if (!Ok()) return FALSE
;
951 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
952 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
953 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
954 RGBColor black
= { 0,0,0} ;
955 RGBForeColor( &m_textForegroundColour
.GetPixel() ) ;
956 RGBBackColor( &m_textBackgroundColour
.GetPixel() ) ;
958 if ( LockPixels(bmappixels
) )
960 Rect srcrect
, dstrect
;
961 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
962 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
963 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
964 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
965 dstrect
.top
= YLOG2DEV(ydest
) ;
966 dstrect
.left
= XLOG2DEV(xdest
) ;
967 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
968 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
970 short mode
= (logical_func
== wxCOPY
? srcCopy
:
971 // logical_func == wxCLEAR ? WHITENESS :
972 // logical_func == wxSET ? BLACKNESS :
973 logical_func
== wxINVERT
? hilite
:
974 // logical_func == wxAND ? MERGECOPY :
975 logical_func
== wxOR
? srcOr
:
976 logical_func
== wxSRC_INVERT
? notSrcCopy
:
977 logical_func
== wxXOR
? srcXor
:
978 // logical_func == wxOR_REVERSE ? MERGEPAINT :
979 // logical_func == wxAND_REVERSE ? SRCERASE :
980 // logical_func == wxSRC_OR ? srcOr :
981 // logical_func == wxSRC_AND ? SRCAND :
984 if ( useMask
&& source
->m_macMask
)
986 wxASSERT( mode
== srcCopy
) ;
987 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
989 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
990 GetPortBitMapForCopyBits( m_macPort
) ,
991 &srcrect
, &srcrect
, &dstrect
) ;
992 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
997 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
998 &srcrect
, &dstrect
, mode
, NULL
) ;
1000 UnlockPixels( bmappixels
) ;
1003 m_macPenInstalled
= false ;
1004 m_macBrushInstalled
= false ;
1005 m_macFontInstalled
= false ;
1010 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
1014 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
1020 long xx
= XLOG2DEV(x
);
1021 long yy
= YLOG2DEV(y
);
1023 // if (m_pen.GetStyle() != wxTRANSPARENT)
1027 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1029 ::ClipRect( &clip ) ;
1033 ::GetFontInfo( &fi
) ;
1036 ::MoveTo( xx
, yy
);
1037 if ( m_backgroundMode
== wxTRANSPARENT
)
1039 ::TextMode( srcOr
) ;
1043 ::TextMode( srcCopy
) ;
1046 const char *text
= NULL
;
1050 if ( wxApp::s_macDefaultEncodingIsPC
)
1052 macText
= wxMacMakeMacStringFromPC( strtext
) ;
1054 length
= macText
.Length() ;
1059 length
= strtext
.Length() ;
1068 if( text
[i
] == 13 || text
[i
] == 10)
1070 ::DrawText( text
, laststop
, i
- laststop
) ;
1072 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
1078 ::DrawText( text
, laststop
, i
- laststop
) ;
1079 ::TextMode( srcOr
) ;
1083 bool wxDC::CanGetTextExtent(void) const
1091 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1092 wxCoord
*descent
, wxCoord
*externalLeading
,
1093 wxFont
*theFont
) const
1100 wxFont formerFont
= m_font
;
1104 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1108 ::TextFont( font
->m_macFontNum
) ;
1109 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
1110 ::TextFace( font
->m_macFontStyle
) ;
1119 ::GetFontInfo( &fi
) ;
1122 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
1124 *descent
=YDEV2LOGREL( fi
.descent
);
1125 if ( externalLeading
)
1126 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
1128 const char *text
= NULL
;
1131 if ( wxApp::s_macDefaultEncodingIsPC
)
1133 macText
= wxMacMakeMacStringFromPC( string
) ;
1135 length
= macText
.Length() ;
1140 length
= string
.Length() ;
1152 if( text
[i
] == 13 || text
[i
] == 10)
1155 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1156 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1157 if ( curwidth
> *width
)
1158 *width
= XDEV2LOGREL( curwidth
) ;
1164 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1165 if ( curwidth
> *width
)
1166 *width
= XDEV2LOGREL( curwidth
) ;
1171 m_macFontInstalled
= false ;
1175 wxCoord
wxDC::GetCharWidth(void) const
1185 ::GetFontInfo( &fi
) ;
1187 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1190 wxCoord
wxDC::GetCharHeight(void) const
1200 ::GetFontInfo( &fi
) ;
1202 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1205 void wxDC::Clear(void)
1210 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1212 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1215 ::EraseRect( &rect
) ;
1219 void wxDC::MacInstallFont() const
1225 if ( m_macFontInstalled
)
1227 Pattern blackColor
;
1229 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1233 ::TextFont( font
->m_macFontNum
) ;
1234 ::TextSize( m_scaleY
* font
->m_macFontSize
) ;
1235 ::TextFace( font
->m_macFontStyle
) ;
1237 m_macFontInstalled
= true ;
1238 m_macBrushInstalled
= false ;
1239 m_macPenInstalled
= false ;
1241 ::RGBForeColor(&m_textForegroundColour
.GetPixel() );
1242 ::RGBBackColor(&m_textBackgroundColour
.GetPixel() );
1248 GetFNum( "\pGeneva" , &fontnum
) ;
1249 ::TextFont( fontnum
) ;
1250 ::TextSize( m_scaleY
* 10 ) ;
1253 // todo reset after spacing changes - or store the current spacing somewhere
1255 m_macFontInstalled
= true ;
1256 m_macBrushInstalled
= false ;
1257 m_macPenInstalled
= false ;
1258 ::RGBForeColor( &(m_textForegroundColour
.GetPixel()) );
1259 ::RGBBackColor(&m_textBackgroundColour
.GetPixel() );
1263 short mode
= patCopy
;
1267 switch( m_logicalFunction
)
1272 case wxINVERT
: // NOT dst
1273 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1276 case wxXOR
: // src XOR dst
1279 case wxOR_REVERSE
: // src OR (NOT dst)
1282 case wxSRC_INVERT
: // (NOT src)
1289 case wxAND_REVERSE
:// src AND (NOT dst)
1290 case wxAND
: // src AND dst
1291 case wxAND_INVERT
: // (NOT src) AND dst
1292 case wxNO_OP
: // dst
1293 case wxNOR
: // (NOT src) AND (NOT dst)
1294 case wxEQUIV
: // (NOT src) XOR dst
1295 case wxOR_INVERT
: // (NOT src) OR dst
1296 case wxNAND
: // (NOT src) OR (NOT dst)
1297 case wxOR
: // src OR dst
1299 // case wxSRC_OR: // source _bitmap_ OR destination
1300 // case wxSRC_AND: // source _bitmap_ AND destination
1306 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1308 int thePatListID
= sysPatListID
;
1312 case wxBDIAGONAL_HATCH
:
1313 theIndex
= 34; // WCH: this is not good
1315 case wxFDIAGONAL_HATCH
:
1321 case wxHORIZONTAL_HATCH
:
1324 case wxVERTICAL_HATCH
:
1327 case wxCROSSDIAG_HATCH
:
1328 theIndex
= 4; // WCH: this is not good
1331 theIndex
= 1; // solid pattern
1334 GetIndPattern( pattern
, thePatListID
, theIndex
);
1337 void wxDC::MacInstallPen() const
1345 if ( m_macPenInstalled
)
1348 ::RGBForeColor(&m_pen
.GetColour().GetPixel() );
1349 ::RGBBackColor(&m_backgroundBrush
.GetColour().GetPixel() );
1352 int penWidth
= m_pen
.GetWidth();
1353 ::PenSize(penWidth
, penWidth
);
1355 int penStyle
= m_pen
.GetStyle();
1357 if (penStyle
== wxSOLID
)
1358 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1359 else if (IS_HATCH(penStyle
))
1362 wxMacGetHatchPattern(penStyle
, &pat
);
1367 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1370 short mode
= patCopy
;
1374 switch( m_logicalFunction
)
1379 case wxINVERT
: // NOT dst
1380 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1383 case wxXOR
: // src XOR dst
1386 case wxOR_REVERSE
: // src OR (NOT dst)
1389 case wxSRC_INVERT
: // (NOT src)
1396 case wxAND_REVERSE
:// src AND (NOT dst)
1397 case wxAND
: // src AND dst
1398 case wxAND_INVERT
: // (NOT src) AND dst
1399 case wxNO_OP
: // dst
1400 case wxNOR
: // (NOT src) AND (NOT dst)
1401 case wxEQUIV
: // (NOT src) XOR dst
1402 case wxOR_INVERT
: // (NOT src) OR dst
1403 case wxNAND
: // (NOT src) OR (NOT dst)
1404 case wxOR
: // src OR dst
1406 // case wxSRC_OR: // source _bitmap_ OR destination
1407 // case wxSRC_AND: // source _bitmap_ AND destination
1411 m_macPenInstalled
= true ;
1412 m_macBrushInstalled
= false ;
1413 m_macFontInstalled
= false ;
1416 void wxDC::MacInstallBrush() const
1421 Pattern blackColor
, whiteColor
;
1422 if ( m_macBrushInstalled
)
1427 ::RGBForeColor(&m_brush
.GetColour().GetPixel() );
1428 ::RGBBackColor(&m_backgroundBrush
.GetColour().GetPixel() );
1430 int brushStyle
= m_brush
.GetStyle();
1431 if (brushStyle
== wxSOLID
)
1432 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1433 else if (IS_HATCH(brushStyle
))
1436 wxMacGetHatchPattern(brushStyle
, &pat
);
1441 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1447 brushStyle
= m_backgroundBrush
.GetStyle();
1448 if (brushStyle
== wxSOLID
)
1449 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1450 else if (IS_HATCH(brushStyle
))
1453 wxMacGetHatchPattern(brushStyle
, &pat
);
1458 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1461 short mode
= patCopy
;
1465 switch( m_logicalFunction
)
1470 case wxINVERT
: // NOT dst
1471 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1474 case wxXOR
: // src XOR dst
1477 case wxOR_REVERSE
: // src OR (NOT dst)
1480 case wxSRC_INVERT
: // (NOT src)
1487 case wxAND_REVERSE
:// src AND (NOT dst)
1488 case wxAND
: // src AND dst
1489 case wxAND_INVERT
: // (NOT src) AND dst
1490 case wxNO_OP
: // dst
1491 case wxNOR
: // (NOT src) AND (NOT dst)
1492 case wxEQUIV
: // (NOT src) XOR dst
1493 case wxOR_INVERT
: // (NOT src) OR dst
1494 case wxNAND
: // (NOT src) OR (NOT dst)
1495 case wxOR
: // src OR dst
1497 // case wxSRC_OR: // source _bitmap_ OR destination
1498 // case wxSRC_AND: // source _bitmap_ AND destination
1502 m_macBrushInstalled
= true ;
1503 m_macPenInstalled
= false ;
1504 m_macFontInstalled
= false ;
1507 // ---------------------------------------------------------------------------
1508 // coordinates transformations
1509 // ---------------------------------------------------------------------------
1512 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1514 return ((wxDC
*)this)->XDEV2LOG(x
);
1517 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1519 return ((wxDC
*)this)->YDEV2LOG(y
);
1522 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1524 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1527 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1529 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1532 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1534 return ((wxDC
*)this)->XLOG2DEV(x
);
1537 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1539 return ((wxDC
*)this)->YLOG2DEV(y
);
1542 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1544 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1547 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1549 return ((wxDC
*)this)->YLOG2DEVREL(y
);