On 06.01.2013 09:01, Greg Ercolano wrote:
> On 01/04/13 05:22, Albrecht Schlosser wrote:
>> I'd like to know if there are more FLTK users who have the need
>> to track the widget that currently has the focus.
>
> I wouldn't be against it.. sounds reasonable.
>
>> I could imagine something like a callback that could be called
>> whenever the current focus widget (Fl::focus()) changes. This
>> could be something like:
>>
>> Fl::register_focus[_tracking] (my_widget,callback,arg)
>
> Seems like:
>
> Fl::add_focus_callback(cb, data);
> Fl::remove_focus_callback(cb,data);
>
> ..would make sense.
>
>> void callback (Fl_Widget *w, long or void * arg, Fl_Widget *focus)
>> The last argument is just to avoid calling Fl::focus() each time
>> the callback is called, but could also be removed.
>
> I'd prefer the user's callback code do the Fl::focus() call
> (if it needs it) rather than a third arg so as to be consistent
> with Fl_Callback and it's always easier to remember shorter arg lists.
Agreed, 100%. All good points.
> Plus whatever few cycles are saved by preventing the user from calling
> Fl::focus() are probably undone by the stack manipulations of handling
> a third arg in the callback..
Yep, you're right, thanks. Calling Fl::focus() is a simple pointer
assignment, usually handled inline:
From FL/Fl.H:
static Fl_Widget* focus() {return focus_;}
Note also that I currently believe that the first argument I had in my
register... method should be dropped, because it's useless or redundant.
If someone would want to save the widget that is interested in the focus
change somewhere, s/he could use the data arg for this or save it
elsewhere.
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk