In this program, I've derived from Fl_Menu_Bar and overridden the
handle(int) function. That's because I need the submenu to pop up when
the mouse enters the the menu, without the user having to press a mouse
button.
It seems that pulldown() doesn't return until I press Esc, and
handle(FL_LEAVE) doesn't get called until then.
Thinking of my Fl_Menu_Bar derived class and its submenus as a unit, I
need to somehow detect as soon as the mouse cursor enters or leaves that
unit, without requiring a keyboard press or mouse click.
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.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) {
switch (e) {
case FL_ENTER: {
fprintf(stderr, "FL_ENTER Calling pulldown()\n");
const Fl_Menu_Item *v = menu()->pulldown(x(), y(), w(),
h(), v, this, 0, 1);
fprintf(stderr, "FL_ENTER pulldown() returned\n");
return 1;
}
case FL_LEAVE:
fprintf(stderr, "FL_LEAVE\n");
break;
}
return Fl_Menu_Bar::handle(e);
}
};
int main(int argc, char **argv) {
Fl_Double_Window *win = new Fl_Double_Window(300,250);
MyBar* menubar = new MyBar (0,0,300,25);
menubar->add("One");
menubar->add("Two/A");
menubar->add("Two/B");
win->end();
win->show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk