]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/dc.cpp
1a21092f9495300fe10a3b4420a19e566ef65911
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( 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
);
108 ::ClipRect(&m_macClipRect
);
110 m_macFontInstalled
= false ;
111 m_macBrushInstalled
= false ;
112 m_macPenInstalled
= false ;
115 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
121 wxMacPortSetter
helper(this) ;
123 long xx1
= XLOG2DEV(x
);
124 long yy1
= YLOG2DEV(y
);
127 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
131 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
133 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
134 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
135 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
137 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
139 if ( bmap
->m_hBitmap
)
141 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
142 PixMapHandle bmappixels
;
143 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
144 RGBColor black
= { 0,0,0} ;
145 RGBForeColor( &black
) ;
146 RGBBackColor( &white
) ;
148 bmappixels
= GetGWorldPixMap( bmapworld
) ;
149 if ( LockPixels(bmappixels
) )
154 source
.right
= bmap
->m_width
;
155 source
.bottom
= bmap
->m_height
;
156 dest
.top
= YLOG2DEV(y
) ;
157 dest
.left
= XLOG2DEV(x
) ;
158 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
159 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
161 if ( useMask
&& bmp
.GetMask() )
163 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
165 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
166 GetPortBitMapForCopyBits( m_macPort
) ,
167 &source
, &source
, &dest
) ;
168 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
172 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
173 &source
, &dest
, srcCopy
, NULL
) ;
175 UnlockPixels( bmappixels
) ;
177 m_macPenInstalled
= false ;
178 m_macBrushInstalled
= false ;
179 m_macFontInstalled
= false ;
186 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
190 wxMacPortSetter
helper(this) ;
192 long xx1
= XLOG2DEV(x
);
193 long yy1
= YLOG2DEV(y
);
196 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
198 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
200 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
201 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
202 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
207 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
209 wxMacPortSetter
helper(this) ;
212 m_clipX1
= wxMax( m_clipX1
, x
) ;
213 m_clipY1
= wxMax( m_clipY1
,y
);
214 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
215 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
223 m_clipX2
= x
+ width
;
224 m_clipY2
= y
+ height
;
227 long x1
= XLOG2DEV(m_clipX1
);
228 long y1
= YLOG2DEV(m_clipY1
);
229 long x2
= XLOG2DEV(m_clipX2
);
230 long y2
= YLOG2DEV(m_clipY2
);
232 Rect clip
= { y1
, x1
, y2
, x2
} ;
234 ::ClipRect( &clip
) ;
238 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
240 wxCHECK_RET( Ok(), wxT("invalid window dc") );
242 wxMacPortSetter
helper(this) ;
245 DestroyClippingRegion();
249 wxCoord xx
, yy
, ww
, hh
;
250 region
.GetBox( xx
, yy
, ww
, hh
);
251 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
254 void wxDC::DestroyClippingRegion(void)
256 wxMacPortSetter
helper(this) ;
258 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
259 ::ClipRect(&m_macClipRect
);
262 void wxDC::DoGetSize( int* width
, int* height
) const
264 *width
= m_maxX
-m_minX
;
265 *height
= m_maxY
-m_minY
;
268 void wxDC::DoGetSizeMM( int* width
, int* height
) const
273 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
274 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
277 void wxDC::SetTextForeground( const wxColour
&col
)
280 m_textForegroundColour
= col
;
281 m_macFontInstalled
= false ;
284 void wxDC::SetTextBackground( const wxColour
&col
)
287 m_textBackgroundColour
= col
;
288 m_macFontInstalled
= false ;
291 void wxDC::SetMapMode( int mode
)
296 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
299 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
302 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
305 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
309 SetLogicalScale( 1.0, 1.0 );
312 if (mode
!= wxMM_TEXT
)
314 m_needComputeScaleX
= TRUE
;
315 m_needComputeScaleY
= TRUE
;
319 void wxDC::SetUserScale( double x
, double y
)
321 // allow negative ? -> no
324 ComputeScaleAndOrigin();
327 void wxDC::SetLogicalScale( double x
, double y
)
332 ComputeScaleAndOrigin();
335 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
337 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
338 m_logicalOriginY
= y
* m_signY
;
339 ComputeScaleAndOrigin();
342 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
344 m_externalDeviceOriginX
= x
;
345 m_externalDeviceOriginY
= y
;
346 ComputeScaleAndOrigin();
349 void wxDC::SetInternalDeviceOrigin( long x, long y )
351 m_internalDeviceOriginX = x;
352 m_internalDeviceOriginY = y;
353 ComputeScaleAndOrigin();
356 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
358 if (x) *x = m_internalDeviceOriginX;
359 if (y) *y = m_internalDeviceOriginY;
362 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
364 m_signX
= (xLeftRight
? 1 : -1);
365 m_signY
= (yBottomUp
? -1 : 1);
366 ComputeScaleAndOrigin();
370 void wxDC::CalcBoundingBox( long x, long y )
372 if (x < m_minX) m_minX = x;
373 if (y < m_minY) m_minY = y;
374 if (x > m_maxX) m_maxX = x;
375 if (y > m_maxY) m_maxY = y;
378 wxSize
wxDC::GetPPI() const
380 return wxSize(72, 72);
383 int wxDC::GetDepth() const
385 return wxDisplayDepth() ;
388 void wxDC::ComputeScaleAndOrigin(void)
390 // CMB: copy scale to see if it changes
391 double origScaleX
= m_scaleX
;
392 double origScaleY
= m_scaleY
;
394 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
395 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
397 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
398 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
400 // CMB: if scale has changed call SetPen to recalulate the line width
401 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
403 // this is a bit artificial, but we need to force wxDC to think
404 // the pen has changed
405 wxPen
* pen
= & GetPen();
412 void wxDC::SetPalette( const wxPalette
& palette
)
416 void wxDC::SetBackgroundMode( int mode
)
418 m_backgroundMode
= mode
;
421 void wxDC::SetFont( const wxFont
&font
)
426 // wxMacPortSetter helper(this) ;
429 m_macFontInstalled
= false ;
432 void wxDC::SetPen( const wxPen
&pen
)
437 // wxMacPortSetter helper(this) ;
447 m_macPenInstalled
= false ;
450 void wxDC::SetBrush( const wxBrush
&brush
)
454 // wxMacPortSetter helper(this) ;
456 if (m_brush
== brush
)
460 m_macBrushInstalled
= false ;
463 void wxDC::SetBackground( const wxBrush
&brush
)
467 // wxMacPortSetter helper(this) ;
469 if (m_backgroundBrush
== brush
)
472 m_backgroundBrush
= brush
;
474 if (!m_backgroundBrush
.Ok())
476 m_macBrushInstalled
= false ;
479 void wxDC::SetLogicalFunction( int function
)
481 if (m_logicalFunction
== function
)
484 m_logicalFunction
= function
;
485 m_macFontInstalled
= false ;
486 m_macBrushInstalled
= false ;
487 m_macPenInstalled
= false ;
490 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
495 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
500 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
505 wxMacPortSetter
helper(this) ;
507 if (m_pen
.GetStyle() != wxTRANSPARENT
)
510 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
511 long xx1
= XLOG2DEV(x1
);
512 long yy1
= YLOG2DEV(y1
);
513 long xx2
= XLOG2DEV(x2
);
514 long yy2
= YLOG2DEV(y2
);
516 ::MoveTo(xx1
- offset
,yy1
- offset
);
517 ::LineTo(xx2
- offset
, yy2
- offset
);
521 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
525 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
526 wxCoord x2
, wxCoord y2
,
527 wxCoord xc
, wxCoord yc
)
531 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
532 double sa
, double ea
)
536 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
541 wxMacPortSetter
helper(this) ;
543 if (m_pen
.GetStyle() != wxTRANSPARENT
)
546 long xx1
= XLOG2DEV(x
);
547 long yy1
= YLOG2DEV(y
);
550 ::LineTo(xx1
+1, yy1
+1);
554 void wxDC::DoDrawLines(int n
, wxPoint points
[],
555 wxCoord xoffset
, wxCoord yoffset
)
559 wxMacPortSetter
helper(this) ;
561 if (m_pen
.GetStyle() == wxTRANSPARENT
)
566 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
567 long x1
, x2
, y1
, y2
;
568 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
569 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
570 ::MoveTo(x1
- offset
,y1
- offset
);
572 for (int i
= 0; i
< n
-1; i
++)
574 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
575 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
576 ::LineTo(x2
- offset
, y2
- offset
);
580 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
581 wxCoord xoffset
, wxCoord yoffset
,
586 wxMacPortSetter
helper(this) ;
588 PolyHandle polygon
= OpenPoly() ;
589 long x1
, x2
, y1
, y2
;
590 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
591 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
594 for (int i
= 0; i
< n
-1; i
++)
596 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
597 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
602 if (m_brush
.GetStyle() != wxTRANSPARENT
)
605 ::PaintPoly( polygon
) ;
608 if (m_pen
.GetStyle() != wxTRANSPARENT
)
611 ::FramePoly( polygon
) ;
613 KillPoly( polygon
) ;
616 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
620 wxMacPortSetter
helper(this) ;
622 long xx
= XLOG2DEV(x
);
623 long yy
= YLOG2DEV(y
);
624 long ww
= m_signX
* XLOG2DEVREL(width
);
625 long hh
= m_signY
* YLOG2DEVREL(height
);
627 // CMB: draw nothing if transformed w or h is 0
628 if (ww
== 0 || hh
== 0)
631 // CMB: handle -ve width and/or height
644 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
646 if (m_brush
.GetStyle() != wxTRANSPARENT
)
649 ::PaintRect( &rect
) ;
652 if (m_pen
.GetStyle() != wxTRANSPARENT
)
655 ::FrameRect( &rect
) ;
659 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
660 wxCoord width
, wxCoord height
,
665 wxMacPortSetter
helper(this) ;
668 radius
= - radius
* ((width
< height
) ? width
: height
);
670 long xx
= XLOG2DEV(x
);
671 long yy
= YLOG2DEV(y
);
672 long ww
= m_signX
* XLOG2DEVREL(width
);
673 long hh
= m_signY
* YLOG2DEVREL(height
);
675 // CMB: draw nothing if transformed w or h is 0
676 if (ww
== 0 || hh
== 0)
679 // CMB: handle -ve width and/or height
692 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
694 if (m_brush
.GetStyle() != wxTRANSPARENT
)
697 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
700 if (m_pen
.GetStyle() != wxTRANSPARENT
)
703 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
707 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
711 wxMacPortSetter
helper(this) ;
713 long xx
= XLOG2DEV(x
);
714 long yy
= YLOG2DEV(y
);
715 long ww
= m_signX
* XLOG2DEVREL(width
);
716 long hh
= m_signY
* YLOG2DEVREL(height
);
718 // CMB: draw nothing if transformed w or h is 0
719 if (ww
== 0 || hh
== 0)
722 // CMB: handle -ve width and/or height
735 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
737 if (m_brush
.GetStyle() != wxTRANSPARENT
)
740 ::PaintOval( &rect
) ;
743 if (m_pen
.GetStyle() != wxTRANSPARENT
)
746 ::FrameOval( &rect
) ;
752 bool wxDC::CanDrawBitmap(void) const
758 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
759 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
761 if (!Ok()) return FALSE
;
762 wxMacPortSetter
helper(this) ;
764 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
765 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
766 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
767 RGBColor black
= { 0,0,0} ;
768 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
769 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
770 RGBForeColor( &forecolor
) ;
771 RGBBackColor( &backcolor
) ;
773 if ( LockPixels(bmappixels
) )
775 Rect srcrect
, dstrect
;
776 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
777 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
778 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
779 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
780 dstrect
.top
= YLOG2DEV(ydest
) ;
781 dstrect
.left
= XLOG2DEV(xdest
) ;
782 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
783 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
785 short mode
= (logical_func
== wxCOPY
? srcCopy
:
786 // logical_func == wxCLEAR ? WHITENESS :
787 // logical_func == wxSET ? BLACKNESS :
788 logical_func
== wxINVERT
? hilite
:
789 // logical_func == wxAND ? MERGECOPY :
790 logical_func
== wxOR
? srcOr
:
791 logical_func
== wxSRC_INVERT
? notSrcCopy
:
792 logical_func
== wxXOR
? srcXor
:
793 // logical_func == wxOR_REVERSE ? MERGEPAINT :
794 // logical_func == wxAND_REVERSE ? SRCERASE :
795 // logical_func == wxSRC_OR ? srcOr :
796 // logical_func == wxSRC_AND ? SRCAND :
799 if ( useMask
&& source
->m_macMask
)
801 wxASSERT( mode
== srcCopy
) ;
802 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
804 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
805 GetPortBitMapForCopyBits( m_macPort
) ,
806 &srcrect
, &srcrect
, &dstrect
) ;
807 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
812 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
813 &srcrect
, &dstrect
, mode
, NULL
) ;
815 UnlockPixels( bmappixels
) ;
818 m_macPenInstalled
= false ;
819 m_macBrushInstalled
= false ;
820 m_macFontInstalled
= false ;
825 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
829 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
833 wxMacPortSetter
helper(this) ;
835 long xx
= XLOG2DEV(x
);
836 long yy
= YLOG2DEV(y
);
838 // if (m_pen.GetStyle() != wxTRANSPARENT)
842 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
844 ::ClipRect( &clip ) ;
848 ::GetFontInfo( &fi
) ;
852 if ( m_backgroundMode
== wxTRANSPARENT
)
858 ::TextMode( srcCopy
) ;
861 const char *text
= NULL
;
865 if ( wxApp::s_macDefaultEncodingIsPC
)
867 macText
= wxMacMakeMacStringFromPC( strtext
) ;
869 length
= macText
.Length() ;
874 length
= strtext
.Length() ;
883 if( text
[i
] == 13 || text
[i
] == 10)
885 ::DrawText( text
, laststop
, i
- laststop
) ;
887 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
893 ::DrawText( text
, laststop
, i
- laststop
) ;
894 ::TextMode( srcOr
) ;
898 bool wxDC::CanGetTextExtent(void) const
906 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
907 wxCoord
*descent
, wxCoord
*externalLeading
,
908 wxFont
*theFont
) const
913 wxMacPortSetter
helper(this) ;
915 wxFont formerFont
= m_font
;
919 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
923 ::TextFont( font
->m_macFontNum
) ;
924 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
925 ::TextFace( font
->m_macFontStyle
) ;
934 ::GetFontInfo( &fi
) ;
937 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
939 *descent
=YDEV2LOGREL( fi
.descent
);
940 if ( externalLeading
)
941 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
943 const char *text
= NULL
;
946 if ( wxApp::s_macDefaultEncodingIsPC
)
948 macText
= wxMacMakeMacStringFromPC( string
) ;
950 length
= macText
.Length() ;
955 length
= string
.Length() ;
967 if( text
[i
] == 13 || text
[i
] == 10)
970 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
971 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
972 if ( curwidth
> *width
)
973 *width
= XDEV2LOGREL( curwidth
) ;
979 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
980 if ( curwidth
> *width
)
981 *width
= XDEV2LOGREL( curwidth
) ;
986 m_macFontInstalled
= false ;
990 wxCoord
wxDC::GetCharWidth(void) const
995 wxMacPortSetter
helper(this) ;
1000 ::GetFontInfo( &fi
) ;
1002 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1005 wxCoord
wxDC::GetCharHeight(void) const
1010 wxMacPortSetter
helper(this) ;
1015 ::GetFontInfo( &fi
) ;
1017 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1020 void wxDC::Clear(void)
1024 wxMacPortSetter
helper(this) ;
1025 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1027 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1030 ::EraseRect( &rect
) ;
1034 void wxDC::MacInstallFont() const
1039 // if ( m_macFontInstalled )
1041 Pattern blackColor
;
1043 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1047 ::TextFont( font
->m_macFontNum
) ;
1048 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1049 ::TextFace( font
->m_macFontStyle
) ;
1051 m_macFontInstalled
= true ;
1052 m_macBrushInstalled
= false ;
1053 m_macPenInstalled
= false ;
1055 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1056 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1057 ::RGBForeColor( &forecolor
);
1058 ::RGBBackColor( &backcolor
);
1064 GetFNum( "\pGeneva" , &fontnum
) ;
1065 ::TextFont( fontnum
) ;
1066 ::TextSize( short(m_scaleY
* 10) ) ;
1069 // todo reset after spacing changes - or store the current spacing somewhere
1071 m_macFontInstalled
= true ;
1072 m_macBrushInstalled
= false ;
1073 m_macPenInstalled
= false ;
1075 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1076 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1077 ::RGBForeColor( &forecolor
);
1078 ::RGBBackColor( &backcolor
);
1081 short mode
= patCopy
;
1085 switch( m_logicalFunction
)
1090 case wxINVERT
: // NOT dst
1091 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1094 case wxXOR
: // src XOR dst
1097 case wxOR_REVERSE
: // src OR (NOT dst)
1100 case wxSRC_INVERT
: // (NOT src)
1107 case wxAND_REVERSE
:// src AND (NOT dst)
1108 case wxAND
: // src AND dst
1109 case wxAND_INVERT
: // (NOT src) AND dst
1110 case wxNO_OP
: // dst
1111 case wxNOR
: // (NOT src) AND (NOT dst)
1112 case wxEQUIV
: // (NOT src) XOR dst
1113 case wxOR_INVERT
: // (NOT src) OR dst
1114 case wxNAND
: // (NOT src) OR (NOT dst)
1115 case wxOR
: // src OR dst
1117 // case wxSRC_OR: // source _bitmap_ OR destination
1118 // case wxSRC_AND: // source _bitmap_ AND destination
1124 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1126 int thePatListID
= sysPatListID
;
1130 case wxBDIAGONAL_HATCH
:
1131 theIndex
= 34; // WCH: this is not good
1133 case wxFDIAGONAL_HATCH
:
1139 case wxHORIZONTAL_HATCH
:
1142 case wxVERTICAL_HATCH
:
1145 case wxCROSSDIAG_HATCH
:
1146 theIndex
= 4; // WCH: this is not good
1149 theIndex
= 1; // solid pattern
1152 GetIndPattern( pattern
, thePatListID
, theIndex
);
1155 void wxDC::MacInstallPen() const
1162 // if ( m_macPenInstalled )
1165 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1166 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1167 ::RGBForeColor( &forecolor
);
1168 ::RGBBackColor( &backcolor
);
1171 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1173 // null means only one pixel, at whatever resolution
1174 if ( penWidth
== 0 )
1176 ::PenSize(penWidth
, penWidth
);
1178 int penStyle
= m_pen
.GetStyle();
1180 if (penStyle
== wxSOLID
)
1182 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1184 else if (IS_HATCH(penStyle
))
1187 wxMacGetHatchPattern(penStyle
, &pat
);
1192 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1195 short mode
= patCopy
;
1199 switch( m_logicalFunction
)
1204 case wxINVERT
: // NOT dst
1205 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1208 case wxXOR
: // src XOR dst
1211 case wxOR_REVERSE
: // src OR (NOT dst)
1214 case wxSRC_INVERT
: // (NOT src)
1221 case wxAND_REVERSE
:// src AND (NOT dst)
1222 case wxAND
: // src AND dst
1223 case wxAND_INVERT
: // (NOT src) AND dst
1224 case wxNO_OP
: // dst
1225 case wxNOR
: // (NOT src) AND (NOT dst)
1226 case wxEQUIV
: // (NOT src) XOR dst
1227 case wxOR_INVERT
: // (NOT src) OR dst
1228 case wxNAND
: // (NOT src) OR (NOT dst)
1229 case wxOR
: // src OR dst
1231 // case wxSRC_OR: // source _bitmap_ OR destination
1232 // case wxSRC_AND: // source _bitmap_ AND destination
1236 m_macPenInstalled
= true ;
1237 m_macBrushInstalled
= false ;
1238 m_macFontInstalled
= false ;
1241 void wxDC::MacInstallBrush() const
1246 Pattern blackColor
, whiteColor
;
1247 // if ( m_macBrushInstalled )
1252 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1253 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1254 ::RGBForeColor( &forecolor
);
1255 ::RGBBackColor( &backcolor
);
1257 int brushStyle
= m_brush
.GetStyle();
1258 if (brushStyle
== wxSOLID
)
1259 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1260 else if (IS_HATCH(brushStyle
))
1263 wxMacGetHatchPattern(brushStyle
, &pat
);
1268 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1274 brushStyle
= m_backgroundBrush
.GetStyle();
1275 if (brushStyle
== wxSOLID
)
1276 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1277 else if (IS_HATCH(brushStyle
))
1280 wxMacGetHatchPattern(brushStyle
, &pat
);
1285 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1288 short mode
= patCopy
;
1292 switch( m_logicalFunction
)
1297 case wxINVERT
: // NOT dst
1298 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1301 case wxXOR
: // src XOR dst
1304 case wxOR_REVERSE
: // src OR (NOT dst)
1307 case wxSRC_INVERT
: // (NOT src)
1314 case wxAND_REVERSE
:// src AND (NOT dst)
1315 case wxAND
: // src AND dst
1316 case wxAND_INVERT
: // (NOT src) AND dst
1317 case wxNO_OP
: // dst
1318 case wxNOR
: // (NOT src) AND (NOT dst)
1319 case wxEQUIV
: // (NOT src) XOR dst
1320 case wxOR_INVERT
: // (NOT src) OR dst
1321 case wxNAND
: // (NOT src) OR (NOT dst)
1322 case wxOR
: // src OR dst
1324 // case wxSRC_OR: // source _bitmap_ OR destination
1325 // case wxSRC_AND: // source _bitmap_ AND destination
1329 m_macBrushInstalled
= true ;
1330 m_macPenInstalled
= false ;
1331 m_macFontInstalled
= false ;
1334 // ---------------------------------------------------------------------------
1335 // coordinates transformations
1336 // ---------------------------------------------------------------------------
1339 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1341 return ((wxDC
*)this)->XDEV2LOG(x
);
1344 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1346 return ((wxDC
*)this)->YDEV2LOG(y
);
1349 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1351 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1354 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1356 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1359 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1361 return ((wxDC
*)this)->XLOG2DEV(x
);
1364 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1366 return ((wxDC
*)this)->YLOG2DEV(y
);
1369 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1371 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1374 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1376 return ((wxDC
*)this)->YLOG2DEVREL(y
);