From 4d7e2cdad3ccf26cc5185eb30ef827b1c767e7c4 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 20 Dec 2006 08:45:48 +0000 Subject: [PATCH] best size fix for multi-line fields git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/stattext.cpp | 75 +++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp index 21ed1ed771..be737ac8be 100644 --- a/src/mac/carbon/stattext.cpp +++ b/src/mac/carbon/stattext.cpp @@ -74,45 +74,56 @@ bool wxStaticText::Create( wxWindow *parent, wxSize wxStaticText::DoGetBestSize() const { - ControlFontStyleRec controlFont; - OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); - verify_noerr( err ); - + Rect bestsize = { 0 , 0 , 0 , 0 } ; Point bounds; - SInt16 baseline; - wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); - - if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) + + // try the built-in best size if available + m_peer->GetBestRect( &bestsize ) ; + if ( !EmptyRect( &bestsize ) ) { - err = GetThemeTextDimensions( - (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), - m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); - verify_noerr( err ); + bounds.h = bestsize.right - bestsize.left ; + bounds.v = bestsize.bottom - bestsize.top ; } else { -#if wxMAC_USE_CORE_GRAPHICS - wxClientDC dc(const_cast(this)); - wxCoord width, height ; - dc.GetTextExtent( m_label , &width, &height); - bounds.h = width; - bounds.v = height; -#else - wxMacWindowStateSaver sv( this ); - ::TextFont( m_font.MacGetFontNum() ); - ::TextSize( (short)(m_font.MacGetFontSize()) ); - ::TextFace( m_font.MacGetFontStyle() ); - - err = GetThemeTextDimensions( - (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), - kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); + ControlFontStyleRec controlFont; + OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); verify_noerr( err ); -#endif + + SInt16 baseline; + wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); + + if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) + { + err = GetThemeTextDimensions( + (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), + m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); + verify_noerr( err ); + } + else + { + #if wxMAC_USE_CORE_GRAPHICS + wxClientDC dc(const_cast(this)); + wxCoord width, height ; + dc.GetTextExtent( m_label , &width, &height); + bounds.h = width; + bounds.v = height; + #else + wxMacWindowStateSaver sv( this ); + ::TextFont( m_font.MacGetFontNum() ); + ::TextSize( (short)(m_font.MacGetFontSize()) ); + ::TextFace( m_font.MacGetFontStyle() ); + + err = GetThemeTextDimensions( + (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), + kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); + verify_noerr( err ); + #endif + } + + if ( m_label.empty() ) + bounds.h = 0; } - - if ( m_label.empty() ) - bounds.h = 0; - bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize(); bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();