]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/dc.cpp
6756d9df035fdb6956bab407304acc496481b37a
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 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
48 m_mm_to_pix_x
= mm2pt
;
49 m_mm_to_pix_y
= mm2pt
;
51 m_internalDeviceOriginX
= 0;
52 m_internalDeviceOriginY
= 0;
53 m_externalDeviceOriginX
= 0;
54 m_externalDeviceOriginY
= 0;
56 m_logicalScaleX
= 1.0;
57 m_logicalScaleY
= 1.0;
63 m_needComputeScaleX
= FALSE
;
64 m_needComputeScaleY
= FALSE
;
66 m_maxX
= m_maxY
= -100000;
67 m_minY
= m_minY
= 100000;
73 m_macFontInstalled
= false ;
74 m_macBrushInstalled
= false ;
75 m_macPenInstalled
= false ;
77 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
78 m_macClipRect
.left
= -32000 ;
79 m_macClipRect
.top
= -32000 ;
80 m_macClipRect
.right
= 32000 ;
81 m_macClipRect
.bottom
= 32000 ;
84 m_font
= *wxNORMAL_FONT
;
85 m_brush
= *wxWHITE_BRUSH
;
88 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc
) :
91 wxASSERT( dc
->Ok() ) ;
93 dc
->MacSetupPort(&m_ph
) ;
96 wxMacPortSetter::~wxMacPortSetter()
104 void wxDC::MacSetupPort(AGAPortHelper
* help
) const
106 // help->Setup( m_macPort ) ;
107 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
110 long x1
= XLOG2DEV(m_clipX1
);
111 long y1
= YLOG2DEV(m_clipY1
);
112 long x2
= XLOG2DEV(m_clipX2
);
113 long y2
= YLOG2DEV(m_clipY2
);
115 Rect clip
= { y1
, x1
, y2
, x2
} ;
116 ::SectRect( &clip
, &m_macClipRect
, &clip
) ;
117 ::ClipRect( &clip
) ;
121 ::ClipRect(&m_macClipRect
);
125 m_macFontInstalled
= false ;
126 m_macBrushInstalled
= false ;
127 m_macPenInstalled
= false ;
130 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
136 wxMacPortSetter
helper(this) ;
138 long xx1
= XLOG2DEV(x
);
139 long yy1
= YLOG2DEV(y
);
142 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
146 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
148 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
149 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
150 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
152 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
154 if ( bmap
->m_hBitmap
)
156 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
157 PixMapHandle bmappixels
;
158 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
159 RGBColor black
= { 0,0,0} ;
160 RGBForeColor( &black
) ;
161 RGBBackColor( &white
) ;
163 bmappixels
= GetGWorldPixMap( bmapworld
) ;
164 if ( LockPixels(bmappixels
) )
169 source
.right
= bmap
->m_width
;
170 source
.bottom
= bmap
->m_height
;
171 dest
.top
= YLOG2DEV(y
) ;
172 dest
.left
= XLOG2DEV(x
) ;
173 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
174 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
176 if ( useMask
&& bmp
.GetMask() )
178 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
180 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
181 GetPortBitMapForCopyBits( m_macPort
) ,
182 &source
, &source
, &dest
) ;
183 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
187 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
188 &source
, &dest
, srcCopy
, NULL
) ;
190 UnlockPixels( bmappixels
) ;
192 m_macPenInstalled
= false ;
193 m_macBrushInstalled
= false ;
194 m_macFontInstalled
= false ;
201 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
205 wxMacPortSetter
helper(this) ;
207 long xx1
= XLOG2DEV(x
);
208 long yy1
= YLOG2DEV(y
);
211 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
213 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
215 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
216 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
217 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
222 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
226 m_clipX1
= wxMax( m_clipX1
, x
) ;
227 m_clipY1
= wxMax( m_clipY1
,y
);
228 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
229 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
237 m_clipX2
= x
+ width
;
238 m_clipY2
= y
+ height
;
242 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
244 wxCHECK_RET( Ok(), wxT("invalid window dc") );
246 wxMacPortSetter
helper(this) ;
249 DestroyClippingRegion();
253 wxCoord xx
, yy
, ww
, hh
;
254 region
.GetBox( xx
, yy
, ww
, hh
);
255 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
258 void wxDC::DestroyClippingRegion(void)
260 wxMacPortSetter
helper(this) ;
264 void wxDC::DoGetSize( int* width
, int* height
) const
266 *width
= m_maxX
-m_minX
;
267 *height
= m_maxY
-m_minY
;
270 void wxDC::DoGetSizeMM( int* width
, int* height
) const
275 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
276 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
279 void wxDC::SetTextForeground( const wxColour
&col
)
282 m_textForegroundColour
= col
;
283 m_macFontInstalled
= false ;
286 void wxDC::SetTextBackground( const wxColour
&col
)
289 m_textBackgroundColour
= col
;
290 m_macFontInstalled
= false ;
293 void wxDC::SetMapMode( int mode
)
298 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
301 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
304 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
307 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
311 SetLogicalScale( 1.0, 1.0 );
314 if (mode
!= wxMM_TEXT
)
316 m_needComputeScaleX
= TRUE
;
317 m_needComputeScaleY
= TRUE
;
321 void wxDC::SetUserScale( double x
, double y
)
323 // allow negative ? -> no
326 ComputeScaleAndOrigin();
329 void wxDC::SetLogicalScale( double x
, double y
)
334 ComputeScaleAndOrigin();
337 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
339 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
340 m_logicalOriginY
= y
* m_signY
;
341 ComputeScaleAndOrigin();
344 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
346 m_externalDeviceOriginX
= x
;
347 m_externalDeviceOriginY
= y
;
348 ComputeScaleAndOrigin();
351 void wxDC::SetInternalDeviceOrigin( long x, long y )
353 m_internalDeviceOriginX = x;
354 m_internalDeviceOriginY = y;
355 ComputeScaleAndOrigin();
358 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
360 if (x) *x = m_internalDeviceOriginX;
361 if (y) *y = m_internalDeviceOriginY;
364 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
366 m_signX
= (xLeftRight
? 1 : -1);
367 m_signY
= (yBottomUp
? -1 : 1);
368 ComputeScaleAndOrigin();
372 void wxDC::CalcBoundingBox( long x, long y )
374 if (x < m_minX) m_minX = x;
375 if (y < m_minY) m_minY = y;
376 if (x > m_maxX) m_maxX = x;
377 if (y > m_maxY) m_maxY = y;
380 wxSize
wxDC::GetPPI() const
382 return wxSize(72, 72);
385 int wxDC::GetDepth() const
387 return wxDisplayDepth() ;
390 void wxDC::ComputeScaleAndOrigin(void)
392 // CMB: copy scale to see if it changes
393 double origScaleX
= m_scaleX
;
394 double origScaleY
= m_scaleY
;
396 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
397 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
399 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
400 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
402 // CMB: if scale has changed call SetPen to recalulate the line width
403 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
405 // this is a bit artificial, but we need to force wxDC to think
406 // the pen has changed
407 wxPen
* pen
= & GetPen();
414 void wxDC::SetPalette( const wxPalette
& palette
)
418 void wxDC::SetBackgroundMode( int mode
)
420 m_backgroundMode
= mode
;
423 void wxDC::SetFont( const wxFont
&font
)
428 // wxMacPortSetter helper(this) ;
431 m_macFontInstalled
= false ;
434 void wxDC::SetPen( const wxPen
&pen
)
439 // wxMacPortSetter helper(this) ;
449 m_macPenInstalled
= false ;
452 void wxDC::SetBrush( const wxBrush
&brush
)
456 // wxMacPortSetter helper(this) ;
458 if (m_brush
== brush
)
462 m_macBrushInstalled
= false ;
465 void wxDC::SetBackground( const wxBrush
&brush
)
469 // wxMacPortSetter helper(this) ;
471 if (m_backgroundBrush
== brush
)
474 m_backgroundBrush
= brush
;
476 if (!m_backgroundBrush
.Ok())
478 m_macBrushInstalled
= false ;
481 void wxDC::SetLogicalFunction( int function
)
483 if (m_logicalFunction
== function
)
486 m_logicalFunction
= function
;
487 m_macFontInstalled
= false ;
488 m_macBrushInstalled
= false ;
489 m_macPenInstalled
= false ;
492 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
497 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
502 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
507 wxMacPortSetter
helper(this) ;
509 if (m_pen
.GetStyle() != wxTRANSPARENT
)
512 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
513 long xx1
= XLOG2DEV(x1
);
514 long yy1
= YLOG2DEV(y1
);
515 long xx2
= XLOG2DEV(x2
);
516 long yy2
= YLOG2DEV(y2
);
518 ::MoveTo(xx1
- offset
,yy1
- offset
);
519 ::LineTo(xx2
- offset
, yy2
- offset
);
523 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
527 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
528 wxCoord x2
, wxCoord y2
,
529 wxCoord xc
, wxCoord yc
)
533 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
534 double sa
, double ea
)
538 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
543 wxMacPortSetter
helper(this) ;
545 if (m_pen
.GetStyle() != wxTRANSPARENT
)
548 long xx1
= XLOG2DEV(x
);
549 long yy1
= YLOG2DEV(y
);
552 ::LineTo(xx1
+1, yy1
+1);
556 void wxDC::DoDrawLines(int n
, wxPoint points
[],
557 wxCoord xoffset
, wxCoord yoffset
)
561 wxMacPortSetter
helper(this) ;
563 if (m_pen
.GetStyle() == wxTRANSPARENT
)
568 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
569 long x1
, x2
, y1
, y2
;
570 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
571 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
572 ::MoveTo(x1
- offset
,y1
- offset
);
574 for (int i
= 0; i
< n
-1; i
++)
576 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
577 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
578 ::LineTo(x2
- offset
, y2
- offset
);
582 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
583 wxCoord xoffset
, wxCoord yoffset
,
588 wxMacPortSetter
helper(this) ;
590 PolyHandle polygon
= OpenPoly() ;
591 long x1
, x2
, y1
, y2
;
592 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
593 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
596 for (int i
= 0; i
< n
-1; i
++)
598 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
599 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
604 if (m_brush
.GetStyle() != wxTRANSPARENT
)
607 ::PaintPoly( polygon
) ;
610 if (m_pen
.GetStyle() != wxTRANSPARENT
)
613 ::FramePoly( polygon
) ;
615 KillPoly( polygon
) ;
618 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
622 wxMacPortSetter
helper(this) ;
624 long xx
= XLOG2DEV(x
);
625 long yy
= YLOG2DEV(y
);
626 long ww
= m_signX
* XLOG2DEVREL(width
);
627 long hh
= m_signY
* YLOG2DEVREL(height
);
629 // CMB: draw nothing if transformed w or h is 0
630 if (ww
== 0 || hh
== 0)
633 // CMB: handle -ve width and/or height
646 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
648 if (m_brush
.GetStyle() != wxTRANSPARENT
)
651 ::PaintRect( &rect
) ;
654 if (m_pen
.GetStyle() != wxTRANSPARENT
)
657 ::FrameRect( &rect
) ;
661 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
662 wxCoord width
, wxCoord height
,
667 wxMacPortSetter
helper(this) ;
670 radius
= - radius
* ((width
< height
) ? width
: height
);
672 long xx
= XLOG2DEV(x
);
673 long yy
= YLOG2DEV(y
);
674 long ww
= m_signX
* XLOG2DEVREL(width
);
675 long hh
= m_signY
* YLOG2DEVREL(height
);
677 // CMB: draw nothing if transformed w or h is 0
678 if (ww
== 0 || hh
== 0)
681 // CMB: handle -ve width and/or height
694 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
696 if (m_brush
.GetStyle() != wxTRANSPARENT
)
699 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
702 if (m_pen
.GetStyle() != wxTRANSPARENT
)
705 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
709 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
713 wxMacPortSetter
helper(this) ;
715 long xx
= XLOG2DEV(x
);
716 long yy
= YLOG2DEV(y
);
717 long ww
= m_signX
* XLOG2DEVREL(width
);
718 long hh
= m_signY
* YLOG2DEVREL(height
);
720 // CMB: draw nothing if transformed w or h is 0
721 if (ww
== 0 || hh
== 0)
724 // CMB: handle -ve width and/or height
737 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
739 if (m_brush
.GetStyle() != wxTRANSPARENT
)
742 ::PaintOval( &rect
) ;
745 if (m_pen
.GetStyle() != wxTRANSPARENT
)
748 ::FrameOval( &rect
) ;
754 bool wxDC::CanDrawBitmap(void) const
760 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
761 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
763 if (!Ok()) return FALSE
;
764 wxMacPortSetter
helper(this) ;
766 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
767 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
768 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
769 RGBColor black
= { 0,0,0} ;
770 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
771 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
772 RGBForeColor( &forecolor
) ;
773 RGBBackColor( &backcolor
) ;
775 if ( LockPixels(bmappixels
) )
777 Rect srcrect
, dstrect
;
778 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
779 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
780 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
781 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
782 dstrect
.top
= YLOG2DEV(ydest
) ;
783 dstrect
.left
= XLOG2DEV(xdest
) ;
784 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
785 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
787 short mode
= (logical_func
== wxCOPY
? srcCopy
:
788 // logical_func == wxCLEAR ? WHITENESS :
789 // logical_func == wxSET ? BLACKNESS :
790 logical_func
== wxINVERT
? hilite
:
791 // logical_func == wxAND ? MERGECOPY :
792 logical_func
== wxOR
? srcOr
:
793 logical_func
== wxSRC_INVERT
? notSrcCopy
:
794 logical_func
== wxXOR
? srcXor
:
795 // logical_func == wxOR_REVERSE ? MERGEPAINT :
796 // logical_func == wxAND_REVERSE ? SRCERASE :
797 // logical_func == wxSRC_OR ? srcOr :
798 // logical_func == wxSRC_AND ? SRCAND :
801 if ( useMask
&& source
->m_macMask
)
803 wxASSERT( mode
== srcCopy
) ;
804 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
806 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
807 GetPortBitMapForCopyBits( m_macPort
) ,
808 &srcrect
, &srcrect
, &dstrect
) ;
809 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
814 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
815 &srcrect
, &dstrect
, mode
, NULL
) ;
817 UnlockPixels( bmappixels
) ;
820 m_macPenInstalled
= false ;
821 m_macBrushInstalled
= false ;
822 m_macFontInstalled
= false ;
827 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
831 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
835 wxMacPortSetter
helper(this) ;
837 long xx
= XLOG2DEV(x
);
838 long yy
= YLOG2DEV(y
);
840 // if (m_pen.GetStyle() != wxTRANSPARENT)
844 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
846 ::ClipRect( &clip ) ;
850 ::GetFontInfo( &fi
) ;
854 if ( m_backgroundMode
== wxTRANSPARENT
)
860 ::TextMode( srcCopy
) ;
863 const char *text
= NULL
;
867 if ( wxApp::s_macDefaultEncodingIsPC
)
869 macText
= wxMacMakeMacStringFromPC( strtext
) ;
871 length
= macText
.Length() ;
876 length
= strtext
.Length() ;
885 if( text
[i
] == 13 || text
[i
] == 10)
887 ::DrawText( text
, laststop
, i
- laststop
) ;
889 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
895 ::DrawText( text
, laststop
, i
- laststop
) ;
896 ::TextMode( srcOr
) ;
900 bool wxDC::CanGetTextExtent(void) const
908 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
909 wxCoord
*descent
, wxCoord
*externalLeading
,
910 wxFont
*theFont
) const
915 wxMacPortSetter
helper(this) ;
917 wxFont formerFont
= m_font
;
921 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
925 ::TextFont( font
->m_macFontNum
) ;
926 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
927 ::TextFace( font
->m_macFontStyle
) ;
936 ::GetFontInfo( &fi
) ;
939 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
941 *descent
=YDEV2LOGREL( fi
.descent
);
942 if ( externalLeading
)
943 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
945 const char *text
= NULL
;
948 if ( wxApp::s_macDefaultEncodingIsPC
)
950 macText
= wxMacMakeMacStringFromPC( string
) ;
952 length
= macText
.Length() ;
957 length
= string
.Length() ;
969 if( text
[i
] == 13 || text
[i
] == 10)
972 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
973 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
974 if ( curwidth
> *width
)
975 *width
= XDEV2LOGREL( curwidth
) ;
981 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
982 if ( curwidth
> *width
)
983 *width
= XDEV2LOGREL( curwidth
) ;
988 m_macFontInstalled
= false ;
992 wxCoord
wxDC::GetCharWidth(void) const
997 wxMacPortSetter
helper(this) ;
1002 ::GetFontInfo( &fi
) ;
1004 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1007 wxCoord
wxDC::GetCharHeight(void) const
1012 wxMacPortSetter
helper(this) ;
1017 ::GetFontInfo( &fi
) ;
1019 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1022 void wxDC::Clear(void)
1026 wxMacPortSetter
helper(this) ;
1027 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1029 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1032 ::EraseRect( &rect
) ;
1036 void wxDC::MacInstallFont() const
1041 // if ( m_macFontInstalled )
1043 Pattern blackColor
;
1045 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1049 ::TextFont( font
->m_macFontNum
) ;
1050 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1051 ::TextFace( font
->m_macFontStyle
) ;
1053 m_macFontInstalled
= true ;
1054 m_macBrushInstalled
= false ;
1055 m_macPenInstalled
= false ;
1057 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1058 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1059 ::RGBForeColor( &forecolor
);
1060 ::RGBBackColor( &backcolor
);
1066 GetFNum( "\pGeneva" , &fontnum
) ;
1067 ::TextFont( fontnum
) ;
1068 ::TextSize( short(m_scaleY
* 10) ) ;
1071 // todo reset after spacing changes - or store the current spacing somewhere
1073 m_macFontInstalled
= true ;
1074 m_macBrushInstalled
= false ;
1075 m_macPenInstalled
= false ;
1077 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1078 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1079 ::RGBForeColor( &forecolor
);
1080 ::RGBBackColor( &backcolor
);
1083 short mode
= patCopy
;
1087 switch( m_logicalFunction
)
1092 case wxINVERT
: // NOT dst
1093 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1096 case wxXOR
: // src XOR dst
1099 case wxOR_REVERSE
: // src OR (NOT dst)
1102 case wxSRC_INVERT
: // (NOT src)
1109 case wxAND_REVERSE
:// src AND (NOT dst)
1110 case wxAND
: // src AND dst
1111 case wxAND_INVERT
: // (NOT src) AND dst
1112 case wxNO_OP
: // dst
1113 case wxNOR
: // (NOT src) AND (NOT dst)
1114 case wxEQUIV
: // (NOT src) XOR dst
1115 case wxOR_INVERT
: // (NOT src) OR dst
1116 case wxNAND
: // (NOT src) OR (NOT dst)
1117 case wxOR
: // src OR dst
1119 // case wxSRC_OR: // source _bitmap_ OR destination
1120 // case wxSRC_AND: // source _bitmap_ AND destination
1126 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1128 int thePatListID
= sysPatListID
;
1132 case wxBDIAGONAL_HATCH
:
1133 theIndex
= 34; // WCH: this is not good
1135 case wxFDIAGONAL_HATCH
:
1141 case wxHORIZONTAL_HATCH
:
1144 case wxVERTICAL_HATCH
:
1147 case wxCROSSDIAG_HATCH
:
1148 theIndex
= 4; // WCH: this is not good
1151 theIndex
= 1; // solid pattern
1154 GetIndPattern( pattern
, thePatListID
, theIndex
);
1157 void wxDC::MacInstallPen() const
1164 // if ( m_macPenInstalled )
1167 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1168 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1169 ::RGBForeColor( &forecolor
);
1170 ::RGBBackColor( &backcolor
);
1173 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1175 // null means only one pixel, at whatever resolution
1176 if ( penWidth
== 0 )
1178 ::PenSize(penWidth
, penWidth
);
1180 int penStyle
= m_pen
.GetStyle();
1182 if (penStyle
== wxSOLID
)
1184 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1186 else if (IS_HATCH(penStyle
))
1189 wxMacGetHatchPattern(penStyle
, &pat
);
1194 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1197 short mode
= patCopy
;
1201 switch( m_logicalFunction
)
1206 case wxINVERT
: // NOT dst
1207 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1210 case wxXOR
: // src XOR dst
1213 case wxOR_REVERSE
: // src OR (NOT dst)
1216 case wxSRC_INVERT
: // (NOT src)
1223 case wxAND_REVERSE
:// src AND (NOT dst)
1224 case wxAND
: // src AND dst
1225 case wxAND_INVERT
: // (NOT src) AND dst
1226 case wxNO_OP
: // dst
1227 case wxNOR
: // (NOT src) AND (NOT dst)
1228 case wxEQUIV
: // (NOT src) XOR dst
1229 case wxOR_INVERT
: // (NOT src) OR dst
1230 case wxNAND
: // (NOT src) OR (NOT dst)
1231 case wxOR
: // src OR dst
1233 // case wxSRC_OR: // source _bitmap_ OR destination
1234 // case wxSRC_AND: // source _bitmap_ AND destination
1238 m_macPenInstalled
= true ;
1239 m_macBrushInstalled
= false ;
1240 m_macFontInstalled
= false ;
1243 void wxDC::MacInstallBrush() const
1248 Pattern blackColor
, whiteColor
;
1249 // if ( m_macBrushInstalled )
1254 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1255 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1256 ::RGBForeColor( &forecolor
);
1257 ::RGBBackColor( &backcolor
);
1259 int brushStyle
= m_brush
.GetStyle();
1260 if (brushStyle
== wxSOLID
)
1261 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1262 else if (IS_HATCH(brushStyle
))
1265 wxMacGetHatchPattern(brushStyle
, &pat
);
1270 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1276 brushStyle
= m_backgroundBrush
.GetStyle();
1277 if (brushStyle
== wxSOLID
)
1278 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1279 else if (IS_HATCH(brushStyle
))
1282 wxMacGetHatchPattern(brushStyle
, &pat
);
1287 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1290 short mode
= patCopy
;
1294 switch( m_logicalFunction
)
1299 case wxINVERT
: // NOT dst
1300 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1303 case wxXOR
: // src XOR dst
1306 case wxOR_REVERSE
: // src OR (NOT dst)
1309 case wxSRC_INVERT
: // (NOT src)
1316 case wxAND_REVERSE
:// src AND (NOT dst)
1317 case wxAND
: // src AND dst
1318 case wxAND_INVERT
: // (NOT src) AND dst
1319 case wxNO_OP
: // dst
1320 case wxNOR
: // (NOT src) AND (NOT dst)
1321 case wxEQUIV
: // (NOT src) XOR dst
1322 case wxOR_INVERT
: // (NOT src) OR dst
1323 case wxNAND
: // (NOT src) OR (NOT dst)
1324 case wxOR
: // src OR dst
1326 // case wxSRC_OR: // source _bitmap_ OR destination
1327 // case wxSRC_AND: // source _bitmap_ AND destination
1331 m_macBrushInstalled
= true ;
1332 m_macPenInstalled
= false ;
1333 m_macFontInstalled
= false ;
1336 // ---------------------------------------------------------------------------
1337 // coordinates transformations
1338 // ---------------------------------------------------------------------------
1341 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1343 return ((wxDC
*)this)->XDEV2LOG(x
);
1346 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1348 return ((wxDC
*)this)->YDEV2LOG(y
);
1351 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1353 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1356 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1358 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1361 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1363 return ((wxDC
*)this)->XLOG2DEV(x
);
1366 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1368 return ((wxDC
*)this)->YLOG2DEV(y
);
1371 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1373 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1376 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1378 return ((wxDC
*)this)->YLOG2DEVREL(y
);