summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2012-06-11 21:21:10 +0000
committerCarl Hetherington <carl@carlh.net>2012-06-11 21:21:10 +0000
commitf4ed14a83b3dfc0af9b92db5f73f3389c7773a04 (patch)
tree567975a635ed74a761df1452054cf4d41caad286 /libs
parent366b7ac36baecba48e59e9d96f8b2fd27633957b (diff)
Factor out 'persistent' tooltip code from the panner
interface and use it for processor box sliders (#4461). git-svn-id: svn://localhost/ardour2/branches/3.0@12661 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/persistent_tooltip.h67
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/utils.h2
-rw-r--r--libs/gtkmm2ext/persistent_tooltip.cc148
-rw-r--r--libs/gtkmm2ext/utils.cc19
-rw-r--r--libs/gtkmm2ext/wscript1
5 files changed, 237 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/persistent_tooltip.h b/libs/gtkmm2ext/gtkmm2ext/persistent_tooltip.h
new file mode 100644
index 0000000000..edd1e199e4
--- /dev/null
+++ b/libs/gtkmm2ext/gtkmm2ext/persistent_tooltip.h
@@ -0,0 +1,67 @@
+/*
+ Copyright (C) 2012 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef gtkmm2ext_persistent_tooltip_h
+#define gtkmm2ext_persistent_tooltip_h
+
+#include <sigc++/trackable.h>
+
+namespace Gtkmm2ext {
+
+/** A class which offers a tooltip-like window which can be made to
+ * stay open during a drag.
+ */
+class PersistentTooltip : public sigc::trackable
+{
+public:
+ PersistentTooltip (Gtk::Widget *);
+ virtual ~PersistentTooltip ();
+
+ void set_tip (std::string);
+
+ virtual bool dragging () const;
+
+private:
+ bool timeout ();
+ void show ();
+ void hide ();
+ bool enter (GdkEventCrossing *);
+ bool leave (GdkEventCrossing *);
+ bool press (GdkEventButton *);
+ bool release (GdkEventButton *);
+
+ /** The widget that we are providing a tooltip for */
+ Gtk::Widget* _target;
+ /** Our window */
+ Gtk::Window* _window;
+ /** Our label */
+ Gtk::Label* _label;
+ /** true if we are `dragging', in the sense that button 1
+ is being held over _target.
+ */
+ bool _maybe_dragging;
+ /** Connection to a timeout used to open the tooltip */
+ sigc::connection _timeout;
+ /** The tip text */
+ std::string _tip;
+};
+
+}
+
+#endif
diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h
index b7e27ea351..c4c9a4125c 100644
--- a/libs/gtkmm2ext/gtkmm2ext/utils.h
+++ b/libs/gtkmm2ext/gtkmm2ext/utils.h
@@ -108,6 +108,8 @@ namespace Gtkmm2ext {
void rounded_bottom_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
Gtk::Label* left_aligned_label (std::string const &);
+
+ void set_no_tooltip_whatsoever (Gtk::Widget &);
};
#endif /* __gtkmm2ext_utils_h__ */
diff --git a/libs/gtkmm2ext/persistent_tooltip.cc b/libs/gtkmm2ext/persistent_tooltip.cc
new file mode 100644
index 0000000000..d50bbe7588
--- /dev/null
+++ b/libs/gtkmm2ext/persistent_tooltip.cc
@@ -0,0 +1,148 @@
+/*
+ Copyright (C) 2012 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <gtkmm/window.h>
+#include <gtkmm/label.h>
+#include "gtkmm2ext/persistent_tooltip.h"
+
+#include "i18n.h"
+
+using namespace std;
+using namespace Gtk;
+using namespace Gtkmm2ext;
+
+/** @param target The widget to provide the tooltip for */
+PersistentTooltip::PersistentTooltip (Gtk::Widget* target)
+ : _target (target)
+ , _window (0)
+ , _label (0)
+ , _maybe_dragging (false)
+{
+ target->signal_enter_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::enter), false);
+ target->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::leave), false);
+ target->signal_button_press_event().connect (sigc::mem_fun (*this, &PersistentTooltip::press), false);
+ target->signal_button_release_event().connect (sigc::mem_fun (*this, &PersistentTooltip::release), false);
+}
+
+PersistentTooltip::~PersistentTooltip ()
+{
+ delete _window;
+}
+
+bool
+PersistentTooltip::enter (GdkEventCrossing *)
+{
+ _timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &PersistentTooltip::timeout), 500);
+ return false;
+}
+
+bool
+PersistentTooltip::timeout ()
+{
+ show ();
+ return false;
+}
+
+bool
+PersistentTooltip::leave (GdkEventCrossing *)
+{
+ _timeout.disconnect ();
+ if (!dragging ()) {
+ hide ();
+ }
+
+ return false;
+}
+
+bool
+PersistentTooltip::press (GdkEventButton* ev)
+{
+ if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
+ _maybe_dragging = true;
+ }
+
+ return false;
+}
+
+bool
+PersistentTooltip::release (GdkEventButton* ev)
+{
+ if (ev->type == GDK_BUTTON_RELEASE && ev->button == 1) {
+ _maybe_dragging = false;
+ }
+
+ return false;
+}
+
+bool
+PersistentTooltip::dragging () const
+{
+ return _maybe_dragging;
+}
+
+void
+PersistentTooltip::hide ()
+{
+ if (_window) {
+ _window->hide ();
+ }
+}
+
+void
+PersistentTooltip::show ()
+{
+ if (!_window) {
+ _window = new Window (WINDOW_POPUP);
+ _window->set_name (X_("ContrastingPopup"));
+ _window->set_position (WIN_POS_MOUSE);
+ _window->set_decorated (false);
+
+ _label = manage (new Label);
+ _label->set_use_markup (true);
+
+ _window->set_border_width (6);
+ _window->add (*_label);
+ _label->show ();
+
+ Gtk::Window* tlw = dynamic_cast<Gtk::Window*> (_target->get_toplevel ());
+ if (tlw) {
+ _window->set_transient_for (*tlw);
+ }
+ }
+
+ set_tip (_tip);
+
+ if (!_window->is_visible ()) {
+ /* move the window a little away from the mouse */
+ int rx, ry;
+ _target->get_window()->get_origin (rx, ry);
+ _window->move (rx, ry + _target->get_height());
+ _window->present ();
+ }
+}
+
+void
+PersistentTooltip::set_tip (string t)
+{
+ _tip = t;
+
+ if (_label) {
+ _label->set_markup (t);
+ }
+}
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc
index 63d7655331..11c5b90722 100644
--- a/libs/gtkmm2ext/utils.cc
+++ b/libs/gtkmm2ext/utils.cc
@@ -30,6 +30,7 @@
#include <gtkmm/paned.h>
#include <gtkmm/label.h>
#include <gtkmm/comboboxtext.h>
+#include <gtkmm/tooltip.h>
#include "i18n.h"
@@ -631,3 +632,21 @@ Gtkmm2ext::left_aligned_label (string const & t)
l->set_alignment (0, 0.5);
return l;
}
+
+static bool
+make_null_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>& t)
+{
+ t->set_tip_area (Gdk::Rectangle (0, 0, 0, 0));
+ return true;
+}
+
+/** Hackily arrange for the provided widget to have no tooltip,
+ * and also to stop any other widget from providing one while
+ * the mouse is over w.
+ */
+void
+Gtkmm2ext::set_no_tooltip_whatsoever (Gtk::Widget& w)
+{
+ w.property_has_tooltip() = true;
+ w.signal_query_tooltip().connect (sigc::ptr_fun (make_null_tooltip));
+}
diff --git a/libs/gtkmm2ext/wscript b/libs/gtkmm2ext/wscript
index 1d386ce6ee..2f7d8b77b4 100644
--- a/libs/gtkmm2ext/wscript
+++ b/libs/gtkmm2ext/wscript
@@ -45,6 +45,7 @@ gtkmm2ext_sources = [
'idle_adjustment.cc',
'keyboard.cc',
'motionfeedback.cc',
+ 'persistent_tooltip.cc',
'prolooks_helpers.c',
'pixfader.cc',
'pixscroller.cc',