display and position canvas tooltip window
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 26 Sep 2014 15:05:24 +0000 (11:05 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 26 Sep 2014 15:05:24 +0000 (11:05 -0400)
libs/canvas/canvas.cc
libs/canvas/canvas/canvas.h

index c671ce253efc80e01dfa63216f940ff728eef6e3..9d35d1091c83bdcd07c0ae672dc76c5aab503b7a 100644 (file)
@@ -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<Gtk::Window*>(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;
 }
 
index a7da4517bbed6ce0b3b98b531f58f063d5aa11a9..77fc2d5f9249f4dd402e748cfdb93fb90ea60077 100644 (file)
 
 #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 ();