changeset 1891:799e0de4d690

push/pop for List
author corvid <corvid@lavabit.com>
date Sat, 29 Jan 2011 06:24:08 +0000
parents 6b9486c3be92
children bc24273a26e4
files dw/fltkui.cc dw/fltkui.hh
diffstat 2 files changed, 35 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkui.cc	Sat Jan 29 05:33:49 2011 +0000
+++ b/dw/fltkui.cc	Sat Jan 29 06:24:08 2011 +0000
@@ -1042,6 +1042,8 @@
 // tree->clear_flag (SHORTCUT_LABEL);
    tree->callback(widgetCallback,this);
    tree->when(FL_WHEN_CHANGED);
+
+   currParent = tree->root();
    return tree;
 }
 
@@ -1058,27 +1060,49 @@
    }
 }
 
+void *FltkListResource::newItem (const char *str, bool enabled)
+{
+   Fl_Tree *tree = (Fl_Tree *) widget;
+   Fl_Tree_Item *parent = (Fl_Tree_Item *)currParent;
+   Fl_Tree_Item *item = tree->add(parent, str);
+
+   enabled &= parent->is_active();
+   item->activate(enabled);
+   itemsSelected.increase ();
+
+   return item;
+}
+
 void FltkListResource::addItem (const char *str, bool enabled, bool selected)
 {
    Fl_Tree *tree = (Fl_Tree *) widget;
-   Fl_Tree_Item *item = tree->add(tree->root(), str);
-   int index = itemsSelected.size ();
+   Fl_Tree_Item *item = (Fl_Tree_Item *) newItem(str, enabled);
 
-   item->activate(enabled);
-
-   itemsSelected.increase ();
-   itemsSelected.set (index,selected);
+   itemsSelected.set (itemsSelected.size() - 1, selected);
 
    if (selected) {
       if (mode == SELECTION_MULTIPLE)
          item->select(selected);
       else
-         ((Fl_Tree *)widget)->select_only(item, 0);
+         tree->select_only(item, 0);
    }
+   queueResize (true);
+}
 
+void FltkListResource::pushGroup (const char *name, bool enabled)
+{
+   currParent = (Fl_Tree_Item *) newItem(name, enabled);
    queueResize (true);
 }
 
+void FltkListResource::popGroup ()
+{
+   Fl_Tree_Item *p = (Fl_Tree_Item *)currParent;
+
+   if (p->parent())
+      currParent = p->parent();
+}
+
 int FltkListResource::getMaxItemWidth()
 {
    Fl_Tree *tree = (Fl_Tree *)widget;
--- a/dw/fltkui.hh	Sat Jan 29 05:33:49 2011 +0000
+++ b/dw/fltkui.hh	Sat Jan 29 06:24:08 2011 +0000
@@ -514,6 +514,8 @@
 
 private:
    static void widgetCallback (Fl_Widget *widget, void *data);
+   void *newItem (const char *str, bool enabled);
+   void *currParent;
    lout::misc::SimpleVector <bool> itemsSelected;
    int showRows;
    ListResource::SelectionMode mode;
@@ -524,8 +526,8 @@
    ~FltkListResource ();
 
    void addItem (const char *str, bool enabled, bool selected);
-   void pushGroup (const char *name, bool enabled) {};
-   void popGroup () {};
+   void pushGroup (const char *name, bool enabled);
+   void popGroup ();
 
    void sizeRequest (core::Requisition *requisition);
    bool isSelected (int index);