X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c20e8f816b21b911e3a8ed8197c21df6ce726d6..80f3f3beb68c3aabfdf521e78b383c41399ac75e:/src/mac/carbon/button.cpp?ds=sidebyside diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index b1d1f7228f..42e2004f51 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -15,6 +15,8 @@ #ifndef WX_PRECOMP #include "wx/panel.h" + #include "wx/toplevel.h" + #include "wx/dcclient.h" #endif #include "wx/stockitem.h" @@ -42,7 +44,7 @@ bool wxButton::Create(wxWindow *parent, if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) return false; - m_label = label ; + m_labelOrig = m_label = label ; OSStatus err; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; @@ -100,20 +102,19 @@ bool wxButton::Create(wxWindow *parent, return true; } -void wxButton::SetDefault() +wxWindow *wxButton::SetDefault() { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - wxButton *btnOldDefault = NULL; - if ( tlw ) - { - btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - tlw->SetDefaultItem(this); - } + wxWindow *btnOldDefault = wxButtonBase::SetDefault(); if ( btnOldDefault ) - btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ; + { + // cast needed to access the protected member + btnOldDefault->GetPeer()->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ; + } m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ; + + return btnOldDefault; } wxSize wxButton::DoGetBestSize() const @@ -122,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: @@ -148,14 +147,54 @@ 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 { wBtn = bestsize.right - bestsize.left ; - sz.y = bestsize.bottom - bestsize.top ; + // non 'normal' window variants don't return the correct height + // sz.y = bestsize.bottom - bestsize.top ; } if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))