Fix bezel used for bitmap buttons in wxOSX/Cocoa.

Don't use NSRoundedBezelStyle for bitmap buttons as this bezel has fixed
height. Instead, use NSRegularSquareBezelStyle which can used with buttons of
any size and is the correct bezel to use for the buttons mostly identified by
their icon according to Apple docs.

Notice that we still use the standard bezel for the "small" (where "small" is
arbitrarily defined by the hard coded 20 pixels height) icons as those are
usually used in addition to the text and not replacing it and so it makes more
sense to use the same bezel as for the normal buttons for them.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-11-28 23:56:38 +00:00
parent 6ceeeafd56
commit 0c2e6e8b36
2 changed files with 15 additions and 10 deletions

View File

@ -208,7 +208,8 @@ void
SetBezelStyleFromBorderFlags(NSButton *v, SetBezelStyleFromBorderFlags(NSButton *v,
long style, long style,
wxWindowID winid, 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 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 // we only use it if we are using the default label. wxButton itself checks
@ -220,10 +221,13 @@ SetBezelStyleFromBorderFlags(NSButton *v,
} }
else else
{ {
// We can't use rounded bezel styles for multiline buttons as they are // We can't use rounded bezel styles neither for multiline buttons nor
// only meant to be used at certain sizes, so the style used depends on // for buttons containing (big) icons as they are only meant to be used
// whether the label is single or multi line. // at certain sizes, so the style used depends on whether the label is
const bool isSingleLine = label.find_first_of("\n\r") == wxString::npos; // single or multi line.
const bool
isSimpleText = (label.find_first_of("\n\r") == wxString::npos)
&& (!bitmap.IsOk() || bitmap.GetHeight() < 20);
NSBezelStyle bezel; NSBezelStyle bezel;
switch ( style & wxBORDER_MASK ) switch ( style & wxBORDER_MASK )
@ -238,7 +242,7 @@ SetBezelStyleFromBorderFlags(NSButton *v,
break; break;
case wxBORDER_SUNKEN: case wxBORDER_SUNKEN:
bezel = isSingleLine ? NSTexturedRoundedBezelStyle bezel = isSimpleText ? NSTexturedRoundedBezelStyle
: NSSmallSquareBezelStyle; : NSSmallSquareBezelStyle;
break; break;
@ -250,7 +254,7 @@ SetBezelStyleFromBorderFlags(NSButton *v,
case wxBORDER_STATIC: case wxBORDER_STATIC:
case wxBORDER_RAISED: case wxBORDER_RAISED:
case wxBORDER_THEME: case wxBORDER_THEME:
bezel = isSingleLine ? NSRoundedBezelStyle bezel = isSimpleText ? NSRoundedBezelStyle
: NSRegularSquareBezelStyle; : NSRegularSquareBezelStyle;
break; break;
} }
@ -340,7 +344,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer,
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
SetBezelStyleFromBorderFlags(v, style, winid); SetBezelStyleFromBorderFlags(v, style, winid, wxString(), bitmap);
if (bitmap.IsOk()) if (bitmap.IsOk())
[v setImage:bitmap.GetNSImage() ]; [v setImage:bitmap.GetNSImage() ];

View File

@ -30,7 +30,8 @@
extern "C" void SetBezelStyleFromBorderFlags(NSButton *v, extern "C" void SetBezelStyleFromBorderFlags(NSButton *v,
long style, long style,
wxWindowID winid = wxID_ANY, wxWindowID winid = wxID_ANY,
const wxString& label = wxString()); const wxString& label = wxString(),
const wxBitmap& bitmap = wxBitmap());
wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateToggleButton( wxWindowMac* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
@ -63,7 +64,7 @@ wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer,
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
wxNSButton* v = [[wxNSButton alloc] initWithFrame:r]; wxNSButton* v = [[wxNSButton alloc] initWithFrame:r];
SetBezelStyleFromBorderFlags(v, style, winid); SetBezelStyleFromBorderFlags(v, style, winid, wxString(), label);
if (label.IsOk()) if (label.IsOk())
[v setImage:label.GetNSImage() ]; [v setImage:label.GetNSImage() ];