changeset 2015:025c664fa44f

forms menu/list selection
author corvid <corvid@lavabit.com>
date Sat, 14 May 2011 06:43:17 +0000
parents a1527f16dc76
children 8cf59505bd0a
files dw/fltkui.cc dw/fltkui.hh
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkui.cc	Fri May 13 14:34:31 2011 -0400
+++ b/dw/fltkui.cc	Sat May 14 06:43:17 2011 +0000
@@ -875,6 +875,7 @@
    menu = new Fl_Menu_Item[itemsAllocated];
    memset(menu, 0, itemsAllocated * sizeof(Fl_Menu_Item));
    itemsUsed = 1; // menu[0].text == NULL, which is an end-of-menu marker.
+   visibleItems = 0;
 
    init (platform);
 }
@@ -986,12 +987,11 @@
    Fl_Menu_Item *item = newItem();
 
    item->text = strdup(str);
+   item->argument(visibleItems++);
 
    if (enabled == false)
       item->flags = FL_MENU_INACTIVE;
 
-   // TODO: verify that an array index is exactly what value() wants,
-   // even when there are submenus.
    if (selected)
       ((Fl_Choice *)widget)->value(item);
 
@@ -1003,6 +1003,7 @@
    Fl_Menu_Item *item = newItem();
 
    item->text = strdup(name);
+   item->argument(visibleItems++);
 
    if (enabled == false)
       item->flags = FL_MENU_INACTIVE;
@@ -1021,7 +1022,7 @@
 
 bool FltkOptionMenuResource::isSelected (int index)
 {
-   return index == ((Fl_Choice *)widget)->value();
+   return index == (int) ((Fl_Choice *)widget)->mvalue()->user_data();
 }
 
 int FltkOptionMenuResource::getNumberOfItems()
@@ -1096,9 +1097,11 @@
    Fl_Tree *tree = (Fl_Tree *) widget;
    Fl_Tree_Item *parent = (Fl_Tree_Item *)currParent;
    Fl_Tree_Item *item = tree->add(parent, str);
+   int index = itemsSelected.size();
 
    enabled &= parent->is_active();
    item->activate(enabled);
+   item->user_data((void *)index);
    itemsSelected.increase ();
 
    return item;
@@ -1109,19 +1112,21 @@
    Fl_Tree *tree = (Fl_Tree *) widget;
    Fl_Tree_Item *item = (Fl_Tree_Item *) newItem(str, enabled);
 
-   itemsSelected.set (itemsSelected.size() - 1, selected);
-
    if (selected) {
-      if (mode == SELECTION_MULTIPLE)
+      if (mode == SELECTION_MULTIPLE) {
          item->select(selected);
-      else
-         tree->select_only(item, 0);
+         itemsSelected.set (itemsSelected.size() - 1, selected);
+      } else {
+         const bool do_callback = true;
+         tree->select_only(item, do_callback);
+      }
    }
    queueResize (true);
 }
 
 void FltkListResource::pushGroup (const char *name, bool enabled)
 {
+   /* TODO: make it impossible to select a group */
    currParent = (Fl_Tree_Item *) newItem(name, enabled);
    queueResize (true);
 }
--- a/dw/fltkui.hh	Fri May 13 14:34:31 2011 -0400
+++ b/dw/fltkui.hh	Sat May 14 06:43:17 2011 +0000
@@ -465,6 +465,7 @@
    Fl_Menu_Item *newItem();
    Fl_Menu_Item *menu;
    int itemsAllocated, itemsUsed;
+   int visibleItems; /* not counting the invisible ones that close a group */
 public:
    FltkOptionMenuResource (FltkPlatform *platform);
    ~FltkOptionMenuResource ();