From 624aba07ddb745b84ca253451cafb189e929210d Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Thu, 28 Apr 2016 14:54:14 +0200
Subject: [PATCH] new function text_list_del

---
 common/utils/T/tracer/gui/gui.h       |  1 +
 common/utils/T/tracer/gui/text_list.c | 28 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h
index 45acf8de3d..7646b0849e 100644
--- a/common/utils/T/tracer/gui/gui.h
+++ b/common/utils/T/tracer/gui/gui.h
@@ -27,6 +27,7 @@ void xy_plot_set_points(gui *gui, widget *this,
     int npoints, float *x, float *y);
 
 void text_list_add(gui *gui, widget *this, const char *text, int position);
+void text_list_del(gui *gui, widget *this, int position);
 
 void gui_loop(gui *gui);
 
diff --git a/common/utils/T/tracer/gui/text_list.c b/common/utils/T/tracer/gui/text_list.c
index 89b7e8822d..59de2809d7 100644
--- a/common/utils/T/tracer/gui/text_list.c
+++ b/common/utils/T/tracer/gui/text_list.c
@@ -93,3 +93,31 @@ void text_list_add(gui *_gui, widget *_this, const char *text, int position)
 
   gunlock(g);
 }
+
+void text_list_del(gui *_gui, widget *_this, int position)
+{
+  struct gui *g = _gui;
+  struct text_list_widget *this = _this;
+
+  glock(g);
+
+  /* TODO: useful check? */
+  if (this->text_count == 0) goto done;
+
+  if (position < 0) position = this->text_count;
+  if (position > this->text_count-1) position = this->text_count-1;
+
+  free(this->text[position]);
+
+  memmove(this->text + position, this->text + position + 1,
+          (this->text_count-1 - position) * sizeof(char *));
+
+  this->text_count--;
+  this->text = realloc(this->text, this->text_count * sizeof(char *));
+  if (this->text == NULL) OOM;
+
+  send_event(g, DIRTY, this->common.id);
+
+done:
+  gunlock(g);
+}
-- 
2.26.2