On 03/26/12 01:08, leowang wrote:
> Dear All,
> I have a question of event handle. Suppose I have Window A,
> it has a sub-window named B, Window B has a Widget C in it.
> So my question is: if I return 0 in B::handle(event),
> the event will transfer to A or C?

        Probably depends on the event type.

        This is one you can probably answer yourself by making
        an example to find out. This is what I did (below) to show
        you how to find out yourself, in this case, using KEY events.

        With keys, if C has focus, C will get first shot at it,
        then B, then A. And if none respond, it gets resent as a shortcut
        to the main window (A).

        For instance, if I run the following program, when I hit 'z' I get:

Button C (KEY): z
Window B (KEY): z
Window A (KEY): z
Window A (SHORTCUT): z

        Here's the test program:

#include <fltk/Window.h>
#include <fltk/Button.h>
#include <fltk/events.h>
#include <fltk/run.h>
class MyWindow : public fltk::Window {
public:
    MyWindow(int W,int H,const char* L) : fltk::Window(W,H,L) {
    }
    MyWindow(int X,int Y,int W,int H,const char* L) : fltk::Window(X,Y,W,H,L) {
    }
    int handle(int e) {
        if ( e == fltk::KEY && fltk::event_key() == 'z' ) {
            printf("Window %s (KEY): z\n", label());
            return(0);
        }
        if ( e == fltk::SHORTCUT && fltk::event_key() == 'z' ) {
            printf("Window %s (SHORTCUT): z\n", label());
            return(0);
        }
        return(fltk::Window::handle(e));
    }
};
class MyButton : public fltk::Button {
public:
    MyButton(int X,int Y,int W,int H,const char* L) : fltk::Button(X,Y,W,H,L) {
    }
    int handle(int e) {
        if ( e == fltk::KEY && fltk::event_key() == 'z' ) {
            printf("Button %s (KEY): z\n", label());
            return(0);
        }
        if ( e == fltk::SHORTCUT && fltk::event_key() == 'z' ) {
            printf("Button %s (SHORTCUT): z\n", label());
            return(0);
        }
        return(fltk::Button::handle(e));
    }
};
int main() {
  MyWindow *a = new MyWindow(300, 180,"A");
  a->begin();
  MyWindow *b = new MyWindow(10,20,280,150,"B");
  b->color(45);
  b->begin();
  MyButton *c = new MyButton(20,30,100,25,"C");
  MyButton *d = new MyButton(20,70,100,25,"D");
  c->take_focus();
  b->end();
  b->end();
  a->show();
  return fltk::run();
}
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to