>>>> I would like to cause a callback if I click anywhere on the
>>>> background of my window . Not just if I click on the closing-x
>>>> on the upper right corner. How do I do that?

>>> Derive your own subclassed widget.
>>> In the handle method, call the base class handle method and check
>>> the return value [..]

>> I'm really new in C++, so how do I call the handle method in my
>> subclass to get the return value?

        Here's the bare minimum.

        In this case the methods MyPush() and MyRelease() are each called
        separately when a mouse button is pushed or released on the window.

        As Duncan said, you can see my other examples and esp. read the
        docs he referred you to on FLTK "Handling Events", especially
        that last little sentence at the bottom of that section, quoted below
        as well:

------------------------------------------------------------------------------ 
snip
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <stdio.h>

// Derive our own class from Fl_Window, so we can intercept all events to the 
window
class MyWindow : public Fl_Window {
    void MyPush() {                             // Called when someone pushes 
down on a mouse button
        fprintf(stderr, "PUSH: you clicked button %d at %d,%d\n",
                Fl::event_button(), Fl::event_x(), Fl::event_y());
    }
    void MyRelease() {                          // Called when someone releases 
a mouse button
        fprintf(stderr, "RELEASE: you released button %d at %d,%d\n",
                Fl::event_button(), Fl::event_x(), Fl::event_y());
    }
    int handle(int e) {                         // Window's handle() method -- 
called by FLTK on any window event
        int ret = Fl_Window::handle(e);         // Pass all events to Fl_Window 
base class so it can process them first
        switch (e) {
            case FL_PUSH:                       // A mouse button push event?
                MyPush();                       // ..invoke MyPush() method
                ret=1;                          // ..set ret=1 to indicate we 
'handled' the event (see docs **)
                break;
            case FL_RELEASE:                    // A mouse button release event?
                MyRelease();                    // ..invoke MyRelease() method
                ret=1;                          // ..set ret=1 to indicate we 
'handled' the event (see docs **)
                break;
        }
        return(ret);                            // maintain return value 
(IMPORTANT)
    }

public:
    MyWindow(int w,int h) : Fl_Window(w,h) {    // Constructor
    }
};

int main(int argc, char** argv) {
    MyWindow win(300,300);                      // Make an instance of our 
window instead of Fl_Window
    win.end();
    win.show();
    return(Fl::run());
}

// ** Quoting the docs on "Handling Events":
//    http://www.fltk.org/documentation.php/doc-1.1/subclassing.html#handle
//
//    "You must return non-zero if your handle() method uses the event.
//     If you return zero, the parent widget will try sending the event
//     to another widget."
//

------------------------------------------------------------------------------ 
snip
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to