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:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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))];
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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];
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user