Hello Everyone.  I'm trying to understand how events are propagated among 
widgets and windows.

I have a class derived from Widget and it overrides "int handle(int)".

I instantiate the class in a Window along with a Button Widget. The Button 
Widget has a callback.

When I click the Button Widget, my derived class handles it!?

How do I prevent this from happening?  I would like the derived Widget to only 
handle events when those events occur with respect to it.


Here is the code:
//----------------------------------------------------
#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/Button.h>
#include <fltk/events.h>
#include <fltk/run.h>
using namespace fltk;
#include <iostream>
using namespace std;

class A : public Widget {
public:
        A(int x,int y,int w,int h, const char *l=0) : Widget(x,y,w,h,l) {
                add_timeout(0.5);
        }
        int handle(int event) {
                if (event == TIMEOUT) {
                        if (event_state(BUTTON1))
                                cout << "Mouse Button1" << endl;

                        repeat_timeout(0.5);
                }
                return 1;
        }
};

void myCallback(Widget* w, void* d) {/*do it*/}

int main(void) {
        Window W(0,0,150,150,"Main");
        W.begin();
                A* classA = new A(0,0,150,100,"Class A :\n  public Widget");
                Button B(0,110,100,30,"Button");
                B.callback((Callback*)myCallback);
        W.end();
        W.show();
        return run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to