DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

One very annoying feature in FLTK is that browsing menus with up and down
arrow keys do not wrap around. In most Windows and KDE applications
pressing down arrow key at the end of menu selects topmost menu item and
pressing up key at the top moves to last item. This does not seem to
happen in FLTK.

I'm not sure if this is intended behavior or just some kind of bug, but
what follows is some quick hacks with FLTK2 source code to enable menu
wrap around.

I made following modifications to Menu_popup.cxx (added or modified lines
marked with //##):

static bool forward(MenuState& p, int menu) {
  // go to next item in menu menu if possible
  MWindow &m = *(p.menus[menu]);
  for (int item = p.indexes[menu]+1; item < m.children; item++) {
    Widget* widget = m.get_widget(item);
    if (widget->takesevents()) return setitem(p, menu, item);
  }
  for (int item = 0; item < p.indexes[menu]; item++) { //##
    Widget* widget = m.get_widget(item); //##
    if (widget->takesevents()) return setitem(p, menu, item); //##
  } //##
  return false;
}

static bool backward(MenuState& p, int menu) {
  // previous item in menu menu if possible
  MWindow &m = *(p.menus[menu]);
  for (int item = p.indexes[menu]-1; item >= 0; item--) {
    Widget* widget = m.get_widget(item);
    if (widget->takesevents()) return setitem(p, menu, item);
  }
  for (int item = m.children-1; item > p.indexes[menu]; item--) { //##
    Widget* widget = m.get_widget(item); //##
    if (widget->takesevents()) return setitem(p, menu, item); //##
  } //##
  return false;
}

int MWindow::handle(int event) {
...
    case UpKey:
      if (p.hmenubar && p.level == 0) backward(p, 1); //##
      else if (backward(p, p.level));
      else if (p.hmenubar) setitem(p, 0, p.indexes[0]);
      return 1;
...
}

Initial tests with Windows XP SP2 and Mandriva Linux 2007/KDE (sorry, I
don't have Mac...) seem to work. So, what do you think?

    Mikko

Link: http://www.fltk.org/str.php?L1648
Version: 2.0-feature

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

Reply via email to