3a2f5bbbc837e423e78379a2ae05e25792a77947
[ardour.git] / libs / gtkmm2ext / binding_proxy.cc
1 /*
2     Copyright (C) 2006 Paul Davis
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation; either version 2 of the License, or
6     (at your option) any later version.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17     $Id$
18 */
19
20 #include <string>
21 #include <climits>
22 #include <iostream>
23
24 #include <pbd/controllable.h>
25
26 #include <gtkmm2ext/binding_proxy.h>
27
28 #include "i18n.h"
29
30 using namespace Gtkmm2ext;
31 using namespace std;
32 using namespace PBD;
33
34 BindingProxy::BindingProxy (Controllable& c)
35         : prompter (Gtk::WIN_POS_MOUSE, 30000, false),
36           controllable (c),
37           bind_button (2),
38           bind_statemask (Gdk::CONTROL_MASK)
39
40 {                         
41         prompter.signal_unmap_event().connect (mem_fun (*this, &BindingProxy::prompter_hiding));
42 }
43
44 void
45 BindingProxy::set_bind_button_state (guint button, guint statemask)
46 {
47         bind_button = button;
48         bind_statemask = statemask;
49 }
50
51 void
52 BindingProxy::get_bind_button_state (guint &button, guint &statemask)
53 {
54         button = bind_button;
55         statemask = bind_statemask;
56 }
57
58 bool
59 BindingProxy::button_press_handler (GdkEventButton *ev)
60 {
61         if ((ev->state & bind_statemask) && ev->button == bind_button) { 
62                 if (Controllable::StartLearning (&controllable)) {
63                         string prompt = _("operate controller now");
64                         prompter.set_text (prompt);
65                         prompter.touch (); // shows popup
66                         learning_connection = controllable.LearningFinished.connect (mem_fun (*this, &BindingProxy::learning_finished));
67                 }
68                 return true;
69         }
70         
71         return false;
72 }
73
74 void
75 BindingProxy::learning_finished ()
76 {
77         learning_connection.disconnect ();
78         prompter.touch (); // hides popup
79 }
80
81
82 bool
83 BindingProxy::prompter_hiding (GdkEventAny *ev)
84 {
85         learning_connection.disconnect ();
86         Controllable::StopLearning (&controllable);
87         return false;
88 }
89