X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d16b634fa336d09050d01786fb420d32ef43d311..c77eea28f955e9c5e59d952594ccc5e96de1597e:/src/mac/classic/dc.cpp diff --git a/src/mac/classic/dc.cpp b/src/mac/classic/dc.cpp index 8281192642..273aa554bd 100644 --- a/src/mac/classic/dc.cpp +++ b/src/mac/classic/dc.cpp @@ -1,29 +1,31 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: dc.cpp +// Name: src/mac/classic/dc.cpp // Purpose: wxDC class // Author: Stefan Csomor // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "dc.h" -#endif +#include "wx/wxprec.h" #include "wx/dc.h" -#include "wx/app.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/dcmemory.h" + #include "wx/dcprint.h" + #include "wx/region.h" + #include "wx/image.h" +#endif + #include "wx/mac/uma.h" -#include "wx/dcmemory.h" -#include "wx/dcprint.h" -#include "wx/region.h" -#include "wx/image.h" -#include "wx/log.h" #if __MSL__ >= 0x6000 -#include "math.h" +namespace std {} using namespace std ; #endif @@ -32,25 +34,13 @@ using namespace std ; #include #include #include -#if !USE_SHARED_LIBRARY + IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) -#endif //----------------------------------------------------------------------------- // constants //----------------------------------------------------------------------------- -#define mm2inches 0.0393700787402 -#define inches2mm 25.4 -#define mm2twips 56.6929133859 -#define twips2mm 0.0176388888889 -#define mm2pt 2.83464566929 -#define pt2mm 0.352777777778 -#if !defined( __DARWIN__ ) || defined(__MWERKS__) -#ifndef M_PI -const double M_PI = 3.14159265358979 ; -#endif -#endif const double RAD2DEG = 180.0 / M_PI; const short kEmulatedMode = -1 ; const short kUnsupportedMode = -2 ; @@ -76,23 +66,23 @@ wxMacPortSetter::~wxMacPortSetter() class wxMacFastPortSetter { public : - wxMacFastPortSetter( const wxDC *dc ) + wxMacFastPortSetter( const wxDC *dc ) { - wxASSERT( dc->Ok() ) ; - GetPort( &m_oldPort ) ; - SetPort( (GrafPtr) dc->m_macPort ) ; - m_clipRgn = NewRgn() ; - GetClip( m_clipRgn ) ; - m_dc = dc ; - dc->MacSetupPort( NULL ) ; + wxASSERT( dc->Ok() ) ; + GetPort( &m_oldPort ) ; + SetPort( (GrafPtr) dc->m_macPort ) ; + m_clipRgn = NewRgn() ; + GetClip( m_clipRgn ) ; + m_dc = dc ; + dc->MacSetupPort( NULL ) ; } ~wxMacFastPortSetter() { SetPort( (GrafPtr) m_dc->m_macPort ) ; SetClip( m_clipRgn ) ; - SetPort( m_oldPort ) ; - m_dc->MacCleanupPort( NULL ) ; - DisposeRgn( m_clipRgn ) ; + SetPort( m_oldPort ) ; + m_dc->MacCleanupPort( NULL ) ; + DisposeRgn( m_clipRgn ) ; } private : RgnHandle m_clipRgn ; @@ -128,12 +118,12 @@ public : #endif -wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) +wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) { m_formerClip = NewRgn() ; m_newClip = NewRgn() ; GetClip( m_formerClip ) ; - + if ( win ) { #if 0 @@ -144,8 +134,8 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) wxWindow *parent = win->GetParent() ; parent->MacWindowToRootWindow( &x,&y ) ; wxSize size = parent->GetSize() ; - SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() , - size.x - parent->MacGetRightBorderSize(), + SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() , + size.x - parent->MacGetRightBorderSize(), size.y - parent->MacGetBottomBorderSize()) ; CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip ) ; SectRgn( m_newClip , insidergn , m_newClip ) ; @@ -158,11 +148,11 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ; OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; -#endif +#endif } } -wxMacWindowClipper::~wxMacWindowClipper() +wxMacWindowClipper::~wxMacWindowClipper() { SetClip( m_formerClip ) ; DisposeRgn( m_newClip ) ; @@ -269,8 +259,8 @@ void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColo wxDC::wxDC() { - m_ok = FALSE; - m_colour = TRUE; + m_ok = false; + m_colour = true; m_mm_to_pix_x = mm2pt; m_mm_to_pix_y = mm2pt; m_internalDeviceOriginX = 0; @@ -283,11 +273,11 @@ wxDC::wxDC() m_userScaleY = 1.0; m_scaleX = 1.0; m_scaleY = 1.0; - m_needComputeScaleX = FALSE; - m_needComputeScaleY = FALSE; + m_needComputeScaleX = false; + m_needComputeScaleY = false; m_macPort = NULL ; m_macMask = NULL ; - m_ok = FALSE ; + m_ok = false ; m_macFontInstalled = false ; m_macBrushInstalled = false ; m_macPenInstalled = false ; @@ -300,7 +290,7 @@ wxDC::wxDC() m_font = *wxNORMAL_FONT; m_brush = *wxWHITE_BRUSH; #ifdef __WXDEBUG__ - // needed to debug possible errors with two active drawing methods at the same time on + // needed to debug possible errors with two active drawing methods at the same time on // the same DC m_macCurrentPortStateHelper = NULL ; #endif @@ -473,7 +463,7 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei } else { - m_clipping = TRUE; + m_clipping = true; m_clipX1 = xx; m_clipY1 = yy; m_clipX2 = xx + ww; @@ -520,7 +510,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) } else { - m_clipping = TRUE; + m_clipping = true; m_clipX1 = xx; m_clipY1 = yy; m_clipX2 = xx + ww; @@ -582,8 +572,8 @@ void wxDC::SetMapMode( int mode ) } if (mode != wxMM_TEXT) { - m_needComputeScaleX = TRUE; - m_needComputeScaleY = TRUE; + m_needComputeScaleX = true; + m_needComputeScaleY = true; } } @@ -1100,7 +1090,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC")); if ( logical_func == wxNO_OP ) - return TRUE ; + return true ; if (xsrcMask == -1 && ysrcMask == -1) { xsrcMask = xsrc; ysrcMask = ysrc; @@ -1179,7 +1169,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, if ( mode == kUnsupportedMode ) { wxFAIL_MSG(wxT("unsupported blitting mode" )); - return FALSE ; + return false ; } CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; @@ -1338,7 +1328,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, m_macPenInstalled = false ; m_macBrushInstalled = false ; m_macFontInstalled = false ; - return TRUE; + return true; } #ifndef FixedToInt @@ -1365,9 +1355,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, return; } - if ( str.Length() == 0 ) + if ( str.length() == 0 ) return ; - + wxMacFastPortSetter helper(this) ; MacInstallFont() ; @@ -1379,9 +1369,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, } OSStatus status = noErr ; ATSUTextLayout atsuLayout ; - UniCharCount chars = str.Length() ; + UniCharCount chars = str.length() ; #if wxUSE_UNICODE - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 , + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.length() , str.length() , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; #else wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; @@ -1393,13 +1383,13 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, int iAngle = int( angle ); int drawX = XLOG2DEVMAC(x) ; int drawY = YLOG2DEVMAC(y) ; - + ATSUTextMeasurement textBefore ; ATSUTextMeasurement textAfter ; ATSUTextMeasurement ascent ; ATSUTextMeasurement descent ; - - + + if ( abs(iAngle) > 0 ) { Fixed atsuAngle = IntToFixed( iAngle ) ; @@ -1420,7 +1410,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, } status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, &textBefore , &textAfter, &ascent , &descent ); - + drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent)); drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent)); status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, @@ -1470,7 +1460,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { ::TextMode( srcCopy ) ; } - int length = strtext.Length() ; + int length = strtext.length() ; int laststop = 0 ; int i = 0 ; @@ -1514,7 +1504,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) else #endif { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; ::DrawText( text , 0 , strlen(text) ) ; if ( m_backgroundMode != wxTRANSPARENT ) { @@ -1573,7 +1563,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) else #endif { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; if ( m_backgroundMode != wxTRANSPARENT ) { Rect frame = { yy - fi.ascent + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy - fi.ascent + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; @@ -1609,7 +1599,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h MacInstallFont() ; FontInfo fi ; ::GetFontInfo( &fi ) ; -#if TARGET_CARBON +#if TARGET_CARBON bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) useGetThemeText = false ; @@ -1620,7 +1610,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; - int length = strtext.Length() ; + int length = strtext.length() ; int laststop = 0 ; int i = 0 ; @@ -1653,7 +1643,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h else #endif { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) @@ -1662,7 +1652,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h } i++ ; } - + wxString linetext = strtext.Mid( laststop , i - laststop ) ; #endif // 0 wxString linetext = strtext ; @@ -1683,7 +1673,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h else #endif { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) @@ -1703,14 +1693,14 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); widths.Empty(); - widths.Add(0, text.Length()); + widths.Add(0, text.length()); - if (text.Length() == 0) + if (text.length() == 0) return false; - + wxMacFastPortSetter helper(this) ; MacInstallFont() ; -#if TARGET_CARBON +#if TARGET_CARBON bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) useGetThemeText = false ; @@ -1722,7 +1712,7 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con // fonts, please change it. Currently it is measuring from the // begining of the string for each succeding substring, which is much // slower than this should be. - for (size_t i=0; i