Implement most of wxRadioBox's methods.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47567 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2007-07-19 17:58:38 +00:00
parent 6420b4c55d
commit 4c1a4c4180
2 changed files with 47 additions and 8 deletions

View File

@@ -109,6 +109,22 @@ public:
protected: protected:
WX_NSMatrix GetNSMatrix() const; WX_NSMatrix GetNSMatrix() const;
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
int GetRowForIndex(int n) const
{
if(m_windowStyle & wxRA_SPECIFY_COLS)
return n / GetMajorDim();
else
return n % GetMajorDim();
}
int GetColumnForIndex(int n) const
{
if(m_windowStyle & wxRA_SPECIFY_COLS)
return n % GetMajorDim();
else
return n / GetMajorDim();
}
}; };
#endif // __WX_COCOA_RADIOBOX_H__ #endif // __WX_COCOA_RADIOBOX_H__

View File

@@ -79,7 +79,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(choices[i])]; [currCell setTitle: wxNSStringWithWxString(wxStripMenuCodes(choices[i], wxStrip_Mnemonics))];
[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.
@@ -92,12 +92,11 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
// (thousands) which makes every cell in the matrix that big. Not good. // (thousands) which makes every cell in the matrix that big. Not good.
// Be safe and initialize a text cell with an empty string. That always works. // Be safe and initialize a text cell with an empty string. That always works.
currCell = [[NSCell alloc] initTextCell:@""]; currCell = [[NSCell alloc] initTextCell:@""];
[currCell setEnabled:NO]; // Don't allow user to select this cell
for(int i=n; i < majorDim * minorDim; ++i) for(int i=n; i < majorDim * minorDim; ++i)
{ {
[allCells addObject: currCell]; [allCells addObject: currCell];
// NOTE: Use the same instance.. this should work and save some heap allocations. // NOTE: Use the same instance.. this should work and save some heap allocations.
// It will, however, make the selection rather indeterminate if the user clicks
// on the empty space.
#if 0 #if 0
[currCell release]; [currCell release];
currCell = [currCell copy]; currCell = [currCell copy];
@@ -143,7 +142,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID winid,
[GetNSBox() setContentView:radioBox]; [GetNSBox() setContentView:radioBox];
[radioBox release]; // The NSBox retains it for us. [radioBox release]; // The NSBox retains it for us.
[GetNSBox() setTitle:wxNSStringWithWxString(title)]; [GetNSBox() setTitle:wxNSStringWithWxString(wxStripMenuCodes(title, wxStrip_Mnemonics))];
// [GetNSBox() setBorderType:NSLineBorder]; // why?? // [GetNSBox() setBorderType:NSLineBorder]; // why??
SetMajorDim(majorDim, style); SetMajorDim(majorDim, style);
@@ -170,11 +169,20 @@ WX_NSMatrix wxRadioBox::GetNSMatrix() const
// selection // selection
void wxRadioBox::SetSelection(int n) void wxRadioBox::SetSelection(int n)
{ {
int r = GetRowForIndex(n);
int c = GetColumnForIndex(n);
[GetNSMatrix() selectCellAtRow:r column:c];
} }
int wxRadioBox::GetSelection() const int wxRadioBox::GetSelection() const
{ {
return 0; NSMatrix *radioBox = GetNSMatrix();
NSInteger r = [radioBox selectedRow];
NSInteger c = [radioBox selectedColumn];
if(m_windowStyle & wxRA_SPECIFY_COLS)
return r * GetMajorDim() + c;
else
return c * GetMajorDim() + r;
} }
// string access // string access
@@ -190,23 +198,38 @@ unsigned int wxRadioBox::GetCount() const
wxString wxRadioBox::GetString(unsigned int n) const wxString wxRadioBox::GetString(unsigned int n) const
{ {
return wxEmptyString; int r = GetRowForIndex(n);
int c = GetColumnForIndex(n);
// FIXME: Cocoa stores the mnemonic-stripped title.
return wxStringWithNSString([[GetNSMatrix() cellAtRow:r column:c] title]);
} }
void wxRadioBox::SetString(unsigned int n, const wxString& label) 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))];
} }
// change the individual radio button state // change the individual radio button state
bool wxRadioBox::Enable(unsigned int n, bool enable) bool wxRadioBox::Enable(unsigned int n, bool enable)
{ {
// TODO int r = GetRowForIndex(n);
int c = GetColumnForIndex(n);
NSCell *cell = [GetNSMatrix() cellAtRow:r column:c];
if(cell == nil)
return false; return false;
bool wasEnabled = [cell isEnabled];
[cell setEnabled:enable];
return (wasEnabled && !enable) || (!wasEnabled && enable);
} }
bool wxRadioBox::Show(unsigned int n, bool show) bool wxRadioBox::Show(unsigned int n, bool show)
{ {
// TODO // TODO
// NOTE: Cocoa has no visible state for cells so we'd need to replace the
// cell with a dummy one to hide it or alternatively subclass NSButtonCell
// and add the behavior.
return false; return false;
} }