From 8f50b77e30502403708455e2313d5339f8922592 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Wed, 4 May 2016 15:56:06 +0200
Subject: [PATCH] make label clickable (the user has to ask for it, it's
 non-clickable by default)

---
 common/utils/T/tracer/gui/gui.h   |  4 ++++
 common/utils/T/tracer/gui/label.c | 34 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h
index 2561fe6d16..9d7f283ea1 100644
--- a/common/utils/T/tracer/gui/gui.h
+++ b/common/utils/T/tracer/gui/gui.h
@@ -26,6 +26,8 @@ widget *new_xy_plot(gui *gui, int width, int height, char *label,
     int vruler_width);
 widget *new_textlist(gui *_gui, int width, int nlines, int background_color);
 
+void label_set_clickable(gui *gui, widget *label, int clickable);
+
 void container_set_child_growable(gui *_gui, widget *_this,
     widget *child, int growable);
 
@@ -60,6 +62,8 @@ int new_color(gui *gui, char *color);
  *      - scrollup   { void *: NULL }
  *      - scrolldown { void *: NULL }
  *      - click      { int [2]: line, button }
+ * - label:
+ *      - click      { int: button } (if enabled)
  */
 
 /* same type as in gui_defs.h */
diff --git a/common/utils/T/tracer/gui/label.c b/common/utils/T/tracer/gui/label.c
index 35b4f7b667..80d885f1d2 100644
--- a/common/utils/T/tracer/gui/label.c
+++ b/common/utils/T/tracer/gui/label.c
@@ -44,3 +44,37 @@ widget *new_label(gui *_gui, const char *label)
 
   return w;
 }
+
+static void button(gui *gui, widget *_this, int x, int y, int button, int up)
+{
+  LOGD("BUTTON label %p xy %d %d button %d up %d\n", _this, x, y, button, up);
+
+  if (up != 0) return;
+
+  gui_notify(gui, "click", _this, &button);
+}
+
+/* we could use default_button, but it's in widget.c, so, well... */
+static void no_button(gui *gui, widget *_this, int x,int y,int button,int up)
+{
+  /* do nothing */
+}
+
+/*************************************************************************/
+/*                             public functions                          */
+/*************************************************************************/
+
+void label_set_clickable(gui *_g, widget *_this, int clickable)
+{
+  struct gui *g = _g;
+  struct label_widget *this = _this;
+
+  glock(g);
+
+  if (clickable)
+    this->common.button = button;
+  else
+    this->common.button = no_button;
+
+  gunlock(g);
+}
-- 
GitLab