I'd like to propose this extra bit among FL_WHEN flags to indicate that the callback should be also called on widget destruction. If set, upon widget destruction callback would be called but with first parameter NULL to indicate destruction (the widget is mostly destroyed at that moment anyway, so there is not much use of it...):
Fl_Widget::~Fl_Widget{ ... if((when() & FL_WHEN_DESTRUCTED) && callback()) (*callback())(0, user_data()); } This simple addition would turn the couple calback/user_data to full-blown widget plugin with no extra widget space required. Then one can built for instance sophisticated callback (or signal/slot) structures or to do other things without the need of subclassing of every widget or hacking FLTK (bazaar if full of these forks). Following is a mere example what user can do: // single callback wrapper void callback_wrapper(Fl_Widget * w, void * data){ if(w) ((Callback *)data)->call(); // Normal call: calling virtual function of callback object, a functor which // can bind or reference real function pointer, (object/method), parameters etc... else delete (Callback *)data; // Calling virtual destuctor of callback object } // Function to assign Callback object fl_callback(Fl_Widget * w, Callback * c){ w->callback(&callback_wrapper, c); w->when(w->when() | FL_WHEN_DESTRUCTED); } Note that the data does not need to be a single object, it can be a linked list or other animals (with proper handling/unlinking in their destructors or callback wrapper). Any other/better ideas for widget plugins? Roman _______________________________________________ fltk-dev mailing list fltk-dev@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-dev