summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2001-08-01 21:24:49 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2001-08-01 21:24:49 +0000
commitbd069130577e28b3b26dbb5637bb3172fe108e81 (patch)
treefcf77d8c891ad889902cc4f606b348374f2691bb /src
parent3cb5ebe0e811f3db008085d985b7761725589a74 (diff)
First bunch of changes for the 1.1 branch - tooltips.
NOTE: looking into a problem with the tooltip not going away when you ESCape a window (close it)... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1514 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl.cxx6
-rw-r--r--src/Fl_Button.cxx10
-rw-r--r--src/Fl_Group.cxx22
-rw-r--r--src/Fl_Tooltip.cxx241
-rw-r--r--src/Makefile5
5 files changed, 163 insertions, 121 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx
index 0837daff3..b973d1748 100644
--- a/src/Fl.cxx
+++ b/src/Fl.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl.cxx,v 1.24.2.41 2001/02/26 00:19:02 spitzak Exp $"
+// "$Id: Fl.cxx,v 1.24.2.41.2.1 2001/08/01 21:24:49 easysw Exp $"
//
// Main event handling code for the Fast Light Tool Kit (FLTK).
//
@@ -605,6 +605,8 @@ int Fl::handle(int event, Fl_Window* window)
void Fl_Window::hide() {
clear_visible();
+ Fl_Tooltip::exit(this);
+
if (!shown()) return;
// remove from the list of windows:
@@ -780,5 +782,5 @@ void Fl_Window::flush() {
}
//
-// End of "$Id: Fl.cxx,v 1.24.2.41 2001/02/26 00:19:02 spitzak Exp $".
+// End of "$Id: Fl.cxx,v 1.24.2.41.2.1 2001/08/01 21:24:49 easysw Exp $".
//
diff --git a/src/Fl_Button.cxx b/src/Fl_Button.cxx
index 34320b7ba..50934aaee 100644
--- a/src/Fl_Button.cxx
+++ b/src/Fl_Button.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Button.cxx,v 1.4.2.6 2001/01/22 15:13:39 easysw Exp $"
+// "$Id: Fl_Button.cxx,v 1.4.2.6.2.1 2001/08/01 21:24:49 easysw Exp $"
//
// Button widget for the Fast Light Tool Kit (FLTK).
//
@@ -26,6 +26,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Group.H>
+#include <FL/Fl_Tooltip.H> // tooltip
// There are a lot of subclasses, named Fl_*_Button. Some of
// them are implemented by setting the type() value and testing it
@@ -60,11 +61,15 @@ int Fl_Button::handle(int event) {
int newval;
switch (event) {
case FL_ENTER:
+ Fl_Tooltip::enter(this); // tooltip
+ return 1; // tooltip
case FL_LEAVE:
// if ((value_?selection_color():color())==FL_GRAY) redraw();
+ Fl_Tooltip::exit(this); // tooltip
return 1;
case FL_PUSH:
case FL_DRAG:
+ Fl_Tooltip::exit(this); // tooltip
if (Fl::event_inside(this)) {
if (type() == FL_RADIO_BUTTON) newval = 1;
else newval = !oldval;
@@ -77,6 +82,7 @@ int Fl_Button::handle(int event) {
}
return 1;
case FL_RELEASE:
+ Fl_Tooltip::exit(this); // tooltip
if (value_ == oldval) {
if (when() & FL_WHEN_NOT_CHANGED) do_callback();
return 1;
@@ -118,5 +124,5 @@ Fl_Button::Fl_Button(int x,int y,int w,int h, const char *l)
}
//
-// End of "$Id: Fl_Button.cxx,v 1.4.2.6 2001/01/22 15:13:39 easysw Exp $".
+// End of "$Id: Fl_Button.cxx,v 1.4.2.6.2.1 2001/08/01 21:24:49 easysw Exp $".
//
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx
index 19e65b8ec..2b371da36 100644
--- a/src/Fl_Group.cxx
+++ b/src/Fl_Group.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Group.cxx,v 1.8.2.8 2001/01/22 15:13:39 easysw Exp $"
+// "$Id: Fl_Group.cxx,v 1.8.2.8.2.1 2001/08/01 21:24:49 easysw Exp $"
//
// Group widget for the Fast Light Tool Kit (FLTK).
//
@@ -33,6 +33,7 @@
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
#include <stdlib.h>
+#include <FL/Fl_Tooltip.H> // tooltip
Fl_Group* Fl_Group::current_;
@@ -120,9 +121,11 @@ int Fl_Group::handle(int event) {
return 0;
case FL_KEYBOARD:
+ Fl_Tooltip::exit(this); // tooltip
return navigation(navkey());
case FL_SHORTCUT:
+ Fl_Tooltip::exit(this); // tooltip
for (i = children(); i--;) {
o = a[i];
if (o->takesevents() && Fl::event_inside(o) && send(o,FL_SHORTCUT))
@@ -137,6 +140,7 @@ int Fl_Group::handle(int event) {
return 0;
case FL_ENTER:
+ Fl_Tooltip::enter(this); // tooltip
case FL_MOVE:
for (i = children(); i--;) {
o = a[i];
@@ -153,6 +157,7 @@ int Fl_Group::handle(int event) {
return 1;
case FL_PUSH:
+ Fl_Tooltip::exit(this); // tooltip
for (i = children(); i--;) {
o = a[i];
if (o->takesevents() && Fl::event_inside(o)) {
@@ -180,6 +185,9 @@ int Fl_Group::handle(int event) {
}
return 1;
+ case FL_LEAVE: // tooltip
+ Fl_Tooltip::exit(this); // tooltip
+
default:
return 0;
@@ -270,12 +278,18 @@ void Fl_Group::clear() {
for (int i=old_children; i--;) {
Fl_Widget* o = *a++;
// test the parent to see if child already destructed:
- if (o->parent() == this) delete o;
+ if (o->parent() == this) {
+ Fl_Tooltip::exit(o);
+ delete o;
+ }
}
if (old_children > 1) free((void*)old_array);
}
-Fl_Group::~Fl_Group() {clear();}
+Fl_Group::~Fl_Group() {
+ Fl_Tooltip::exit(this);
+ clear();
+}
void Fl_Group::insert(Fl_Widget &o, int index) {
if (o.parent()) {
@@ -513,5 +527,5 @@ void Fl_Group::draw_outside_label(const Fl_Widget& w) const {
}
//
-// End of "$Id: Fl_Group.cxx,v 1.8.2.8 2001/01/22 15:13:39 easysw Exp $".
+// End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.1 2001/08/01 21:24:49 easysw Exp $".
//
diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx
index e963424ad..a2c05b07a 100644
--- a/src/Fl_Tooltip.cxx
+++ b/src/Fl_Tooltip.cxx
@@ -1,9 +1,9 @@
//
-// "$Id: Fl_Tooltip.cxx,v 1.38 2001/07/23 09:50:05 spitzak Exp $"
+// "$Id: Fl_Tooltip.cxx,v 1.38.2.1 2001/08/01 21:24:49 easysw Exp $"
//
-// Tooltip code for the Fast Light Tool Kit (FLTK).
+// Tooltip source file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-1999 by Bill Spitzak and others.
+// Copyright 1998-2001 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@@ -20,138 +20,157 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
-// Please report all bugs and problems to "fltk-bugs@easysw.com".
+// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
-#include <fltk/Fl_Tooltip.h>
-#include <fltk/fl_draw.h>
-#include <fltk/Fl_Menu_Window.h>
+#include <FL/Fl.H>
+#include <FL/Fl_Menu_Window.H>
+#include <FL/Fl_Box.H>
+#include <FL/fl_draw.H>
-float Fl_Tooltip::delay_ = 0.5f;
-int Fl_Tooltip::enabled_ = 1;
+#include <stdio.h>
-#define MAX_WIDTH 400
+//
+// Fl_Tooltip global variables...
+//
-class Fl_TooltipBox : public Fl_Menu_Window {
-public:
- Fl_TooltipBox() : Fl_Menu_Window(0, 0, 0, 0) {
- style(Fl_Tooltip::default_style);}
- void draw();
- void layout();
-};
+void (*Fl_Tooltip::tooltip_callback_)(void *) = 0;
+void (*Fl_Tooltip::tooltip_exit_)(void *) = 0;
+float Fl_Tooltip::delay_ = 0.5;
+Fl_TooltipBox *Fl_Tooltip::box = 0;
+Fl_Menu_Window *Fl_Tooltip::window = 0;
+Fl_Widget *Fl_Tooltip::widget = 0;
+int Fl_Tooltip::shown = 0;
+uchar Fl_Tooltip::color_ = FL_YELLOW;
+int Fl_Tooltip::font_ = FL_HELVETICA;
+int Fl_Tooltip::size_ = FL_NORMAL_SIZE;
+
+
+//
+// Tooltip label class...
+//
-static const char* tip;
-static Fl_Widget* widget;
-static Fl_TooltipBox *window = 0;
-static int X,Y,W,H;
-
-void Fl_TooltipBox::layout() {
- fl_font(label_font(), label_size());
- int ww, hh;
- ww = MAX_WIDTH;
- fl_measure(tip, ww, hh, FL_ALIGN_LEFT|FL_ALIGN_WRAP|FL_ALIGN_INSIDE);
- ww += 6; hh += 6;
-
- // find position on the screen of the widget:
- int ox = Fl::event_x_root()+5;
- //int ox = X+W/2;
- int oy = Y + H+2;
- for (Fl_Widget* p = widget; p; p = p->parent()) {
- //ox += p->x();
- oy += p->y();
+class Fl_TooltipBox : public Fl_Box {
+public:
+
+ Fl_TooltipBox() : Fl_Box(0,0,10,10) {
+ color(Fl_Tooltip::color_);
+ align(FL_ALIGN_CENTER);
+ box(FL_BORDER_BOX);
+ Fl_Tooltip::widget = 0;
}
- if (ox+ww > Fl::w()) ox = Fl::w() - ww;
- if (ox < 0) ox = 0;
- if (H > 30) {
- oy = Fl::event_y_root()+13;
- if (oy+hh > Fl::h()) oy -= 23+hh;
- } else {
- if (oy+hh > Fl::h()) oy -= (4+hh+H);
+
+ ~Fl_TooltipBox() { }
+
+ 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) {
+ printf("!widgetWindow\n");
+ 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());
+
+ int ox =
+ widgetWindow->x_root() + Fl_Tooltip::widget->x() + Fl_Tooltip::widget->w()/2;
+ int oy =
+ widgetWindow->y_root() + Fl_Tooltip::widget->y() + Fl_Tooltip::widget->h() + 10;
+
+ if (ox >= Fl::w())
+ ox = Fl::w() - ww - 6;
+ if (oy >= Fl::h())
+ oy = widgetWindow->y_root() + Fl_Tooltip::widget->y() - hh - 6;
+
+ parent()->resize(ox, oy, ww+6, hh+6);
+
+ draw_box();
+ draw_label();
}
- if (oy < 0) oy = 0;
+};
- resize(ox, oy, ww, hh);
- Fl_Menu_Window::layout();
-}
-void Fl_TooltipBox::draw() {
- draw_box();
- draw_label(3, 3, w()-6, h()-6, FL_ALIGN_LEFT|FL_ALIGN_WRAP|FL_ALIGN_INSIDE);
+// This function is called by widgets
+// when the pointer enters them
+void
+Fl_Tooltip::enter(Fl_Widget *w) {
+ if (!tooltip_callback_ || !w || !w->tooltip()) return;
+ Fl::add_timeout(delay_, tooltip_callback_, w);
}
-static void tooltip_timeout(void*) {
- if (Fl::grab()) return;
-
- if (window) delete window;
- Fl_Group* saveCurrent = Fl_Group::current();
- Fl_Group::current(0);
- window = new Fl_TooltipBox;
- window->set_override();
- window->end();
- Fl_Group::current(saveCurrent);
-
- // this cast bypasses the normal Fl_Window label() code:
- ((Fl_Widget*)window)->label(tip);
- window->relayout();
- window->show();
+// This function must be called when
+// an event != FL_MOVE has occured in
+// the widget
+void
+Fl_Tooltip::exit(Fl_Widget *w) {
+ if (tooltip_exit_ && w && w->tooltip()) tooltip_exit_(w);
}
-static int cheesy_flag = 0;
-
-static void
-tt_exit(Fl_Widget *w) {
- if (!w || w != widget) return;
- widget = 0;
- Fl::remove_timeout((Fl_Timeout_Handler)tooltip_timeout);
- if (window) {
- // This flag makes sure that tootip_enter() isn't executed because of
- // this destroy() which could cause unwanted recursion in tooltip_enter()
- cheesy_flag = 1;
- window->destroy();
- cheesy_flag = 0;
+void
+Fl_Tooltip::tooltip_exit(Fl_Widget *w) {
+ Fl::remove_timeout(tooltip_callback_, w);
+ if ((w == widget || (widget && w == widget->window())) && shown && window) {
+ widget = 0;
+ window->hide();
+ shown = 0;
}
}
-static void
-tt_enter_area(Fl_Widget* w, int X, int Y, int W, int H, const char* t) {
- if (cheesy_flag) return;
- if (w == widget && X == ::X && Y == ::Y && W == ::W && H == ::H && t == tip)
+void
+Fl_Tooltip::tooltip_timeout(void *v) {
+ if (!window) {
+ Fl_Group* saveCurrent = Fl_Group::current();
+ Fl_Group::current(0);
+ window = new Fl_Menu_Window(0, 0, 10, 10, 0);
+ window->clear_border();
+ window->box(FL_NO_BOX);
+
+ window->begin();
+ box = new Fl_TooltipBox;
+ box->color(FL_YELLOW);
+ box->align(FL_ALIGN_CENTER);
+ window->resizable(box);
+ window->end();
+ Fl_Group::current(saveCurrent);
+ }
+
+ if (!v)
return;
- tt_exit(widget);
- widget = w; ::X = X; ::Y = Y; ::W = W; ::H = H; tip = t;
- if (!t || !Fl_Tooltip::enabled()) return;
- float d = Fl_Tooltip::delay();
- if (d < .01f) d = .01f;
- Fl::add_timeout(d, (Fl_Timeout_Handler)tooltip_timeout);
-}
-static void
-tt_enter(Fl_Widget* w) {
- if (cheesy_flag || w == widget) return;
- if (!w || w == window) { tt_exit(widget); widget = 0; return; }
- tt_enter_area(w, 0, 0, w->w(), w->h(), w->tooltip());
-}
+ if (shown && widget != (Fl_Widget *)v) {
+ tooltip_exit(widget);
+ }
+
+ widget = (Fl_Widget*) v;
+ Fl_Window *widgetWindow = widget->window();
-void Fl_Widget::tooltip(const char *tt) {
- static int do_once = 0;
- if (!do_once) {
- do_once = 1;
- Fl_Tooltip::enter = tt_enter;
- Fl_Tooltip::enter_area = tt_enter_area;
- Fl_Tooltip::exit = tt_exit;
+ if (widgetWindow) {
+ Fl::grab(*widgetWindow);
+ window->show();
+ Fl::release();
+ shown = 1;
+ } else {
+ widget = 0;
}
- tooltip_ = tt;
}
-static void revert(Fl_Style* s) {
- s->box = FL_BORDER_BOX;
- s->color = (Fl_Color)215;
- s->label_color = FL_BLACK;
-}
-static Fl_Named_Style style("Tooltip", revert, &Fl_Tooltip::default_style);
-Fl_Named_Style* Fl_Tooltip::default_style = &::style;
//
-// End of "$Id: Fl_Tooltip.cxx,v 1.38 2001/07/23 09:50:05 spitzak Exp $".
+// End of "$Id: Fl_Tooltip.cxx,v 1.38.2.1 2001/08/01 21:24:49 easysw Exp $".
//
diff --git a/src/Makefile b/src/Makefile
index f667b8430..4c6349e04 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
#
-# "$Id: Makefile,v 1.18.2.14 2001/01/22 15:13:40 easysw Exp $"
+# "$Id: Makefile,v 1.18.2.14.2.1 2001/08/01 21:24:49 easysw Exp $"
#
# Library makefile for the Fast Light Tool Kit (FLTK).
#
@@ -71,6 +71,7 @@ CPPFILES = \
Fl_Slider.cxx \
Fl_Tabs.cxx \
Fl_Tile.cxx \
+ Fl_Tooltip.cxx \
Fl_Valuator.cxx \
Fl_Value_Input.cxx \
Fl_Value_Output.cxx \
@@ -207,5 +208,5 @@ install: $(LIBRARY) $(DSONAME)
ln -s FL $(includedir)/Fl
#
-# End of "$Id: Makefile,v 1.18.2.14 2001/01/22 15:13:40 easysw Exp $".
+# End of "$Id: Makefile,v 1.18.2.14.2.1 2001/08/01 21:24:49 easysw Exp $".
#