From 4586bf0fccc12328f6f876c527648f9260c406dc Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 9 Apr 2002 17:20:24 +0000 Subject: Tooltip fixes: ignore keyboard events, immediately disable new tooltips, show tooltips for box widgets. Add docos for Fl_Widget::tooltip() methods. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2060 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Box.cxx | 6 ++---- src/Fl_Group.cxx | 12 +++++++----- src/Fl_Tooltip.cxx | 51 +++++++++++++++++++++++++++++++++++++++++---------- src/Fl_Widget.cxx | 9 ++++++--- 4 files changed, 56 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Fl_Box.cxx b/src/Fl_Box.cxx index cde26f9ae..e8ab59998 100644 --- a/src/Fl_Box.cxx +++ b/src/Fl_Box.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Box.cxx,v 1.4.2.3.2.1 2002/01/01 15:11:29 easysw Exp $" +// "$Id: Fl_Box.cxx,v 1.4.2.3.2.2 2002/04/09 17:20:23 easysw Exp $" // // Box widget for the Fast Light Tool Kit (FLTK). // @@ -26,13 +26,11 @@ #include #include -// MRS - shouldn't we inline this? - void Fl_Box::draw() { draw_box(); draw_label(); } // -// End of "$Id: Fl_Box.cxx,v 1.4.2.3.2.1 2002/01/01 15:11:29 easysw Exp $". +// End of "$Id: Fl_Box.cxx,v 1.4.2.3.2.2 2002/04/09 17:20:23 easysw Exp $". // diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 85d4273ae..e65a45a9b 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Group.cxx,v 1.8.2.8.2.11 2002/02/24 17:52:17 matthiaswm Exp $" +// "$Id: Fl_Group.cxx,v 1.8.2.8.2.12 2002/04/09 17:20:23 easysw Exp $" // // Group widget for the Fast Light Tool Kit (FLTK). // @@ -28,6 +28,7 @@ // Fl_Window itself is a subclass of this, and most of the event // handling is designed so windows themselves work correctly. +#include #include #include #include @@ -158,10 +159,11 @@ int Fl_Group::handle(int event) { case FL_ENTER: Fl_Tooltip::enter(this); // tooltip + case FL_MOVE: for (i = children(); i--;) { o = a[i]; - if (o->takesevents() && Fl::event_inside(o)) { + if (o->visible() && Fl::event_inside(o)) { if (o->contains(Fl::belowmouse())) { return send(o,FL_MOVE); } else if (send(o,FL_ENTER)) { @@ -239,13 +241,13 @@ int Fl_Group::handle(int event) { default: // For all other events, try to give to each child, starting at focus: for (i = 0; i < children(); i ++) - if (Fl::focus_ == child(i)) break; + if (Fl::focus_ == a[i]) break; if (i >= children()) i = 0; if (children()) { for (int j = i;;) { - if (send(child(j), event)) return 1; + if (send(a[j], event)) return 1; j++; if (j >= children()) j = 0; if (j == i) break; @@ -585,5 +587,5 @@ void Fl_Group::draw_outside_label(const Fl_Widget& w) const { } // -// End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.11 2002/02/24 17:52:17 matthiaswm Exp $". +// End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.12 2002/04/09 17:20:23 easysw Exp $". // diff --git a/src/Fl_Tooltip.cxx b/src/Fl_Tooltip.cxx index f424516ed..0c35f2e33 100644 --- a/src/Fl_Tooltip.cxx +++ b/src/Fl_Tooltip.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Tooltip.cxx,v 1.38.2.10 2002/01/01 15:11:31 easysw Exp $" +// "$Id: Fl_Tooltip.cxx,v 1.38.2.11 2002/04/09 17:20:24 easysw Exp $" // // Tooltip source file for the Fast Light Tool Kit (FLTK). // @@ -38,8 +38,8 @@ void (*Fl_Tooltip::tooltip_callback_)(void *) = Fl_Tooltip::tooltip_timeout; void (*Fl_Tooltip::tooltip_exit_)(void *) = (void (*)(void *))Fl_Tooltip::tooltip_exit; float Fl_Tooltip::delay_ = 0.5; -Fl_TooltipBox *Fl_Tooltip::box = 0; -Fl_Menu_Window *Fl_Tooltip::window = 0; +Fl_Tooltip_Box *Fl_Tooltip::box = 0; +Fl_Tooltip_Window *Fl_Tooltip::window = 0; Fl_Widget *Fl_Tooltip::widget = 0; int Fl_Tooltip::shown = 0; unsigned Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1, @@ -49,21 +49,45 @@ int Fl_Tooltip::font_ = FL_HELVETICA; int Fl_Tooltip::size_ = FL_NORMAL_SIZE; +// +// 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) {} + + virtual FL_EXPORT int handle(int event); +}; + + +int +Fl_Tooltip_Window::handle(int event) { + if (event == FL_KEYDOWN || event == FL_KEYUP || event == FL_SHORTCUT) return 0; + else return Fl_Menu_Window::handle(event); +} + + // // Tooltip label class... // -class Fl_TooltipBox : public Fl_Box { +class Fl_Tooltip_Box : public Fl_Box { public: - Fl_TooltipBox() : Fl_Box(0,0,10,10) { + Fl_Tooltip_Box() : Fl_Box(0,0,10,10) { color(Fl_Tooltip::color_); align(FL_ALIGN_CENTER); box(FL_BORDER_BOX); Fl_Tooltip::widget = 0; } - ~Fl_TooltipBox() { } + ~Fl_Tooltip_Box() { } void draw() { tooltip(0); // Just in case @@ -110,6 +134,12 @@ public: // when the pointer enters them void Fl_Tooltip::enter(Fl_Widget *w) { +// 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()); +// } if ((!w || !w->tooltip()) && tooltip_callback_ && window) { Fl::remove_timeout(tooltip_callback_); window->hide(); @@ -118,7 +148,8 @@ Fl_Tooltip::enter(Fl_Widget *w) { } if (!tooltip_callback_ || !w || !w->tooltip()) return; Fl::remove_timeout(tooltip_callback_); - Fl::add_timeout(delay_, tooltip_callback_, w); + if (window && window->shown()) (*tooltip_callback_)(w); + else Fl::add_timeout(delay_, tooltip_callback_, w); } @@ -153,13 +184,13 @@ 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 = new Fl_Tooltip_Window(0, 0, 10, 10, 0); window->clear_border(); window->box(FL_NO_BOX); window->set_override(); window->begin(); - box = new Fl_TooltipBox; + box = new Fl_Tooltip_Box; box->color(FL_YELLOW); box->align(FL_ALIGN_CENTER); window->resizable(box); @@ -189,5 +220,5 @@ Fl_Tooltip::tooltip_timeout(void *v) { // -// End of "$Id: Fl_Tooltip.cxx,v 1.38.2.10 2002/01/01 15:11:31 easysw Exp $". +// End of "$Id: Fl_Tooltip.cxx,v 1.38.2.11 2002/04/09 17:20:24 easysw Exp $". // diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index aaa8ff69e..190018434 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.14 2002/01/07 20:40:02 easysw Exp $" +// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.15 2002/04/09 17:20:24 easysw Exp $" // // Base widget class for the Fast Light Tool Kit (FLTK). // @@ -68,7 +68,10 @@ Fl_Widget *Fl::readqueue() { //////////////////////////////////////////////////////////////// -int Fl_Widget::handle(int) {return 0;} +int Fl_Widget::handle(int event) { + if (event == FL_ENTER || event == FL_LEAVE) return 1; + else return 0; +} int FL_NORMAL_SIZE = 14; @@ -248,5 +251,5 @@ int Fl_Widget::contains(const Fl_Widget *o) const { } // -// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.14 2002/01/07 20:40:02 easysw Exp $". +// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.15 2002/04/09 17:20:24 easysw Exp $". // -- cgit v1.2.3