From 525007cf12a3025c2a6ca3c58663062e567c0e25 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 6 Aug 2007 13:47:09 +0000 Subject: [PATCH] Consolidate cocoa view/control/cell label setting into wxControl::CocoaSetLabelForObject. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/control.h | 9 +++++++++ src/cocoa/button.mm | 4 ++-- src/cocoa/checkbox.mm | 4 ++-- src/cocoa/control.mm | 7 +++++++ src/cocoa/radiobox.mm | 6 +++--- src/cocoa/radiobut.mm | 2 +- src/cocoa/statbox.mm | 4 ++-- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/wx/cocoa/control.h b/include/wx/cocoa/control.h index ce13947692..1921d083ec 100644 --- a/include/wx/cocoa/control.h +++ b/include/wx/cocoa/control.h @@ -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 diff --git a/src/cocoa/button.mm b/src/cocoa/button.mm index 2e9cb7103c..624e5271bd 100644 --- a/src/cocoa/button.mm +++ b/src/cocoa/button.mm @@ -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 diff --git a/src/cocoa/checkbox.mm b/src/cocoa/checkbox.mm index c17d1152fc..ec2915a257 100644 --- a/src/cocoa/checkbox.mm +++ b/src/cocoa/checkbox.mm @@ -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 diff --git a/src/cocoa/control.mm b/src/cocoa/control.mm index 475a372d5e..9fabb68103 100644 --- a/src/cocoa/control.mm +++ b/src/cocoa/control.mm @@ -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))]; +} + diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm index 0d71ecdfad..5ee7d00586 100644 --- a/src/cocoa/radiobox.mm +++ b/src/cocoa/radiobox.mm @@ -96,7 +96,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid, NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n]; for(int i=0; iCocoaAddChild(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 -- 2.45.2