]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #include "wx/mac/uma.h"
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 #define mm2inches 0.0393700787402
33 #define inches2mm 25.4
34 #define mm2twips 56.6929133859
35 #define twips2mm 0.0176388888889
36 #define mm2pt 2.83464566929
37 #define pt2mm 0.352777777778
39 long wxDC::m_macCurrentPortId
= 1 ;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
48 // m_optimize = FALSE;
49 // m_autoSetting = FALSE;
53 m_mm_to_pix_x
= mm2pt
;
54 m_mm_to_pix_y
= mm2pt
;
60 m_internalDeviceOriginX
= 0;
61 m_internalDeviceOriginY
= 0;
62 m_externalDeviceOriginX
= 0;
63 m_externalDeviceOriginY
= 0;
65 m_logicalScaleX
= 1.0;
66 m_logicalScaleY
= 1.0;
72 m_mappingMode
= wxMM_TEXT
;
73 m_needComputeScaleX
= FALSE
;
74 m_needComputeScaleY
= FALSE
;
76 m_signX
= 1; // default x-axis left to right
77 m_signY
= 1; // default y-axis top down
79 m_maxX
= m_maxY
= -100000;
80 m_minY
= m_minY
= 100000;
82 m_logicalFunction
= wxCOPY
;
83 // m_textAlignment = wxALIGN_TOP_LEFT;
84 m_backgroundMode
= wxTRANSPARENT
;
86 m_textForegroundColour
= *wxBLACK
;
87 m_textBackgroundColour
= *wxWHITE
;
89 m_font
= *wxNORMAL_FONT
;
90 m_brush
= *wxTRANSPARENT_BRUSH
;
91 m_backgroundBrush
= *wxWHITE_BRUSH
;
93 // m_palette = wxAPP_COLOURMAP;
98 m_macFontInstalled
= false ;
99 m_macBrushInstalled
= false ;
100 m_macPenInstalled
= false ;
103 m_macLocalOrigin
.h
= m_macLocalOrigin
.v
= 0 ;
104 m_macClipRect
.left
= -32000 ;
105 m_macClipRect
.top
= -32000 ;
106 m_macClipRect
.right
= 32000 ;
107 m_macClipRect
.bottom
= 32000 ;
108 ::GetPort( &m_macOrigPort
) ;
113 if ( !m_macPortHelper
.IsCleared() )
117 SetPort( m_macPortHelper
.GetCurrentPort() ) ;
124 ::SetPort( m_macPort ) ;
125 ::SetOrigin( 0 , 0 ) ;
126 ::ClipRect( &m_macPort->portRect ) ;
128 ::SetPort( m_macOrigPort ) ;
131 ++m_macCurrentPortId
;
134 void wxDC::MacSetupPort() const
136 AGAPortHelper
* help
= (AGAPortHelper
*) &m_macPortHelper
;
137 help
->Setup( m_macPort
) ;
138 m_macPortId
= ++m_macCurrentPortId
;
139 ::SetOrigin(-m_macLocalOrigin
.h
, -m_macLocalOrigin
.v
);
140 ::ClipRect(&m_macClipRect
);
142 m_macFontInstalled
= false ;
143 m_macBrushInstalled
= false ;
144 m_macPenInstalled
= false ;
147 void wxDC::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
155 long xx1
= XLOG2DEV(x
);
156 long yy1
= YLOG2DEV(y
);
159 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( bmp
.GetRefData()) ;
163 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
165 Rect bitmaprect
= { 0 , 0 , int(bmap
->m_height
* scale
) , int(bmap
->m_width
* scale
)} ;
166 ::OffsetRect( &bitmaprect
, xx1
, yy1
) ;
167 ::DrawPicture( bmap
->m_hPict
, &bitmaprect
) ;
169 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
171 if ( bmap
->m_hBitmap
)
173 GWorldPtr bmapworld
= bmap
->m_hBitmap
;
174 PixMapHandle bmappixels
;
175 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
176 RGBColor black
= { 0,0,0} ;
177 RGBForeColor( &black
) ;
178 RGBBackColor( &white
) ;
180 bmappixels
= GetGWorldPixMap( bmapworld
) ;
181 if ( LockPixels(bmappixels
) )
186 source
.right
= bmap
->m_width
;
187 source
.bottom
= bmap
->m_height
;
188 dest
.top
= YLOG2DEV(y
) ;
189 dest
.left
= XLOG2DEV(x
) ;
190 dest
.bottom
= YLOG2DEV(y
+ bmap
->m_height
* scale
) ;
191 dest
.right
= XLOG2DEV(x
+ bmap
->m_width
* scale
) ;
193 if ( useMask
&& bmp
.GetMask() )
195 if ( LockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) )
197 CopyMask( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( bmp
.GetMask()->GetMaskBitmap( ) ) ,
198 GetPortBitMapForCopyBits( m_macPort
) ,
199 &source
, &source
, &dest
) ;
200 UnlockPixels( GetGWorldPixMap( bmp
.GetMask()->GetMaskBitmap( ) ) ) ;
204 CopyBits( GetPortBitMapForCopyBits( bmapworld
) , GetPortBitMapForCopyBits( m_macPort
),
205 &source
, &dest
, srcCopy
, NULL
) ;
207 UnlockPixels( bmappixels
) ;
209 m_macPenInstalled
= false ;
210 m_macBrushInstalled
= false ;
211 m_macFontInstalled
= false ;
218 void wxDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
224 long xx1
= XLOG2DEV(x
);
225 long yy1
= YLOG2DEV(y
);
228 wxIconRefData
* iconref
= (wxIconRefData
*) ( icon
.GetRefData()) ;
230 if ( iconref
&& iconref
->m_ok
&& iconref
->m_hIcon
)
232 Rect bitmaprect
= { 0 , 0 , iconref
->m_height
, iconref
->m_width
} ;
233 OffsetRect( &bitmaprect
, xx1
, yy1
) ;
234 PlotCIconHandle( &bitmaprect
, atNone
, ttNone
, iconref
->m_hIcon
) ;
239 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
244 m_clipX1
= wxMax( m_clipX1
, x
) ;
245 m_clipY1
= wxMax( m_clipY1
,y
);
246 m_clipX2
= wxMin( m_clipX2
, (x
+ width
));
247 m_clipY2
= wxMin( m_clipY2
,(y
+ height
));
255 m_clipX2
= x
+ width
;
256 m_clipY2
= y
+ height
;
259 long x1
= XLOG2DEV(m_clipX1
);
260 long y1
= YLOG2DEV(m_clipY1
);
261 long x2
= XLOG2DEV(m_clipX2
);
262 long y2
= YLOG2DEV(m_clipY2
);
264 Rect clip
= { y1
, x1
, y2
, x2
} ;
266 ::ClipRect( &clip
) ;
270 void wxDC::DoSetClippingRegionAsRegion( const wxRegion
®ion
)
272 wxCHECK_RET( Ok(), wxT("invalid window dc") );
277 DestroyClippingRegion();
281 wxCoord xx
, yy
, ww
, hh
;
282 region
.GetBox( xx
, yy
, ww
, hh
);
283 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
286 void wxDC::DestroyClippingRegion(void)
290 // Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
291 ::ClipRect(&m_macClipRect
);
294 void wxDC::DoGetSize( int* width
, int* height
) const
296 *width
= m_maxX
-m_minX
;
297 *height
= m_maxY
-m_minY
;
300 void wxDC::DoGetSizeMM( int* width
, int* height
) const
305 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
306 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
309 void wxDC::SetTextForeground( const wxColour
&col
)
312 m_textForegroundColour
= col
;
313 m_macFontInstalled
= false ;
316 void wxDC::SetTextBackground( const wxColour
&col
)
319 m_textBackgroundColour
= col
;
320 m_macFontInstalled
= false ;
323 void wxDC::SetMapMode( int mode
)
328 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
331 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
334 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
337 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
341 SetLogicalScale( 1.0, 1.0 );
344 if (mode
!= wxMM_TEXT
)
346 m_needComputeScaleX
= TRUE
;
347 m_needComputeScaleY
= TRUE
;
351 void wxDC::SetUserScale( double x
, double y
)
353 // allow negative ? -> no
356 ComputeScaleAndOrigin();
359 void wxDC::SetLogicalScale( double x
, double y
)
364 ComputeScaleAndOrigin();
367 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
369 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
370 m_logicalOriginY
= y
* m_signY
;
371 ComputeScaleAndOrigin();
374 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
376 m_externalDeviceOriginX
= x
;
377 m_externalDeviceOriginY
= y
;
378 ComputeScaleAndOrigin();
381 void wxDC::SetInternalDeviceOrigin( long x, long y )
383 m_internalDeviceOriginX = x;
384 m_internalDeviceOriginY = y;
385 ComputeScaleAndOrigin();
388 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
390 if (x) *x = m_internalDeviceOriginX;
391 if (y) *y = m_internalDeviceOriginY;
394 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
396 m_signX
= (xLeftRight
? 1 : -1);
397 m_signY
= (yBottomUp
? -1 : 1);
398 ComputeScaleAndOrigin();
402 void wxDC::CalcBoundingBox( long x, long y )
404 if (x < m_minX) m_minX = x;
405 if (y < m_minY) m_minY = y;
406 if (x > m_maxX) m_maxX = x;
407 if (y > m_maxY) m_maxY = y;
410 wxSize
wxDC::GetPPI() const
412 return wxSize(72, 72);
415 int wxDC::GetDepth() const
417 return wxDisplayDepth() ;
420 void wxDC::ComputeScaleAndOrigin(void)
422 // CMB: copy scale to see if it changes
423 double origScaleX
= m_scaleX
;
424 double origScaleY
= m_scaleY
;
426 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
427 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
429 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
430 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
432 // CMB: if scale has changed call SetPen to recalulate the line width
433 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
435 // this is a bit artificial, but we need to force wxDC to think
436 // the pen has changed
437 wxPen
* pen
= & GetPen();
444 void wxDC::SetPalette( const wxPalette
& palette
)
448 void wxDC::SetBackgroundMode( int mode
)
450 m_backgroundMode
= mode
;
453 void wxDC::SetFont( const wxFont
&font
)
461 m_macFontInstalled
= false ;
464 void wxDC::SetPen( const wxPen
&pen
)
479 m_macPenInstalled
= false ;
482 void wxDC::SetBrush( const wxBrush
&brush
)
488 if (m_brush
== brush
)
492 m_macBrushInstalled
= false ;
495 void wxDC::SetBackground( const wxBrush
&brush
)
501 if (m_backgroundBrush
== brush
)
504 m_backgroundBrush
= brush
;
506 if (!m_backgroundBrush
.Ok())
508 m_macBrushInstalled
= false ;
511 void wxDC::SetLogicalFunction( int function
)
513 if (m_logicalFunction
== function
)
516 m_logicalFunction
= function
;
517 m_macFontInstalled
= false ;
518 m_macBrushInstalled
= false ;
519 m_macPenInstalled
= false ;
522 void wxDC::DoFloodFill( wxCoord x
, wxCoord y
, const wxColour
& col
,
527 bool wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour
*col
) const
532 void wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
539 if (m_pen
.GetStyle() != wxTRANSPARENT
)
542 int offset
= ( (m_pen
.GetWidth() == 0 ? 1 : m_pen
.GetWidth() ) * m_scaleX
- 1) / 2 ;
543 long xx1
= XLOG2DEV(x1
);
544 long yy1
= YLOG2DEV(y1
);
545 long xx2
= XLOG2DEV(x2
);
546 long yy2
= YLOG2DEV(y2
);
548 ::MoveTo(xx1
- offset
,yy1
- offset
);
549 ::LineTo(xx2
- offset
, yy2
- offset
);
553 void wxDC::DoCrossHair( wxCoord x
, wxCoord y
)
557 void wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
,
558 wxCoord x2
, wxCoord y2
,
559 wxCoord xc
, wxCoord yc
)
563 void wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
564 double sa
, double ea
)
568 void wxDC::DoDrawPoint( wxCoord x
, wxCoord y
)
575 if (m_pen
.GetStyle() != wxTRANSPARENT
)
578 long xx1
= XLOG2DEV(x
);
579 long yy1
= YLOG2DEV(y
);
582 ::LineTo(xx1
+1, yy1
+1);
586 void wxDC::DoDrawLines(int n
, wxPoint points
[],
587 wxCoord xoffset
, wxCoord yoffset
)
593 if (m_pen
.GetStyle() == wxTRANSPARENT
)
598 int offset
= (m_pen
.GetWidth() - 1 ) / 2 ;
599 long x1
, x2
, y1
, y2
;
600 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
601 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
602 ::MoveTo(x1
- offset
,y1
- offset
);
604 for (int i
= 0; i
< n
-1; i
++)
606 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
607 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
608 ::LineTo(x2
- offset
, y2
- offset
);
612 void wxDC::DoDrawPolygon(int n
, wxPoint points
[],
613 wxCoord xoffset
, wxCoord yoffset
,
620 PolyHandle polygon
= OpenPoly() ;
621 long x1
, x2
, y1
, y2
;
622 x1
= XLOG2DEV(points
[0].x
+ xoffset
);
623 y1
= YLOG2DEV(points
[0].y
+ yoffset
);
626 for (int i
= 0; i
< n
-1; i
++)
628 x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
629 y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
634 if (m_brush
.GetStyle() != wxTRANSPARENT
)
637 ::PaintPoly( polygon
) ;
640 if (m_pen
.GetStyle() != wxTRANSPARENT
)
643 ::FramePoly( polygon
) ;
645 KillPoly( polygon
) ;
648 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
654 long xx
= XLOG2DEV(x
);
655 long yy
= YLOG2DEV(y
);
656 long ww
= m_signX
* XLOG2DEVREL(width
);
657 long hh
= m_signY
* YLOG2DEVREL(height
);
659 // CMB: draw nothing if transformed w or h is 0
660 if (ww
== 0 || hh
== 0)
663 // CMB: handle -ve width and/or height
676 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
678 if (m_brush
.GetStyle() != wxTRANSPARENT
)
681 ::PaintRect( &rect
) ;
684 if (m_pen
.GetStyle() != wxTRANSPARENT
)
687 ::FrameRect( &rect
) ;
691 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
692 wxCoord width
, wxCoord height
,
700 radius
= - radius
* ((width
< height
) ? width
: height
);
702 long xx
= XLOG2DEV(x
);
703 long yy
= YLOG2DEV(y
);
704 long ww
= m_signX
* XLOG2DEVREL(width
);
705 long hh
= m_signY
* YLOG2DEVREL(height
);
707 // CMB: draw nothing if transformed w or h is 0
708 if (ww
== 0 || hh
== 0)
711 // CMB: handle -ve width and/or height
724 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
726 if (m_brush
.GetStyle() != wxTRANSPARENT
)
729 ::PaintRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
732 if (m_pen
.GetStyle() != wxTRANSPARENT
)
735 ::FrameRoundRect( &rect
, int(radius
* 2) , int(radius
* 2) ) ;
739 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
745 long xx
= XLOG2DEV(x
);
746 long yy
= YLOG2DEV(y
);
747 long ww
= m_signX
* XLOG2DEVREL(width
);
748 long hh
= m_signY
* YLOG2DEVREL(height
);
750 // CMB: draw nothing if transformed w or h is 0
751 if (ww
== 0 || hh
== 0)
754 // CMB: handle -ve width and/or height
767 Rect rect
= { yy
, xx
, yy
+ hh
, xx
+ ww
} ;
769 if (m_brush
.GetStyle() != wxTRANSPARENT
)
772 ::PaintOval( &rect
) ;
775 if (m_pen
.GetStyle() != wxTRANSPARENT
)
778 ::FrameOval( &rect
) ;
784 bool wxDC::CanDrawBitmap(void) const
790 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
791 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
)
793 if (!Ok()) return FALSE
;
796 CGrafPtr sourcePort
= (CGrafPtr
) source
->m_macPort
;
797 PixMapHandle bmappixels
= GetGWorldPixMap( sourcePort
) ;
798 RGBColor white
= { 0xFFFF, 0xFFFF,0xFFFF} ;
799 RGBColor black
= { 0,0,0} ;
800 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
801 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
802 RGBForeColor( &forecolor
) ;
803 RGBBackColor( &backcolor
) ;
805 if ( LockPixels(bmappixels
) )
807 Rect srcrect
, dstrect
;
808 srcrect
.top
= source
->YLOG2DEV(ysrc
) ;
809 srcrect
.left
= source
->XLOG2DEV(xsrc
) ;
810 srcrect
.right
= source
->XLOG2DEV(xsrc
+ width
) ;
811 srcrect
.bottom
= source
->YLOG2DEV(ysrc
+ height
) ;
812 dstrect
.top
= YLOG2DEV(ydest
) ;
813 dstrect
.left
= XLOG2DEV(xdest
) ;
814 dstrect
.bottom
= YLOG2DEV(ydest
+ height
) ;
815 dstrect
.right
= XLOG2DEV(xdest
+ width
) ;
817 short mode
= (logical_func
== wxCOPY
? srcCopy
:
818 // logical_func == wxCLEAR ? WHITENESS :
819 // logical_func == wxSET ? BLACKNESS :
820 logical_func
== wxINVERT
? hilite
:
821 // logical_func == wxAND ? MERGECOPY :
822 logical_func
== wxOR
? srcOr
:
823 logical_func
== wxSRC_INVERT
? notSrcCopy
:
824 logical_func
== wxXOR
? srcXor
:
825 // logical_func == wxOR_REVERSE ? MERGEPAINT :
826 // logical_func == wxAND_REVERSE ? SRCERASE :
827 // logical_func == wxSRC_OR ? srcOr :
828 // logical_func == wxSRC_AND ? SRCAND :
831 if ( useMask
&& source
->m_macMask
)
833 wxASSERT( mode
== srcCopy
) ;
834 if ( LockPixels( GetGWorldPixMap( source
->m_macMask
) ) )
836 CopyMask( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( source
->m_macMask
) ,
837 GetPortBitMapForCopyBits( m_macPort
) ,
838 &srcrect
, &srcrect
, &dstrect
) ;
839 UnlockPixels( GetGWorldPixMap( source
->m_macMask
) ) ;
844 CopyBits( GetPortBitMapForCopyBits( sourcePort
) , GetPortBitMapForCopyBits( m_macPort
) ,
845 &srcrect
, &dstrect
, mode
, NULL
) ;
847 UnlockPixels( bmappixels
) ;
850 m_macPenInstalled
= false ;
851 m_macBrushInstalled
= false ;
852 m_macFontInstalled
= false ;
857 void wxDC::DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
861 void wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
)
867 long xx
= XLOG2DEV(x
);
868 long yy
= YLOG2DEV(y
);
870 // if (m_pen.GetStyle() != wxTRANSPARENT)
874 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
876 ::ClipRect( &clip ) ;
880 ::GetFontInfo( &fi
) ;
884 if ( m_backgroundMode
== wxTRANSPARENT
)
890 ::TextMode( srcCopy
) ;
893 const char *text
= NULL
;
897 if ( wxApp::s_macDefaultEncodingIsPC
)
899 macText
= wxMacMakeMacStringFromPC( strtext
) ;
901 length
= macText
.Length() ;
906 length
= strtext
.Length() ;
915 if( text
[i
] == 13 || text
[i
] == 10)
917 ::DrawText( text
, laststop
, i
- laststop
) ;
919 ::MoveTo( xx
, yy
+ line
*(fi
.descent
+ fi
.ascent
+ fi
.leading
) );
925 ::DrawText( text
, laststop
, i
- laststop
) ;
926 ::TextMode( srcOr
) ;
930 bool wxDC::CanGetTextExtent(void) const
938 void wxDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
939 wxCoord
*descent
, wxCoord
*externalLeading
,
940 wxFont
*theFont
) const
947 wxFont formerFont
= m_font
;
951 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
955 ::TextFont( font
->m_macFontNum
) ;
956 ::TextSize( YLOG2DEVREL( font
->m_macFontSize
) ) ;
957 ::TextFace( font
->m_macFontStyle
) ;
966 ::GetFontInfo( &fi
) ;
969 *height
= YDEV2LOGREL( fi
.descent
+ fi
.ascent
) ;
971 *descent
=YDEV2LOGREL( fi
.descent
);
972 if ( externalLeading
)
973 *externalLeading
= YDEV2LOGREL( fi
.leading
) ;
975 const char *text
= NULL
;
978 if ( wxApp::s_macDefaultEncodingIsPC
)
980 macText
= wxMacMakeMacStringFromPC( string
) ;
982 length
= macText
.Length() ;
987 length
= string
.Length() ;
999 if( text
[i
] == 13 || text
[i
] == 10)
1002 *height
+= YDEV2LOGREL( fi
.descent
+ fi
.ascent
+ fi
.leading
) ;
1003 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1004 if ( curwidth
> *width
)
1005 *width
= XDEV2LOGREL( curwidth
) ;
1011 curwidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
1012 if ( curwidth
> *width
)
1013 *width
= XDEV2LOGREL( curwidth
) ;
1018 m_macFontInstalled
= false ;
1022 wxCoord
wxDC::GetCharWidth(void) const
1032 ::GetFontInfo( &fi
) ;
1034 return YDEV2LOGREL((fi
.descent
+ fi
.ascent
) / 2) ;
1037 wxCoord
wxDC::GetCharHeight(void) const
1047 ::GetFontInfo( &fi
) ;
1049 return YDEV2LOGREL( fi
.descent
+ fi
.ascent
);
1052 void wxDC::Clear(void)
1057 Rect rect
= { -32767 , -32767 , 32767 , 32767 } ;
1059 if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
1062 ::EraseRect( &rect
) ;
1066 void wxDC::MacInstallFont() const
1072 if ( m_macFontInstalled
)
1074 Pattern blackColor
;
1076 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
1080 ::TextFont( font
->m_macFontNum
) ;
1081 ::TextSize( short(m_scaleY
* font
->m_macFontSize
) ) ;
1082 ::TextFace( font
->m_macFontStyle
) ;
1084 m_macFontInstalled
= true ;
1085 m_macBrushInstalled
= false ;
1086 m_macPenInstalled
= false ;
1088 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1089 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1090 ::RGBForeColor( &forecolor
);
1091 ::RGBBackColor( &backcolor
);
1097 GetFNum( "\pGeneva" , &fontnum
) ;
1098 ::TextFont( fontnum
) ;
1099 ::TextSize( short(m_scaleY
* 10) ) ;
1102 // todo reset after spacing changes - or store the current spacing somewhere
1104 m_macFontInstalled
= true ;
1105 m_macBrushInstalled
= false ;
1106 m_macPenInstalled
= false ;
1108 RGBColor forecolor
= m_textForegroundColour
.GetPixel();
1109 RGBColor backcolor
= m_textBackgroundColour
.GetPixel();
1110 ::RGBForeColor( &forecolor
);
1111 ::RGBBackColor( &backcolor
);
1114 short mode
= patCopy
;
1118 switch( m_logicalFunction
)
1123 case wxINVERT
: // NOT dst
1124 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1127 case wxXOR
: // src XOR dst
1130 case wxOR_REVERSE
: // src OR (NOT dst)
1133 case wxSRC_INVERT
: // (NOT src)
1140 case wxAND_REVERSE
:// src AND (NOT dst)
1141 case wxAND
: // src AND dst
1142 case wxAND_INVERT
: // (NOT src) AND dst
1143 case wxNO_OP
: // dst
1144 case wxNOR
: // (NOT src) AND (NOT dst)
1145 case wxEQUIV
: // (NOT src) XOR dst
1146 case wxOR_INVERT
: // (NOT src) OR dst
1147 case wxNAND
: // (NOT src) OR (NOT dst)
1148 case wxOR
: // src OR dst
1150 // case wxSRC_OR: // source _bitmap_ OR destination
1151 // case wxSRC_AND: // source _bitmap_ AND destination
1157 static void wxMacGetHatchPattern(int hatchStyle
, Pattern
*pattern
)
1159 int thePatListID
= sysPatListID
;
1163 case wxBDIAGONAL_HATCH
:
1164 theIndex
= 34; // WCH: this is not good
1166 case wxFDIAGONAL_HATCH
:
1172 case wxHORIZONTAL_HATCH
:
1175 case wxVERTICAL_HATCH
:
1178 case wxCROSSDIAG_HATCH
:
1179 theIndex
= 4; // WCH: this is not good
1182 theIndex
= 1; // solid pattern
1185 GetIndPattern( pattern
, thePatListID
, theIndex
);
1188 void wxDC::MacInstallPen() const
1196 if ( m_macPenInstalled
)
1199 RGBColor forecolor
= m_pen
.GetColour().GetPixel();
1200 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1201 ::RGBForeColor( &forecolor
);
1202 ::RGBBackColor( &backcolor
);
1205 int penWidth
= m_pen
.GetWidth() * m_scaleX
;
1207 // null means only one pixel, at whatever resolution
1208 if ( penWidth
== 0 )
1210 ::PenSize(penWidth
, penWidth
);
1212 int penStyle
= m_pen
.GetStyle();
1214 if (penStyle
== wxSOLID
)
1216 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1218 else if (IS_HATCH(penStyle
))
1221 wxMacGetHatchPattern(penStyle
, &pat
);
1226 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1229 short mode
= patCopy
;
1233 switch( m_logicalFunction
)
1238 case wxINVERT
: // NOT dst
1239 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1242 case wxXOR
: // src XOR dst
1245 case wxOR_REVERSE
: // src OR (NOT dst)
1248 case wxSRC_INVERT
: // (NOT src)
1255 case wxAND_REVERSE
:// src AND (NOT dst)
1256 case wxAND
: // src AND dst
1257 case wxAND_INVERT
: // (NOT src) AND dst
1258 case wxNO_OP
: // dst
1259 case wxNOR
: // (NOT src) AND (NOT dst)
1260 case wxEQUIV
: // (NOT src) XOR dst
1261 case wxOR_INVERT
: // (NOT src) OR dst
1262 case wxNAND
: // (NOT src) OR (NOT dst)
1263 case wxOR
: // src OR dst
1265 // case wxSRC_OR: // source _bitmap_ OR destination
1266 // case wxSRC_AND: // source _bitmap_ AND destination
1270 m_macPenInstalled
= true ;
1271 m_macBrushInstalled
= false ;
1272 m_macFontInstalled
= false ;
1275 void wxDC::MacInstallBrush() const
1280 Pattern blackColor
, whiteColor
;
1281 if ( m_macBrushInstalled
)
1286 RGBColor forecolor
= m_brush
.GetColour().GetPixel();
1287 RGBColor backcolor
= m_backgroundBrush
.GetColour().GetPixel();
1288 ::RGBForeColor( &forecolor
);
1289 ::RGBBackColor( &backcolor
);
1291 int brushStyle
= m_brush
.GetStyle();
1292 if (brushStyle
== wxSOLID
)
1293 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1294 else if (IS_HATCH(brushStyle
))
1297 wxMacGetHatchPattern(brushStyle
, &pat
);
1302 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1308 brushStyle
= m_backgroundBrush
.GetStyle();
1309 if (brushStyle
== wxSOLID
)
1310 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1311 else if (IS_HATCH(brushStyle
))
1314 wxMacGetHatchPattern(brushStyle
, &pat
);
1319 ::BackPat(GetQDGlobalsWhite(&whiteColor
));
1322 short mode
= patCopy
;
1326 switch( m_logicalFunction
)
1331 case wxINVERT
: // NOT dst
1332 ::PenPat(GetQDGlobalsBlack(&blackColor
));
1335 case wxXOR
: // src XOR dst
1338 case wxOR_REVERSE
: // src OR (NOT dst)
1341 case wxSRC_INVERT
: // (NOT src)
1348 case wxAND_REVERSE
:// src AND (NOT dst)
1349 case wxAND
: // src AND dst
1350 case wxAND_INVERT
: // (NOT src) AND dst
1351 case wxNO_OP
: // dst
1352 case wxNOR
: // (NOT src) AND (NOT dst)
1353 case wxEQUIV
: // (NOT src) XOR dst
1354 case wxOR_INVERT
: // (NOT src) OR dst
1355 case wxNAND
: // (NOT src) OR (NOT dst)
1356 case wxOR
: // src OR dst
1358 // case wxSRC_OR: // source _bitmap_ OR destination
1359 // case wxSRC_AND: // source _bitmap_ AND destination
1363 m_macBrushInstalled
= true ;
1364 m_macPenInstalled
= false ;
1365 m_macFontInstalled
= false ;
1368 // ---------------------------------------------------------------------------
1369 // coordinates transformations
1370 // ---------------------------------------------------------------------------
1373 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1375 return ((wxDC
*)this)->XDEV2LOG(x
);
1378 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1380 return ((wxDC
*)this)->YDEV2LOG(y
);
1383 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1385 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1388 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1390 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1393 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1395 return ((wxDC
*)this)->XLOG2DEV(x
);
1398 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1400 return ((wxDC
*)this)->YLOG2DEV(y
);
1403 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1405 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1408 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1410 return ((wxDC
*)this)->YLOG2DEVREL(y
);