2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/window.h>
21 #include <gtkmm/label.h>
22 #include "gtkmm2ext/persistent_tooltip.h"
28 using namespace Gtkmm2ext;
30 /** @param target The widget to provide the tooltip for */
31 PersistentTooltip::PersistentTooltip (Gtk::Widget* target)
35 , _maybe_dragging (false)
37 target->signal_enter_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::enter), false);
38 target->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::leave), false);
39 target->signal_button_press_event().connect (sigc::mem_fun (*this, &PersistentTooltip::press), false);
40 target->signal_button_release_event().connect (sigc::mem_fun (*this, &PersistentTooltip::release), false);
43 PersistentTooltip::~PersistentTooltip ()
49 PersistentTooltip::enter (GdkEventCrossing *)
51 if (_timeout.connected()) {
54 _timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &PersistentTooltip::timeout), 500);
59 PersistentTooltip::timeout ()
66 PersistentTooltip::leave (GdkEventCrossing *)
68 _timeout.disconnect ();
77 PersistentTooltip::press (GdkEventButton* ev)
79 if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
80 _maybe_dragging = true;
87 PersistentTooltip::release (GdkEventButton* ev)
89 if (ev->type == GDK_BUTTON_RELEASE && ev->button == 1) {
90 _maybe_dragging = false;
97 PersistentTooltip::dragging () const
99 return _maybe_dragging;
103 PersistentTooltip::hide ()
111 PersistentTooltip::show ()
114 _window = new Window (WINDOW_POPUP);
115 _window->set_name (X_("ContrastingPopup"));
116 _window->set_position (WIN_POS_MOUSE);
117 _window->set_decorated (false);
119 _label = manage (new Label);
120 _label->set_use_markup (true);
122 _window->set_border_width (6);
123 _window->add (*_label);
126 Gtk::Window* tlw = dynamic_cast<Gtk::Window*> (_target->get_toplevel ());
128 _window->set_transient_for (*tlw);
134 if (!_window->is_visible ()) {
136 sw= gdk_screen_width();
137 _target->get_window()->get_origin (rx, ry);
138 _window->move (rx, ry + _target->get_height());
141 /* the window needs to be realized first
142 * for _window->get_width() to be correct.
144 if (sw < rx + _window->get_width()) {
145 rx = sw - _window->get_width();
146 _window->move (rx, ry + _target->get_height());
152 PersistentTooltip::set_tip (string t)
157 _label->set_markup (t);