On 22.09.2010, at 14:19, paul wrote:

> But like Colombo...'just one more thing..'>
>
> button->callback(button_cb);
>
> why only one argument in this?

Just as you like and need it, the 2nd arg. is optional.
If you don't use it, this call doesn't touch the user_data
variable.

> when below:
>
> void Fl_Widget::callback (Fl_Callback *cb, void *p);
>>
>> This means that calling:
>>
>>     window->callback(win_cb,(void *)button);
>>
>> is the same as:
>>
>>     window->callback(win_cb); // is this the same as your 
>> button->callback(button_cb) call?
>                                 //and that it also effectively implies 
> window->user_data(etc?)

Just as above: if you use the 2nd argument, user_data will be set,
otherwise it won't be touched at all ...

> the 'input' example in the test folder seems a very useful one due to the 
> various callback types it illustrates, however a couple of the statements are 
> pretty complex, (to me at least) could you perhaps decipher this one?
>
> int when = 0;
> Fl_Input *input[5];
>
> void toggle_cb(Fl_Widget *o, long v) {
>    if (((Fl_Toggle_Button*)o)->value()) when |= v; else when&= ~v; //this 
> line! (from 'when', i understand the part in the if())
>    for (int i=0; i<5; i++) input[i]->when(when);
> }

I don't grok what you understand and what not from what your write,
thus here a short explanation (I just saw that Ian explained the
bits'n'details very well, so you should look at his post too):

Look at the setup of the buttons. These are Fl_Toggle_Buttons, i.e.
they change their state (value()) each time you click on them. They
all share the *same* callback function.

The if(...) line casts the 1st argument to Fl_Toggle_Button, reads
its value() and sets or clears the corresponding bit in the
variable when. The following for loop calls Fl_Widget::when() [1]
for all 5 buttons and hence sets the new when() state of all
buttons. when() is used to decide when a widget's (button's)
callback should be called by FLTK.

BTW. I suggest that you read the first tutorial chapters of the
FLTK docs (either 1.1 or 1.3) to get a better feeling what we're
talking about. Although I must admit that it can be difficult to
understand until you know how event-driven GUI programming works
(as opposed to classic sequential programming like your console
app).

Albrecht

[1] I wrote Fl_Widget::when() because this is what happens
finally, although the correct method is Fl_Toggle_Button::when().
But since Fl_[Toggle_]Button doesn't override Fl_Widget's method
(AFAIK), this is what happens.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to