Provide dialogs to edit pan values numerically, at least for
[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 "panner_editor.h"
24 #include "global_signals.h"
25
26 #include "i18n.h"
27
28 using namespace std;
29 using namespace Gtk;
30 using namespace ARDOUR;
31 using namespace Gtkmm2ext;
32
33 PannerInterface::PannerInterface (boost::shared_ptr<Panner> p)
34         : _panner (p)
35         , _drag_data_window (0)
36         , _drag_data_label (0)
37         , _dragging (false)
38         , _editor (0)
39 {
40         set_flags (Gtk::CAN_FOCUS);
41
42         add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|
43                     Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|
44                     Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|
45                     Gdk::SCROLL_MASK|
46                     Gdk::POINTER_MOTION_MASK);
47
48 }
49
50 PannerInterface::~PannerInterface ()
51 {
52         delete _drag_data_window;
53         delete _editor;
54 }
55
56 void
57 PannerInterface::show_drag_data_window ()
58 {
59         if (!_drag_data_window) {
60                 _drag_data_window = new Window (WINDOW_POPUP);
61                 _drag_data_window->set_name (X_("ContrastingPopup"));
62                 _drag_data_window->set_position (WIN_POS_MOUSE);
63                 _drag_data_window->set_decorated (false);
64                 
65                 _drag_data_label = manage (new Label);
66                 _drag_data_label->set_use_markup (true);
67                 
68                 _drag_data_window->set_border_width (6);
69                 _drag_data_window->add (*_drag_data_label);
70                 _drag_data_label->show ();
71                 
72                 Window* toplevel = dynamic_cast<Window*> (get_toplevel());
73                 if (toplevel) {
74                         _drag_data_window->set_transient_for (*toplevel);
75                 }
76         }
77
78         set_drag_data ();
79         
80         if (!_drag_data_window->is_visible ()) {
81                 /* move the window a little away from the mouse */
82                 int rx, ry;
83                 get_window()->get_origin (rx, ry);
84                 _drag_data_window->move (rx, ry + get_height());
85                 _drag_data_window->present ();
86         }
87 }
88
89 void
90 PannerInterface::hide_drag_data_window ()
91 {
92         if (_drag_data_window) {
93                 _drag_data_window->hide ();
94         }
95 }
96
97 bool
98 PannerInterface::on_enter_notify_event (GdkEventCrossing *)
99 {
100         grab_focus ();
101         Keyboard::magic_widget_grab_focus ();
102
103         _drag_data_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &PannerInterface::drag_data_timeout), 500);
104         
105         return false;
106 }
107
108 bool
109 PannerInterface::drag_data_timeout ()
110 {
111         show_drag_data_window ();
112         return false;
113 }
114
115 bool
116 PannerInterface::on_leave_notify_event (GdkEventCrossing *)
117 {
118         Keyboard::magic_widget_drop_focus ();
119
120         _drag_data_timeout.disconnect ();
121         if (!_dragging) {
122                 hide_drag_data_window ();
123         }
124         
125         return false;
126 }
127
128 bool
129 PannerInterface::on_key_release_event (GdkEventKey*)
130 {
131         return false;
132 }
133
134 void
135 PannerInterface::value_change ()
136 {
137         set_drag_data ();
138         queue_draw ();
139 }
140
141 bool
142 PannerInterface::on_button_press_event (GdkEventButton* ev)
143 {
144         if (Gtkmm2ext::Keyboard::is_edit_event (ev)) {
145                 edit ();
146                 return true;
147         }
148
149         return false;
150 }
151
152 bool
153 PannerInterface::on_button_release_event (GdkEventButton* ev)
154 {
155         if (Gtkmm2ext::Keyboard::is_edit_event (ev)) {
156                 /* We edited on the press, so claim the release */
157                 return true;
158         }
159
160         return false;
161 }
162
163 void
164 PannerInterface::edit ()
165 {
166         delete _editor;
167         _editor = editor ();
168         _editor->show ();
169 }