Add a Lua SetSession signal/hook
[ardour.git] / gtk2_ardour / stripable_colorpicker.cc
index 2e341f4d7e45ad68f4a3b094ba075d913a6a50ef..4e8fe339d476a43f03643f3d943420980a1e77b6 100644 (file)
@@ -33,6 +33,31 @@ StripableColorDialog::StripableColorDialog ()
 {
        initialize_color_palette ();
        signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
+
+#ifdef __APPLE__
+       /* hide eyedropper button -- which does not work on OSX:
+        * " the problem is worse than just `not getting the color' though.
+        *   The action doesn't actually complete, and window focus is in a
+        *   `weird state' until you click inside the color-picker dialog twice;
+        *   then it all seems back to normal (but no color got picked)"
+        *
+        * the alternative is to patch gtk's source:
+        * gtk/gtkcolorsel.c  gtk_color_selection_init() which packs
+        *
+        *  top_hbox [ VBOX [ triangle || hbox [ sample-area || picker-button] ] || ... ]
+        */
+       ColorSelection* cs = get_colorsel(); // IS-A VBOX
+       if (!cs) { return ; }
+       Gtk::HBox* top_hbox = dynamic_cast<Gtk::HBox*> (cs->children()[0].get_widget());
+       if (!top_hbox) { return ; }
+       Gtk::VBox* vbox = dynamic_cast<Gtk::VBox*> (top_hbox->children()[0].get_widget());
+       if (!vbox) { return ; }
+       Gtk::HBox* hbox = dynamic_cast<Gtk::HBox*> (vbox->children()[1].get_widget());
+       if (!hbox) { return ; }
+       Gtk::Button* picker = dynamic_cast<Gtk::Button*> (hbox->children()[1].get_widget());
+       if (!picker) { return ; }
+       picker->hide ();
+#endif
 }
 
 StripableColorDialog::~StripableColorDialog ()
@@ -74,6 +99,26 @@ StripableColorDialog::reset ()
                _stripable->set_active_color_picker (0);
        }
        _stripable.reset ();
+       _color_changed_connection.disconnect ();
+}
+
+void
+StripableColorDialog::popup (const std::string& name, uint32_t color)
+{
+       set_title (string_compose (_("Color Selection: %1"), name));
+       _initial_color = color;
+
+       get_colorsel()->set_has_opacity_control (false);
+       get_colorsel()->set_has_palette (true);
+
+       Gdk::Color c = gdk_color_from_rgba (_initial_color);
+
+       get_colorsel()->set_previous_color (c);
+       get_colorsel()->set_current_color (c);
+       _color_changed_connection.disconnect ();
+       _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
+
+       present ();
 }
 
 void
@@ -91,24 +136,49 @@ StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
 
        _stripable = s;
        _stripable->set_active_color_picker (this);
-       set_title (string_compose (_("Color Selection: %1"), s->name()));
-
-       get_colorsel()->set_has_opacity_control (false);
-       get_colorsel()->set_has_palette (true);
-
-       Gdk::Color c = gdk_color_from_rgba (_stripable->presentation_info().color ());
-
-       get_colorsel()->set_previous_color (c);
-       get_colorsel()->set_current_color (c);
-
-       present ();
+       popup (s->name(), _stripable->presentation_info().color ());
 }
 
 void
 StripableColorDialog::finish_color_edit (int response)
 {
+       if (response == RESPONSE_OK) {
+               ColorChanged (gdk_color_to_rgba (get_colorsel()->get_current_color())); /* EMIT SIGNAL */
+       }
        if (_stripable && response == RESPONSE_OK) {
                _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
+       } else if (_stripable) {
+               _stripable->presentation_info().set_color (_initial_color);
        }
        reset ();
 }
+
+void
+StripableColorDialog::color_changed ()
+{
+       if (_stripable) {
+               _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
+       }
+}
+
+
+ArdourColorButton::ArdourColorButton ()
+{
+       _color_picker.ColorChanged.connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected));
+}
+
+void
+ArdourColorButton::on_clicked ()
+{
+       _color_picker.popup ("", gdk_color_to_rgba (get_color ()));
+       _color_picker.get_window ()->set_transient_for (get_window ());
+}
+
+void
+ArdourColorButton::color_selected (uint32_t color)
+{
+       Gdk::Color c;
+       set_color_from_rgba (c, color);
+       set_color (c);
+       g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0);
+}