diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2006-03-27 12:59:49 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2006-03-27 12:59:49 +0000 |
| commit | 094f1b0f7e80c15764b33f2e166697a8f8989597 (patch) | |
| tree | 308e60d6d55a4dac4089ed3bc950c337cdf61723 /src/Fl_Menu.cxx | |
| parent | 7d8d1883d5bad9605b7ed19284ae1d33a525f802 (diff) | |
STR 1213: leaving the area of a menubar when dragging would not cancel out the menu selection. This version now deselects a menu if the mouse leaves a menu structure, moving or dragging.
This is an extension of the original patch which would file on selecting menu titles, or returning to the previous menu window inside a menu hierarchy.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4866 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Menu.cxx')
| -rw-r--r-- | src/Fl_Menu.cxx | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx index 34f6b4b99..80ceea9ff 100644 --- a/src/Fl_Menu.cxx +++ b/src/Fl_Menu.cxx @@ -107,6 +107,7 @@ public: int titlex(int); void autoscroll(int); void position(int x, int y); + int is_inside(int x, int y); }; #define LEADING 4 // extra vertical leading @@ -458,6 +459,15 @@ int menuwindow::titlex(int n) { return xx; } +// return 1, if the given root coordinates are inside the window +int menuwindow::is_inside(int mx, int my) { + if ( mx < x_root() || mx >= x_root() + w() || + my < y_root() || my >= y_root() + h()) { + return 0; + } + return 1; +} + //////////////////////////////////////////////////////////////// // Fl_Menu_Item::popup(...) @@ -488,9 +498,20 @@ struct menustate { int nummenus; int menubar; // if true p[0] is a menubar int state; + int is_inside(int mx, int my); }; static menustate* p; +// return 1 if the coordinates are inside any of the menuwindows +int menustate::is_inside(int mx, int my) { + int i; + for (i=nummenus-1; i>=0; i--) { + if (p[i]->is_inside(mx, my)) + return 1; + } + return 0; +} + static inline void setitem(const Fl_Menu_Item* i, int m, int n) { p->current_item = i; p->menu_number = m; @@ -595,14 +616,11 @@ int menuwindow::handle(int e) { int mx = Fl::event_x_root(); int my = Fl::event_y_root(); int item=0; int mymenu = pp.nummenus-1; - if (e == FL_PUSH && (!pp.menubar || mymenu) && - (mx < pp.p[mymenu]->x_root() || - mx >= (pp.p[mymenu]->x_root() + pp.p[mymenu]->w()) || - my < pp.p[mymenu]->y_root() || - my >= (pp.p[mymenu]->y_root() + pp.p[mymenu]->h()))) { - // Clicking outside menu cancels it... + // Clicking or dragging outside menu cancels it... + if ((!pp.menubar || mymenu) && !pp.is_inside(mx, my)) { setitem(0, -1, 0); - pp.state = DONE_STATE; + if (e==FL_PUSH) + pp.state = DONE_STATE; return 1; } for (mymenu = pp.nummenus-1; ; mymenu--) { |
