]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dc.cpp
119818f6c6b631efb09998ea6ec72878af26ff95
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
) ;
90 if ( !m_macPortHelper
.IsCleared() )
94 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
101 ::SetPort( m_macPort ) ;
102 ::SetOrigin( 0 , 0 ) ;
103 ::ClipRect( &m_macPort->portRect ) ;
105 ::SetPort( m_macOrigPort ) ;
108 ++m_macCurrentPortId
;
111 void wxDC::MacSetupPort() const
113 AGAPortHelper
* help
= (AGAPortHelper
*) &m_macPortHelper
;
114 help
->Setup( m_macPort
) ;
115 m_macPortId
= ++m_macCurrentPortId
;
116 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
117 ::ClipRect(&m_macClipRect
);
119 m_macFontInstalled
= false ;
120 m_macBrushInstalled
= false ;
121 m_macPenInstalled
= false ;
124 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
132 long xx1
= XLOG2DEV(x
);
133 long yy1
= YLOG2DEV(y
);
136 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
140 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
142 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
143 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
144 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
146 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
148 if ( bmap
->m_hBitmap
)
150 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
151 PixMapHandle bmappixels
;
152 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
153 RGBColor black
= { 0,0,0} ;
154 RGBForeColor( &black
) ;
155 RGBBackColor( &white
) ;
157 bmappixels
= GetGWorldPixMap( bmapworld
) ;
158 if ( LockPixels(bmappixels
) )
163 source
.right
= bmap
->m_width
;
164 source
.bottom
= bmap
->m_height
;
165 dest
.top
= YLOG2DEV(y
) ;
166 dest
.left
= XLOG2DEV(x
) ;
167 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
168 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
170 if ( useMask
&& bmp
.GetMask() )
172 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
174 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
175 GetPortBitMapForCopyBits( m_macPort
) ,
176 &source
, &source
, &dest
) ;
177 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
181 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
182 &source
, &dest
, srcCopy
, NULL
) ;
184 UnlockPixels( bmappixels
) ;
186 m_macPenInstalled
= false ;
187 m_macBrushInstalled
= false ;
188 m_macFontInstalled
= false ;
195 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
201 long xx1
= XLOG2DEV(x
);
202 long yy1
= YLOG2DEV(y
);
205 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
207 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
209 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
210 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
211 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
216 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
221 m_clipX1
= wxMax( m_clipX1
, x
) ;
222 m_clipY1
= wxMax( m_clipY1
,y
);
223 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
224 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
232 m_clipX2
= x
+ width
;
233 m_clipY2
= y
+ height
;
236 long x1
= XLOG2DEV(m_clipX1
);
237 long y1
= YLOG2DEV(m_clipY1
);
238 long x2
= XLOG2DEV(m_clipX2
);
239 long y2
= YLOG2DEV(m_clipY2
);
241 Rect clip
= { y1
, x1
, y2
, x2
} ;
243 ::ClipRect( &clip
) ;
247 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
249 wxCHECK_RET( Ok(), wxT("invalid window dc") );
254 DestroyClippingRegion();
258 wxCoord xx
, yy
, ww
, hh
;
259 region
.GetBox( xx
, yy
, ww
, hh
);
260 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
263 void wxDC::DestroyClippingRegion(void)
267 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
268 ::ClipRect(&m_macClipRect
);
271 void wxDC::DoGetSize( int* width
, int* height
) const
273 *width
= m_maxX
-m_minX
;
274 *height
= m_maxY
-m_minY
;
277 void wxDC::DoGetSizeMM( int* width
, int* height
) const
282 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
283 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
286 void wxDC::SetTextForeground( const wxColour
&col
)
289 m_textForegroundColour
= col
;
290 m_macFontInstalled
= false ;
293 void wxDC::SetTextBackground( const wxColour
&col
)
296 m_textBackgroundColour
= col
;
297 m_macFontInstalled
= false ;
300 void wxDC::SetMapMode( int mode
)
305 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
308 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
311 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
314 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
318 SetLogicalScale( 1.0, 1.0 );
321 if (mode
!= wxMM_TEXT
)
323 m_needComputeScaleX
= TRUE
;
324 m_needComputeScaleY
= TRUE
;
328 void wxDC::SetUserScale( double x
, double y
)
330 // allow negative ? -> no
333 ComputeScaleAndOrigin();
336 void wxDC::SetLogicalScale( double x
, double y
)
341 ComputeScaleAndOrigin();
344 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
346 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
347 m_logicalOriginY
= y
* m_signY
;
348 ComputeScaleAndOrigin();
351 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
353 m_externalDeviceOriginX
= x
;
354 m_externalDeviceOriginY
= y
;
355 ComputeScaleAndOrigin();
358 void wxDC::SetInternalDeviceOrigin( long x, long y )
360 m_internalDeviceOriginX = x;
361 m_internalDeviceOriginY = y;
362 ComputeScaleAndOrigin();
365 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
367 if (x) *x = m_internalDeviceOriginX;
368 if (y) *y = m_internalDeviceOriginY;
371 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
373 m_signX
= (xLeftRight
? 1 : -1);
374 m_signY
= (yBottomUp
? -1 : 1);
375 ComputeScaleAndOrigin();
379 void wxDC::CalcBoundingBox( long x, long y )
381 if (x < m_minX) m_minX = x;
382 if (y < m_minY) m_minY = y;
383 if (x > m_maxX) m_maxX = x;
384 if (y > m_maxY) m_maxY = y;
387 wxSize
wxDC::GetPPI() const
389 return wxSize(72, 72);
392 int wxDC::GetDepth() const
394 return wxDisplayDepth() ;
397 void wxDC::ComputeScaleAndOrigin(void)
399 // CMB: copy scale to see if it changes
400 double origScaleX
= m_scaleX
;
401 double origScaleY
= m_scaleY
;
403 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
404 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
406 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
407 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
409 // CMB: if scale has changed call SetPen to recalulate the line width
410 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
412 // this is a bit artificial, but we need to force wxDC to think
413 // the pen has changed
414 wxPen
* pen
= & GetPen();
421 void wxDC::SetPalette( const wxPalette
& palette
)
425 void wxDC::SetBackgroundMode( int mode
)
427 m_backgroundMode
= mode
;
430 void wxDC::SetFont( const wxFont
&font
)
438 m_macFontInstalled
= false ;
441 void wxDC::SetPen( const wxPen
&pen
)
456 m_macPenInstalled
= false ;
459 void wxDC::SetBrush( const wxBrush
&brush
)
465 if (m_brush
== brush
)
469 m_macBrushInstalled
= false ;
472 void wxDC::SetBackground( const wxBrush
&brush
)
478 if (m_backgroundBrush
== brush
)
481 m_backgroundBrush
= brush
;
483 if (!m_backgroundBrush
.Ok())
485 m_macBrushInstalled
= false ;
488 void wxDC::SetLogicalFunction( int function
)
490 if (m_logicalFunction
== function
)
493 m_logicalFunction
= function
;
494 m_macFontInstalled
= false ;
495 m_macBrushInstalled
= false ;
496 m_macPenInstalled
= false ;
499 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
504 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
509 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
516 if (m_pen
.GetStyle() != wxTRANSPARENT
)
519 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
520 long xx1
= XLOG2DEV(x1
);
521 long yy1
= YLOG2DEV(y1
);
522 long xx2
= XLOG2DEV(x2
);
523 long yy2
= YLOG2DEV(y2
);
525 ::MoveTo(xx1
- offset
,yy1
- offset
);
526 ::LineTo(xx2
- offset
, yy2
- offset
);
530 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
534 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
535 wxCoord x2
, wxCoord y2
,
536 wxCoord xc
, wxCoord yc
)
540 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
541 double sa
, double ea
)
545 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
552 if (m_pen
.GetStyle() != wxTRANSPARENT
)
555 long xx1
= XLOG2DEV(x
);
556 long yy1
= YLOG2DEV(y
);
559 ::LineTo(xx1
+1, yy1
+1);
563 void wxDC::DoDrawLines(int n
, wxPoint points
[],
564 wxCoord xoffset
, wxCoord yoffset
)
570 if (m_pen
.GetStyle() == wxTRANSPARENT
)
575 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
576 long x1
, x2
, y1
, y2
;
577 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
578 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
579 ::MoveTo(x1
- offset
,y1
- offset
);
581 for (int i
= 0; i
< n
-1; i
++)
583 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
584 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
585 ::LineTo(x2
- offset
, y2
- offset
);
589 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
590 wxCoord xoffset
, wxCoord yoffset
,
597 PolyHandle polygon
= OpenPoly() ;
598 long x1
, x2
, y1
, y2
;
599 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
600 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
603 for (int i
= 0; i
< n
-1; i
++)
605 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
606 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
611 if (m_brush
.GetStyle() != wxTRANSPARENT
)
614 ::PaintPoly( polygon
) ;
617 if (m_pen
.GetStyle() != wxTRANSPARENT
)
620 ::FramePoly( polygon
) ;
622 KillPoly( polygon
) ;
625 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
631 long xx
= XLOG2DEV(x
);
632 long yy
= YLOG2DEV(y
);
633 long ww
= m_signX
* XLOG2DEVREL(width
);
634 long hh
= m_signY
* YLOG2DEVREL(height
);
636 // CMB: draw nothing if transformed w or h is 0
637 if (ww
== 0 || hh
== 0)
640 // CMB: handle -ve width and/or height
653 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
655 if (m_brush
.GetStyle() != wxTRANSPARENT
)
658 ::PaintRect( &rect
) ;
661 if (m_pen
.GetStyle() != wxTRANSPARENT
)
664 ::FrameRect( &rect
) ;
668 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
669 wxCoord width
, wxCoord height
,
677 radius
= - radius
* ((width
< height
) ? width
: height
);
679 long xx
= XLOG2DEV(x
);
680 long yy
= YLOG2DEV(y
);
681 long ww
= m_signX
* XLOG2DEVREL(width
);
682 long hh
= m_signY
* YLOG2DEVREL(height
);
684 // CMB: draw nothing if transformed w or h is 0
685 if (ww
== 0 || hh
== 0)
688 // CMB: handle -ve width and/or height
701 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
703 if (m_brush
.GetStyle() != wxTRANSPARENT
)
706 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
709 if (m_pen
.GetStyle() != wxTRANSPARENT
)
712 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
716 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
722 long xx
= XLOG2DEV(x
);
723 long yy
= YLOG2DEV(y
);
724 long ww
= m_signX
* XLOG2DEVREL(width
);
725 long hh
= m_signY
* YLOG2DEVREL(height
);
727 // CMB: draw nothing if transformed w or h is 0
728 if (ww
== 0 || hh
== 0)
731 // CMB: handle -ve width and/or height
744 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
746 if (m_brush
.GetStyle() != wxTRANSPARENT
)
749 ::PaintOval( &rect
) ;
752 if (m_pen
.GetStyle() != wxTRANSPARENT
)
755 ::FrameOval( &rect
) ;
761 bool wxDC::CanDrawBitmap(void) const
767 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
768 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
770 if (!Ok()) return FALSE
;
773 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
774 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
775 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
776 RGBColor black
= { 0,0,0} ;
777 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
778 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
779 RGBForeColor( &forecolor
) ;
780 RGBBackColor( &backcolor
) ;
782 if ( LockPixels(bmappixels
) )
784 Rect srcrect
, dstrect
;
785 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
786 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
787 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
788 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
789 dstrect
.top
= YLOG2DEV(ydest
) ;
790 dstrect
.left
= XLOG2DEV(xdest
) ;
791 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
792 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
794 short mode
= (logical_func
== wxCOPY
? srcCopy
:
795 // logical_func == wxCLEAR ? WHITENESS :
796 // logical_func == wxSET ? BLACKNESS :
797 logical_func
== wxINVERT
? hilite
:
798 // logical_func == wxAND ? MERGECOPY :
799 logical_func
== wxOR
? srcOr
:
800 logical_func
== wxSRC_INVERT
? notSrcCopy
:
801 logical_func
== wxXOR
? srcXor
:
802 // logical_func == wxOR_REVERSE ? MERGEPAINT :
803 // logical_func == wxAND_REVERSE ? SRCERASE :
804 // logical_func == wxSRC_OR ? srcOr :
805 // logical_func == wxSRC_AND ? SRCAND :
808 if ( useMask
&& source
->m_macMask
)
810 wxASSERT( mode
== srcCopy
) ;
811 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
813 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
814 GetPortBitMapForCopyBits( m_macPort
) ,
815 &srcrect
, &srcrect
, &dstrect
) ;
816 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
821 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
822 &srcrect
, &dstrect
, mode
, NULL
) ;
824 UnlockPixels( bmappixels
) ;
827 m_macPenInstalled
= false ;
828 m_macBrushInstalled
= false ;
829 m_macFontInstalled
= false ;
834 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
838 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
844 long xx
= XLOG2DEV(x
);
845 long yy
= YLOG2DEV(y
);
847 // if (m_pen.GetStyle() != wxTRANSPARENT)
851 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
853 ::ClipRect( &clip ) ;
857 ::GetFontInfo( &fi
) ;
861 if ( m_backgroundMode
== wxTRANSPARENT
)
867 ::TextMode( srcCopy
) ;
870 const char *text
= NULL
;
874 if ( wxApp::s_macDefaultEncodingIsPC
)
876 macText
= wxMacMakeMacStringFromPC( strtext
) ;
878 length
= macText
.Length() ;
883 length
= strtext
.Length() ;
892 if( text
[i
] == 13 || text
[i
] == 10)
894 ::DrawText( text
, laststop
, i
- laststop
) ;
896 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
902 ::DrawText( text
, laststop
, i
- laststop
) ;
903 ::TextMode( srcOr
) ;
907 bool wxDC::CanGetTextExtent(void) const
915 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
916 wxCoord
*descent
, wxCoord
*externalLeading
,
917 wxFont
*theFont
) const
924 wxFont formerFont
= m_font
;
928 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
932 ::TextFont( font
->m_macFontNum
) ;
933 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
934 ::TextFace( font
->m_macFontStyle
) ;
943 ::GetFontInfo( &fi
) ;
946 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
948 *descent
=YDEV2LOGREL( fi
.descent
);
949 if ( externalLeading
)
950 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
952 const char *text
= NULL
;
955 if ( wxApp::s_macDefaultEncodingIsPC
)
957 macText
= wxMacMakeMacStringFromPC( string
) ;
959 length
= macText
.Length() ;
964 length
= string
.Length() ;
976 if( text
[i
] == 13 || text
[i
] == 10)
979 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
980 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
981 if ( curwidth
> *width
)
982 *width
= XDEV2LOGREL( curwidth
) ;
988 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
989 if ( curwidth
> *width
)
990 *width
= XDEV2LOGREL( curwidth
) ;
995 m_macFontInstalled
= false ;
999 wxCoord
wxDC::GetCharWidth(void) const
1009 ::GetFontInfo( &fi
) ;
1011 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1014 wxCoord
wxDC::GetCharHeight(void) const
1024 ::GetFontInfo( &fi
) ;
1026 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1029 void wxDC::Clear(void)
1034 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1036 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1039 ::EraseRect( &rect
) ;
1043 void wxDC::MacInstallFont() const
1049 if ( m_macFontInstalled
)
1051 Pattern blackColor
;
1053 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1057 ::TextFont( font
->m_macFontNum
) ;
1058 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1059 ::TextFace( font
->m_macFontStyle
) ;
1061 m_macFontInstalled
= true ;
1062 m_macBrushInstalled
= false ;
1063 m_macPenInstalled
= false ;
1065 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1066 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1067 ::RGBForeColor( &forecolor
);
1068 ::RGBBackColor( &backcolor
);
1074 GetFNum( "\pGeneva" , &fontnum
) ;
1075 ::TextFont( fontnum
) ;
1076 ::TextSize( short(m_scaleY
* 10) ) ;
1079 // todo reset after spacing changes - or store the current spacing somewhere
1081 m_macFontInstalled
= true ;
1082 m_macBrushInstalled
= false ;
1083 m_macPenInstalled
= false ;
1085 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1086 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1087 ::RGBForeColor( &forecolor
);
1088 ::RGBBackColor( &backcolor
);
1091 short mode
= patCopy
;
1095 switch( m_logicalFunction
)
1100 case wxINVERT
: // NOT dst
1101 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1104 case wxXOR
: // src XOR dst
1107 case wxOR_REVERSE
: // src OR (NOT dst)
1110 case wxSRC_INVERT
: // (NOT src)
1117 case wxAND_REVERSE
:// src AND (NOT dst)
1118 case wxAND
: // src AND dst
1119 case wxAND_INVERT
: // (NOT src) AND dst
1120 case wxNO_OP
: // dst
1121 case wxNOR
: // (NOT src) AND (NOT dst)
1122 case wxEQUIV
: // (NOT src) XOR dst
1123 case wxOR_INVERT
: // (NOT src) OR dst
1124 case wxNAND
: // (NOT src) OR (NOT dst)
1125 case wxOR
: // src OR dst
1127 // case wxSRC_OR: // source _bitmap_ OR destination
1128 // case wxSRC_AND: // source _bitmap_ AND destination
1134 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1136 int thePatListID
= sysPatListID
;
1140 case wxBDIAGONAL_HATCH
:
1141 theIndex
= 34; // WCH: this is not good
1143 case wxFDIAGONAL_HATCH
:
1149 case wxHORIZONTAL_HATCH
:
1152 case wxVERTICAL_HATCH
:
1155 case wxCROSSDIAG_HATCH
:
1156 theIndex
= 4; // WCH: this is not good
1159 theIndex
= 1; // solid pattern
1162 GetIndPattern( pattern
, thePatListID
, theIndex
);
1165 void wxDC::MacInstallPen() const
1173 if ( m_macPenInstalled
)
1176 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1177 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1178 ::RGBForeColor( &forecolor
);
1179 ::RGBBackColor( &backcolor
);
1182 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1184 // null means only one pixel, at whatever resolution
1185 if ( penWidth
== 0 )
1187 ::PenSize(penWidth
, penWidth
);
1189 int penStyle
= m_pen
.GetStyle();
1191 if (penStyle
== wxSOLID
)
1193 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1195 else if (IS_HATCH(penStyle
))
1198 wxMacGetHatchPattern(penStyle
, &pat
);
1203 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1206 short mode
= patCopy
;
1210 switch( m_logicalFunction
)
1215 case wxINVERT
: // NOT dst
1216 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1219 case wxXOR
: // src XOR dst
1222 case wxOR_REVERSE
: // src OR (NOT dst)
1225 case wxSRC_INVERT
: // (NOT src)
1232 case wxAND_REVERSE
:// src AND (NOT dst)
1233 case wxAND
: // src AND dst
1234 case wxAND_INVERT
: // (NOT src) AND dst
1235 case wxNO_OP
: // dst
1236 case wxNOR
: // (NOT src) AND (NOT dst)
1237 case wxEQUIV
: // (NOT src) XOR dst
1238 case wxOR_INVERT
: // (NOT src) OR dst
1239 case wxNAND
: // (NOT src) OR (NOT dst)
1240 case wxOR
: // src OR dst
1242 // case wxSRC_OR: // source _bitmap_ OR destination
1243 // case wxSRC_AND: // source _bitmap_ AND destination
1247 m_macPenInstalled
= true ;
1248 m_macBrushInstalled
= false ;
1249 m_macFontInstalled
= false ;
1252 void wxDC::MacInstallBrush() const
1257 Pattern blackColor
, whiteColor
;
1258 if ( m_macBrushInstalled
)
1263 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1264 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1265 ::RGBForeColor( &forecolor
);
1266 ::RGBBackColor( &backcolor
);
1268 int brushStyle
= m_brush
.GetStyle();
1269 if (brushStyle
== wxSOLID
)
1270 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1271 else if (IS_HATCH(brushStyle
))
1274 wxMacGetHatchPattern(brushStyle
, &pat
);
1279 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1285 brushStyle
= m_backgroundBrush
.GetStyle();
1286 if (brushStyle
== wxSOLID
)
1287 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1288 else if (IS_HATCH(brushStyle
))
1291 wxMacGetHatchPattern(brushStyle
, &pat
);
1296 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1299 short mode
= patCopy
;
1303 switch( m_logicalFunction
)
1308 case wxINVERT
: // NOT dst
1309 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1312 case wxXOR
: // src XOR dst
1315 case wxOR_REVERSE
: // src OR (NOT dst)
1318 case wxSRC_INVERT
: // (NOT src)
1325 case wxAND_REVERSE
:// src AND (NOT dst)
1326 case wxAND
: // src AND dst
1327 case wxAND_INVERT
: // (NOT src) AND dst
1328 case wxNO_OP
: // dst
1329 case wxNOR
: // (NOT src) AND (NOT dst)
1330 case wxEQUIV
: // (NOT src) XOR dst
1331 case wxOR_INVERT
: // (NOT src) OR dst
1332 case wxNAND
: // (NOT src) OR (NOT dst)
1333 case wxOR
: // src OR dst
1335 // case wxSRC_OR: // source _bitmap_ OR destination
1336 // case wxSRC_AND: // source _bitmap_ AND destination
1340 m_macBrushInstalled
= true ;
1341 m_macPenInstalled
= false ;
1342 m_macFontInstalled
= false ;
1345 // ---------------------------------------------------------------------------
1346 // coordinates transformations
1347 // ---------------------------------------------------------------------------
1350 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1352 return ((wxDC
*)this)->XDEV2LOG(x
);
1355 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1357 return ((wxDC
*)this)->YDEV2LOG(y
);
1360 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1362 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1365 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1367 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1370 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1372 return ((wxDC
*)this)->XLOG2DEV(x
);
1375 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1377 return ((wxDC
*)this)->YLOG2DEV(y
);
1380 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1382 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1385 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1387 return ((wxDC
*)this)->YLOG2DEVREL(y
);