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);
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

View File

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

View 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

View 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,6 +140,6 @@ void wxCheckBox::Cocoa_wxNSButtonAction(void)
void wxCheckBox::SetLabel(const wxString& s)
{
wxAutoNSAutoreleasePool pool;
[GetNSButton() setTitle:wxNSStringWithWxString(s)];
CocoaSetLabelForObject(s, GetNSButton());
}
#endif

View File

@@ -19,6 +19,7 @@
#include "wx/cocoa/string.h"
#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h"
#include "wx/cocoa/trackingrectmanager.h"
#include "wx/cocoa/objc/objc_uniquifying.h"
@@ -275,6 +276,11 @@ void wxControl::CocoaSetEnabled(bool enable)
[GetNSControl() setEnabled: enable];
}
/*static*/ void wxControl::CocoaSetLabelForObject(const wxString& label, struct objc_object *aView)
{
[aView setTitle:wxNSStringWithWxString(GetLabelText(label))];
}
wxString wxControl::GetLabel() const
{
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];
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

View 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];

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