DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2010
Version: 2.0-feature


I'd like to be able to use dynamic tooltips, ie, change them on the fly
based on the data being shown (specially in an elided header in a
browser).

I added copy_tooltip in the same way that copy_label is implemented.

HOWEVER that means another flag() value is burned which could cause all
kinds of trouble.


Link: http://www.fltk.org/str.php?L2010
Version: 2.0-feature
Index: fltk/Widget.h
===================================================================
--- fltk/Widget.h       (revision 6147)
+++ fltk/Widget.h       (working copy)
@@ -99,7 +99,8 @@
   void image(const Symbol& a)  { image_ = &a; }
 
   const char *tooltip() const  { return tooltip_; }
-  void tooltip(const char *t)  { tooltip_ = t; }
+  void tooltip(const char* t);
+  void copy_tooltip(const char* t);
 
   unsigned shortcut() const    ;
   bool shortcut(unsigned key)  ;
Index: src/Widget.cxx
===================================================================
--- src/Widget.cxx      (revision 6147)
+++ src/Widget.cxx      (working copy)
@@ -99,6 +99,7 @@
     delete (Style*)style_; // cast away const
   }
   if (flags_&COPIED_LABEL) delete[] const_cast<char*>( label_ );
+  if (flags_&COPIED_TOOLTIP) delete[] const_cast<char*>( tooltip_ );
 }
 
 /*! \fn Group* Widget::parent() const
@@ -153,10 +154,10 @@
   label_ = s;
 }
 
-/*! Sets the label to a copy of the string.
+/*! Sets the tooltip to a copy of the string.
   The passed string is copied to private storage and used to set the
-  label(). The memory will be freed when the widget is destroyed or when
-  copy_label() is called again, or label(const char*) is called.
+  tooltip(). The memory will be freed when the widget is destroyed or when
+  copy_tooltip() is called again, or tooltip(const char*) is called.
 
   Passing NULL will set label() to NULL.
 */
@@ -167,14 +168,6 @@
   flags_ |= COPIED_LABEL;
 }
 
-/*! void Widget::image(Image*)
-  Sets the image. The image is drawn as part of the label, usually to
-  the left of the text. This is designed for icons on menu items. If
-  you want to replace the entire background of the widget with a picture
-  you should set box() instead. Notice that you can also get images into
-  labels by putting '@' commands into the label().
-*/
-
 /*! void Widget::tooltip(const char*)
   Set the string used as the pop-up tooltip. The pointer to the passed string
   is stored, it is not copied! Passing null indicates that the tooltip
@@ -185,7 +178,37 @@
   Putting '@' commands in to bring up Symbol objects will allow a lot
   of interesting things to be put into the tooltip.
 */
+void Widget::tooltip(const char* s) {
+  if (tooltip_ == s) return; // Avoid problems if label(label()) is called
+  if (flags_&COPIED_TOOLTIP) {
+    delete[] const_cast<char*>( tooltip_ );
+    flags_ &= ~COPIED_TOOLTIP;
+  }
+  tooltip_ = s;
+}
 
+/*! Sets the label to a copy of the string.
+  The passed string is copied to private storage and used to set the
+  label(). The memory will be freed when the widget is destroyed or when
+  copy_label() is called again, or label(const char*) is called.
+
+  Passing NULL will set label() to NULL.
+*/
+void Widget::copy_tooltip(const char* s) {
+  if (tooltip_ == s) return; // Avoid problems if label(label()) is called
+  if (flags_&COPIED_TOOLTIP) delete[] const_cast<char*>( tooltip_ );
+  tooltip_ = newstring(s);
+  flags_ |= COPIED_TOOLTIP;
+}
+
+/*! void Widget::image(Image*)
+  Sets the image. The image is drawn as part of the label, usually to
+  the left of the text. This is designed for icons on menu items. If
+  you want to replace the entire background of the widget with a picture
+  you should set box() instead. Notice that you can also get images into
+  labels by putting '@' commands into the label().
+*/
+
 /*! \fn void Widget::callback(fltk::Callback*, void*)
   Each widget has a single callback.  You can set it or examine it with
   these methods. The callback is called with the widget as the first
Index: fltk/Flags.h
===================================================================
--- fltk/Flags.h        (revision 6147)
+++ fltk/Flags.h        (working copy)
@@ -86,17 +86,18 @@
   INVISIBLE              = 0x00001000, //!< !visible(), draw_frame()
   HIGHLIGHT              = 0x00002000, //!< draw highlighted
   CHANGED                = 0x00004000, //!< value changed since last callback
-  COPIED_LABEL           = 0x00008000, //!< copy_label() was called
+  COPIED_LABEL   = 0x00008000, //!< copy_label() was called
   RAW_LABEL              = 0x00010000, //!< don't interpret & or @ in label
-  LAYOUT_VERTICAL        = 0x00020000, //!< fltk::Pack puts this widget 
vertical
-  TAB_TO_FOCUS           = 0x00040000, //!< Widget::tab_to_focus();
-  CLICK_TO_FOCUS         = 0x00080000, //!< Widget::click_to_focus()
-  INACTIVE_R             = 0x00100000, //!< draw it grayed-out
+  LAYOUT_VERTICAL = 0x00020000, //!< fltk::Pack puts this widget vertical
+  TAB_TO_FOCUS   = 0x00040000, //!< Widget::tab_to_focus();
+  CLICK_TO_FOCUS  = 0x00080000, //!< Widget::click_to_focus()
+  INACTIVE_R     = 0x00100000, //!< draw it grayed-out
   FOCUSED                = 0x00200000, //!< draw with keyboard focus
   PUSHED                 = 0x00400000, //!< draw pushed-in 
-  RESIZE_NONE            = 0,  //!< default behavior
-  RESIZE_FIT             = 0x01000000, //!< proportionnaly resize img in widget
-  RESIZE_FILL            = 0x00800000, //!< resize img to fill the widget
+  RESIZE_NONE    = 0,  //!< default behavior
+  RESIZE_FILL    = 0x00800000, //!< resize img to fill the widget
+  RESIZE_FIT     = 0x01000000, //!< proportionnaly resize img in widget
+  COPIED_TOOLTIP  = 0x02000000, //!< copy_tooltip() was called
   OPENED                 = STATE       //!< opened browser hierarchy parent
 };
 
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to