Move some bits from MonoPanner and StereoPanner into a
[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 Gtk;
28 using namespace ARDOUR;
29 using namespace Gtkmm2ext;
30
31 PannerInterface::PannerInterface (boost::shared_ptr<Panner> p)
32         : _panner (p)
33         , _drag_data_window (0)
34         , _drag_data_label (0)
35 {
36         set_flags (Gtk::CAN_FOCUS);
37
38         add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|
39                     Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|
40                     Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|
41                     Gdk::SCROLL_MASK|
42                     Gdk::POINTER_MOTION_MASK);
43
44 }
45
46 PannerInterface::~PannerInterface ()
47 {
48         delete _drag_data_window;
49 }
50
51 void
52 PannerInterface::show_drag_data_window ()
53 {
54         if (!_drag_data_window) {
55                 _drag_data_window = new Window (WINDOW_POPUP);
56                 _drag_data_window->set_name (X_("ContrastingPopup"));
57                 _drag_data_window->set_position (WIN_POS_MOUSE);
58                 _drag_data_window->set_decorated (false);
59                 
60                 _drag_data_label = manage (new Label);
61                 _drag_data_label->set_use_markup (true);
62                 
63                 _drag_data_window->set_border_width (6);
64                 _drag_data_window->add (*_drag_data_label);
65                 _drag_data_label->show ();
66                 
67                 Window* toplevel = dynamic_cast<Window*> (get_toplevel());
68                 if (toplevel) {
69                         _drag_data_window->set_transient_for (*toplevel);
70                 }
71         }
72         
73         if (!_drag_data_window->is_visible ()) {
74                 /* move the window a little away from the mouse */
75                 int rx, ry;
76                 get_window()->get_origin (rx, ry);
77                 _drag_data_window->move (rx, ry + get_height());
78                 _drag_data_window->present ();
79         }
80 }
81
82 bool
83 PannerInterface::on_enter_notify_event (GdkEventCrossing *)
84 {
85         grab_focus ();
86         Keyboard::magic_widget_grab_focus ();
87         return false;
88 }
89
90 bool
91 PannerInterface::on_leave_notify_event (GdkEventCrossing *)
92 {
93         Keyboard::magic_widget_drop_focus ();
94         return false;
95 }
96
97 bool
98 PannerInterface::on_key_release_event (GdkEventKey*)
99 {
100         return false;
101 }
102
103 void
104 PannerInterface::value_change ()
105 {
106         set_drag_data ();
107         queue_draw ();
108 }
109