> MacArthur, Ian (SELEX GALILEO, UK) wrote a nice sample
> > I'm not sure what the exact syntax for fltk-2 is, but it is basically
> > similar.
>
> it is nearly the same,
> Sample for fltk2 without fluid but with membercallback and own window:
>
> /*
> * fltk2-config --compile button_callback.cxx
> */
> #include <fltk/Window.h>
> #include <fltk/Button.h>
> #include <fltk/run.h>
> #include <fltk/events.h>
> #include <stdio.h>
>
> using namespace fltk;
>
> // --- Switchboard.h --------------------------------------------
> template<class T> class Switchboard
> {
> typedef void (T::*MCB)(fltk::Widget*);
> T* parent;
> struct Stub
> {
> T* self; // current instance (class pointer)
> MCB mcb; // member callback (function pointer)
> Stub* next; // pointer to next stub
> Stub(T* self, MCB
> mcb,Stub*next=0):self(self),mcb(mcb),next(next) {}
> void operator()(fltk::Widget* arg) const {(self->*mcb)(arg);}
> }* list;
> static void exec(fltk::Widget* w, void*p) {(*(Stub*)p)(w);}
> public:
> ~Switchboard() {for(Stub*p;(p=list);list=list->next,delete p){};};
> Switchboard(T*parent):parent(parent),list(0){};
> void* stub(MCB mcb) {return list=new Stub(parent,mcb,list);}
> fltk::Callback *operator()() { return &Switchboard<T>::exec;}
> void connect(fltk::Widget*w, MCB mcb) {w->callback(&exec, stub(mcb));}
> void operator()(fltk::Widget*w, MCB mcb) {w->callback(&exec,
> stub(mcb));}
> };
> // --------------------------------------------------------------------
>
> class MyWin:public Window
> {
> Switchboard<MyWin> connect;
> Button b;
> void onButton(Widget*w)
> {
> printf("event=%d\n",event());
> }
> public:
> MyWin(int w, int h):Window(USEDEFAULT,USEDEFAULT,w,h,0,true)
> ,connect(this)
> ,b(25,25,80,40,"Quit")
> {
> end();
> b.when(WHEN_CHANGED);
> connect(&b,&MyWin::onButton);
> }
> int run(int argc, char*argv[])
> {
> show(argc,argv);
> return fltk::run();
> }
> };
>
> int main(int argc, char* argv[])
> {
> MyWin* win=new MyWin(376,278);
> return win->run(argc,argv);
> }
Dear Edzard, Ian & none,
Many thanks for your help.
Just add the p_btn->whne(WHEN_CHANGED) is OK, now it can receive any event in
the callback. Thanks.
Best regards,
Leo
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk