From 69e2a15e311f93d024773284436fd7886071929f Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Fri, 29 Apr 2016 19:40:31 +0200
Subject: [PATCH] prepare container to deal with growable children

---
 common/utils/T/tracer/gui/container.c | 44 +++++++++++++++++++++++++++
 common/utils/T/tracer/gui/gui.h       |  3 ++
 common/utils/T/tracer/gui/gui_defs.h  |  2 ++
 3 files changed, 49 insertions(+)

diff --git a/common/utils/T/tracer/gui/container.c b/common/utils/T/tracer/gui/container.c
index 939f75bc55..97cac62066 100644
--- a/common/utils/T/tracer/gui/container.c
+++ b/common/utils/T/tracer/gui/container.c
@@ -2,6 +2,7 @@
 #include "gui_defs.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define MAX(a, b) ((a)>(b)?(a):(b))
 
@@ -19,6 +20,19 @@ printf("ADD_CHILD container\n");
   struct container_widget *this = _this;
   this->hints_are_valid = 0;
   widget_add_child_internal(g, this, child, position);
+
+  /* initially not growable */
+  this->growable = realloc(this->growable, (this->nchildren+1)*sizeof(int));
+  if (this->growable == NULL) abort();
+
+  if (position == -1) position = this->nchildren;
+
+  memmove(this->growable + position+1, this->growable + position,
+          (this->nchildren - position) * sizeof(int));
+
+  this->growable[position] = 0;
+
+  this->nchildren++;
 }
 
 static void compute_vertical_hints(struct gui *g,
@@ -246,3 +260,33 @@ widget *new_container(gui *_gui, int vertical)
 
   return w;
 }
+
+/*************************************************************************/
+/*                             public functions                          */
+/*************************************************************************/
+
+void container_set_child_growable(gui *_gui, widget *_this,
+    widget *child, int growable)
+{
+  gui *g = _gui;
+  struct container_widget *this = _this;
+  struct widget_list *lcur;
+  int i;
+
+  glock(g);
+
+  lcur = this->common.children;
+  i = 0;
+  while (lcur) {
+    if (lcur->item == child) break;
+    lcur = lcur->next;
+    i++;
+  }
+  if (lcur == NULL) ERR("%s:%d: child not found\n", __FILE__, __LINE__);
+
+  this->growable[i] = growable;
+
+  send_event(g, DIRTY, this->common.id);
+
+  gunlock(g);
+}
diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h
index c1bbbd7d06..b1440a20c4 100644
--- a/common/utils/T/tracer/gui/gui.h
+++ b/common/utils/T/tracer/gui/gui.h
@@ -24,6 +24,9 @@ widget *new_xy_plot(gui *gui, int width, int height, char *label,
     int vruler_width);
 widget *new_text_list(gui *_gui, int width, int nlines, int background_color);
 
+void container_set_child_growable(gui *_gui, widget *_this,
+    widget *child, int growable);
+
 void xy_plot_set_range(gui *gui, widget *this,
     float xmin, float xmax, float ymin, float ymax);
 void xy_plot_set_points(gui *gui, widget *this,
diff --git a/common/utils/T/tracer/gui/gui_defs.h b/common/utils/T/tracer/gui/gui_defs.h
index a80dc24798..58ae329467 100644
--- a/common/utils/T/tracer/gui/gui_defs.h
+++ b/common/utils/T/tracer/gui/gui_defs.h
@@ -69,6 +69,8 @@ struct container_widget {
   int hints_are_valid;     /* used to cache hints values */
   int hint_width;          /* cached hint values - invalid if */
   int hint_height;         /* repack_was_called == 1          */
+  int *growable;
+  int nchildren;
 };
 
 struct text_list_widget {
-- 
GitLab