X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Fpersistent_tooltip.cc;h=c7cb3f4df235b0d36f2be6b659927b4ad9cde4ff;hb=4b9e7386360746232dbdf2609b4e23ef02b0c5e9;hp=ae4c2e45c61407f8aa8b0a160971408143f451b5;hpb=7565ebd4ede96a001c271dc2e139d404526c116b;p=ardour.git diff --git a/libs/gtkmm2ext/persistent_tooltip.cc b/libs/gtkmm2ext/persistent_tooltip.cc index ae4c2e45c6..c7cb3f4df2 100644 --- a/libs/gtkmm2ext/persistent_tooltip.cc +++ b/libs/gtkmm2ext/persistent_tooltip.cc @@ -21,6 +21,8 @@ #include #include "gtkmm2ext/persistent_tooltip.h" +#include "pbd/stacktrace.h" + #include "i18n.h" using namespace std; @@ -28,11 +30,13 @@ using namespace Gtk; using namespace Gtkmm2ext; /** @param target The widget to provide the tooltip for */ -PersistentTooltip::PersistentTooltip (Gtk::Widget* target, int margin_y) +PersistentTooltip::PersistentTooltip (Gtk::Widget* target, bool draggable, int margin_y) : _target (target) , _window (0) , _label (0) + , _draggable (draggable) , _maybe_dragging (false) + , _align_to_center (true) , _margin_y (margin_y) { target->signal_enter_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::enter), false); @@ -66,8 +70,8 @@ PersistentTooltip::timeout () bool PersistentTooltip::leave (GdkEventCrossing *) { + _timeout.disconnect (); if (!dragging ()) { - _timeout.disconnect (); hide (); } @@ -97,7 +101,7 @@ PersistentTooltip::release (GdkEventButton* ev) bool PersistentTooltip::dragging () const { - return _maybe_dragging; + return _maybe_dragging && _draggable; } void @@ -114,6 +118,7 @@ PersistentTooltip::show () if (_tip.empty()) { return; } + if (!_window) { _window = new Window (WINDOW_POPUP); _window->set_name (X_("ContrastingPopup")); @@ -121,6 +126,7 @@ PersistentTooltip::show () _window->set_decorated (false); _label = manage (new Label); + _label->modify_font (_font); _label->set_use_markup (true); _window->set_border_width (6); @@ -132,23 +138,36 @@ PersistentTooltip::show () _window->set_transient_for (*tlw); } } - + set_tip (_tip); if (!_window->is_visible ()) { - int rx, ry, sw; - sw= gdk_screen_width(); + int rx, ry; + int sw = gdk_screen_width (); + _target->get_window()->get_origin (rx, ry); - _window->move (rx, ry + _target->get_height() + _margin_y); - _window->present (); /* the window needs to be realized first * for _window->get_width() to be correct. */ + + if (sw < rx + _window->get_width()) { + /* right edge of window would be off the right edge of + the screen, so don't show it in the usual place. + */ rx = sw - _window->get_width(); - _window->move (rx, ry + _target->get_height()); + _window->move (rx, ry + _target->get_height() + _margin_y); + } else { + if (_align_to_center) { + _window->move (rx + (_target->get_width () - _window->get_width ()) / 2, ry + _target->get_height()); + } else { + _window->move (rx, ry + _target->get_height()); + } } + + _window->present (); + } } @@ -161,3 +180,19 @@ PersistentTooltip::set_tip (string t) _label->set_markup (t); } } + +void +PersistentTooltip::set_font (Pango::FontDescription font) +{ + _font = font; + + if (_label) { + _label->modify_font (_font); + } +} + +void +PersistentTooltip::set_center_alignment (bool align_to_center) +{ + _align_to_center = align_to_center; +}