best size fix for multi-line fields

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2006-12-20 08:45:48 +00:00
parent c0c677934f
commit 4d7e2cdad3

View File

@ -74,45 +74,56 @@ bool wxStaticText::Create( wxWindow *parent,
wxSize wxStaticText::DoGetBestSize() const wxSize wxStaticText::DoGetBestSize() const
{ {
ControlFontStyleRec controlFont; Rect bestsize = { 0 , 0 , 0 , 0 } ;
OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
verify_noerr( err );
Point bounds; Point bounds;
SInt16 baseline;
wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); // try the built-in best size if available
m_peer->GetBestRect( &bestsize ) ;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) if ( !EmptyRect( &bestsize ) )
{ {
err = GetThemeTextDimensions( bounds.h = bestsize.right - bestsize.left ;
(!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), bounds.v = bestsize.bottom - bestsize.top ;
m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
verify_noerr( err );
} }
else else
{ {
#if wxMAC_USE_CORE_GRAPHICS ControlFontStyleRec controlFont;
wxClientDC dc(const_cast<wxStaticText*>(this)); OSStatus err = m_peer->GetData<ControlFontStyleRec>( kControlEntireControl, kControlFontStyleTag, &controlFont );
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 ); 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<wxStaticText*>(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.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize(); bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();