You can inherit Fl_Menu_Bar and catch FL_ENTER events. Here is the
working sample:

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>

class MyBar : public Fl_Menu_Bar {
public:
    MyBar(int X, int Y, int W, int H, const char *l=0) :
    Fl_Menu_Bar(X, Y, W, H, l) { }

    int handle(int e) {
        if(e == FL_ENTER) {
            const Fl_Menu_Item *v;

            v = menu()->pulldown(x(), y(), w(), h(), v, this, 0, 1);
            picked(v);
            return 1;
        }

        return Fl_Menu_Bar::handle(e);
    }
};

int main(int argc, char **argv) {
    Fl_Double_Window *win = new Fl_Double_Window(300,100);
    MyBar *menubar = new MyBar(0,0,300,25);

    menubar->add("&File/Open");
    menubar->add("&File/Save");

    menubar->add("&Edit/Cut");
    menubar->add("&Edit/Copy");
    menubar->add("&Edit/Paste");

    win->end();
    win->show();

    return(Fl::run());
}

pulldown() function will use mouse position and according to
coordinates, select appropriate menu item. The same strategy is used for
getting ordinary 'click-ed' menu event, except it is handled when FLTK
receives FL_PUSH event.

Sanel


On 01/21/2013 06:38 PM, Howard Rubin wrote:
> How can I get a menu item to drop down by hovering the mouse?
> 
> In this program, clicking on the File menu will drop it down, and then I
> can just move the mouse over the Edit menu to drop it down.
> 
> I need the File menu to drop down when I move the mouse over it without
> the mouse click.
> 
> 
> #include <FL/Fl.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Menu_Bar.H>
> 
> int main(int argc, char **argv) {
>     Fl_Double_Window *win = new Fl_Double_Window(300,100);
>     Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,300,25);
> 
>     menubar->add("&File/Open");
>     menubar->add("&File/Save");
> 
>     menubar->add("&Edit/Cut");
>     menubar->add("&Edit/Copy");
>     menubar->add("&Edit/Paste");
> 
>     win->end();
>     win->show();
> 
>     return(Fl::run());
> }
> 
> 

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

Reply via email to