Copy local state in AudioRegionView copy constructor. Fixes #4047.
[ardour2.git] / libs / gtkmm2ext / binding_proxy.cc
blobf12c64cf68973a0bf39a626ee5167abdb2c60a8a
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.
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.
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.
17 $Id$
20 #include <string>
21 #include <climits>
22 #include <iostream>
24 #include <pbd/controllable.h>
26 #include <gtkmm2ext/binding_proxy.h>
28 #include "i18n.h"
30 using namespace Gtkmm2ext;
31 using namespace std;
32 using namespace PBD;
34 BindingProxy::BindingProxy (boost::shared_ptr<Controllable> c)
35 : prompter (0),
36 controllable (c),
37 bind_button (2),
38 bind_statemask (Gdk::CONTROL_MASK)
43 BindingProxy::BindingProxy ()
44 : prompter (0),
45 bind_button (2),
46 bind_statemask (Gdk::CONTROL_MASK)
51 BindingProxy::~BindingProxy ()
53 if (prompter) {
54 delete prompter;
58 void
59 BindingProxy::set_controllable (boost::shared_ptr<Controllable> c)
61 learning_finished ();
62 controllable = c;
65 void
66 BindingProxy::set_bind_button_state (guint button, guint statemask)
68 bind_button = button;
69 bind_statemask = statemask;
72 void
73 BindingProxy::get_bind_button_state (guint &button, guint &statemask)
75 button = bind_button;
76 statemask = bind_statemask;
79 bool
80 BindingProxy::button_press_handler (GdkEventButton *ev)
82 if (controllable && (ev->state & bind_statemask) && ev->button == bind_button) {
83 if (Controllable::StartLearning (controllable.get())) {
84 string prompt = _("operate controller now");
85 if (prompter == 0) {
86 prompter = new PopUp (Gtk::WIN_POS_MOUSE, 30000, false);
87 prompter->signal_unmap_event().connect (mem_fun (*this, &BindingProxy::prompter_hiding));
89 prompter->set_text (prompt);
90 prompter->touch (); // shows popup
91 controllable->LearningFinished.connect_same_thread (learning_connection, boost::bind (&BindingProxy::learning_finished, this));
93 return true;
96 return false;
99 void
100 BindingProxy::learning_finished ()
102 learning_connection.disconnect ();
103 if (prompter) {
104 prompter->touch (); // hides popup
109 bool
110 BindingProxy::prompter_hiding (GdkEventAny */*ev*/)
112 learning_connection.disconnect ();
113 if (controllable) {
114 Controllable::StopLearning (controllable.get());
116 return false;