]> git.saurik.com Git - wxWidgets.git/commitdiff
Update the button bezel to account for multi-line labels in wxOSX.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2012 23:50:50 +0000 (23:50 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 4 Nov 2012 23:50:50 +0000 (23:50 +0000)
If a button was created using a normal single-line label (including empty one)
and then its label was changed to something multi-line later, its size stayed
wrong in wxOSX as it still used the fixed size bezel used by normal buttons.

Adjust the bezel after each bezel change now to update the size of the button
if necessary.

Closes #12491.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/private.h
src/osx/cocoa/button.mm

index bc0c046d849dcbcead33b9af62aee838fd872542..d24e39a1edf15276e7cd3c2786a458df3f7587d4 100644 (file)
@@ -270,7 +270,6 @@ public:
     void GetLayoutInset(int &left , int &top , int &right, int &bottom) const;
     void SetAcceleratorFromLabel(const wxString& label);
 
-private:
     NSButton *GetNSButton() const;
 };
 
index 94c6562b7b4b245d4855f22827701c45af3f312f..16673508c618c7dc784ba52600463d939cbc091b 100644 (file)
@@ -198,23 +198,6 @@ NSButton *wxButtonCocoaImpl::GetNSButton() const
     return static_cast<NSButton *>(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<wxButtonCocoaImpl*>(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).
@@ -276,6 +259,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<wxButtonCocoaImpl*>(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),