Show panner drag information tool-tip style, and also show
[ardour.git] / gtk2_ardour / panner_interface.cc
1 /*
2     Copyright (C) 2011 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <gtkmm.h>
21 #include "gtkmm2ext/keyboard.h"
22 #include "panner_interface.h"
23 #include "global_signals.h"
24
25 #include "i18n.h"
26
27 using namespace std;
28 using namespace Gtk;
29 using namespace ARDOUR;
30 using namespace Gtkmm2ext;
31
32 PannerInterface::PannerInterface (boost::shared_ptr<Panner> p)
33         : _panner (p)
34         , _drag_data_window (0)
35         , _drag_data_label (0)
36         , _dragging (false)
37 {
38         set_flags (Gtk::CAN_FOCUS);
39
40         add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|
41                     Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|
42                     Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|
43                     Gdk::SCROLL_MASK|
44                     Gdk::POINTER_MOTION_MASK);
45
46 }
47
48 PannerInterface::~PannerInterface ()
49 {
50         delete _drag_data_window;
51 }
52
53 void
54 PannerInterface::show_drag_data_window ()
55 {
56         if (!_drag_data_window) {
57                 _drag_data_window = new Window (WINDOW_POPUP);
58                 _drag_data_window->set_name (X_("ContrastingPopup"));
59                 _drag_data_window->set_position (WIN_POS_MOUSE);
60                 _drag_data_window->set_decorated (false);
61                 
62                 _drag_data_label = manage (new Label);
63                 _drag_data_label->set_use_markup (true);
64                 
65                 _drag_data_window->set_border_width (6);
66                 _drag_data_window->add (*_drag_data_label);
67                 _drag_data_label->show ();
68                 
69                 Window* toplevel = dynamic_cast<Window*> (get_toplevel());
70                 if (toplevel) {
71                         _drag_data_window->set_transient_for (*toplevel);
72                 }
73         }
74
75         set_drag_data ();
76         
77         if (!_drag_data_window->is_visible ()) {
78                 /* move the window a little away from the mouse */
79                 int rx, ry;
80                 get_window()->get_origin (rx, ry);
81                 _drag_data_window->move (rx, ry + get_height());
82                 _drag_data_window->present ();
83         }
84 }
85
86 void
87 PannerInterface::hide_drag_data_window ()
88 {
89         if (_drag_data_window) {
90                 _drag_data_window->hide ();
91         }
92 }
93
94 bool
95 PannerInterface::on_enter_notify_event (GdkEventCrossing *)
96 {
97         grab_focus ();
98         Keyboard::magic_widget_grab_focus ();
99
100         _drag_data_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &PannerInterface::drag_data_timeout), 500);
101         
102         return false;
103 }
104
105 bool
106 PannerInterface::drag_data_timeout ()
107 {
108         show_drag_data_window ();
109         return false;
110 }
111
112 bool
113 PannerInterface::on_leave_notify_event (GdkEventCrossing *)
114 {
115         Keyboard::magic_widget_drop_focus ();
116
117         _drag_data_timeout.disconnect ();
118         if (!_dragging) {
119                 hide_drag_data_window ();
120         }
121         
122         return false;
123 }
124
125 bool
126 PannerInterface::on_key_release_event (GdkEventKey*)
127 {
128         return false;
129 }
130
131 void
132 PannerInterface::value_change ()
133 {
134         set_drag_data ();
135         queue_draw ();
136 }
137