changeset 2066:5660c1916c58

Reintroduce @-escaping for tooltips. I don't know what case I managed to test where I thought it was unnecessary with 1.3. I do know that '&' has not been a problem...
author corvid <corvid@lavabit.com>
date Mon, 30 May 2011 13:22:57 +0000
parents f5114f4659b6
children e39acde40d0c
files dw/fltkplatform.cc dw/fltkplatform.hh
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Mon May 30 04:26:35 2011 +0000
+++ b/dw/fltkplatform.cc	Mon May 30 13:22:57 2011 +0000
@@ -191,10 +191,26 @@
 
 FltkTooltip::FltkTooltip (const char *text) : Tooltip(text)
 {
+   if (!strchr(text, '@')) {
+      escaped_str = NULL;
+   } else {
+      /* FLTK likes to interpret symbols, and so they must be escaped */
+      const char *src = text;
+      char *dest = escaped_str = (char *) malloc(strlen(text) * 2 + 1);
+
+      while (*src) {
+         if (*src == '@')
+            *dest++ = *src;
+         *dest++ = *src++;
+      }
+      *dest = '\0';
+   }
 }
 
 FltkTooltip::~FltkTooltip ()
 {
+   if (escaped_str)
+      free(escaped_str);
 }
 
 FltkTooltip *FltkTooltip::create (const char *text)
@@ -207,7 +223,7 @@
    Fl_Widget *widget = Fl::belowmouse();
 
    Fl_Tooltip::enter_area(widget, widget->x(), widget->y(), widget->w(),
-                          widget->h(), str);
+                          widget->h(), escaped_str ? escaped_str : str);
 }
 
 void FltkTooltip::onLeave()
--- a/dw/fltkplatform.hh	Mon May 30 04:26:35 2011 +0000
+++ b/dw/fltkplatform.hh	Mon May 30 13:22:57 2011 +0000
@@ -59,6 +59,7 @@
 private:
    FltkTooltip (const char *text);
    ~FltkTooltip ();
+   char *escaped_str;
 public:
    static FltkTooltip *create(const char *text);
    void onEnter();