I am working on a cross-platform dynamic dialog box builder that runs in macOS and Windows. I have inherited this codebase. I am trying to support radio buttons. The issue is that macOS automatically treats all radio buttons as a group if they share the same superview and the same action selector. This code uses one action selector for all buttons and only has one superview for all the controls. So a single group of radio buttons works like magic, but there is no way to have more than one group on the window.
I am looking for suggestions as to how this might be handled.
- Is there a way to suppress the automatic behavior of
NSButtonStyleRadio
? - Is there a way to dynamically create selectors that point back to the same code? (See below.)
A hackish solution might be to build in some number of radio button selector methods and then not allow more than that many groups on a window. It would look something like this:
- (IBAction)buttonPressed:(id)sender // this is the universal NSButton action
{
if (!_pOwner) return; // _pOwner is a member variable pointing to a C++ class that handles most of the work
int tagid = (int) [sender tag];
_pOwner->Notify_ButtonPressed(tagid);
}
- (IBAction)radioButtonGroup1Pressed:(id)sender
{
if (_pOwner)
[(id)_pOwner->_GetInstance() buttonPressed:sender];
}
- (IBAction)radioButtonGroup2Pressed:(id)sender
{
if (_pOwner)
[(id)_pOwner->_GetInstance() buttonPressed:sender];
}
- (IBAction)radioButtonGroup3Pressed:(id)sender
{
if (_pOwner)
[(id)_pOwner->_GetInstance() buttonPressed:sender];
}
- (IBAction)radioButtonGroup4Pressed:(id)sender
{
if (_pOwner)
[(id)_pOwner->_GetInstance() buttonPressed:sender];
}
This example would allow for up to 4 button groups on the window, and I could keep track of which ones I'd used. But I'd really like to avoid hard-coding it this way. Is there some way to do this dynamically? Or equally okay, disable the automatic behavior altogether?