From e4123a47e0cd401da31cfc9197c3d0fe56182c64 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 21 Sep 2007 20:15:30 +0000 Subject: [PATCH] supporting wxBU_EXACTFIT git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48895 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/button.cpp | 45 +++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 55785b73ac..c77dbe0ed1 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -123,14 +123,12 @@ wxSize wxButton::DoGetBestSize() const return wxSize( 20 , 20 ) ; wxSize sz = GetDefaultSize() ; - int charspace = 8 ; switch (GetWindowVariant()) { case wxWINDOW_VARIANT_NORMAL: case wxWINDOW_VARIANT_LARGE: sz.y = 20 ; - charspace = 10 ; break; case wxWINDOW_VARIANT_SMALL: @@ -149,9 +147,48 @@ wxSize wxButton::DoGetBestSize() const m_peer->GetBestRect( &bestsize ) ; int wBtn; - if ( EmptyRect( &bestsize ) ) + if ( EmptyRect( &bestsize ) || ( GetWindowStyle() & wxBU_EXACTFIT) ) { - wBtn = m_label.length() * charspace + 12 ; + Point bounds; + + ControlFontStyleRec controlFont; + OSStatus err = m_peer->GetData( kControlEntireControl, kControlFontStyleTag, &controlFont ); + verify_noerr( err ); + + SInt16 baseline; + wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); + +#ifndef __LP64__ + if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) + { + err = GetThemeTextDimensions( + (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")), + m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline ); + verify_noerr( err ); + } + else +#endif + { +#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 + } + + wBtn = bounds.h + sz.y; } else {