X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e609c82594a57104ff5e0d4044b2e2697a4b576..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/mac/carbon/button.cpp diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index c5a3f521bd..6d9d195748 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 ) ; @@ -59,7 +61,6 @@ bool wxButton::Create(wxWindow *parent, } else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND) { -#if TARGET_API_MAC_OSX // Button height is static in Mac, can't be changed, so we need to force it here if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE ) { @@ -76,8 +77,6 @@ bool wxButton::Create(wxWindow *parent, bounds.bottom = bounds.top + 15 ; m_maxHeight = 15 ; } -#endif - err = CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""), m_peer->GetControlRefAddr() ); @@ -100,21 +99,19 @@ bool wxButton::Create(wxWindow *parent, return true; } -void wxButton::SetDefault() +wxWindow *wxButton::SetDefault() { - wxWindow *parent = GetParent(); - wxButton *btnOldDefault = NULL; + wxWindow *btnOldDefault = wxButtonBase::SetDefault(); - if ( parent ) + if ( btnOldDefault ) { - btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), wxButton); - parent->SetDefaultItem(this); + // cast needed to access the protected member + btnOldDefault->GetPeer()->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ; } - if ( btnOldDefault ) - btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ; - m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ; + + return btnOldDefault; } wxSize wxButton::DoGetBestSize() const @@ -123,14 +120,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,14 +144,42 @@ 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 ); + + wxMacCFStringHolder str( m_label, m_font.GetEncoding() ); + +#if wxMAC_USE_ATSU_TEXT + SInt16 baseline; + 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 + { + wxClientDC dc(const_cast(this)); + wxCoord width, height ; + dc.GetTextExtent( m_label , &width, &height); + bounds.h = width; + bounds.v = height; + } + + 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))