+ setup_led_rect ();
+ set_colors ();
+}
+
+void
+ArdourButton::set_controllable (boost::shared_ptr<Controllable> c)
+{
+ watch_connection.disconnect ();
+ binding_proxy.set_controllable (c);
+}
+
+void
+ArdourButton::watch ()
+{
+ boost::shared_ptr<Controllable> c (binding_proxy.get_controllable ());
+
+ if (!c) {
+ warning << _("button cannot watch state of non-existing Controllable\n") << endmsg;
+ return;
+ }
+
+ c->Changed.connect (watch_connection, invalidator(*this), boost::bind (&ArdourButton::controllable_changed, this), gui_context());
+}
+
+void
+ArdourButton::controllable_changed ()
+{
+ float val = binding_proxy.get_controllable()->get_value();
+
+ if (fabs (val) >= 0.5f) {
+ set_active_state (Gtkmm2ext::ExplicitActive);
+ } else {
+ unset_active_state ();
+ }
+}
+
+void
+ArdourButton::set_related_action (RefPtr<Action> act)
+{
+ Gtkmm2ext::Activatable::set_related_action (act);
+
+ if (_action) {
+
+ action_tooltip_changed ();
+
+ Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
+ if (tact) {
+ action_toggled ();
+ tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
+ }
+
+ _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &ArdourButton::action_sensitivity_changed));
+ _action->connect_property_changed ("visible", sigc::mem_fun (*this, &ArdourButton::action_visibility_changed));
+ _action->connect_property_changed ("tooltip", sigc::mem_fun (*this, &ArdourButton::action_tooltip_changed));
+ }
+}
+
+void
+ArdourButton::action_toggled ()
+{
+ Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
+
+ if (tact) {
+ if (tact->get_active()) {
+ set_active_state (Gtkmm2ext::ExplicitActive);
+ } else {
+ unset_active_state ();
+ }
+ }
+}
+
+void
+ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
+{
+ set_colors ();
+}
+
+void
+ArdourButton::setup_led_rect ()
+{
+ int text_margin;
+
+ if (get_width() < 75) {
+ text_margin = 3;
+ } else {
+ text_margin = 10;
+ }
+
+ if (_elements & Indicator) {
+ _led_rect = new cairo_rectangle_t;
+
+ if (_elements & Text) {
+ if (_led_left) {
+ _led_rect->x = text_margin;
+ } else {
+ _led_rect->x = get_width() - text_margin - _diameter/2.0;
+ }
+ } else {
+ /* centered */
+ _led_rect->x = get_width()/2.0 - _diameter/2.0;
+ }
+
+ _led_rect->y = get_height()/2.0 - _diameter/2.0;
+ _led_rect->width = _diameter;
+ _led_rect->height = _diameter;
+
+ } else {
+ delete _led_rect;
+ _led_rect = 0;
+ }
+}
+
+void
+ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
+{
+ _pixbuf = img;
+ queue_draw ();
+}
+
+void
+ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
+{
+ bool changed = (_active_state != s);
+ CairoWidget::set_active_state (s);
+ if (changed) {
+ set_colors ();
+ }
+}
+
+void
+ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
+{
+ bool changed = (_visual_state != s);
+ CairoWidget::set_visual_state (s);
+ if (changed) {
+ set_colors ();
+ }
+}
+
+bool
+ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
+{
+ _hovering = true;
+
+ if (ARDOUR::Config->get_widget_prelight()) {
+ queue_draw ();
+ }
+
+ return CairoWidget::on_enter_notify_event (ev);
+}
+
+bool
+ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
+{
+ _hovering = false;
+
+ if (ARDOUR::Config->get_widget_prelight()) {
+ queue_draw ();
+ }
+
+ return CairoWidget::on_leave_notify_event (ev);
+}
+
+void
+ArdourButton::set_tweaks (Tweaks t)
+{
+ if (_tweaks != t) {
+ _tweaks = t;
+ queue_draw ();
+ }
+}
+
+void
+ArdourButton::action_sensitivity_changed ()
+{
+ if (_action->property_sensitive ()) {
+ set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
+ } else {
+ set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
+ }
+
+}
+
+
+void
+ArdourButton::action_visibility_changed ()
+{
+ if (_action->property_visible ()) {
+ show ();
+ } else {
+ hide ();
+ }
+}
+
+void
+ArdourButton::action_tooltip_changed ()
+{
+ string str = _action->property_tooltip().get_value();
+ ARDOUR_UI::instance()->set_tip (*this, str);
+}
+
+void
+ArdourButton::set_rounded_corner_mask (int mask)
+{
+ _corner_mask = mask;
+ queue_draw ();
+}
+
+void
+ArdourButton::set_elements (Element e)
+{
+ _elements = e;