Fix wxButton::SetBitmap() to keep correct button style in OS X
- Before, when setting a new bitmap (e.g. from Play bitmap
to Pause bitmap) the button would be recreated in pure
text button style, much too narrow.
- Then secondly, when taking into account the bitmap, it
switch from slightly rounded to unrounded corners. I assume
that the initial look with slightly rounded corners was
intented (and intended to be kept) and now it is preserved
after setting a new bitmap
Move NSButton style flag calculation to single place
wxRichTextCtrl: Enhance macOS key bindings Update key bindings for macOS to more closely match native behavior. Currently, Cmd+Left goes to the left word boundary, and Cmd+Right goes to the right word boundary, like on Windows (wxWidgets treats Cmd on Mac as if it were Ctrl for keyboard modifier key purposes). Alt/Opt+Left and Alt/Opt+Right do nothing. This change maps Cmd+Left to the start of the line, and Cmd+Right to the end of the line. It also maps Alt/Opt+Left to WordLeft() and Alt/Opt+Right to WordRight(), which is conventional on native Cocoa controls (including other wxWidgets controls that map directly to Cocoa controls). Closes #26064. Closes #26066.
Merge branch 'osx_bitmap_button_fix' of github.com:RobertRoeb/wxWidgets Fix wxButton::SetBitmap() to keep correct button style in wxOSX. See #26025.
| ... | ... | @@ -88,18 +88,78 @@ wxButtonCocoaImpl::wxButtonCocoaImpl(wxWindowMac *wxpeer, wxNSButton *v) |
| 88 | 88 | SetNeedsFrame(false);
|
| 89 | 89 | }
|
| 90 | 90 | |
| 91 | -void wxButtonCocoaImpl::SetBitmap(const wxBitmapBundle& bitmap)
|
|
| 91 | +// Set bezel style depending on the wxBORDER_XXX flags specified by the style
|
|
| 92 | +// and also accounting for the label (bezels are different for multiline
|
|
| 93 | +// buttons and normal ones) and the ID (special bezel is used for help button).
|
|
| 94 | +static
|
|
| 95 | +void
|
|
| 96 | +SetBezelStyleFromBorderFlags(NSButton *v,
|
|
| 97 | + long style,
|
|
| 98 | + wxWindowID winid,
|
|
| 99 | + const wxString& label = wxString(),
|
|
| 100 | + const wxBitmapBundle& bitmap = wxBitmapBundle())
|
|
| 92 | 101 | {
|
| 93 | - // switch bezel style for plain pushbuttons
|
|
| 94 | - if ( bitmap.IsOk() )
|
|
| 102 | + // We can't display a custom label inside a button with help bezel style so
|
|
| 103 | + // we only use it if we are using the default label. wxButton itself checks
|
|
| 104 | + // if the label is just "Help" in which case it discards it and passes us
|
|
| 105 | + // an empty string.
|
|
| 106 | + if ( winid == wxID_HELP && label.empty() )
|
|
| 95 | 107 | {
|
| 96 | - if ([GetNSButton() bezelStyle] == NSRoundedBezelStyle)
|
|
| 97 | - [GetNSButton() setBezelStyle:NSRegularSquareBezelStyle];
|
|
| 108 | + [v setBezelStyle:NSHelpButtonBezelStyle];
|
|
| 98 | 109 | }
|
| 99 | 110 | else
|
| 100 | 111 | {
|
| 101 | - [GetNSButton() setBezelStyle:NSRoundedBezelStyle];
|
|
| 112 | + // We can't use rounded bezel styles either for multiline buttons or
|
|
| 113 | + // for buttons containing (big) icons as they are only meant to be used
|
|
| 114 | + // at certain sizes, so the style used depends on whether the label is
|
|
| 115 | + // single or multi line.
|
|
| 116 | + const bool
|
|
| 117 | + isSimpleText = (label.find_first_of("\n\r") == wxString::npos)
|
|
| 118 | + && (!bitmap.IsOk() || bitmap.GetDefaultSize().y < 20);
|
|
| 119 | + |
|
| 120 | + NSBezelStyle bezel;
|
|
| 121 | + switch ( style & wxBORDER_MASK )
|
|
| 122 | + {
|
|
| 123 | + case wxBORDER_NONE:
|
|
| 124 | + bezel = NSShadowlessSquareBezelStyle;
|
|
| 125 | + [v setBordered:NO];
|
|
| 126 | + break;
|
|
| 127 | + |
|
| 128 | + case wxBORDER_SIMPLE:
|
|
| 129 | + bezel = NSSmallSquareBezelStyle;
|
|
| 130 | + break;
|
|
| 131 | + |
|
| 132 | + case wxBORDER_SUNKEN:
|
|
| 133 | + bezel = isSimpleText ? NSTexturedRoundedBezelStyle
|
|
| 134 | + : NSSmallSquareBezelStyle;
|
|
| 135 | + break;
|
|
| 136 | + |
|
| 137 | + default:
|
|
| 138 | + wxFAIL_MSG( "Unknown border style" );
|
|
| 139 | + wxFALLTHROUGH;
|
|
| 140 | + |
|
| 141 | + case 0:
|
|
| 142 | + case wxBORDER_STATIC:
|
|
| 143 | + case wxBORDER_RAISED:
|
|
| 144 | + case wxBORDER_THEME:
|
|
| 145 | + bezel = isSimpleText ? NSRoundedBezelStyle
|
|
| 146 | + : NSRegularSquareBezelStyle;
|
|
| 147 | + break;
|
|
| 148 | + }
|
|
| 149 | + |
|
| 150 | + [v setBezelStyle:bezel];
|
|
| 102 | 151 | }
|
| 152 | +}
|
|
| 153 | + |
|
| 154 | +void wxButtonCocoaImpl::SetBitmap(const wxBitmapBundle& bitmap)
|
|
| 155 | +{
|
|
| 156 | + // Update the bezel style as may be necessary if our new label is multi
|
|
| 157 | + // line while the old one wasn't (or vice versa).
|
|
| 158 | + SetBezelStyleFromBorderFlags(GetNSButton(),
|
|
| 159 | + GetWXPeer()->GetWindowStyle(),
|
|
| 160 | + GetWXPeer()->GetId(),
|
|
| 161 | + GetWXPeer()->GetLabel(),
|
|
| 162 | + bitmap );
|
|
| 103 | 163 | |
| 104 | 164 | wxWidgetCocoaImpl::SetBitmap(bitmap);
|
| 105 | 165 | }
|
| ... | ... | @@ -171,69 +231,6 @@ NSButton *wxButtonCocoaImpl::GetNSButton() const |
| 171 | 231 | return static_cast<NSButton *>(m_osxView);
|
| 172 | 232 | }
|
| 173 | 233 | |
| 174 | -// Set bezel style depending on the wxBORDER_XXX flags specified by the style
|
|
| 175 | -// and also accounting for the label (bezels are different for multiline
|
|
| 176 | -// buttons and normal ones) and the ID (special bezel is used for help button).
|
|
| 177 | -static
|
|
| 178 | -void
|
|
| 179 | -SetBezelStyleFromBorderFlags(NSButton *v,
|
|
| 180 | - long style,
|
|
| 181 | - wxWindowID winid,
|
|
| 182 | - const wxString& label = wxString(),
|
|
| 183 | - const wxBitmapBundle& bitmap = wxBitmapBundle())
|
|
| 184 | -{
|
|
| 185 | - // We can't display a custom label inside a button with help bezel style so
|
|
| 186 | - // we only use it if we are using the default label. wxButton itself checks
|
|
| 187 | - // if the label is just "Help" in which case it discards it and passes us
|
|
| 188 | - // an empty string.
|
|
| 189 | - if ( winid == wxID_HELP && label.empty() )
|
|
| 190 | - {
|
|
| 191 | - [v setBezelStyle:NSHelpButtonBezelStyle];
|
|
| 192 | - }
|
|
| 193 | - else
|
|
| 194 | - {
|
|
| 195 | - // We can't use rounded bezel styles either for multiline buttons or
|
|
| 196 | - // for buttons containing (big) icons as they are only meant to be used
|
|
| 197 | - // at certain sizes, so the style used depends on whether the label is
|
|
| 198 | - // single or multi line.
|
|
| 199 | - const bool
|
|
| 200 | - isSimpleText = (label.find_first_of("\n\r") == wxString::npos)
|
|
| 201 | - && (!bitmap.IsOk() || bitmap.GetDefaultSize().y < 20);
|
|
| 202 | - |
|
| 203 | - NSBezelStyle bezel;
|
|
| 204 | - switch ( style & wxBORDER_MASK )
|
|
| 205 | - {
|
|
| 206 | - case wxBORDER_NONE:
|
|
| 207 | - bezel = NSShadowlessSquareBezelStyle;
|
|
| 208 | - [v setBordered:NO];
|
|
| 209 | - break;
|
|
| 210 | - |
|
| 211 | - case wxBORDER_SIMPLE:
|
|
| 212 | - bezel = NSSmallSquareBezelStyle;
|
|
| 213 | - break;
|
|
| 214 | - |
|
| 215 | - case wxBORDER_SUNKEN:
|
|
| 216 | - bezel = isSimpleText ? NSTexturedRoundedBezelStyle
|
|
| 217 | - : NSSmallSquareBezelStyle;
|
|
| 218 | - break;
|
|
| 219 | - |
|
| 220 | - default:
|
|
| 221 | - wxFAIL_MSG( "Unknown border style" );
|
|
| 222 | - wxFALLTHROUGH;
|
|
| 223 | - |
|
| 224 | - case 0:
|
|
| 225 | - case wxBORDER_STATIC:
|
|
| 226 | - case wxBORDER_RAISED:
|
|
| 227 | - case wxBORDER_THEME:
|
|
| 228 | - bezel = isSimpleText ? NSRoundedBezelStyle
|
|
| 229 | - : NSSmallSquareBezelStyle;
|
|
| 230 | - break;
|
|
| 231 | - }
|
|
| 232 | - |
|
| 233 | - [v setBezelStyle:bezel];
|
|
| 234 | - }
|
|
| 235 | -}
|
|
| 236 | - |
|
| 237 | 234 | // Set the keyboard accelerator key from the label (e.g. "Click &Me")
|
| 238 | 235 | void wxButton::OSXUpdateAfterLabelChange(const wxString& label)
|
| 239 | 236 | {
|
| ... | ... | @@ -244,7 +241,8 @@ void wxButton::OSXUpdateAfterLabelChange(const wxString& label) |
| 244 | 241 | SetBezelStyleFromBorderFlags(impl->GetNSButton(),
|
| 245 | 242 | GetWindowStyle(),
|
| 246 | 243 | GetId(),
|
| 247 | - label);
|
|
| 244 | + label,
|
|
| 245 | + GetBitmap() );
|
|
| 248 | 246 | |
| 249 | 247 | |
| 250 | 248 | // Skip setting the accelerator for the default buttons as this would
|
| ... | ... | @@ -1655,8 +1655,10 @@ Left: left one character |
| 1655 | 1655 | Right: right one character
|
| 1656 | 1656 | Up: up one line
|
| 1657 | 1657 | Down: down one line
|
| 1658 | -Ctrl-Left: left one word
|
|
| 1659 | -Ctrl-Right: right one word
|
|
| 1658 | +Ctrl-Left: left one word (start of line on macOS)
|
|
| 1659 | +Ctrl-Right: right one word (end of line on macOS)
|
|
| 1660 | +Alt-Left: left one word (macOS only)
|
|
| 1661 | +Alt-Right: right one word (macOS only)
|
|
| 1660 | 1662 | Ctrl-Up: previous paragraph start
|
| 1661 | 1663 | Ctrl-Down: next start of paragraph
|
| 1662 | 1664 | Home: start of line
|
| ... | ... | @@ -1684,17 +1686,35 @@ bool wxRichTextCtrl::KeyboardNavigate(int keyCode, int flags) |
| 1684 | 1686 | |
| 1685 | 1687 | if (keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT)
|
| 1686 | 1688 | {
|
| 1689 | +#ifdef __WXMAC__
|
|
| 1690 | + if (flags & wxRICHTEXT_CTRL_DOWN)
|
|
| 1691 | + success = MoveToLineEnd(flags);
|
|
| 1692 | + else if (flags & wxRICHTEXT_ALT_DOWN)
|
|
| 1693 | + success = WordRight(1, flags);
|
|
| 1694 | + else
|
|
| 1695 | + success = MoveRight(1, flags);
|
|
| 1696 | +#else
|
|
| 1687 | 1697 | if (flags & wxRICHTEXT_CTRL_DOWN)
|
| 1688 | 1698 | success = WordRight(1, flags);
|
| 1689 | 1699 | else
|
| 1690 | 1700 | success = MoveRight(1, flags);
|
| 1701 | +#endif
|
|
| 1691 | 1702 | }
|
| 1692 | 1703 | else if (keyCode == WXK_LEFT || keyCode == WXK_NUMPAD_LEFT)
|
| 1693 | 1704 | {
|
| 1705 | +#ifdef __WXMAC__
|
|
| 1706 | + if (flags & wxRICHTEXT_CTRL_DOWN)
|
|
| 1707 | + success = MoveToLineStart(flags);
|
|
| 1708 | + else if (flags & wxRICHTEXT_ALT_DOWN)
|
|
| 1709 | + success = WordLeft(1, flags);
|
|
| 1710 | + else
|
|
| 1711 | + success = MoveLeft(1, flags);
|
|
| 1712 | +#else
|
|
| 1694 | 1713 | if (flags & wxRICHTEXT_CTRL_DOWN)
|
| 1695 | 1714 | success = WordLeft(1, flags);
|
| 1696 | 1715 | else
|
| 1697 | 1716 | success = MoveLeft(1, flags);
|
| 1717 | +#endif
|
|
| 1698 | 1718 | }
|
| 1699 | 1719 | else if (keyCode == WXK_UP || keyCode == WXK_NUMPAD_UP)
|
| 1700 | 1720 | {
|
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help