summaryrefslogtreecommitdiff
path: root/src/Fl_Menu.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-05-06 16:29:16 +0000
committerManolo Gouy <Manolo>2011-05-06 16:29:16 +0000
commit26f81a4834ddcb839efeba1f11a23d900dae6262 (patch)
tree0442df1aa30031a3dee36363e17a4918350ff64f /src/Fl_Menu.cxx
parent3110a13aa22c13d8675db6542ab6e9860ff5dc0c (diff)
Fix STR #2613. Allows a menu item to be invisible but with functional shortcut
as authorized by the doc. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8639 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Menu.cxx')
-rw-r--r--src/Fl_Menu.cxx42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/Fl_Menu.cxx b/src/Fl_Menu.cxx
index 04d5291d8..5f3f89b32 100644
--- a/src/Fl_Menu.cxx
+++ b/src/Fl_Menu.cxx
@@ -53,6 +53,23 @@ int Fl_Menu_Item::size() const {
}
}
+// Advance a pointer to next visible or invisible item of a menu array,
+// skipping the contents of submenus.
+static const Fl_Menu_Item* next_visible_or_not(const Fl_Menu_Item* m) {
+ int nest = 0;
+ do {
+ if (!m->text) {
+ if (!nest) return m;
+ nest--;
+ } else if (m->flags&FL_SUBMENU) {
+ nest++;
+ }
+ m++;
+ }
+ while (nest);
+ return m;
+}
+
/**
Advance a pointer by n items through a menu array, skipping
the contents of submenus and invisible items. There are two calls so
@@ -61,17 +78,10 @@ int Fl_Menu_Item::size() const {
const Fl_Menu_Item* Fl_Menu_Item::next(int n) const {
if (n < 0) return 0; // this is so selected==-1 returns NULL
const Fl_Menu_Item* m = this;
- int nest = 0;
if (!m->visible()) n++;
- while (n>0) {
- if (!m->text) {
- if (!nest) return m;
- nest--;
- } else if (m->flags&FL_SUBMENU) {
- nest++;
- }
- m++;
- if (!nest && m->visible()) n--;
+ while (n) {
+ m = next_visible_or_not(m);
+ if (m->visible()) n--;
}
return m;
}
@@ -1002,9 +1012,9 @@ const Fl_Menu_Item* Fl_Menu_Item::popup(
\return found Fl_Menu_Item or NULL
*/
const Fl_Menu_Item* Fl_Menu_Item::find_shortcut(int* ip, const bool require_alt) const {
- const Fl_Menu_Item* m = first();
- if (m) for (int ii = 0; m->text; m = m->next(), ii++) {
- if (m->activevisible()) {
+ const Fl_Menu_Item* m = this;
+ if (m) for (int ii = 0; m->text; m = next_visible_or_not(m), ii++) {
+ if (m->active()) {
if (Fl::test_shortcut(m->shortcut_)
|| Fl_Widget::test_shortcut(m->text, require_alt)) {
if (ip) *ip=ii;
@@ -1026,10 +1036,10 @@ const Fl_Menu_Item* Fl_Menu_Item::find_shortcut(int* ip, const bool require_alt)
preceeded by '
*/
const Fl_Menu_Item* Fl_Menu_Item::test_shortcut() const {
- const Fl_Menu_Item* m = first();
+ const Fl_Menu_Item* m = this;
const Fl_Menu_Item* ret = 0;
- if (m) for (; m->text; m = m->next()) {
- if (m->activevisible()) {
+ if (m) for (; m->text; m = next_visible_or_not(m)) {
+ if (m->active()) {
// return immediately any match of an item in top level menu:
if (Fl::test_shortcut(m->shortcut_)) return m;
// if (Fl_Widget::test_shortcut(m->text)) return m;