Add Zoom/Expand icon
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / bindable_button.h
index 7400cf15d092416362d76a8f9f4f9a549961037a..d96f8145a44bc5bbe8b1fd4cf2f8dd00eb5bfdf5 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
-#ifndef __pbd_gtkmm_bindable_button_h__
-#define __pbd_gtkmm_bindable_button_h__
+#ifndef __bindable_button_h__
+#define __bindable_button_h__
 
 #include <string>
 
-#include <gtkmm2ext/stateful_button.h>
-#include <gtkmm2ext/popup.h>
+#include "pbd/signals.h"
 
-namespace MIDI {
+#include "gtkmm2ext/visibility.h"
+#include "gtkmm2ext/stateful_button.h"
+#include "gtkmm2ext/binding_proxy.h"
+
+namespace PBD {
        class Controllable;
 }
 
-namespace Gtkmm2ext {
-
-class BindableToggleButton : public Gtk::ToggleButton
+class LIBGTKMM2EXT_API BindableToggleButton : public Gtkmm2ext::StatefulToggleButton
 {
    public:
-       BindableToggleButton(MIDI::Controllable *);
-
-       //: Create a check button with a label.
-       //- You won't be able
-       //- to add a widget in this button since it already has a {\class Gtk_Label}
-       //- in it.
-       explicit BindableToggleButton(MIDI::Controllable *, const std::string &label);
+       BindableToggleButton (const std::string &label)
+               : Gtkmm2ext::StatefulToggleButton (label) {}
+       BindableToggleButton () {}
 
        virtual ~BindableToggleButton() {}
-       
-       void set_bind_button_state (guint button, guint statemask);
-       void get_bind_button_state (guint &button, guint &statemask);
-       
-       void midicontrol_set_tip ();
-
-       void midi_learn ();
-       
+
+       bool on_button_press_event (GdkEventButton *ev) {
+               if (!binding_proxy.button_press_handler (ev)) {
+                       StatefulToggleButton::on_button_press_event (ev);
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
+       void set_controllable (boost::shared_ptr<PBD::Controllable> c);
+        void watch ();
+
   protected:
+        void controllable_changed ();
+        PBD::ScopedConnection watch_connection;
 
-       Gtkmm2ext::PopUp     prompter;
-       
-       MIDI::Controllable* midi_control;
-
-       guint bind_button;
-       guint bind_statemask;
-
-       bool prompting, unprompting;
-       
-       void init_events ();
-       bool prompter_hiding (GdkEventAny *);
-       void midicontrol_prompt ();
-       void midicontrol_unprompt ();
-       
-       bool on_button_press_event (GdkEventButton *);
+  private:
+       BindingProxy binding_proxy;
 };
 
+class LIBGTKMM2EXT_API BindableButton : public Gtkmm2ext::StatefulButton
+{
+   public:
+       BindableButton (boost::shared_ptr<PBD::Controllable> c) : binding_proxy (c) {}
+       ~BindableButton() {}
+
+       bool on_button_press_event (GdkEventButton *ev) {
+               if (!binding_proxy.button_press_handler (ev)) {
+                       StatefulButton::on_button_press_event (ev);
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
+       void set_controllable (boost::shared_ptr<PBD::Controllable> c) { binding_proxy.set_controllable (c); }
+
+  private:
+       BindingProxy binding_proxy;
 };
 
 #endif