static void gimp_color_button_clicked (GtkButton *button) { GimpColorButton *color_button = GIMP_COLOR_BUTTON (button); if (! color_button->dialog) { GtkWidget *dialog; GtkWidget *selection; GimpRGB color; gimp_color_button_get_color (color_button, &color); dialog = color_button->dialog = gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY, gtk_widget_get_toplevel (GTK_WIDGET (button)), 0, gimp_color_button_help_func, NULL, GIMP_STOCK_RESET, RESPONSE_RESET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), RESPONSE_RESET, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); g_signal_connect (dialog, "response", G_CALLBACK (gimp_color_button_dialog_response), color_button); g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &color_button->dialog); selection = gimp_color_selection_new (); gtk_container_set_border_width (GTK_CONTAINER (selection), 6); gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (selection), gimp_color_button_has_alpha (color_button)); gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color); gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (selection), &color); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), selection, TRUE, TRUE, 0); gtk_widget_show (selection); g_signal_connect (selection, "color-changed", G_CALLBACK (gimp_color_button_selection_changed), button); g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY, selection); } gtk_window_present (GTK_WINDOW (color_button->dialog)); }
static WidgetInfo * create_color_selection (void) { GtkWidget *vbox; GtkWidget *selection; GtkWidget *align; GimpRGB color; color_init (&color); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); selection = gimp_color_selection_new (); gimp_color_selection_set_show_alpha(GIMP_COLOR_SELECTION (selection), TRUE); gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color); gtk_widget_set_size_request (selection, 400, -1); gtk_container_add (GTK_CONTAINER (align), selection); gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Color Selection"), FALSE, FALSE, 0); return new_widget_info ("gimp-widget-color-selection", vbox, ASIS); }
GtkWidget * gimp_color_dialog_new (GimpViewable *viewable, GimpContext *context, const gchar *title, const gchar *stock_id, const gchar *desc, GtkWidget *parent, GimpDialogFactory *dialog_factory, const gchar *dialog_identifier, const GimpRGB *color, gboolean wants_updates, gboolean show_alpha) { GimpColorDialog *dialog; const gchar *role; g_return_val_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable), NULL); g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); g_return_val_if_fail (dialog_factory == NULL || GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL); g_return_val_if_fail (dialog_factory == NULL || dialog_identifier != NULL, NULL); g_return_val_if_fail (color != NULL, NULL); if (! context) g_warning ("gimp_color_dialog_new() called with a NULL context"); role = dialog_identifier ? dialog_identifier : "gimp-color-selector"; dialog = g_object_new (GIMP_TYPE_COLOR_DIALOG, "title", title, "role", role, "help-func", gimp_color_dialog_help_func, "help-id", GIMP_HELP_COLOR_DIALOG, "stock-id", stock_id, "description", desc, "parent", parent, NULL); if (viewable) { gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (dialog), viewable, context); } else { GtkWidget *parent; parent = gtk_widget_get_parent (GIMP_VIEWABLE_DIALOG (dialog)->icon); parent = gtk_widget_get_parent (parent); gtk_widget_hide (parent); } dialog->wants_updates = wants_updates; if (dialog_factory) gimp_dialog_factory_add_foreign (dialog_factory, dialog_identifier, GTK_WIDGET (dialog)); gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (dialog->selection), show_alpha); if (context) { g_object_set_data (G_OBJECT (context->gimp->config->color_management), "gimp-context", context); gimp_color_selection_set_config (GIMP_COLOR_SELECTION (dialog->selection), context->gimp->config->color_management); g_object_set_data (G_OBJECT (context->gimp->config->color_management), "gimp-context", NULL); } gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection), color); gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (dialog->selection), color); return GTK_WIDGET (dialog); }