2001-08-02 01:24:49 +04:00
|
|
|
//
|
2002-04-24 16:20:36 +04:00
|
|
|
// "$Id: Fl_Tooltip.cxx,v 1.38.2.14 2002/04/24 12:20:36 easysw Exp $"
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2001-08-02 01:24:49 +04:00
|
|
|
// Tooltip source file for the Fast Light Tool Kit (FLTK).
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
2002-01-01 18:11:33 +03:00
|
|
|
// Copyright 1998-2002 by Bill Spitzak and others.
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2001-08-02 01:24:49 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Menu_Window.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2001-08-02 19:32:00 +04:00
|
|
|
#include <FL/Fl_Tooltip.H>
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
#include <stdio.h>
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Fl_Tooltip global variables...
|
|
|
|
//
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-11-28 23:43:44 +03:00
|
|
|
void (*Fl_Tooltip::tooltip_callback_)(void *) = Fl_Tooltip::tooltip_timeout;
|
2001-11-28 23:48:49 +03:00
|
|
|
void (*Fl_Tooltip::tooltip_exit_)(void *) = (void (*)(void *))Fl_Tooltip::tooltip_exit;
|
2001-08-02 01:24:49 +04:00
|
|
|
float Fl_Tooltip::delay_ = 0.5;
|
2002-04-09 21:20:24 +04:00
|
|
|
Fl_Tooltip_Box *Fl_Tooltip::box = 0;
|
|
|
|
Fl_Tooltip_Window *Fl_Tooltip::window = 0;
|
2001-08-02 01:24:49 +04:00
|
|
|
Fl_Widget *Fl_Tooltip::widget = 0;
|
|
|
|
int Fl_Tooltip::shown = 0;
|
2001-10-29 06:44:33 +03:00
|
|
|
unsigned Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1,
|
2001-10-18 22:53:20 +04:00
|
|
|
FL_NUM_GREEN - 1,
|
|
|
|
FL_NUM_BLUE - 2);
|
2001-08-02 01:24:49 +04:00
|
|
|
int Fl_Tooltip::font_ = FL_HELVETICA;
|
|
|
|
int Fl_Tooltip::size_ = FL_NORMAL_SIZE;
|
|
|
|
|
|
|
|
|
2002-04-09 21:20:24 +04:00
|
|
|
//
|
|
|
|
// Tooltip window class...
|
|
|
|
//
|
|
|
|
|
|
|
|
class Fl_Tooltip_Window : public Fl_Menu_Window {
|
|
|
|
public:
|
|
|
|
|
|
|
|
FL_EXPORT ~Fl_Tooltip_Window() {}
|
|
|
|
Fl_Tooltip_Window(int W, int H, const char *l = 0)
|
|
|
|
: Fl_Menu_Window(W,H,l) {}
|
|
|
|
Fl_Tooltip_Window(int X, int Y, int W, int H, const char *l = 0)
|
|
|
|
: Fl_Menu_Window(X,Y,W,H,l) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|
|
|
|
// Tooltip label class...
|
|
|
|
//
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2002-04-09 21:20:24 +04:00
|
|
|
class Fl_Tooltip_Box : public Fl_Box {
|
2001-08-02 01:24:49 +04:00
|
|
|
public:
|
|
|
|
|
2002-04-09 21:20:24 +04:00
|
|
|
Fl_Tooltip_Box() : Fl_Box(0,0,10,10) {
|
2001-08-02 01:24:49 +04:00
|
|
|
color(Fl_Tooltip::color_);
|
|
|
|
align(FL_ALIGN_CENTER);
|
|
|
|
box(FL_BORDER_BOX);
|
|
|
|
Fl_Tooltip::widget = 0;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2002-04-09 21:20:24 +04:00
|
|
|
~Fl_Tooltip_Box() { }
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
void draw() {
|
|
|
|
tooltip(0); // Just in case
|
|
|
|
|
|
|
|
if (!Fl_Tooltip::widget || !Fl_Tooltip::widget->tooltip())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Fl_Window *widgetWindow = Fl_Tooltip::widget->window();
|
|
|
|
|
|
|
|
if (!widgetWindow) {
|
2001-08-02 19:32:00 +04:00
|
|
|
// printf("!widgetWindow\n");
|
2001-08-02 01:24:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ww, hh;
|
|
|
|
ww = 0;
|
|
|
|
|
|
|
|
labelfont(Fl_Tooltip::font_);
|
|
|
|
labelsize(Fl_Tooltip::size_);
|
|
|
|
color(Fl_Tooltip::color_);
|
|
|
|
|
|
|
|
fl_font(Fl_Tooltip::font_, Fl_Tooltip::size_);
|
|
|
|
|
|
|
|
fl_measure(Fl_Tooltip::widget->tooltip(), ww, hh);
|
|
|
|
label(Fl_Tooltip::widget->tooltip());
|
|
|
|
|
2001-10-18 22:53:20 +04:00
|
|
|
int ox = Fl::event_x_root() + 10;
|
|
|
|
int oy = Fl::event_y_root() + 10;
|
|
|
|
|
2001-11-17 21:20:09 +03:00
|
|
|
if (ox >= (Fl::w() - ww - 6))
|
2001-08-02 01:24:49 +04:00
|
|
|
ox = Fl::w() - ww - 6;
|
2001-11-17 21:20:09 +03:00
|
|
|
if (oy >= (Fl::h() - hh - 6))
|
2001-08-02 01:24:49 +04:00
|
|
|
oy = widgetWindow->y_root() + Fl_Tooltip::widget->y() - hh - 6;
|
|
|
|
|
|
|
|
parent()->resize(ox, oy, ww+6, hh+6);
|
|
|
|
|
|
|
|
draw_box();
|
|
|
|
draw_label();
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
2001-08-02 01:24:49 +04:00
|
|
|
};
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
// This function is called by widgets
|
|
|
|
// when the pointer enters them
|
|
|
|
void
|
|
|
|
Fl_Tooltip::enter(Fl_Widget *w) {
|
2002-04-09 21:20:24 +04:00
|
|
|
// printf("Fl_Tooltip::enter(%p)\n", w);
|
|
|
|
// if (w) {
|
|
|
|
// printf(" label() = \"%s\"\n", w->label() ? w->label() : "(null)");
|
|
|
|
// printf(" visible() = %d\n", w->visible());
|
|
|
|
// printf(" active() = %d\n", w->active());
|
|
|
|
// }
|
2002-04-14 06:43:48 +04:00
|
|
|
Fl_Widget* temp = w;
|
|
|
|
while (temp && !temp->tooltip()) {
|
|
|
|
if (temp == window) return; // Don't do anything if pointed at tooltip
|
|
|
|
temp = temp->parent();
|
|
|
|
}
|
|
|
|
|
2001-08-02 19:32:00 +04:00
|
|
|
if ((!w || !w->tooltip()) && tooltip_callback_ && window) {
|
2002-04-14 06:43:48 +04:00
|
|
|
// puts("Hiding tooltip...");
|
2001-08-02 19:32:00 +04:00
|
|
|
Fl::remove_timeout(tooltip_callback_);
|
|
|
|
window->hide();
|
|
|
|
shown = 0;
|
|
|
|
return;
|
|
|
|
}
|
2001-08-02 01:24:49 +04:00
|
|
|
if (!tooltip_callback_ || !w || !w->tooltip()) return;
|
2001-11-17 21:18:53 +03:00
|
|
|
Fl::remove_timeout(tooltip_callback_);
|
2002-04-09 21:20:24 +04:00
|
|
|
if (window && window->shown()) (*tooltip_callback_)(w);
|
|
|
|
else Fl::add_timeout(delay_, tooltip_callback_, w);
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
// This function must be called when
|
|
|
|
// an event != FL_MOVE has occured in
|
|
|
|
// the widget
|
|
|
|
void
|
|
|
|
Fl_Tooltip::exit(Fl_Widget *w) {
|
2001-11-18 23:52:28 +03:00
|
|
|
// printf("Fl_Tooltip::exit(%p)\n", w);
|
2001-08-02 19:32:00 +04:00
|
|
|
if (tooltip_exit_) tooltip_exit_(w);
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
void
|
|
|
|
Fl_Tooltip::tooltip_exit(Fl_Widget *w) {
|
2001-08-02 19:32:00 +04:00
|
|
|
// printf("Fl_Tooltip::tooltip_exit(%p), widget = %p, window = %p, shown = %d\n",
|
|
|
|
// w, widget, window, shown);
|
|
|
|
if (!w || w != widget) return;
|
|
|
|
|
|
|
|
Fl::remove_timeout(tooltip_callback_);
|
|
|
|
|
|
|
|
widget = 0;
|
|
|
|
|
|
|
|
if (window) {
|
2002-04-14 06:43:48 +04:00
|
|
|
// puts("Hiding tooltip...");
|
2001-08-02 01:24:49 +04:00
|
|
|
window->hide();
|
|
|
|
shown = 0;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
void
|
|
|
|
Fl_Tooltip::tooltip_timeout(void *v) {
|
2001-08-02 19:32:00 +04:00
|
|
|
// printf("Fl_Tooltip::tooltip_timeout(%p)\n", v);
|
2001-08-02 01:24:49 +04:00
|
|
|
if (!window) {
|
|
|
|
Fl_Group* saveCurrent = Fl_Group::current();
|
|
|
|
Fl_Group::current(0);
|
2002-04-09 21:20:24 +04:00
|
|
|
window = new Fl_Tooltip_Window(0, 0, 10, 10, 0);
|
2001-08-02 01:24:49 +04:00
|
|
|
window->clear_border();
|
|
|
|
window->box(FL_NO_BOX);
|
2001-10-18 22:53:20 +04:00
|
|
|
window->set_override();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
|
|
|
window->begin();
|
2002-04-09 21:20:24 +04:00
|
|
|
box = new Fl_Tooltip_Box;
|
2001-08-02 01:24:49 +04:00
|
|
|
box->color(FL_YELLOW);
|
|
|
|
box->align(FL_ALIGN_CENTER);
|
|
|
|
window->resizable(box);
|
|
|
|
window->end();
|
|
|
|
Fl_Group::current(saveCurrent);
|
2002-04-14 06:43:48 +04:00
|
|
|
|
|
|
|
// printf("Fl_Tooltip::window = %p\n", window);
|
|
|
|
// printf("Fl_Tooltip::box = %p\n", box);
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!v)
|
2001-08-02 01:24:49 +04:00
|
|
|
return;
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
if (shown && widget != (Fl_Widget *)v) {
|
|
|
|
tooltip_exit(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
widget = (Fl_Widget*) v;
|
|
|
|
Fl_Window *widgetWindow = widget->window();
|
2001-08-02 01:24:49 +04:00
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
if (widgetWindow) {
|
2002-04-14 06:43:48 +04:00
|
|
|
// puts("Showing tooltip");
|
2001-08-02 01:24:49 +04:00
|
|
|
window->show();
|
|
|
|
shown = 1;
|
|
|
|
} else {
|
|
|
|
widget = 0;
|
2001-08-02 01:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2002-04-24 16:20:36 +04:00
|
|
|
// End of "$Id: Fl_Tooltip.cxx,v 1.38.2.14 2002/04/24 12:20:36 easysw Exp $".
|
2001-08-02 01:24:49 +04:00
|
|
|
//
|