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
This commit is contained in:
David Elliott
2007-08-06 13:47:09 +00:00
parent 35c63208f0
commit 525007cf12
7 changed files with 26 additions and 10 deletions

View File

@@ -63,6 +63,15 @@ public:
virtual void CocoaSetEnabled(bool enable); virtual void CocoaSetEnabled(bool enable);
protected: protected:
virtual wxSize DoGetBestSize() const; 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 #endif

View File

@@ -48,7 +48,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID winid,
[m_cocoaNSView release]; [m_cocoaNSView release];
[GetNSButton() setBezelStyle:NSRoundedBezelStyle]; [GetNSButton() setBezelStyle:NSRoundedBezelStyle];
[GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))]; CocoaSetLabelForObject(label, GetNSButton());
[GetNSControl() sizeToFit]; [GetNSControl() sizeToFit];
if(m_parent) if(m_parent)
@@ -78,7 +78,7 @@ wxString wxButton::GetLabel() const
void wxButton::SetLabel(const wxString& label) void wxButton::SetLabel(const wxString& label)
{ {
[GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))]; CocoaSetLabelForObject(label, GetNSButton());
} }
wxSize wxButton::DoGetBestSize() const wxSize wxButton::DoGetBestSize() const

View File

@@ -47,7 +47,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID winid,
[m_cocoaNSView release]; [m_cocoaNSView release];
[GetNSButton() setButtonType: NSSwitchButton]; [GetNSButton() setButtonType: NSSwitchButton];
[GetNSButton() setAllowsMixedState: Is3State()]; [GetNSButton() setAllowsMixedState: Is3State()];
[GetNSButton() setTitle:wxNSStringWithWxString(GetLabelText(label))]; CocoaSetLabelForObject(label, GetNSButton());
[GetNSControl() sizeToFit]; [GetNSControl() sizeToFit];
if(m_parent) if(m_parent)
@@ -140,7 +140,7 @@ void wxCheckBox::Cocoa_wxNSButtonAction(void)
void wxCheckBox::SetLabel(const wxString& s) void wxCheckBox::SetLabel(const wxString& s)
{ {
wxAutoNSAutoreleasePool pool; wxAutoNSAutoreleasePool pool;
[GetNSButton() setTitle:wxNSStringWithWxString(s)]; CocoaSetLabelForObject(s, GetNSButton());
} }
wxString wxCheckBox::GetLabel() const wxString wxCheckBox::GetLabel() const

View File

@@ -18,6 +18,7 @@
#endif #endif
#include "wx/cocoa/autorelease.h" #include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h"
#include "wx/cocoa/trackingrectmanager.h" #include "wx/cocoa/trackingrectmanager.h"
#include "wx/cocoa/objc/objc_uniquifying.h" #include "wx/cocoa/objc/objc_uniquifying.h"
@@ -253,3 +254,9 @@ void wxControl::CocoaSetEnabled(bool enable)
{ {
[GetNSControl() setEnabled: enable]; [GetNSControl() setEnabled: enable];
} }
/*static*/ void wxControl::CocoaSetLabelForObject(const wxString& label, struct objc_object *aView)
{
[aView setTitle:wxNSStringWithWxString(GetLabelText(label))];
}

View File

@@ -96,7 +96,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n]; NSMutableArray *allCells = [NSMutableArray arrayWithCapacity:n];
for(int i=0; i<n; ++i) for(int i=0; i<n; ++i)
{ {
[currCell setTitle: wxNSStringWithWxString(wxStripMenuCodes(choices[i], wxStrip_Mnemonics))]; CocoaSetLabelForObject(choices[i], currCell);
[allCells addObject: currCell]; [allCells addObject: currCell];
[currCell release]; [currCell release];
// NOTE: We can still safely message currCell as the array has retained it. // 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]; [theBox release];
[GetNSBox() setTitle:wxNSStringWithWxString(wxStripMenuCodes(title, wxStrip_Mnemonics))]; CocoaSetLabelForObject(title, GetNSBox());
// [GetNSBox() setBorderType:NSLineBorder]; // why?? // [GetNSBox() setBorderType:NSLineBorder]; // why??
SetMajorDim(majorDim, style); SetMajorDim(majorDim, style);
@@ -229,7 +229,7 @@ void wxRadioBox::SetString(unsigned int n, const wxString& label)
{ {
int r = GetRowForIndex(n); int r = GetRowForIndex(n);
int c = GetColumnForIndex(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 // change the individual radio button state

View File

@@ -77,7 +77,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID winid,
SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]); SetNSButton([[NSButton alloc] initWithFrame: MakeDefaultNSRect(size)]);
[m_cocoaNSView release]; [m_cocoaNSView release];
[GetNSButton() setButtonType: NSRadioButton]; [GetNSButton() setButtonType: NSRadioButton];
[GetNSButton() setTitle:wxNSStringWithWxString(label)]; CocoaSetLabelForObject(label, GetNSButton());
// If it's the first in a group, it should be selected // If it's the first in a group, it should be selected
if(style&wxRB_GROUP) if(style&wxRB_GROUP)
[GetNSButton() setState: NSOnState]; [GetNSButton() setState: NSOnState];

View File

@@ -37,7 +37,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid,
return false; return false;
m_cocoaNSView = NULL; m_cocoaNSView = NULL;
SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]); SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
[GetNSBox() setTitle:wxNSStringWithWxString(GetLabelText(title))]; CocoaSetLabelForObject(title, GetNSBox());
if(m_parent) if(m_parent)
m_parent->CocoaAddChild(this); m_parent->CocoaAddChild(this);
SetInitialFrameRect(pos,size); SetInitialFrameRect(pos,size);
@@ -67,7 +67,7 @@ void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
void wxStaticBox::SetLabel(const wxString& label) void wxStaticBox::SetLabel(const wxString& label)
{ {
wxAutoNSAutoreleasePool pool; wxAutoNSAutoreleasePool pool;
[GetNSBox() setTitle:wxNSStringWithWxString(label)]; CocoaSetLabelForObject(label, GetNSBox());
} }
wxString wxStaticBox::GetLabel() const wxString wxStaticBox::GetLabel() const