changeset 1346:7cdd8e4f8076

tooltip workaround for chars special to fltk
author corvid <corvid@lavabit.com>
date Sat, 10 Oct 2009 03:04:12 +0000
parents f45f1226f936
children 4704ad910042
files dw/fltkplatform.cc dw/fltkplatform.hh
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Sat Oct 10 00:38:01 2009 +0000
+++ b/dw/fltkplatform.cc	Sat Oct 10 03:04:12 2009 +0000
@@ -153,12 +153,34 @@
    if (!widget)
       widget = new ::fltk::InvisibleBox(1, 1, 0, 0, NULL);
    shown = false;
+
+   if (!text || !strpbrk(text, "&@")) {
+      escaped_str = NULL;
+   } else {
+      /*
+       * WORKAROUND: ::fltk::Tooltip::tooltip_timeout() makes instance_
+       * if necessary, and immediately uses it. This means that we can't
+       * get our hands on it to set RAW_LABEL until after it has been shown
+       * once. So let's escape the special characters ourselves.
+       */
+      const char *src = text;
+      char *dest = escaped_str = (char *) malloc(strlen(text) * 2 + 1);
+
+      while (*src) {
+         if (*src == '&' || *src == '@')
+            *dest++ = *src;
+         *dest++ = *src++;
+      }
+      *dest = '\0';
+   }
 }
 
 FltkTooltip::~FltkTooltip ()
 {
    if (shown)
       ::fltk::Tooltip::exit();
+   if (escaped_str)
+      free(escaped_str);
 }
 
 FltkTooltip *FltkTooltip::create (const char *text)
@@ -170,7 +192,7 @@
 {
    Rectangle rect;
    widget->get_absolute_rect(&rect);
-   ::fltk::Tooltip::enter(widget, rect, str);
+   ::fltk::Tooltip::enter(widget, rect, escaped_str ? escaped_str : str);
    shown = true;
 }
 
--- a/dw/fltkplatform.hh	Sat Oct 10 00:38:01 2009 +0000
+++ b/dw/fltkplatform.hh	Sat Oct 10 03:04:12 2009 +0000
@@ -49,6 +49,7 @@
    FltkTooltip (const char *text);
    ~FltkTooltip ();
    bool shown;
+   char *escaped_str; /* fltk WORKAROUND */
    static ::fltk::Widget *widget;
 public:
    static FltkTooltip *create(const char *text);