Other unrelated option:
"bloated" widget class with templated calback functions.

This obviously should not be a part of the fltk library but I leave this
template as an example for the "reach callback" possibility with
templated widget and special My_Callback functor class:


------------------------------------------------------

template <typename WIDGET>
class Fl_Callback_Widget: public WIDGET{

  bool is_my_callback;

  void delete_previous_callback(){
    if(is_my_callback){
       delete ((My_Callback *)user_data());
       is_my_callback = 0;
    }
  }

public:
  template <typename T1, ....>
  void callback(T1 t1, ...){
    delete_previous_callback()
    Fl_Widget::callback(&my_special_callback_function,
                        new My_Callback(t1, ....));

   ~Fl_Callback_Widget(){
        delete_previous_callback();
   }

  // other temples for callback functions
  // ie with different numbers of parameters
  ...



 // All possible constructors with all possible number of parameters:

  Fl_Callback_Widget():WIDGET(), is_my_callback(0){}

  template <typename T1>
  Fl_Callback_Widget(T1 t1):WIDGET(t1), is_my_callback(0){}

  template <typename T1, typename T2>
  Fl_Callback_Widget(T1 t1, T2 t2):WIDGET(t1, t2), is_my_callback(0){}

  template <typename T1, typename T2, typemname T3>
  Fl_Callback_Widget(T1 t1,T2 t2,T3 t3):
          WIDGET(t1,t2,t2), is_my_callback(0){}

 // ... and so on to - say 7 parameters
 //  to accomodate for all possible widget constructors


}

// Single special callback for My_Callback functors:

void my_callback(Fl_Widget * w, void * data){
  (My_Callback *)
}

--------------------------------------------------------------

The advantage of this solution is tat it is an add-on (no changes to the
library) and you can use this template like ANY other widget but you
have this extra reach callback system:

Fl_Callback_Widget<Fl_Browser> browser(x, y, w, h, "My browser");
browser.callback(some_class,&Some_Class::method,argument_value_pointer);

The disadvantage is bloat -  for each used widget class there is new
specialization of the template class.

R.
_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to