summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2010-12-02 17:58:58 +0000
committerGreg Ercolano <erco@seriss.com>2010-12-02 17:58:58 +0000
commita343f7555b23074237b08518c9dab7b51fe33777 (patch)
treed3d4931148aff5ccbf956e879d5d15a8b73e9b92 /src
parent3578d1d6f809a25d98d539963170de56c9b3dd16 (diff)
STR#2466: Added copy_tooltip().
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7940 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tooltip.cxx59
-rw-r--r--src/Fl_Widget.cxx1
2 files changed, 58 insertions, 2 deletions
diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx
index 4216f39c7..7239d8f46 100644
--- a/src/Fl_Tooltip.cxx
+++ b/src/Fl_Tooltip.cxx
@@ -30,6 +30,7 @@
#include <FL/Fl_Menu_Window.H>
#include <stdio.h>
+#include <string.h> // strdup()
float Fl_Tooltip::delay_ = 1.0f;
float Fl_Tooltip::hoverdelay_ = 0.2f;
@@ -275,14 +276,68 @@ void Fl_Tooltip::enter_area(Fl_Widget* wid, int x,int y,int w,int h, const char*
#endif // DEBUG
}
-void Fl_Widget::tooltip(const char *tt) {
+void Fl_Tooltip::set_enter_exit_once_() {
static char beenhere = 0;
if (!beenhere) {
beenhere = 1;
Fl_Tooltip::enter = Fl_Tooltip::enter_;
Fl_Tooltip::exit = Fl_Tooltip::exit_;
}
- tooltip_ = tt;
+}
+
+/**
+ Sets the current tooltip text.
+
+ Sets a string of text to display in a popup tooltip window when the user
+ hovers the mouse over the widget. The string is <I>not</I> copied, so
+ make sure any formatted string is stored in a static, global,
+ or allocated buffer. If you want a copy made and managed for you,
+ use the copy_tooltip() method, which will manage the tooltip string
+ automatically.
+
+ If no tooltip is set, the tooltip of the parent is inherited. Setting a
+ tooltip for a group and setting no tooltip for a child will show the
+ group's tooltip instead. To avoid this behavior, you can set the child's
+ tooltip to an empty string ("").
+ \param[in] text New tooltip text (no copy is made)
+ \see copy_tooltip(const char*), tooltip()
+*/
+void Fl_Widget::tooltip(const char *text) {
+ Fl_Tooltip::set_enter_exit_once_();
+ if (flags() & COPIED_TOOLTIP) {
+ // reassigning a copied tooltip remains the same copied tooltip
+ if (tooltip_ == text) return;
+ free((void*)(tooltip_)); // free maintained copy
+ clear_flag(COPIED_TOOLTIP); // disable copy flag (WE don't make copies)
+ }
+ tooltip_ = text;
+}
+
+/**
+ Sets the current tooltip text.
+ Unlike tooltip(), this method allocates a copy of the tooltip
+ string instead of using the original string pointer.
+
+ The internal copy will automatically be freed whenever you assign
+ a new tooltip or when the widget is destroyed.
+
+ If no tooltip is set, the tooltip of the parent is inherited. Setting a
+ tooltip for a group and setting no tooltip for a child will show the
+ group's tooltip instead. To avoid this behavior, you can set the child's
+ tooltip to an empty string ("").
+ \param[in] text New tooltip text (an internal copy is made and managed)
+ \see tooltip(const char*), tooltip()
+*/
+void Fl_Widget::copy_tooltip(const char *text) {
+ Fl_Tooltip::set_enter_exit_once_();
+ if (flags() & COPIED_TOOLTIP) free((void *)(tooltip_));
+ if (text) {
+ set_flag(COPIED_TOOLTIP);
+ tooltip_ = strdup(text);
+ } else {
+ clear_flag(COPIED_TOOLTIP);
+ tooltip_ = (char *)0;
+ }
}
//
diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx
index 000046179..7114421a6 100644
--- a/src/Fl_Widget.cxx
+++ b/src/Fl_Widget.cxx
@@ -168,6 +168,7 @@ extern void fl_throw_focus(Fl_Widget*); // in Fl_x.cxx
Fl_Widget::~Fl_Widget() {
Fl::clear_widget_pointer(this);
if (flags() & COPIED_LABEL) free((void *)(label_.value));
+ if (flags() & COPIED_TOOLTIP) free((void *)(tooltip_));
// remove from parent group
if (parent_) parent_->remove(this);
#ifdef DEBUG_DELETE