diff options
| author | Matthias Melcher <git@matthiasm.com> | 2019-02-02 23:56:45 +0100 |
|---|---|---|
| committer | Matthias Melcher <git@matthiasm.com> | 2019-02-02 23:56:45 +0100 |
| commit | 2be4d720ab2c97720a7ebb0a4c34581ed7df58fb (patch) | |
| tree | aa03da65f70dd6abee302f5717504b017a58878a | |
| parent | 0bf8197a24cb004f402de18e005d9f00819d958c (diff) | |
Tooltips hide by themselves after 12 seconds (STR #2584).
| -rw-r--r-- | CHANGES.txt | 1 | ||||
| -rw-r--r-- | FL/Fl_Tooltip.H | 5 | ||||
| -rw-r--r-- | src/Fl_Tooltip.cxx | 31 |
3 files changed, 33 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index a0b9ff814..f6cc68a23 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2019 New Features and Extensions - (add new items here) + - Tooltips hide by themselves after 12 seconds (STR #2584). - New member functions Fl_Paged_Device::begin_job() and begin_page() replace start_job() and start_page(). The start_... names are maintained for API compatibility. diff --git a/FL/Fl_Tooltip.H b/FL/Fl_Tooltip.H index 984eb8694..e25cf9e6c 100644 --- a/FL/Fl_Tooltip.H +++ b/FL/Fl_Tooltip.H @@ -40,6 +40,10 @@ public: static float delay() { return delay_; } /** Sets the tooltip delay. The default delay is 1.0 seconds. */ static void delay(float f) { delay_ = f; } + /** Gets the time unitl an open tooltip hides again. The default delay is 12.0 seconds. */ + static float hidedelay() { return hidedelay_; } + /** Sets the time unitl an open tooltip hides again. The default delay is 12.0 seconds. */ + static void hidedelay(float f) { hidedelay_ = f; } /** Gets the tooltip hover delay, the delay between tooltips. The default delay is 0.2 seconds. @@ -105,6 +109,7 @@ private: private: static float delay_; //!< delay before a tooltip is shown + static float hidedelay_; //!< delay until tooltip is closed again static float hoverdelay_; //!< delay between tooltips static Fl_Color color_; static Fl_Color textcolor_; diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx index b05e036f0..5d572ac72 100644 --- a/src/Fl_Tooltip.cxx +++ b/src/Fl_Tooltip.cxx @@ -26,6 +26,7 @@ #include <string.h> // strdup() float Fl_Tooltip::delay_ = 1.0f; +float Fl_Tooltip::hidedelay_ = 12.0f; float Fl_Tooltip::hoverdelay_ = 0.2f; Fl_Color Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1, FL_NUM_GREEN - 1, @@ -40,6 +41,8 @@ const int Fl_Tooltip::draw_symbols_ = 1; static const char* tip; +static void tooltip_hide_timeout(void*); + /** This widget creates a tooltip box window, with no caption. */ @@ -63,6 +66,7 @@ public: int handle(int e) { if (e == FL_PUSH || e == FL_KEYDOWN) { hide(); + Fl::remove_timeout(tooltip_hide_timeout); return 1; } return Fl_Menu_Window::handle(e); @@ -139,6 +143,11 @@ static int top_win_iconified_() { return !topwin->visible() ? 1 : 0; } +static void tooltip_hide_timeout(void*) { + if (window) window->hide(); + recent_tooltip = 0; +} + static void tooltip_timeout(void*) { #ifdef DEBUG puts("tooltip_timeout();"); @@ -149,6 +158,7 @@ static void tooltip_timeout(void*) { if (!top_win_iconified_()) { // no tooltip if top win iconified (STR #3157) if (!tip || !*tip) { if (window) window->hide(); + Fl::remove_timeout(tooltip_hide_timeout); } else { int condition = 1; // bugfix: no need to refactor @@ -162,6 +172,7 @@ static void tooltip_timeout(void*) { // printf("tooltip_timeout: Showing window %p with tooltip \"%s\"...\n", // window, tip ? tip : "(null)"); window->show(); + Fl::add_timeout(Fl_Tooltip::hidedelay(), tooltip_hide_timeout); } } } @@ -238,7 +249,10 @@ void Fl_Tooltip::exit_(Fl_Widget *w) { widget_ = 0; Fl::remove_timeout(tooltip_timeout); Fl::remove_timeout(recent_timeout); - if (window && window->visible()) window->hide(); + if (window && window->visible()) { + window->hide(); + Fl::remove_timeout(tooltip_hide_timeout); + } if (recent_tooltip) { if (Fl::event_state() & FL_BUTTONS) recent_tooltip = 0; else Fl::add_timeout(Fl_Tooltip::hoverdelay(), recent_timeout); @@ -284,14 +298,23 @@ void Fl_Tooltip::enter_area(Fl_Widget* wid, int x,int y,int w,int h, const char* widget_ = wid; currentTooltipY = y; currentTooltipH = h; tip = t; // popup the tooltip immediately if it was recently up: if (recent_tooltip) { - if (window) window->hide(); + if (window) { + window->hide(); + Fl::remove_timeout(tooltip_hide_timeout); + } Fl::add_timeout(Fl_Tooltip::hoverdelay(), tooltip_timeout); // possible fix for the Windows titlebar, it seems to want the // window to be destroyed, moving it messes up the parenting: - if (Fl::system_driver()->use_recent_tooltip_fix() && window && window->visible()) window->hide(); + if (Fl::system_driver()->use_recent_tooltip_fix() && window && window->visible()) { + window->hide(); + Fl::remove_timeout(tooltip_hide_timeout); + } tooltip_timeout(0); } else { - if (window && window->visible()) window->hide(); + if (window && window->visible()) { + window->hide(); + Fl::remove_timeout(tooltip_hide_timeout); + } Fl::add_timeout(Fl_Tooltip::delay(), tooltip_timeout); } |
