From bb68d83e438b710e5fb73d1302adb73c270f3617 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 26 Sep 2014 11:05:24 -0400 Subject: [PATCH] display and position canvas tooltip window --- libs/canvas/canvas.cc | 55 ++++++++++++++++++++++++++++--------- libs/canvas/canvas/canvas.h | 6 ++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/libs/canvas/canvas.cc b/libs/canvas/canvas.cc index c671ce253e..9d35d1091c 100644 --- a/libs/canvas/canvas.cc +++ b/libs/canvas/canvas.cc @@ -1000,8 +1000,6 @@ GtkCanvas::start_tooltip_timeout (Item* item) 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)); } } @@ -1013,11 +1011,7 @@ GtkCanvas::really_start_tooltip_timeout () * 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); } @@ -1027,9 +1021,6 @@ GtkCanvas::really_start_tooltip_timeout () 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 (); } @@ -1037,13 +1028,51 @@ GtkCanvas::stop_tooltip_timeout () 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"; + Rect tooltip_item_bbox; + + if (!current_tooltip_item || current_tooltip_item->tooltip().empty() || !current_tooltip_item->bounding_box()) { + return false; } + if (!tooltip_window) { + tooltip_window = new Gtk::Window (Gtk::WINDOW_POPUP); + tooltip_label = manage (new Gtk::Label); + tooltip_label->show (); + tooltip_window->add (*tooltip_label); + tooltip_window->set_border_width (6); + tooltip_window->set_name ("tooltip"); + } + + tooltip_label->set_text (current_tooltip_item->tooltip()); + + /* figure out where to position the tooltip */ + + Gtk::Widget* toplevel = get_toplevel(); + assert (toplevel); + int pointer_x, pointer_y; + Gdk::ModifierType mask; + + (void) toplevel->get_window()->get_pointer (pointer_x, pointer_y, mask); + + Duple tooltip_item_center (pointer_x, pointer_y); + + /* convert to root window coordinates */ + + int win_x, win_y; + dynamic_cast(toplevel)->get_position (win_x, win_y); + + tooltip_item_center = tooltip_item_center.translate (Duple (win_x, win_y)); + + /* move the tooltip window into position */ + + tooltip_window->move (tooltip_item_center.x, tooltip_item_center.y); + + /* ready to show */ + + tooltip_window->present (); + /* called from a timeout handler, don't call it again */ + return false; } diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h index a7da4517bb..77fc2d5f92 100644 --- a/libs/canvas/canvas/canvas.h +++ b/libs/canvas/canvas/canvas.h @@ -38,6 +38,11 @@ #include "canvas/root_group.h" +namespace Gtk { + class Window; + class Label; +} + namespace ArdourCanvas { struct Rect; @@ -215,6 +220,7 @@ private: sigc::connection _current_timeout_connection; Item* current_tooltip_item; Gtk::Window* tooltip_window; + Gtk::Label* tooltip_label; bool show_tooltip (); void hide_tooltip (); bool really_start_tooltip_timeout ();