I've just committed the beginnings of radio and checkbox buttons and
wanted to quickly discuss the API since it is a bit different from
Cocoa's. The main issue arrises from the fact that Cappuccino doesn't
have cells and that in Cocoa checkboxes and radio buttons are just
normal buttons with their images/alt. images set to radio/checkbox
images.
In Cappuccino we decided to stray from this for a number of reasons:
1. As stated before, we don't have cells so we can't and shouldn't
make use of NSMatrix to control the interaction between radio buttons.
2. In Cocoa, there is no reasonable way to ask a button whether it is
no a radio or checkbox -> the closest thing you can do is [[button
image] name] isEqualTo:@"NSCheckBox"], which is not the most elegant
thing in the universe.
3. In Cocoa, you can't have a checkbox or radio with an image, since
the image is already in use to show the actual checkbox/radio UI. In
other words, [myCheckBox setImage:someOptionImage] will make the
checkmark UI go away.
So, what we've done is create the CPRadio and CPCheckBox classes. This
allows us to make them separately themable from normal buttons, and
allows us to actually ask a button if its a radio/checkbox
(isKindOfClass:[CPCheckBox class]).
Creating a checkbox is easy enough:
checkbox = [[CPCheckBox alloc] initWithFrame:aFrame];
That's basically all there is to it. Radio buttons are very similar,
the key difference is the introduction of a new class CPRadioGroup,
which defines which radio buttons are part of the same group:
[myRadioButton setRadioGroup:aRadioGroup];
Every radio button receives a unique radio group by default (so if you
do nothing further, they will all behave independently), but you can
use an existing radio button's group with other buttons as so:
button1 = [[CPRadio alloc] initWithFrame:aFrame];
...
button2 = [[CPRadio alloc] initWithFrame:aFrame radioGroup:[button1
radioGroup]];
...
button3 = [[CPRadio alloc] initWithFrame:aFrame radioGroup:[button1
radioGroup]];
...etc...
Here, all the radio buttons will act "together". [[button1 radioGroup]
allRadios] returns every button that's part of this group, and
[[button1 radioGroup] selectedRadio] returns the currently selected
option.