brosnan wrote:
> I am quite confused that it didn't return "test" when
> I selected a item and hit shift or enter in the keyboard?

        Please see the section on handling events, eg:
        http://fltk.org/doc-1.3/events.html
        Under the section on "Keyboard Events":

            "To receive FL_KEYBOARD events you must also respond to the
            FL_FOCUS and FL_UNFOCUS events."

        So to see clicks on the keyboard (such as Shift, Arrow keys, etc):

    int handle(int e) {
        int ret = Fl_Browser::handle(e);    // REQUIRED
        switch (e) {
            case FL_FOCUS:
            case FL_UNFOCUS:
                return(1);                  // Return 1 for FOCUS/UNFOCUS to 
get keyboard events
            case FL_KEYBOARD:
                cout << "keyboard" << endl;
                return(1);
        }
        return(ret);
    }

        For clicking/selecting items in Fl_Browser, you'd normally want
        to set a callback() for the widget to invoke a function to handle
        clicking on items.

        But if you want to get mouse click events in an Fl_Browser, you can
        flesh out the above:

    int handle(int e) {
        int ret = Fl_Browser::handle(e);
        switch (e) {
            case FL_FOCUS:
            case FL_UNFOCUS:
                return(1);
            case FL_KEYBOARD:
                cout << "test" << endl;
                break;
            case FL_PUSH:                    // MOUSE CLICK PUSH
                cout << "push" << endl;
                ret = 1;
                break;
            case FL_RELEASE:                 // MOUSE CLICK RELEASE
                cout << "release" << endl;
                ret = 1;
                break;
        }
        return(ret);
    }

        Here's a working program showing all the above:

#include <iostream>
#include <FL/Fl_Window.H>
#include <FL/Fl_Browser.H>
using namespace std;
class flbrw : public Fl_Browser {
    public:
    flbrw(int X,int Y,int W,int H,const char*L=0):Fl_Browser(X,Y,W,H,L) {
        add("one");
        add("two");
        add("three");
        type(FL_MULTI_BROWSER);
    }
    int handle(int e) {
        int ret = Fl_Browser::handle(e);
        switch (e) {
            case FL_FOCUS:
            case FL_UNFOCUS:
                return(1);
            case FL_KEYBOARD:
                cout << "test" << endl;
                break;
            case FL_PUSH:
                cout << "push" << endl;
                ret = 1;
                break;
            case FL_RELEASE:
                cout << "release" << endl;
                ret = 1;
                break;
        }
        return(ret);
    }
};
int main() {
    Fl_Window *win = new Fl_Window(300,200);
    flbrw *brow = new flbrw(10,10,300-20,200-20);
    win->end();
    win->show();
    return(Fl::run());
}


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

Reply via email to