On 22.03.2010, at 10:15, Domingo Alvarez Duarte wrote:
> I'm experimenting with dao http://daovm.net/ and his author did an
> amazing job creating a automated tool that can create bindings to almost
> all fltk 1.3 including deriving fltk classes, but for it to work with
> callbacks easily he needs to make "void do_callback(Fl_Widget* o,void*
> arg=0)" a virtual function.
>
> I propose to make this modification on the official FLTK sources.
>
> Changes:
> from: void do_callback(Fl_Widget* o,void* arg=0);
> to: virtual void do_callback(Fl_Widget* o,void* arg=0);

Interesting idea. Maybe +1 from me. Some thoughts, though:

There are at least 3 overloaded versions of do_callback(), and
we would have to make all virtual, IIRC, not only the one you
mentioned.

If someone would override do_callback() in a derived class, he
would have to override all three versions, IIRC.

> With this modification examples like this works:
>
> ------
> load DaoFLTK;
>
> class Button1 : Fl_Button
> {
> sub do_callback( w : Fl_Widget, a : cdata ){
> io.write( '\07' );
> io.flush();
> }
> }
> class Button2 : Fl_Button
> {
> sub do_callback( w : Fl_Widget, a : cdata ){
> std.exit(0);
> }
> }
>
> window = Fl_Window(320,65);
> b1 = Button1(20, 20, 80, 25, '&Beep');
> b2 = Fl_Button(120,20, 80, 25, '&no op');
> b3 = Button2(220,20, 80, 25, 'E&xit');
> window.end();
> window.show();
> Fl.run();
> ------

Your example is bad for 2 reasons:

  (1) to understand it, you must know Dao, otherwise I can only
      guess what you want to do, see ...

  (2) do_callback() is _not_ intended to do anything except calling
      the user's callback function. Your example seems to _implement_
      a callback in the do_callback() method. If you derive your own
      class, then you can probably do that in the class's virtual
      handle() method anyway.

However, another reason to override do_callback() might be *not* to
call clear_changed() after the callback, as it is currently done :-(
or anything else that needs to be done before or after calling the
user callback.

Thus, I think that I would generally say +1, with the necessary
additions in the code and a clear documentation when (and how) to
override do_callback().

Albrecht
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to