diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-09-25 21:43:15 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-09-25 21:43:15 -0400 |
commit | d0dafc171c75146e16081c263e92190570b88a0f (patch) | |
tree | b5fa97e74687ed11b0bb05e6d5ce0d4082d31574 /libs/canvas/canvas.cc | |
parent | 3ec0f367c10bcb4a6095e950bdc4575911231273 (diff) |
basic design of Canvas item tooltip mechanism.
No window yet to actually display the tooltip.
Diffstat (limited to 'libs/canvas/canvas.cc')
-rw-r--r-- | libs/canvas/canvas.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index b61afed751..c671ce253e 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -26,6 +26,7 @@ #include <cassert> #include <gtkmm/adjustment.h> #include <gtkmm/label.h> +#include <gtkmm/window.h> #include "pbd/compose.h" #include "pbd/stacktrace.h" @@ -345,6 +346,8 @@ GtkCanvas::GtkCanvas () , _new_current_item (0) , _grabbed_item (0) , _focused_item (0) + , current_tooltip_item (0) + , tooltip_window (0) { /* these are the events we want to know about */ add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::POINTER_MOTION_MASK | @@ -607,7 +610,9 @@ GtkCanvas::deliver_enter_leave (Duple const & point, int state) _new_current_item->Event ((GdkEvent*)&enter_event); } + start_tooltip_timeout (_new_current_item); _current_item = _new_current_item; + } @@ -689,6 +694,11 @@ GtkCanvas::item_going_away (Item* item, boost::optional<Rect> bounding_box) _focused_item = 0; } + if (current_tooltip_item) { + current_tooltip_item = 0; + stop_tooltip_timeout (); + } + ScrollGroup* sg = dynamic_cast<ScrollGroup*>(item); if (sg) { scrollers.remove (sg); @@ -834,6 +844,8 @@ GtkCanvas::get_mouse_position (Duple& winpos) const bool GtkCanvas::on_motion_notify_event (GdkEventMotion* ev) { + hide_tooltip (); + /* translate event coordinates from window to canvas */ GdkEvent copy = *((GdkEvent*)ev); @@ -974,6 +986,75 @@ GtkCanvas::height() const return get_allocation().get_height(); } +void +GtkCanvas::start_tooltip_timeout (Item* item) +{ + stop_tooltip_timeout (); + + if (item) { + current_tooltip_item = item; + + /* wait for the first idle that happens after this is + called. this means that we've stopped processing events, which + in turn implies that the user has stopped doing stuff for a + little while. + */ + + std::cerr << "wait for idle now that we're in " << item->name << std::endl; + + Glib::signal_idle().connect (sigc::mem_fun (*this, &GtkCanvas::really_start_tooltip_timeout)); + } +} + +bool +GtkCanvas::really_start_tooltip_timeout () +{ + /* an idle has occured since we entered a tooltip-bearing widget. Now + * wait 1 second and if the timeout isn't cancelled, show the tooltip. + */ + + std::cerr << "gone idle\n"; + + + if (current_tooltip_item) { + std::cerr << "have an item " << current_tooltip_item->name << " now wait 1second\n"; + _current_timeout_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &GtkCanvas::show_tooltip), 1000); + } + + return false; /* this is called from an idle callback, don't call it again */ +} + +void +GtkCanvas::stop_tooltip_timeout () +{ + if (current_tooltip_item) { + std::cerr << "Stop timeout for " << current_tooltip_item->name << "\n"; + } + current_tooltip_item = 0; + _current_timeout_connection.disconnect (); +} + +bool +GtkCanvas::show_tooltip () +{ + if (current_tooltip_item) { + std::cerr << "Would show a tooltip for " << current_tooltip_item->name << '\n'; + } else { + std::cerr << "tooltip timeout expired, but no item\n"; + } + + /* called from a timeout handler, don't call it again */ + return false; +} + +void +GtkCanvas::hide_tooltip () +{ + if (tooltip_window) { + tooltip_window->hide (); + } +} + /** Create a GtkCanvaSViewport. * @param hadj Adjustment to use for horizontal scrolling. * @param vadj Adjustment to use for vertica scrolling. |