From: Stefan Csomor Date: Mon, 17 Jun 2002 19:38:57 +0000 (+0000) Subject: using Theme layout for measuring as well X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f52640f373f873596bdcd99bd5a1876965616bd3 using Theme layout for measuring as well git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15868 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index 2acff5c48a..d5f9cbac2b 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -1584,22 +1584,17 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he if ( theFont ) { - wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; - - if ( font ) - { - ::TextFont( font->m_macFontNum ) ; - ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; - ::TextFace( font->m_macFontStyle ) ; - } - } - else - { - MacInstallFont() ; + // work around the constness + *((wxFont*)(&m_font)) = *theFont ; } + MacInstallFont() ; + FontInfo fi ; ::GetFontInfo( &fi ) ; +#if TARGET_CARBON + bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; +#endif if ( height ) *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; @@ -1636,21 +1631,59 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he { if ( height ) *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; - curwidth = ::TextWidth( text , laststop , i - laststop ) ; +#if TARGET_CARBON + if ( useGetThemeText ) + { + Point bounds={0,0} ; + CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + ::GetThemeTextDimensions( mString, + kThemeCurrentPortFont, + kThemeStateActive, + true, + &bounds, + nil ); + CFRelease( mString ) ; + curwidth = bounds.h ; + } + else +#endif + { + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; laststop = i+1 ; } i++ ; } - - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + +#if TARGET_CARBON + if ( useGetThemeText ) + { + Point bounds={0,0} ; + CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + ::GetThemeTextDimensions( mString, + kThemeCurrentPortFont, + kThemeStateActive, + true, + &bounds, + nil ); + CFRelease( mString ) ; + curwidth = bounds.h ; + } + else +#endif + { + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; } if ( theFont ) { + // work around the constness + *((wxFont*)(&m_font)) = formerFont ; m_macFontInstalled = false ; } } diff --git a/src/mac/dc.cpp b/src/mac/dc.cpp index 2acff5c48a..d5f9cbac2b 100644 --- a/src/mac/dc.cpp +++ b/src/mac/dc.cpp @@ -1584,22 +1584,17 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he if ( theFont ) { - wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; - - if ( font ) - { - ::TextFont( font->m_macFontNum ) ; - ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; - ::TextFace( font->m_macFontStyle ) ; - } - } - else - { - MacInstallFont() ; + // work around the constness + *((wxFont*)(&m_font)) = *theFont ; } + MacInstallFont() ; + FontInfo fi ; ::GetFontInfo( &fi ) ; +#if TARGET_CARBON + bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; +#endif if ( height ) *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; @@ -1636,21 +1631,59 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he { if ( height ) *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; - curwidth = ::TextWidth( text , laststop , i - laststop ) ; +#if TARGET_CARBON + if ( useGetThemeText ) + { + Point bounds={0,0} ; + CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + ::GetThemeTextDimensions( mString, + kThemeCurrentPortFont, + kThemeStateActive, + true, + &bounds, + nil ); + CFRelease( mString ) ; + curwidth = bounds.h ; + } + else +#endif + { + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; laststop = i+1 ; } i++ ; } - - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + +#if TARGET_CARBON + if ( useGetThemeText ) + { + Point bounds={0,0} ; + CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + ::GetThemeTextDimensions( mString, + kThemeCurrentPortFont, + kThemeStateActive, + true, + &bounds, + nil ); + CFRelease( mString ) ; + curwidth = bounds.h ; + } + else +#endif + { + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; } if ( theFont ) { + // work around the constness + *((wxFont*)(&m_font)) = formerFont ; m_macFontInstalled = false ; } }