Tooltips hide by themselves after 12 seconds (STR #2584).

This commit is contained in:
Matthias Melcher 2019-02-02 23:56:45 +01:00
parent 0bf8197a24
commit 2be4d720ab
3 changed files with 33 additions and 4 deletions

View File

@ -18,6 +18,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2019
New Features and Extensions New Features and Extensions
- (add new items here) - (add new items here)
- Tooltips hide by themselves after 12 seconds (STR #2584).
- New member functions Fl_Paged_Device::begin_job() and begin_page() - New member functions Fl_Paged_Device::begin_job() and begin_page()
replace start_job() and start_page(). The start_... names are maintained replace start_job() and start_page(). The start_... names are maintained
for API compatibility. for API compatibility.

View File

@ -40,6 +40,10 @@ public:
static float delay() { return delay_; } static float delay() { return delay_; }
/** Sets the tooltip delay. The default delay is 1.0 seconds. */ /** Sets the tooltip delay. The default delay is 1.0 seconds. */
static void delay(float f) { delay_ = f; } 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. Gets the tooltip hover delay, the delay between tooltips.
The default delay is 0.2 seconds. The default delay is 0.2 seconds.
@ -105,6 +109,7 @@ private:
private: private:
static float delay_; //!< delay before a tooltip is shown 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 float hoverdelay_; //!< delay between tooltips
static Fl_Color color_; static Fl_Color color_;
static Fl_Color textcolor_; static Fl_Color textcolor_;

View File

@ -26,6 +26,7 @@
#include <string.h> // strdup() #include <string.h> // strdup()
float Fl_Tooltip::delay_ = 1.0f; float Fl_Tooltip::delay_ = 1.0f;
float Fl_Tooltip::hidedelay_ = 12.0f;
float Fl_Tooltip::hoverdelay_ = 0.2f; float Fl_Tooltip::hoverdelay_ = 0.2f;
Fl_Color Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1, Fl_Color Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1,
FL_NUM_GREEN - 1, FL_NUM_GREEN - 1,
@ -40,6 +41,8 @@ const int Fl_Tooltip::draw_symbols_ = 1;
static const char* tip; static const char* tip;
static void tooltip_hide_timeout(void*);
/** /**
This widget creates a tooltip box window, with no caption. This widget creates a tooltip box window, with no caption.
*/ */
@ -63,6 +66,7 @@ public:
int handle(int e) { int handle(int e) {
if (e == FL_PUSH || e == FL_KEYDOWN) { if (e == FL_PUSH || e == FL_KEYDOWN) {
hide(); hide();
Fl::remove_timeout(tooltip_hide_timeout);
return 1; return 1;
} }
return Fl_Menu_Window::handle(e); return Fl_Menu_Window::handle(e);
@ -139,6 +143,11 @@ static int top_win_iconified_() {
return !topwin->visible() ? 1 : 0; return !topwin->visible() ? 1 : 0;
} }
static void tooltip_hide_timeout(void*) {
if (window) window->hide();
recent_tooltip = 0;
}
static void tooltip_timeout(void*) { static void tooltip_timeout(void*) {
#ifdef DEBUG #ifdef DEBUG
puts("tooltip_timeout();"); 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 (!top_win_iconified_()) { // no tooltip if top win iconified (STR #3157)
if (!tip || !*tip) { if (!tip || !*tip) {
if (window) window->hide(); if (window) window->hide();
Fl::remove_timeout(tooltip_hide_timeout);
} else { } else {
int condition = 1; int condition = 1;
// bugfix: no need to refactor // bugfix: no need to refactor
@ -162,6 +172,7 @@ static void tooltip_timeout(void*) {
// printf("tooltip_timeout: Showing window %p with tooltip \"%s\"...\n", // printf("tooltip_timeout: Showing window %p with tooltip \"%s\"...\n",
// window, tip ? tip : "(null)"); // window, tip ? tip : "(null)");
window->show(); window->show();
Fl::add_timeout(Fl_Tooltip::hidedelay(), tooltip_hide_timeout);
} }
} }
} }
@ -238,7 +249,10 @@ void Fl_Tooltip::exit_(Fl_Widget *w) {
widget_ = 0; widget_ = 0;
Fl::remove_timeout(tooltip_timeout); Fl::remove_timeout(tooltip_timeout);
Fl::remove_timeout(recent_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 (recent_tooltip) {
if (Fl::event_state() & FL_BUTTONS) recent_tooltip = 0; if (Fl::event_state() & FL_BUTTONS) recent_tooltip = 0;
else Fl::add_timeout(Fl_Tooltip::hoverdelay(), recent_timeout); 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; widget_ = wid; currentTooltipY = y; currentTooltipH = h; tip = t;
// popup the tooltip immediately if it was recently up: // popup the tooltip immediately if it was recently up:
if (recent_tooltip) { 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); Fl::add_timeout(Fl_Tooltip::hoverdelay(), tooltip_timeout);
// possible fix for the Windows titlebar, it seems to want the // possible fix for the Windows titlebar, it seems to want the
// window to be destroyed, moving it messes up the parenting: // 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); tooltip_timeout(0);
} else { } 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); Fl::add_timeout(Fl_Tooltip::delay(), tooltip_timeout);
} }