Merged 47902 from trunk:

Consolidate cocoa view/control/cell label setting into wxControl::CocoaSetLabelForObject.

Also implements wxStaticBox Get/SetLabel which wasn't in the 2.8 branch.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@47903 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2007-08-06 14:19:41 +00:00
parent e91a95b89e
commit 9330455ae2
8 changed files with 40 additions and 9 deletions

View File

@@ -66,6 +66,15 @@ public:
void SetLabel(const wxString& label); void SetLabel(const wxString& label);
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

@@ -41,6 +41,9 @@ public:
long style = 0, const wxString& name = wxStaticBoxNameStr); long style = 0, const wxString& name = wxStaticBoxNameStr);
virtual ~wxStaticBox(); virtual ~wxStaticBox();
virtual void SetLabel(const wxString& label);
virtual wxString GetLabel() const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Cocoa callbacks // Cocoa callbacks
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

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,6 +140,6 @@ 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());
} }
#endif #endif

View File

@@ -19,6 +19,7 @@
#include "wx/cocoa/string.h" #include "wx/cocoa/string.h"
#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"
@@ -275,6 +276,11 @@ 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))];
}
wxString wxControl::GetLabel() const wxString wxControl::GetLabel() const
{ {
if([GetNSControl() isKindOfClass:[WX_GET_OBJC_CLASS(wxNonControlNSControl) class]]) if([GetNSControl() isKindOfClass:[WX_GET_OBJC_CLASS(wxNonControlNSControl) class]])

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);
@@ -63,3 +63,16 @@ void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
if(nextBorder > *borderOther) if(nextBorder > *borderOther)
*borderOther = nextBorder; *borderOther = nextBorder;
} }
void wxStaticBox::SetLabel(const wxString& label)
{
wxAutoNSAutoreleasePool pool;
CocoaSetLabelForObject(label, GetNSBox());
}
wxString wxStaticBox::GetLabel() const
{
wxAutoNSAutoreleasePool pool;
return wxStringWithNSString([GetNSBox() title]);
}