changeset 945:9f5c99b18c69

Get callbacks for multiple selections right (fixes 4d76ce512830).
author corvid <corvid@lavabit.com>
date Fri, 13 Feb 2009 18:16:50 -0300
parents ff7476f5317b
children f06d5c581f58
files dw/fltkui.cc
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkui.cc	Fri Feb 13 17:57:50 2009 -0300
+++ b/dw/fltkui.cc	Fri Feb 13 18:16:50 2009 -0300
@@ -1259,8 +1259,21 @@
    if (fltkItem)
       index = (long) (fltkItem->user_data ());
    if (index > -1) {
-      bool selected = fltkItem->selected ();
-      ((FltkListResource *) data)->itemsSelected.set (index, selected);
+      /* A MultiBrowser will trigger a callback for each item that is
+       * selected and each item that is deselected, but a "plain"
+       * Browser will only trigger the callback for the newly selected item
+       * (for which selected() is false, incidentally).
+       */
+      FltkListResource *res = (FltkListResource *) data;
+      if (res->mode == SELECTION_MULTIPLE) {
+         bool selected = fltkItem->selected ();
+         res->itemsSelected.set (index, selected);
+      } else {
+         int size = res->itemsSelected.size();
+         for (int i = 0; i < size; i++)
+            res->itemsSelected.set (i, false);
+         res->itemsSelected.set (index, true);
+      }
    }
 }