X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5af80d3112462332d179fe79dd738cf093c99864..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/cocoa/button.mm diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 94c6562b7b..df1e092402 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -198,23 +198,6 @@ NSButton *wxButtonCocoaImpl::GetNSButton() const return static_cast(m_osxView); } -// Set the keyboard accelerator key from the label (e.g. "Click &Me") -void wxButton::OSXUpdateAfterLabelChange(const wxString& label) -{ - // Skip setting the accelerator for the default buttons as this would - // overwrite the default "Enter" which should be preserved. - wxTopLevelWindow * const - tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - if ( tlw ) - { - if ( tlw->GetDefaultItem() == this ) - return; - } - - wxButtonCocoaImpl *impl = static_cast(GetPeer()); - impl->SetAcceleratorFromLabel(label); -} - // Set bezel style depending on the wxBORDER_XXX flags specified by the style // and also accounting for the label (bezels are different for multiline // buttons and normal ones) and the ID (special bezel is used for help button). @@ -225,7 +208,8 @@ void SetBezelStyleFromBorderFlags(NSButton *v, long style, wxWindowID winid, - const wxString& label = wxString()) + const wxString& label = wxString(), + const wxBitmap& bitmap = wxBitmap()) { // We can't display a custom label inside a button with help bezel style so // we only use it if we are using the default label. wxButton itself checks @@ -237,10 +221,13 @@ SetBezelStyleFromBorderFlags(NSButton *v, } else { - // We can't use rounded bezel styles for multiline buttons as they are - // only meant to be used at certain sizes, so the style used depends on - // whether the label is single or multi line. - const bool isSingleLine = label.find_first_of("\n\r") == wxString::npos; + // We can't use rounded bezel styles neither for multiline buttons nor + // for buttons containing (big) icons as they are only meant to be used + // at certain sizes, so the style used depends on whether the label is + // single or multi line. + const bool + isSimpleText = (label.find_first_of("\n\r") == wxString::npos) + && (!bitmap.IsOk() || bitmap.GetHeight() < 20); NSBezelStyle bezel; switch ( style & wxBORDER_MASK ) @@ -255,7 +242,7 @@ SetBezelStyleFromBorderFlags(NSButton *v, break; case wxBORDER_SUNKEN: - bezel = isSingleLine ? NSTexturedRoundedBezelStyle + bezel = isSimpleText ? NSTexturedRoundedBezelStyle : NSSmallSquareBezelStyle; break; @@ -267,7 +254,7 @@ SetBezelStyleFromBorderFlags(NSButton *v, case wxBORDER_STATIC: case wxBORDER_RAISED: case wxBORDER_THEME: - bezel = isSingleLine ? NSRoundedBezelStyle + bezel = isSimpleText ? NSRoundedBezelStyle : NSRegularSquareBezelStyle; break; } @@ -276,6 +263,32 @@ SetBezelStyleFromBorderFlags(NSButton *v, } } +// Set the keyboard accelerator key from the label (e.g. "Click &Me") +void wxButton::OSXUpdateAfterLabelChange(const wxString& label) +{ + wxButtonCocoaImpl *impl = static_cast(GetPeer()); + + // Update the bezel style as may be necessary if our new label is multi + // line while the old one wasn't (or vice versa). + SetBezelStyleFromBorderFlags(impl->GetNSButton(), + GetWindowStyle(), + GetId(), + label); + + + // Skip setting the accelerator for the default buttons as this would + // overwrite the default "Enter" which should be preserved. + wxTopLevelWindow * const + tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw ) + { + if ( tlw->GetDefaultItem() == this ) + return; + } + + impl->SetAcceleratorFromLabel(label); +} + wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), @@ -331,7 +344,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; - SetBezelStyleFromBorderFlags(v, style, winid); + SetBezelStyleFromBorderFlags(v, style, winid, wxString(), bitmap); if (bitmap.IsOk()) [v setImage:bitmap.GetNSImage() ];