X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4a95c885474a5d7ed9be99b3fa7d3be967b3b5b1..da0766ab2ae2357cd4dc111415731ee85aa45984:/src/mac/carbon/dc.cpp?ds=sidebyside diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index d155b4f711..593c01c367 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -17,6 +17,7 @@ #include "wx/app.h" #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" @@ -25,6 +26,7 @@ #include "math.h" using namespace std ; #endif + #include "wx/mac/private.h" #include "ATSUnicode.h" #include "TextCommon.h" @@ -43,9 +45,11 @@ IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #define twips2mm 0.0176388888889 #define mm2pt 2.83464566929 #define pt2mm 0.352777777778 -#ifndef __DARWIN__ +#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 ; @@ -87,13 +91,13 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; DisposeRgn( insidergn ) ; -#endif - RgnHandle insidergn = NewRgn() ; +#else int x = 0 , y = 0; win->MacWindowToRootWindow( &x,&y ) ; CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ; OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; +#endif } } @@ -234,7 +238,11 @@ wxDC::wxDC() m_pen = *wxBLACK_PEN; 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 + // the same DC m_macCurrentPortStateHelper = NULL ; +#endif m_macATSUIStyle = NULL ; m_macAliasWasEnabled = false; m_macForegroundPixMap = NULL ; @@ -249,8 +257,10 @@ wxDC::~wxDC(void) void wxDC::MacSetupPort(wxMacPortStateHelper* help) const { +#ifdef __WXDEBUG__ wxASSERT( m_macCurrentPortStateHelper == NULL ) ; m_macCurrentPortStateHelper = help ; +#endif SetClip( (RgnHandle) m_macCurrentClipRgn); m_macFontInstalled = false ; m_macBrushInstalled = false ; @@ -259,8 +269,10 @@ void wxDC::MacSetupPort(wxMacPortStateHelper* help) const void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const { +#ifdef __WXDEBUG__ wxASSERT( m_macCurrentPortStateHelper == help ) ; m_macCurrentPortStateHelper = NULL ; +#endif if( m_macATSUIStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); @@ -462,12 +474,6 @@ void wxDC::DestroyClippingRegion() m_clipping = FALSE; } -void wxDC::DoGetSize( int* width, int* height ) const -{ - *width = m_maxX-m_minX; - *height = m_maxY-m_minY; -} - void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; @@ -1110,7 +1116,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, } if ( mode == kUnsupportedMode ) { - wxFAIL_MSG("unsupported blitting mode" ); + wxFAIL_MSG(wxT("unsupported blitting mode" )); return FALSE ; } CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; @@ -1287,24 +1293,19 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, double angle) { wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); + if (angle == 0.0 ) { DrawText(str, x, y); return; } + if ( str.Length() == 0 ) return ; + wxMacPortSetter helper(this) ; MacInstallFont() ; - wxString text ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - text = wxMacMakeMacStringFromPC( str ) ; - } - else - { - text = str ; - } + wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; if ( 0 ) { @@ -1313,23 +1314,33 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, m_macAliasWasEnabled = true ; } OSStatus status = noErr ; + ATSUTextLayout atsuLayout ; + UniCharCount chars = str.Length() ; +#if wxUSE_UNICODE + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 , + &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; +#else TECObjectRef ec; - status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault); - wxASSERT_MSG( status == noErr , "couldn't start converter" ) ; + status = TECCreateConverter(&ec, + wxApp::s_macDefaultEncodingIsPC + ? (int)kTextEncodingWindowsLatin1 + : (int)kTextEncodingMacRoman, + kTextEncodingUnicodeDefault); + + wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ; ByteCount byteOutLen ; - ByteCount byteInLen = text.Length() ; + ByteCount byteInLen = str.Length() ; ByteCount byteBufferLen = byteInLen *2 ; char* buf = new char[byteBufferLen] ; - status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen, + status = TECConvertText(ec, (ConstTextPtr)str.c_str() , byteInLen, &byteInLen, (TextPtr)buf, byteBufferLen, &byteOutLen); - wxASSERT_MSG( status == noErr , "couldn't convert text" ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't convert text") ) ; status = TECDisposeConverter(ec); - wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ; - ATSUTextLayout atsuLayout ; - UniCharCount chars = byteOutLen / 2 ; + wxASSERT_MSG( status == noErr , wxT("couldn't dispose converter") ) ; status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; - wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" ); +#endif + wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); int iAngle = int( angle ); int drawX = XLOG2DEVMAC(x) ; int drawY = YLOG2DEVMAC(y) ; @@ -1361,29 +1372,34 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, &textBefore , &textAfter, &ascent , &descent ); - drawX += sin(angle/RAD2DEG) * FixedToInt(ascent) ; - drawY += cos(angle/RAD2DEG) * FixedToInt(ascent) ; + drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent)); + drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent)); status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, IntToFixed(drawX) , IntToFixed(drawY) ); - wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" ); + wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); Rect rect ; status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, IntToFixed(drawX) , IntToFixed(drawY) , &rect ); - wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" ); + wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ; CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); ::ATSUDisposeTextLayout(atsuLayout); +#if wxUSE_UNICODE +#else delete[] buf ; +#endif } void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); + wxMacPortSetter helper(this) ; long xx = XLOG2DEVMAC(x); long yy = YLOG2DEVMAC(y); #if TARGET_CARBON + bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() ) useDrawThemeText = false ; @@ -1410,33 +1426,22 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { ::TextMode( srcCopy ) ; } - const char *text = NULL ; - int length = 0 ; - wxString macText ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - macText = wxMacMakeMacStringFromPC( strtext ) ; - text = macText ; - length = macText.Length() ; - } - else - { - text = strtext ; - length = strtext.Length() ; - } + int length = strtext.Length() ; + int laststop = 0 ; int i = 0 ; int line = 0 ; { while( i < length ) { - if( text[i] == 13 || text[i] == 10) + if( strtext[i] == 13 || strtext[i] == 10) { + wxString linetext = strtext.Mid( laststop , i - laststop ) ; #if TARGET_CARBON if ( useDrawThemeText ) { Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext ) ; if ( m_backgroundMode != wxTRANSPARENT ) { Point bounds={0,0} ; @@ -1459,13 +1464,13 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) &frame, teJustLeft, nil ); - CFRelease( mString ) ; line++ ; } else #endif { - ::DrawText( text , laststop , i - laststop ) ; + wxCharBuffer text = wxMacStringToCString(linetext) ; + ::DrawText( text , 0 , strlen(text) ) ; line++ ; ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); } @@ -1473,11 +1478,12 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) } i++ ; } + wxString linetext = strtext.Mid( laststop , i - laststop ) ; #if TARGET_CARBON if ( useDrawThemeText ) { Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; - CFStringRef mString = CFStringCreateWithCString( NULL , text + laststop , kCFStringEncodingMacRoman ) ; + wxMacCFStringHolder mString( linetext ) ; if ( m_backgroundMode != wxTRANSPARENT ) { @@ -1501,13 +1507,13 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) &frame, teJustLeft, nil ); - CFRelease( mString ) ; } else #endif { - ::DrawText( text , laststop , i - laststop ) ; - } + wxCharBuffer text = wxMacStringToCString(linetext) ; + ::DrawText( text , 0 , strlen(text) ) ; + } } ::TextMode( srcOr ) ; } @@ -1518,7 +1524,7 @@ bool wxDC::CanGetTextExtent() const return true ; } -void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, +void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading , wxFont *theFont ) const { @@ -1544,8 +1550,9 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; + int length = strtext.Length() ; + /* const char *text = NULL ; - int length = 0 ; wxString macText ; if ( wxApp::s_macDefaultEncodingIsPC ) { @@ -1558,6 +1565,7 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he text = string ; length = string.Length() ; } + */ int laststop = 0 ; int i = 0 ; int curwidth = 0 ; @@ -1566,8 +1574,9 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he *width = 0 ; while( i < length ) { - if( text[i] == 13 || text[i] == 10) + if( strtext[i] == 13 || strtext[i] == 10) { + wxString linetext = strtext.Mid( laststop , i - laststop ) ; if ( height ) *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; #if TARGET_CARBON @@ -1575,20 +1584,20 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he { Point bounds={0,0} ; SInt16 baseline ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = wxMacStringToCString(linetext) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1597,25 +1606,26 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he i++ ; } + wxString linetext = strtext.Mid( laststop , i - laststop ) ; #if TARGET_CARBON if ( useGetThemeText ) { Point bounds={0,0} ; SInt16 baseline ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = wxMacStringToCString(linetext) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1772,7 +1782,7 @@ void wxDC::MacInstallFont() const Style qdStyle = font->m_macFontStyle ; ATSUFontID atsuFont = font->m_macATSUFontID ; status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ; - wxASSERT_MSG( status == noErr , "couldn't create ATSU style" ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ; ATSUAttributeTag atsuTags[] = { kATSUFontTag , @@ -1801,7 +1811,7 @@ void wxDC::MacInstallFont() const } ; Boolean kTrue = true ; Boolean kFalse = false ; - BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ; + //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ; ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = { @@ -1816,9 +1826,9 @@ void wxDC::MacInstallFont() const (qdStyle & condense) ? &kTrue : &kFalse , (qdStyle & extend) ? &kTrue : &kFalse , } ; - status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag), + status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) , atsuTags, atsuSizes, atsuValues); - wxASSERT_MSG( status == noErr , "couldn't set create ATSU style" ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ; } Pattern gHatchPatterns[] = @@ -2202,4 +2212,4 @@ wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const { return ((wxDC *)this)->YLOG2DEVREL(y); -} \ No newline at end of file +}