>> Paul writes:
>> One of the problems i am facing is finding out the status of
>> a large number of checkboxes.
> Albrecht writes:
> Iterating all children of an Fl_Group is easy. You can use children()
> to get the no. of children and use child(i) to get each child.
Right -- looping through the group's children is easy if you don't
want to keep your own array copy of pointers to all the checkboxes.
(That would probably be the 'normal' way of doing this).
You should be aware that some groups (such as Fl_Scroll, IIRC)
can themselves add unexpected widgets to the group's children,
such as scrollbars in the case of Fl_Scroll.
Besides Albrecht's recommendation using variables to keep track
of them and/or dynamic_cast<>, and old school trick is to make
the widgets unique by (ab)using their callback() pointer.
The callback you assign doesn't even have to /do/ anything;
it just needs to exist and only be assigned to those widgets
you want to detect to make them unique.
So for instance if I make an empty callback function CheckBox_CB()
and initialize all the checkboxes to use it as their callback(),
when I walk the child() array looking for checkbox widgets,
I can test the callback() for CheckBox_CB() to find them, eg:
// WALK THE CHILDREN LOOKING FOR CHECKBOX WIDGETS
for ( int t=0; t<children(); t++ )
if ( child(t)->callback() == CheckBox_CB ) // is it a
checkbox widget?
// it is -- do stuff here
else
// it ISN'T -- (ignore, or check for other types)
This should ensure you are only considering checkbox widgets,
without fear of tripping over non-checkbox widgets that might somehow
sneak into the group.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk