]> git.saurik.com Git - wxWidgets.git/commitdiff
Consolidate cocoa view/control/cell label setting into wxControl::CocoaSetLabelForObject.
authorDavid Elliott <dfe@tgwbd.org>
Mon, 6 Aug 2007 13:47:09 +0000 (13:47 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 6 Aug 2007 13:47:09 +0000 (13:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/control.h
src/cocoa/button.mm
src/cocoa/checkbox.mm
src/cocoa/control.mm
src/cocoa/radiobox.mm
src/cocoa/radiobut.mm
src/cocoa/statbox.mm

index ce13947692571e8dd0021b9b0693722fc5aa73e8..1921d083ece885f062997d3eb45428e216ef1779 100644 (file)
@@ -63,6 +63,15 @@ public:
     virtual void CocoaSetEnabled(bool enable);
 protected:
     virtual wxSize DoGetBestSize() const;
+
+    // Provides a common implementation of title setting which strips mnemonics
+    // and then calls setTitle: with the stripped string.  May be implemented
+    // to call setTitleWithMnemonic: on OpenStep-compatible systems.  Only
+    // intended for use by views or cells which implement at least setTitle:
+    // and possibly setTitleWithMnemonic: such as NSBox and NSButton or NSCell
+    // classes, for example as used by wxRadioBox.  Not usable with classes like
+    // NSTextField which expect setStringValue:.
+    static void CocoaSetLabelForObject(const wxString& labelWithWxMnemonic, struct objc_object *anObject);
 };
 
 #endif
index 2e9cb7103c139e88c1d138678b3345833d1637c2..624e5271bd0abf055289bc88de274a3e7a2d0c3e 100644 (file)
@@ -48,7 +48,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID winid,
     [m_cocoaNSView release];
 
     [GetNSButton() setBezelStyle:NSRoundedBezelStyle];
-    [GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))];
+    CocoaSetLabelForObject(label, GetNSButton());
     [GetNSControl() sizeToFit];
 
     if(m_parent)
@@ -78,7 +78,7 @@ wxString wxButton::GetLabel() const
 
 void wxButton::SetLabel(const wxString& label)
 {
-    [GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))];
+    CocoaSetLabelForObject(label, GetNSButton());
 }
 
 wxSize wxButton::DoGetBestSize() const
index c17d1152fcde79448f2a5d0e2d8b03effda96dff..ec2915a257832a808b0075318c5eb438f1ef8711 100644 (file)
@@ -47,7 +47,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
     [m_cocoaNSView release];
     [GetNSButton() setButtonType: NSSwitchButton];
     [GetNSButton() setAllowsMixedState: Is3State()];
-    [GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))];
+    CocoaSetLabelForObject(label, GetNSButton());
     [GetNSControl() sizeToFit];
 
     if(m_parent)
@@ -140,7 +140,7 @@ void wxCheckBox::Cocoa_wxNSButtonAction(void)
 void wxCheckBox::SetLabel(const wxString& s)
 {
     wxAutoNSAutoreleasePool pool;
-    [GetNSButton() setTitle:wxNSStringWithWxString(s)];
+    CocoaSetLabelForObject(s, GetNSButton());
 }
 
 wxString wxCheckBox::GetLabel() const
index 475a372d5e1fc6ef59711076e0e9be56063201e6..9fabb68103e9ccdd44d1480461453423a408a2be 100644 (file)
@@ -18,6 +18,7 @@
 #endif
 
 #include "wx/cocoa/autorelease.h"
+#include "wx/cocoa/string.h"
 #include "wx/cocoa/trackingrectmanager.h"
 #include "wx/cocoa/objc/objc_uniquifying.h"
 
@@ -253,3 +254,9 @@ void wxControl::CocoaSetEnabled(bool enable)
 {
     [GetNSControl() setEnabled: enable];
 }
+
+/*static*/ void wxControl::CocoaSetLabelForObject(const wxString& label, struct objc_object *aView)
+{
+    [aView setTitle:wxNSStringWithWxString(GetLabelText(label))];
+}
+
index 0d71ecdfad5906d7363fbd54a3dfc32592422a7b..5ee7d005867faf920630c1007dec4ddb319be65a 100644 (file)
@@ -96,7 +96,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
     NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n];
     for(int i=0; i<n; ++i)
     {
-        [currCell setTitle: wxNSStringWithWxString(wxStripMenuCodes(choices[i], wxStrip_Mnemonics))];
+        CocoaSetLabelForObject(choices[i], currCell);
         [allCells addObject: currCell];
         [currCell release];
         // NOTE: We can still safely message currCell as the array has retained it.
@@ -162,7 +162,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
     [theBox release];
 
 
-    [GetNSBox() setTitle:wxNSStringWithWxString(wxStripMenuCodes(title, wxStrip_Mnemonics))];
+    CocoaSetLabelForObject(title, GetNSBox());
 //    [GetNSBox() setBorderType:NSLineBorder]; // why??
 
     SetMajorDim(majorDim, style);
@@ -229,7 +229,7 @@ void wxRadioBox::SetString(unsigned int n, const wxString& label)
 {
     int r = GetRowForIndex(n);
     int c = GetColumnForIndex(n);
-    [[GetNSMatrix() cellAtRow:r column:c] setTitle:wxNSStringWithWxString(wxStripMenuCodes(label, wxStrip_Mnemonics))];
+    CocoaSetLabelForObject(label, [GetNSMatrix() cellAtRow:r column:c]);
 }
 
     // change the individual radio button state
index 7054adae238aa51aebaa0cca199f033b6564b39b..3edd79a16d2cdab10b698af7977fb20c555d61b7 100644 (file)
@@ -77,7 +77,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID winid,
     SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
     [m_cocoaNSView release];
     [GetNSButton() setButtonType: NSRadioButton];
-    [GetNSButton() setTitle:wxNSStringWithWxString(label)];
+    CocoaSetLabelForObject(label, GetNSButton());
     // If it's the first in a group, it should be selected
     if(style&wxRB_GROUP)
         [GetNSButton() setState: NSOnState];
index 6bfc8111dd7c15420025578920b71b582023b796..ec2348200291b97d15156776c2cfbd02f2e3eb7c 100644 (file)
@@ -37,7 +37,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid,
         return false;
     m_cocoaNSView = NULL;
     SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
-    [GetNSBox() setTitle:wxNSStringWithWxString(GetLabelText(title))];
+    CocoaSetLabelForObject(title, GetNSBox());
     if(m_parent)
         m_parent->CocoaAddChild(this);
     SetInitialFrameRect(pos,size);
@@ -67,7 +67,7 @@ void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
 void wxStaticBox::SetLabel(const wxString& label)
 {
    wxAutoNSAutoreleasePool pool;
-   [GetNSBox() setTitle:wxNSStringWithWxString(label)];
+   CocoaSetLabelForObject(label, GetNSBox());
 }
 
 wxString wxStaticBox::GetLabel() const