]>
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 //-----------------------------------------------------------------------------
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
);
111 long x1
= XLOG2DEV(m_clipX1
);
112 long y1
= YLOG2DEV(m_clipY1
);
113 long x2
= XLOG2DEV(m_clipX2
);
114 long y2
= YLOG2DEV(m_clipY2
);
116 Rect clip
= { y1
, x1
, y2
, x2
} ;
117 ::SectRect( &clip
, &m_macClipRect
, &clip
) ;
118 ::ClipRect( &clip
) ;
122 ::ClipRect(&m_macClipRect
);
126 m_macFontInstalled
= false ;
127 m_macBrushInstalled
= false ;
128 m_macPenInstalled
= false ;
131 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
137 wxMacPortSetter
helper(this) ;
139 long xx1
= XLOG2DEV(x
);
140 long yy1
= YLOG2DEV(y
);
143 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
147 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
149 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
150 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
151 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
153 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
155 if ( bmap
->m_hBitmap
)
157 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
158 PixMapHandle bmappixels
;
159 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
160 RGBColor black
= { 0,0,0} ;
161 RGBForeColor( &black
) ;
162 RGBBackColor( &white
) ;
164 bmappixels
= GetGWorldPixMap( bmapworld
) ;
165 if ( LockPixels(bmappixels
) )
170 source
.right
= bmap
->m_width
;
171 source
.bottom
= bmap
->m_height
;
172 dest
.top
= YLOG2DEV(y
) ;
173 dest
.left
= XLOG2DEV(x
) ;
174 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
175 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
177 if ( useMask
&& bmp
.GetMask() )
179 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
181 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
182 GetPortBitMapForCopyBits( m_macPort
) ,
183 &source
, &source
, &dest
) ;
184 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
188 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
189 &source
, &dest
, srcCopy
, NULL
) ;
191 UnlockPixels( bmappixels
) ;
193 m_macPenInstalled
= false ;
194 m_macBrushInstalled
= false ;
195 m_macFontInstalled
= false ;
202 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
206 wxMacPortSetter
helper(this) ;
208 long xx1
= XLOG2DEV(x
);
209 long yy1
= YLOG2DEV(y
);
212 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
214 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
216 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
217 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
218 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
223 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
227 m_clipX1
= wxMax( m_clipX1
, x
) ;
228 m_clipY1
= wxMax( m_clipY1
,y
);
229 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
230 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
238 m_clipX2
= x
+ width
;
239 m_clipY2
= y
+ height
;
243 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
245 wxCHECK_RET( Ok(), wxT("invalid window dc") );
247 wxMacPortSetter
helper(this) ;
250 DestroyClippingRegion();
254 wxCoord xx
, yy
, ww
, hh
;
255 region
.GetBox( xx
, yy
, ww
, hh
);
256 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
259 void wxDC::DestroyClippingRegion(void)
261 wxMacPortSetter
helper(this) ;
265 void wxDC::DoGetSize( int* width
, int* height
) const
267 *width
= m_maxX
-m_minX
;
268 *height
= m_maxY
-m_minY
;
271 void wxDC::DoGetSizeMM( int* width
, int* height
) const
276 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
277 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
280 void wxDC::SetTextForeground( const wxColour
&col
)
283 m_textForegroundColour
= col
;
284 m_macFontInstalled
= false ;
287 void wxDC::SetTextBackground( const wxColour
&col
)
290 m_textBackgroundColour
= col
;
291 m_macFontInstalled
= false ;
294 void wxDC::SetMapMode( int mode
)
299 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
302 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
305 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
308 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
312 SetLogicalScale( 1.0, 1.0 );
315 if (mode
!= wxMM_TEXT
)
317 m_needComputeScaleX
= TRUE
;
318 m_needComputeScaleY
= TRUE
;
322 void wxDC::SetUserScale( double x
, double y
)
324 // allow negative ? -> no
327 ComputeScaleAndOrigin();
330 void wxDC::SetLogicalScale( double x
, double y
)
335 ComputeScaleAndOrigin();
338 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
340 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
341 m_logicalOriginY
= y
* m_signY
;
342 ComputeScaleAndOrigin();
345 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
347 m_externalDeviceOriginX
= x
;
348 m_externalDeviceOriginY
= y
;
349 ComputeScaleAndOrigin();
352 void wxDC::SetInternalDeviceOrigin( long x, long y )
354 m_internalDeviceOriginX = x;
355 m_internalDeviceOriginY = y;
356 ComputeScaleAndOrigin();
359 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
361 if (x) *x = m_internalDeviceOriginX;
362 if (y) *y = m_internalDeviceOriginY;
365 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
367 m_signX
= (xLeftRight
? 1 : -1);
368 m_signY
= (yBottomUp
? -1 : 1);
369 ComputeScaleAndOrigin();
373 void wxDC::CalcBoundingBox( long x, long y )
375 if (x < m_minX) m_minX = x;
376 if (y < m_minY) m_minY = y;
377 if (x > m_maxX) m_maxX = x;
378 if (y > m_maxY) m_maxY = y;
381 wxSize
wxDC::GetPPI() const
383 return wxSize(72, 72);
386 int wxDC::GetDepth() const
388 return wxDisplayDepth() ;
391 void wxDC::ComputeScaleAndOrigin(void)
393 // CMB: copy scale to see if it changes
394 double origScaleX
= m_scaleX
;
395 double origScaleY
= m_scaleY
;
397 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
398 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
400 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
401 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
403 // CMB: if scale has changed call SetPen to recalulate the line width
404 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
406 // this is a bit artificial, but we need to force wxDC to think
407 // the pen has changed
408 wxPen
* pen
= & GetPen();
415 void wxDC::SetPalette( const wxPalette
& palette
)
419 void wxDC::SetBackgroundMode( int mode
)
421 m_backgroundMode
= mode
;
424 void wxDC::SetFont( const wxFont
&font
)
429 // wxMacPortSetter helper(this) ;
432 m_macFontInstalled
= false ;
435 void wxDC::SetPen( const wxPen
&pen
)
440 // wxMacPortSetter helper(this) ;
450 m_macPenInstalled
= false ;
453 void wxDC::SetBrush( const wxBrush
&brush
)
457 // wxMacPortSetter helper(this) ;
459 if (m_brush
== brush
)
463 m_macBrushInstalled
= false ;
466 void wxDC::SetBackground( const wxBrush
&brush
)
470 // wxMacPortSetter helper(this) ;
472 if (m_backgroundBrush
== brush
)
475 m_backgroundBrush
= brush
;
477 if (!m_backgroundBrush
.Ok())
479 m_macBrushInstalled
= false ;
482 void wxDC::SetLogicalFunction( int function
)
484 if (m_logicalFunction
== function
)
487 m_logicalFunction
= function
;
488 m_macFontInstalled
= false ;
489 m_macBrushInstalled
= false ;
490 m_macPenInstalled
= false ;
493 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
498 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
503 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
508 wxMacPortSetter
helper(this) ;
510 if (m_pen
.GetStyle() != wxTRANSPARENT
)
513 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
514 long xx1
= XLOG2DEV(x1
);
515 long yy1
= YLOG2DEV(y1
);
516 long xx2
= XLOG2DEV(x2
);
517 long yy2
= YLOG2DEV(y2
);
519 ::MoveTo(xx1
- offset
,yy1
- offset
);
520 ::LineTo(xx2
- offset
, yy2
- offset
);
524 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
528 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
529 wxCoord x2
, wxCoord y2
,
530 wxCoord xc
, wxCoord yc
)
534 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
535 double sa
, double ea
)
539 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
544 wxMacPortSetter
helper(this) ;
546 if (m_pen
.GetStyle() != wxTRANSPARENT
)
549 long xx1
= XLOG2DEV(x
);
550 long yy1
= YLOG2DEV(y
);
553 ::LineTo(xx1
+1, yy1
+1);
557 void wxDC::DoDrawLines(int n
, wxPoint points
[],
558 wxCoord xoffset
, wxCoord yoffset
)
562 wxMacPortSetter
helper(this) ;
564 if (m_pen
.GetStyle() == wxTRANSPARENT
)
569 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
570 long x1
, x2
, y1
, y2
;
571 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
572 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
573 ::MoveTo(x1
- offset
,y1
- offset
);
575 for (int i
= 0; i
< n
-1; i
++)
577 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
578 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
579 ::LineTo(x2
- offset
, y2
- offset
);
583 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
584 wxCoord xoffset
, wxCoord yoffset
,
589 wxMacPortSetter
helper(this) ;
591 PolyHandle polygon
= OpenPoly() ;
592 long x1
, x2
, y1
, y2
;
593 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
594 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
597 for (int i
= 0; i
< n
-1; i
++)
599 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
600 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
605 if (m_brush
.GetStyle() != wxTRANSPARENT
)
608 ::PaintPoly( polygon
) ;
611 if (m_pen
.GetStyle() != wxTRANSPARENT
)
614 ::FramePoly( polygon
) ;
616 KillPoly( polygon
) ;
619 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
623 wxMacPortSetter
helper(this) ;
625 long xx
= XLOG2DEV(x
);
626 long yy
= YLOG2DEV(y
);
627 long ww
= m_signX
* XLOG2DEVREL(width
);
628 long hh
= m_signY
* YLOG2DEVREL(height
);
630 // CMB: draw nothing if transformed w or h is 0
631 if (ww
== 0 || hh
== 0)
634 // CMB: handle -ve width and/or height
647 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
649 if (m_brush
.GetStyle() != wxTRANSPARENT
)
652 ::PaintRect( &rect
) ;
655 if (m_pen
.GetStyle() != wxTRANSPARENT
)
658 ::FrameRect( &rect
) ;
662 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
663 wxCoord width
, wxCoord height
,
668 wxMacPortSetter
helper(this) ;
671 radius
= - radius
* ((width
< height
) ? width
: height
);
673 long xx
= XLOG2DEV(x
);
674 long yy
= YLOG2DEV(y
);
675 long ww
= m_signX
* XLOG2DEVREL(width
);
676 long hh
= m_signY
* YLOG2DEVREL(height
);
678 // CMB: draw nothing if transformed w or h is 0
679 if (ww
== 0 || hh
== 0)
682 // CMB: handle -ve width and/or height
695 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
697 if (m_brush
.GetStyle() != wxTRANSPARENT
)
700 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
703 if (m_pen
.GetStyle() != wxTRANSPARENT
)
706 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
710 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
714 wxMacPortSetter
helper(this) ;
716 long xx
= XLOG2DEV(x
);
717 long yy
= YLOG2DEV(y
);
718 long ww
= m_signX
* XLOG2DEVREL(width
);
719 long hh
= m_signY
* YLOG2DEVREL(height
);
721 // CMB: draw nothing if transformed w or h is 0
722 if (ww
== 0 || hh
== 0)
725 // CMB: handle -ve width and/or height
738 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
740 if (m_brush
.GetStyle() != wxTRANSPARENT
)
743 ::PaintOval( &rect
) ;
746 if (m_pen
.GetStyle() != wxTRANSPARENT
)
749 ::FrameOval( &rect
) ;
755 bool wxDC::CanDrawBitmap(void) const
761 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
762 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
764 if (!Ok()) return FALSE
;
765 wxMacPortSetter
helper(this) ;
767 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
768 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
769 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
770 RGBColor black
= { 0,0,0} ;
771 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
772 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
773 RGBForeColor( &forecolor
) ;
774 RGBBackColor( &backcolor
) ;
776 if ( LockPixels(bmappixels
) )
778 Rect srcrect
, dstrect
;
779 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
780 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
781 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
782 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
783 dstrect
.top
= YLOG2DEV(ydest
) ;
784 dstrect
.left
= XLOG2DEV(xdest
) ;
785 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
786 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
788 short mode
= (logical_func
== wxCOPY
? srcCopy
:
789 // logical_func == wxCLEAR ? WHITENESS :
790 // logical_func == wxSET ? BLACKNESS :
791 logical_func
== wxINVERT
? hilite
:
792 // logical_func == wxAND ? MERGECOPY :
793 logical_func
== wxOR
? srcOr
:
794 logical_func
== wxSRC_INVERT
? notSrcCopy
:
795 logical_func
== wxXOR
? srcXor
:
796 // logical_func == wxOR_REVERSE ? MERGEPAINT :
797 // logical_func == wxAND_REVERSE ? SRCERASE :
798 // logical_func == wxSRC_OR ? srcOr :
799 // logical_func == wxSRC_AND ? SRCAND :
802 if ( useMask
&& source
->m_macMask
)
804 wxASSERT( mode
== srcCopy
) ;
805 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
807 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
808 GetPortBitMapForCopyBits( m_macPort
) ,
809 &srcrect
, &srcrect
, &dstrect
) ;
810 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
815 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
816 &srcrect
, &dstrect
, mode
, NULL
) ;
818 UnlockPixels( bmappixels
) ;
821 m_macPenInstalled
= false ;
822 m_macBrushInstalled
= false ;
823 m_macFontInstalled
= false ;
828 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
832 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
836 wxMacPortSetter
helper(this) ;
838 long xx
= XLOG2DEV(x
);
839 long yy
= YLOG2DEV(y
);
841 // if (m_pen.GetStyle() != wxTRANSPARENT)
845 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
847 ::ClipRect( &clip ) ;
851 ::GetFontInfo( &fi
) ;
855 if ( m_backgroundMode
== wxTRANSPARENT
)
861 ::TextMode( srcCopy
) ;
864 const char *text
= NULL
;
868 if ( wxApp::s_macDefaultEncodingIsPC
)
870 macText
= wxMacMakeMacStringFromPC( strtext
) ;
872 length
= macText
.Length() ;
877 length
= strtext
.Length() ;
886 if( text
[i
] == 13 || text
[i
] == 10)
888 ::DrawText( text
, laststop
, i
- laststop
) ;
890 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
896 ::DrawText( text
, laststop
, i
- laststop
) ;
897 ::TextMode( srcOr
) ;
901 bool wxDC::CanGetTextExtent(void) const
909 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
910 wxCoord
*descent
, wxCoord
*externalLeading
,
911 wxFont
*theFont
) const
916 wxMacPortSetter
helper(this) ;
918 wxFont formerFont
= m_font
;
922 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
926 ::TextFont( font
->m_macFontNum
) ;
927 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
928 ::TextFace( font
->m_macFontStyle
) ;
937 ::GetFontInfo( &fi
) ;
940 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
942 *descent
=YDEV2LOGREL( fi
.descent
);
943 if ( externalLeading
)
944 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
946 const char *text
= NULL
;
949 if ( wxApp::s_macDefaultEncodingIsPC
)
951 macText
= wxMacMakeMacStringFromPC( string
) ;
953 length
= macText
.Length() ;
958 length
= string
.Length() ;
970 if( text
[i
] == 13 || text
[i
] == 10)
973 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
974 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
975 if ( curwidth
> *width
)
976 *width
= XDEV2LOGREL( curwidth
) ;
982 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
983 if ( curwidth
> *width
)
984 *width
= XDEV2LOGREL( curwidth
) ;
989 m_macFontInstalled
= false ;
993 wxCoord
wxDC::GetCharWidth(void) const
998 wxMacPortSetter
helper(this) ;
1003 ::GetFontInfo( &fi
) ;
1005 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1008 wxCoord
wxDC::GetCharHeight(void) const
1013 wxMacPortSetter
helper(this) ;
1018 ::GetFontInfo( &fi
) ;
1020 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1023 void wxDC::Clear(void)
1027 wxMacPortSetter
helper(this) ;
1028 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1030 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1033 ::EraseRect( &rect
) ;
1037 void wxDC::MacInstallFont() const
1042 // if ( m_macFontInstalled )
1044 Pattern blackColor
;
1046 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1050 ::TextFont( font
->m_macFontNum
) ;
1051 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1052 ::TextFace( font
->m_macFontStyle
) ;
1054 m_macFontInstalled
= true ;
1055 m_macBrushInstalled
= false ;
1056 m_macPenInstalled
= false ;
1058 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1059 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1060 ::RGBForeColor( &forecolor
);
1061 ::RGBBackColor( &backcolor
);
1067 GetFNum( "\pGeneva" , &fontnum
) ;
1068 ::TextFont( fontnum
) ;
1069 ::TextSize( short(m_scaleY
* 10) ) ;
1072 // todo reset after spacing changes - or store the current spacing somewhere
1074 m_macFontInstalled
= true ;
1075 m_macBrushInstalled
= false ;
1076 m_macPenInstalled
= false ;
1078 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1079 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1080 ::RGBForeColor( &forecolor
);
1081 ::RGBBackColor( &backcolor
);
1084 short mode
= patCopy
;
1088 switch( m_logicalFunction
)
1093 case wxINVERT
: // NOT dst
1094 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1097 case wxXOR
: // src XOR dst
1100 case wxOR_REVERSE
: // src OR (NOT dst)
1103 case wxSRC_INVERT
: // (NOT src)
1110 case wxAND_REVERSE
:// src AND (NOT dst)
1111 case wxAND
: // src AND dst
1112 case wxAND_INVERT
: // (NOT src) AND dst
1113 case wxNO_OP
: // dst
1114 case wxNOR
: // (NOT src) AND (NOT dst)
1115 case wxEQUIV
: // (NOT src) XOR dst
1116 case wxOR_INVERT
: // (NOT src) OR dst
1117 case wxNAND
: // (NOT src) OR (NOT dst)
1118 case wxOR
: // src OR dst
1120 // case wxSRC_OR: // source _bitmap_ OR destination
1121 // case wxSRC_AND: // source _bitmap_ AND destination
1127 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1129 int thePatListID
= sysPatListID
;
1133 case wxBDIAGONAL_HATCH
:
1134 theIndex
= 34; // WCH: this is not good
1136 case wxFDIAGONAL_HATCH
:
1142 case wxHORIZONTAL_HATCH
:
1145 case wxVERTICAL_HATCH
:
1148 case wxCROSSDIAG_HATCH
:
1149 theIndex
= 4; // WCH: this is not good
1152 theIndex
= 1; // solid pattern
1155 GetIndPattern( pattern
, thePatListID
, theIndex
);
1158 void wxDC::MacInstallPen() const
1165 // if ( m_macPenInstalled )
1168 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1169 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1170 ::RGBForeColor( &forecolor
);
1171 ::RGBBackColor( &backcolor
);
1174 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1176 // null means only one pixel, at whatever resolution
1177 if ( penWidth
== 0 )
1179 ::PenSize(penWidth
, penWidth
);
1181 int penStyle
= m_pen
.GetStyle();
1183 if (penStyle
== wxSOLID
)
1185 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1187 else if (IS_HATCH(penStyle
))
1190 wxMacGetHatchPattern(penStyle
, &pat
);
1195 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1198 short mode
= patCopy
;
1202 switch( m_logicalFunction
)
1207 case wxINVERT
: // NOT dst
1208 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1211 case wxXOR
: // src XOR dst
1214 case wxOR_REVERSE
: // src OR (NOT dst)
1217 case wxSRC_INVERT
: // (NOT src)
1224 case wxAND_REVERSE
:// src AND (NOT dst)
1225 case wxAND
: // src AND dst
1226 case wxAND_INVERT
: // (NOT src) AND dst
1227 case wxNO_OP
: // dst
1228 case wxNOR
: // (NOT src) AND (NOT dst)
1229 case wxEQUIV
: // (NOT src) XOR dst
1230 case wxOR_INVERT
: // (NOT src) OR dst
1231 case wxNAND
: // (NOT src) OR (NOT dst)
1232 case wxOR
: // src OR dst
1234 // case wxSRC_OR: // source _bitmap_ OR destination
1235 // case wxSRC_AND: // source _bitmap_ AND destination
1239 m_macPenInstalled
= true ;
1240 m_macBrushInstalled
= false ;
1241 m_macFontInstalled
= false ;
1244 void wxDC::MacInstallBrush() const
1249 Pattern blackColor
, whiteColor
;
1250 // if ( m_macBrushInstalled )
1255 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1256 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1257 ::RGBForeColor( &forecolor
);
1258 ::RGBBackColor( &backcolor
);
1260 int brushStyle
= m_brush
.GetStyle();
1261 if (brushStyle
== wxSOLID
)
1262 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1263 else if (IS_HATCH(brushStyle
))
1266 wxMacGetHatchPattern(brushStyle
, &pat
);
1271 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1277 brushStyle
= m_backgroundBrush
.GetStyle();
1278 if (brushStyle
== wxSOLID
)
1279 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1280 else if (IS_HATCH(brushStyle
))
1283 wxMacGetHatchPattern(brushStyle
, &pat
);
1288 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1291 short mode
= patCopy
;
1295 switch( m_logicalFunction
)
1300 case wxINVERT
: // NOT dst
1301 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1304 case wxXOR
: // src XOR dst
1307 case wxOR_REVERSE
: // src OR (NOT dst)
1310 case wxSRC_INVERT
: // (NOT src)
1317 case wxAND_REVERSE
:// src AND (NOT dst)
1318 case wxAND
: // src AND dst
1319 case wxAND_INVERT
: // (NOT src) AND dst
1320 case wxNO_OP
: // dst
1321 case wxNOR
: // (NOT src) AND (NOT dst)
1322 case wxEQUIV
: // (NOT src) XOR dst
1323 case wxOR_INVERT
: // (NOT src) OR dst
1324 case wxNAND
: // (NOT src) OR (NOT dst)
1325 case wxOR
: // src OR dst
1327 // case wxSRC_OR: // source _bitmap_ OR destination
1328 // case wxSRC_AND: // source _bitmap_ AND destination
1332 m_macBrushInstalled
= true ;
1333 m_macPenInstalled
= false ;
1334 m_macFontInstalled
= false ;
1337 // ---------------------------------------------------------------------------
1338 // coordinates transformations
1339 // ---------------------------------------------------------------------------
1342 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1344 return ((wxDC
*)this)->XDEV2LOG(x
);
1347 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1349 return ((wxDC
*)this)->YDEV2LOG(y
);
1352 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1354 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1357 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1359 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1362 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1364 return ((wxDC
*)this)->XLOG2DEV(x
);
1367 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1369 return ((wxDC
*)this)->YLOG2DEV(y
);
1372 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1374 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1377 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1379 return ((wxDC
*)this)->YLOG2DEVREL(y
);