]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dc.cpp
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 //-----------------------------------------------------------------------------
50 m_mm_to_pix_x
= mm2pt
;
51 m_mm_to_pix_y
= mm2pt
;
53 m_internalDeviceOriginX
= 0;
54 m_internalDeviceOriginY
= 0;
55 m_externalDeviceOriginX
= 0;
56 m_externalDeviceOriginY
= 0;
58 m_logicalScaleX
= 1.0;
59 m_logicalScaleY
= 1.0;
65 m_needComputeScaleX
= FALSE
;
66 m_needComputeScaleY
= FALSE
;
68 m_maxX
= m_maxY
= -100000;
69 m_minY
= m_minY
= 100000;
75 m_macFontInstalled
= false ;
76 m_macBrushInstalled
= false ;
77 m_macPenInstalled
= false ;
80 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
81 m_macClipRect
.left
= -32000 ;
82 m_macClipRect
.top
= -32000 ;
83 m_macClipRect
.right
= 32000 ;
84 m_macClipRect
.bottom
= 32000 ;
85 ::GetPort( &m_macOrigPort
) ;
88 m_font
= *wxNORMAL_FONT
;
89 m_brush
= *wxWHITE_BRUSH
;
94 if ( !m_macPortHelper
.IsCleared() )
98 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
105 ::SetPort( m_macPort ) ;
106 ::SetOrigin( 0 , 0 ) ;
107 ::ClipRect( &m_macPort->portRect ) ;
109 ::SetPort( m_macOrigPort ) ;
112 ++m_macCurrentPortId
;
115 void wxDC::MacSetupPort() const
117 AGAPortHelper
* help
= (AGAPortHelper
*) &m_macPortHelper
;
118 help
->Setup( m_macPort
) ;
119 m_macPortId
= ++m_macCurrentPortId
;
120 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
121 ::ClipRect(&m_macClipRect
);
123 m_macFontInstalled
= false ;
124 m_macBrushInstalled
= false ;
125 m_macPenInstalled
= false ;
128 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
136 long xx1
= XLOG2DEV(x
);
137 long yy1
= YLOG2DEV(y
);
140 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
144 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
146 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
147 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
148 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
150 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
152 if ( bmap
->m_hBitmap
)
154 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
155 PixMapHandle bmappixels
;
156 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
157 RGBColor black
= { 0,0,0} ;
158 RGBForeColor( &black
) ;
159 RGBBackColor( &white
) ;
161 bmappixels
= GetGWorldPixMap( bmapworld
) ;
162 if ( LockPixels(bmappixels
) )
167 source
.right
= bmap
->m_width
;
168 source
.bottom
= bmap
->m_height
;
169 dest
.top
= YLOG2DEV(y
) ;
170 dest
.left
= XLOG2DEV(x
) ;
171 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
172 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
174 if ( useMask
&& bmp
.GetMask() )
176 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
178 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
179 GetPortBitMapForCopyBits( m_macPort
) ,
180 &source
, &source
, &dest
) ;
181 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
185 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
186 &source
, &dest
, srcCopy
, NULL
) ;
188 UnlockPixels( bmappixels
) ;
190 m_macPenInstalled
= false ;
191 m_macBrushInstalled
= false ;
192 m_macFontInstalled
= false ;
199 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
205 long xx1
= XLOG2DEV(x
);
206 long yy1
= YLOG2DEV(y
);
209 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
211 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
213 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
214 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
215 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
220 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
225 m_clipX1
= wxMax( m_clipX1
, x
) ;
226 m_clipY1
= wxMax( m_clipY1
,y
);
227 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
228 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
236 m_clipX2
= x
+ width
;
237 m_clipY2
= y
+ height
;
240 long x1
= XLOG2DEV(m_clipX1
);
241 long y1
= YLOG2DEV(m_clipY1
);
242 long x2
= XLOG2DEV(m_clipX2
);
243 long y2
= YLOG2DEV(m_clipY2
);
245 Rect clip
= { y1
, x1
, y2
, x2
} ;
247 ::ClipRect( &clip
) ;
251 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
253 wxCHECK_RET( Ok(), wxT("invalid window dc") );
258 DestroyClippingRegion();
262 wxCoord xx
, yy
, ww
, hh
;
263 region
.GetBox( xx
, yy
, ww
, hh
);
264 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
267 void wxDC::DestroyClippingRegion(void)
271 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
272 ::ClipRect(&m_macClipRect
);
275 void wxDC::DoGetSize( int* width
, int* height
) const
277 *width
= m_maxX
-m_minX
;
278 *height
= m_maxY
-m_minY
;
281 void wxDC::DoGetSizeMM( int* width
, int* height
) const
286 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
287 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
290 void wxDC::SetTextForeground( const wxColour
&col
)
293 m_textForegroundColour
= col
;
294 m_macFontInstalled
= false ;
297 void wxDC::SetTextBackground( const wxColour
&col
)
300 m_textBackgroundColour
= col
;
301 m_macFontInstalled
= false ;
304 void wxDC::SetMapMode( int mode
)
309 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
312 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
315 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
318 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
322 SetLogicalScale( 1.0, 1.0 );
325 if (mode
!= wxMM_TEXT
)
327 m_needComputeScaleX
= TRUE
;
328 m_needComputeScaleY
= TRUE
;
332 void wxDC::SetUserScale( double x
, double y
)
334 // allow negative ? -> no
337 ComputeScaleAndOrigin();
340 void wxDC::SetLogicalScale( double x
, double y
)
345 ComputeScaleAndOrigin();
348 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
350 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
351 m_logicalOriginY
= y
* m_signY
;
352 ComputeScaleAndOrigin();
355 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
357 m_externalDeviceOriginX
= x
;
358 m_externalDeviceOriginY
= y
;
359 ComputeScaleAndOrigin();
362 void wxDC::SetInternalDeviceOrigin( long x, long y )
364 m_internalDeviceOriginX = x;
365 m_internalDeviceOriginY = y;
366 ComputeScaleAndOrigin();
369 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
371 if (x) *x = m_internalDeviceOriginX;
372 if (y) *y = m_internalDeviceOriginY;
375 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
377 m_signX
= (xLeftRight
? 1 : -1);
378 m_signY
= (yBottomUp
? -1 : 1);
379 ComputeScaleAndOrigin();
383 void wxDC::CalcBoundingBox( long x, long y )
385 if (x < m_minX) m_minX = x;
386 if (y < m_minY) m_minY = y;
387 if (x > m_maxX) m_maxX = x;
388 if (y > m_maxY) m_maxY = y;
391 wxSize
wxDC::GetPPI() const
393 return wxSize(72, 72);
396 int wxDC::GetDepth() const
398 return wxDisplayDepth() ;
401 void wxDC::ComputeScaleAndOrigin(void)
403 // CMB: copy scale to see if it changes
404 double origScaleX
= m_scaleX
;
405 double origScaleY
= m_scaleY
;
407 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
408 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
410 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
411 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
413 // CMB: if scale has changed call SetPen to recalulate the line width
414 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
416 // this is a bit artificial, but we need to force wxDC to think
417 // the pen has changed
418 wxPen
* pen
= & GetPen();
425 void wxDC::SetPalette( const wxPalette
& palette
)
429 void wxDC::SetBackgroundMode( int mode
)
431 m_backgroundMode
= mode
;
434 void wxDC::SetFont( const wxFont
&font
)
442 m_macFontInstalled
= false ;
445 void wxDC::SetPen( const wxPen
&pen
)
460 m_macPenInstalled
= false ;
463 void wxDC::SetBrush( const wxBrush
&brush
)
469 if (m_brush
== brush
)
473 m_macBrushInstalled
= false ;
476 void wxDC::SetBackground( const wxBrush
&brush
)
482 if (m_backgroundBrush
== brush
)
485 m_backgroundBrush
= brush
;
487 if (!m_backgroundBrush
.Ok())
489 m_macBrushInstalled
= false ;
492 void wxDC::SetLogicalFunction( int function
)
494 if (m_logicalFunction
== function
)
497 m_logicalFunction
= function
;
498 m_macFontInstalled
= false ;
499 m_macBrushInstalled
= false ;
500 m_macPenInstalled
= false ;
503 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
508 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
513 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
520 if (m_pen
.GetStyle() != wxTRANSPARENT
)
523 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
524 long xx1
= XLOG2DEV(x1
);
525 long yy1
= YLOG2DEV(y1
);
526 long xx2
= XLOG2DEV(x2
);
527 long yy2
= YLOG2DEV(y2
);
529 ::MoveTo(xx1
- offset
,yy1
- offset
);
530 ::LineTo(xx2
- offset
, yy2
- offset
);
534 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
538 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
539 wxCoord x2
, wxCoord y2
,
540 wxCoord xc
, wxCoord yc
)
544 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
545 double sa
, double ea
)
549 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
556 if (m_pen
.GetStyle() != wxTRANSPARENT
)
559 long xx1
= XLOG2DEV(x
);
560 long yy1
= YLOG2DEV(y
);
563 ::LineTo(xx1
+1, yy1
+1);
567 void wxDC::DoDrawLines(int n
, wxPoint points
[],
568 wxCoord xoffset
, wxCoord yoffset
)
574 if (m_pen
.GetStyle() == wxTRANSPARENT
)
579 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
580 long x1
, x2
, y1
, y2
;
581 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
582 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
583 ::MoveTo(x1
- offset
,y1
- offset
);
585 for (int i
= 0; i
< n
-1; i
++)
587 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
588 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
589 ::LineTo(x2
- offset
, y2
- offset
);
593 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
594 wxCoord xoffset
, wxCoord yoffset
,
601 PolyHandle polygon
= OpenPoly() ;
602 long x1
, x2
, y1
, y2
;
603 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
604 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
607 for (int i
= 0; i
< n
-1; i
++)
609 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
610 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
615 if (m_brush
.GetStyle() != wxTRANSPARENT
)
618 ::PaintPoly( polygon
) ;
621 if (m_pen
.GetStyle() != wxTRANSPARENT
)
624 ::FramePoly( polygon
) ;
626 KillPoly( polygon
) ;
629 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
635 long xx
= XLOG2DEV(x
);
636 long yy
= YLOG2DEV(y
);
637 long ww
= m_signX
* XLOG2DEVREL(width
);
638 long hh
= m_signY
* YLOG2DEVREL(height
);
640 // CMB: draw nothing if transformed w or h is 0
641 if (ww
== 0 || hh
== 0)
644 // CMB: handle -ve width and/or height
657 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
659 if (m_brush
.GetStyle() != wxTRANSPARENT
)
662 ::PaintRect( &rect
) ;
665 if (m_pen
.GetStyle() != wxTRANSPARENT
)
668 ::FrameRect( &rect
) ;
672 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
673 wxCoord width
, wxCoord height
,
681 radius
= - radius
* ((width
< height
) ? width
: height
);
683 long xx
= XLOG2DEV(x
);
684 long yy
= YLOG2DEV(y
);
685 long ww
= m_signX
* XLOG2DEVREL(width
);
686 long hh
= m_signY
* YLOG2DEVREL(height
);
688 // CMB: draw nothing if transformed w or h is 0
689 if (ww
== 0 || hh
== 0)
692 // CMB: handle -ve width and/or height
705 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
707 if (m_brush
.GetStyle() != wxTRANSPARENT
)
710 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
713 if (m_pen
.GetStyle() != wxTRANSPARENT
)
716 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
720 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
726 long xx
= XLOG2DEV(x
);
727 long yy
= YLOG2DEV(y
);
728 long ww
= m_signX
* XLOG2DEVREL(width
);
729 long hh
= m_signY
* YLOG2DEVREL(height
);
731 // CMB: draw nothing if transformed w or h is 0
732 if (ww
== 0 || hh
== 0)
735 // CMB: handle -ve width and/or height
748 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
750 if (m_brush
.GetStyle() != wxTRANSPARENT
)
753 ::PaintOval( &rect
) ;
756 if (m_pen
.GetStyle() != wxTRANSPARENT
)
759 ::FrameOval( &rect
) ;
765 bool wxDC::CanDrawBitmap(void) const
771 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
772 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
774 if (!Ok()) return FALSE
;
777 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
778 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
779 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
780 RGBColor black
= { 0,0,0} ;
781 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
782 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
783 RGBForeColor( &forecolor
) ;
784 RGBBackColor( &backcolor
) ;
786 if ( LockPixels(bmappixels
) )
788 Rect srcrect
, dstrect
;
789 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
790 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
791 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
792 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
793 dstrect
.top
= YLOG2DEV(ydest
) ;
794 dstrect
.left
= XLOG2DEV(xdest
) ;
795 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
796 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
798 short mode
= (logical_func
== wxCOPY
? srcCopy
:
799 // logical_func == wxCLEAR ? WHITENESS :
800 // logical_func == wxSET ? BLACKNESS :
801 logical_func
== wxINVERT
? hilite
:
802 // logical_func == wxAND ? MERGECOPY :
803 logical_func
== wxOR
? srcOr
:
804 logical_func
== wxSRC_INVERT
? notSrcCopy
:
805 logical_func
== wxXOR
? srcXor
:
806 // logical_func == wxOR_REVERSE ? MERGEPAINT :
807 // logical_func == wxAND_REVERSE ? SRCERASE :
808 // logical_func == wxSRC_OR ? srcOr :
809 // logical_func == wxSRC_AND ? SRCAND :
812 if ( useMask
&& source
->m_macMask
)
814 wxASSERT( mode
== srcCopy
) ;
815 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
817 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
818 GetPortBitMapForCopyBits( m_macPort
) ,
819 &srcrect
, &srcrect
, &dstrect
) ;
820 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
825 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
826 &srcrect
, &dstrect
, mode
, NULL
) ;
828 UnlockPixels( bmappixels
) ;
831 m_macPenInstalled
= false ;
832 m_macBrushInstalled
= false ;
833 m_macFontInstalled
= false ;
838 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
842 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
848 long xx
= XLOG2DEV(x
);
849 long yy
= YLOG2DEV(y
);
851 // if (m_pen.GetStyle() != wxTRANSPARENT)
855 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
857 ::ClipRect( &clip ) ;
861 ::GetFontInfo( &fi
) ;
865 if ( m_backgroundMode
== wxTRANSPARENT
)
871 ::TextMode( srcCopy
) ;
874 const char *text
= NULL
;
878 if ( wxApp::s_macDefaultEncodingIsPC
)
880 macText
= wxMacMakeMacStringFromPC( strtext
) ;
882 length
= macText
.Length() ;
887 length
= strtext
.Length() ;
896 if( text
[i
] == 13 || text
[i
] == 10)
898 ::DrawText( text
, laststop
, i
- laststop
) ;
900 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
906 ::DrawText( text
, laststop
, i
- laststop
) ;
907 ::TextMode( srcOr
) ;
911 bool wxDC::CanGetTextExtent(void) const
919 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
920 wxCoord
*descent
, wxCoord
*externalLeading
,
921 wxFont
*theFont
) const
928 wxFont formerFont
= m_font
;
932 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
936 ::TextFont( font
->m_macFontNum
) ;
937 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
938 ::TextFace( font
->m_macFontStyle
) ;
947 ::GetFontInfo( &fi
) ;
950 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
952 *descent
=YDEV2LOGREL( fi
.descent
);
953 if ( externalLeading
)
954 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
956 const char *text
= NULL
;
959 if ( wxApp::s_macDefaultEncodingIsPC
)
961 macText
= wxMacMakeMacStringFromPC( string
) ;
963 length
= macText
.Length() ;
968 length
= string
.Length() ;
980 if( text
[i
] == 13 || text
[i
] == 10)
983 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
984 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
985 if ( curwidth
> *width
)
986 *width
= XDEV2LOGREL( curwidth
) ;
992 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
993 if ( curwidth
> *width
)
994 *width
= XDEV2LOGREL( curwidth
) ;
999 m_macFontInstalled
= false ;
1003 wxCoord
wxDC::GetCharWidth(void) const
1013 ::GetFontInfo( &fi
) ;
1015 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1018 wxCoord
wxDC::GetCharHeight(void) const
1028 ::GetFontInfo( &fi
) ;
1030 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1033 void wxDC::Clear(void)
1038 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1040 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1043 ::EraseRect( &rect
) ;
1047 void wxDC::MacInstallFont() const
1053 if ( m_macFontInstalled
)
1055 Pattern blackColor
;
1057 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1061 ::TextFont( font
->m_macFontNum
) ;
1062 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1063 ::TextFace( font
->m_macFontStyle
) ;
1065 m_macFontInstalled
= true ;
1066 m_macBrushInstalled
= false ;
1067 m_macPenInstalled
= false ;
1069 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1070 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1071 ::RGBForeColor( &forecolor
);
1072 ::RGBBackColor( &backcolor
);
1078 GetFNum( "\pGeneva" , &fontnum
) ;
1079 ::TextFont( fontnum
) ;
1080 ::TextSize( short(m_scaleY
* 10) ) ;
1083 // todo reset after spacing changes - or store the current spacing somewhere
1085 m_macFontInstalled
= true ;
1086 m_macBrushInstalled
= false ;
1087 m_macPenInstalled
= false ;
1089 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1090 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1091 ::RGBForeColor( &forecolor
);
1092 ::RGBBackColor( &backcolor
);
1095 short mode
= patCopy
;
1099 switch( m_logicalFunction
)
1104 case wxINVERT
: // NOT dst
1105 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1108 case wxXOR
: // src XOR dst
1111 case wxOR_REVERSE
: // src OR (NOT dst)
1114 case wxSRC_INVERT
: // (NOT src)
1121 case wxAND_REVERSE
:// src AND (NOT dst)
1122 case wxAND
: // src AND dst
1123 case wxAND_INVERT
: // (NOT src) AND dst
1124 case wxNO_OP
: // dst
1125 case wxNOR
: // (NOT src) AND (NOT dst)
1126 case wxEQUIV
: // (NOT src) XOR dst
1127 case wxOR_INVERT
: // (NOT src) OR dst
1128 case wxNAND
: // (NOT src) OR (NOT dst)
1129 case wxOR
: // src OR dst
1131 // case wxSRC_OR: // source _bitmap_ OR destination
1132 // case wxSRC_AND: // source _bitmap_ AND destination
1138 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1140 int thePatListID
= sysPatListID
;
1144 case wxBDIAGONAL_HATCH
:
1145 theIndex
= 34; // WCH: this is not good
1147 case wxFDIAGONAL_HATCH
:
1153 case wxHORIZONTAL_HATCH
:
1156 case wxVERTICAL_HATCH
:
1159 case wxCROSSDIAG_HATCH
:
1160 theIndex
= 4; // WCH: this is not good
1163 theIndex
= 1; // solid pattern
1166 GetIndPattern( pattern
, thePatListID
, theIndex
);
1169 void wxDC::MacInstallPen() const
1177 if ( m_macPenInstalled
)
1180 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1181 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1182 ::RGBForeColor( &forecolor
);
1183 ::RGBBackColor( &backcolor
);
1186 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1188 // null means only one pixel, at whatever resolution
1189 if ( penWidth
== 0 )
1191 ::PenSize(penWidth
, penWidth
);
1193 int penStyle
= m_pen
.GetStyle();
1195 if (penStyle
== wxSOLID
)
1197 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1199 else if (IS_HATCH(penStyle
))
1202 wxMacGetHatchPattern(penStyle
, &pat
);
1207 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1210 short mode
= patCopy
;
1214 switch( m_logicalFunction
)
1219 case wxINVERT
: // NOT dst
1220 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1223 case wxXOR
: // src XOR dst
1226 case wxOR_REVERSE
: // src OR (NOT dst)
1229 case wxSRC_INVERT
: // (NOT src)
1236 case wxAND_REVERSE
:// src AND (NOT dst)
1237 case wxAND
: // src AND dst
1238 case wxAND_INVERT
: // (NOT src) AND dst
1239 case wxNO_OP
: // dst
1240 case wxNOR
: // (NOT src) AND (NOT dst)
1241 case wxEQUIV
: // (NOT src) XOR dst
1242 case wxOR_INVERT
: // (NOT src) OR dst
1243 case wxNAND
: // (NOT src) OR (NOT dst)
1244 case wxOR
: // src OR dst
1246 // case wxSRC_OR: // source _bitmap_ OR destination
1247 // case wxSRC_AND: // source _bitmap_ AND destination
1251 m_macPenInstalled
= true ;
1252 m_macBrushInstalled
= false ;
1253 m_macFontInstalled
= false ;
1256 void wxDC::MacInstallBrush() const
1261 Pattern blackColor
, whiteColor
;
1262 if ( m_macBrushInstalled
)
1267 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1268 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1269 ::RGBForeColor( &forecolor
);
1270 ::RGBBackColor( &backcolor
);
1272 int brushStyle
= m_brush
.GetStyle();
1273 if (brushStyle
== wxSOLID
)
1274 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1275 else if (IS_HATCH(brushStyle
))
1278 wxMacGetHatchPattern(brushStyle
, &pat
);
1283 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1289 brushStyle
= m_backgroundBrush
.GetStyle();
1290 if (brushStyle
== wxSOLID
)
1291 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1292 else if (IS_HATCH(brushStyle
))
1295 wxMacGetHatchPattern(brushStyle
, &pat
);
1300 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1303 short mode
= patCopy
;
1307 switch( m_logicalFunction
)
1312 case wxINVERT
: // NOT dst
1313 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1316 case wxXOR
: // src XOR dst
1319 case wxOR_REVERSE
: // src OR (NOT dst)
1322 case wxSRC_INVERT
: // (NOT src)
1329 case wxAND_REVERSE
:// src AND (NOT dst)
1330 case wxAND
: // src AND dst
1331 case wxAND_INVERT
: // (NOT src) AND dst
1332 case wxNO_OP
: // dst
1333 case wxNOR
: // (NOT src) AND (NOT dst)
1334 case wxEQUIV
: // (NOT src) XOR dst
1335 case wxOR_INVERT
: // (NOT src) OR dst
1336 case wxNAND
: // (NOT src) OR (NOT dst)
1337 case wxOR
: // src OR dst
1339 // case wxSRC_OR: // source _bitmap_ OR destination
1340 // case wxSRC_AND: // source _bitmap_ AND destination
1344 m_macBrushInstalled
= true ;
1345 m_macPenInstalled
= false ;
1346 m_macFontInstalled
= false ;
1349 // ---------------------------------------------------------------------------
1350 // coordinates transformations
1351 // ---------------------------------------------------------------------------
1354 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1356 return ((wxDC
*)this)->XDEV2LOG(x
);
1359 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1361 return ((wxDC
*)this)->YDEV2LOG(y
);
1364 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1366 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1369 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1371 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1374 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1376 return ((wxDC
*)this)->XLOG2DEV(x
);
1379 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1381 return ((wxDC
*)this)->YLOG2DEV(y
);
1384 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1386 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1389 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1391 return ((wxDC
*)this)->YLOG2DEVREL(y
);