2010-02-23 18:24:20 +00:00
|
|
|
/*
|
|
|
|
* color.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Berislav Kovacki
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Authors: Berislav Kovacki <pantokrator@pantokrator.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "zenity.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static ZenityData *zen_data;
|
|
|
|
|
|
|
|
static void zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data);
|
|
|
|
|
|
|
|
void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2011-07-26 17:00:28 +00:00
|
|
|
GtkWidget *button;
|
2015-03-22 06:30:57 +00:00
|
|
|
GdkRGBA color;
|
2010-02-23 18:24:20 +00:00
|
|
|
|
|
|
|
zen_data = data;
|
|
|
|
|
2015-03-22 06:30:57 +00:00
|
|
|
dialog = gtk_color_chooser_dialog_new (data->dialog_title, NULL);
|
2010-02-23 18:24:20 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog), "response",
|
|
|
|
G_CALLBACK (zenity_colorselection_dialog_response),
|
|
|
|
color_data);
|
|
|
|
|
|
|
|
if (color_data->color) {
|
2015-03-22 06:30:57 +00:00
|
|
|
if (gdk_rgba_parse (&color, color_data->color)) {
|
|
|
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog), &color);
|
|
|
|
}
|
2010-02-23 18:24:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 19:06:09 +00:00
|
|
|
if (data->extra_label) {
|
|
|
|
gint i=0;
|
|
|
|
while(data->extra_label[i]!=NULL){
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:00:28 +00:00
|
|
|
if (data->ok_label) {
|
2012-08-12 16:20:07 +00:00
|
|
|
g_object_get (G_OBJECT (dialog), "ok-button", &button, NULL);
|
2011-07-26 17:00:28 +00:00
|
|
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
|
|
|
g_object_unref (G_OBJECT (button));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->cancel_label) {
|
2012-08-12 16:20:07 +00:00
|
|
|
g_object_get (G_OBJECT (dialog), "cancel-button", &button, NULL);
|
2011-07-26 17:00:28 +00:00
|
|
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
|
|
|
g_object_unref (G_OBJECT (button));
|
|
|
|
}
|
|
|
|
|
2012-09-18 16:33:07 +00:00
|
|
|
if (data->modal)
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
|
2015-03-22 06:30:57 +00:00
|
|
|
g_object_set (dialog, "show-editor", !color_data->show_palette, NULL);
|
2010-02-23 18:24:20 +00:00
|
|
|
|
2013-08-23 01:15:07 +00:00
|
|
|
zenity_util_show_dialog (dialog, data->attach);
|
2010-02-23 18:24:20 +00:00
|
|
|
|
|
|
|
if (data->timeout_delay > 0) {
|
2014-10-21 14:32:14 +00:00
|
|
|
g_timeout_add_seconds (data->timeout_delay,
|
2014-10-21 14:05:31 +00:00
|
|
|
(GSourceFunc) zenity_util_timeout_handle,
|
|
|
|
dialog);
|
2010-02-23 18:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|
|
|
{
|
2015-03-22 06:30:57 +00:00
|
|
|
GdkRGBA color;
|
2010-02-23 18:24:20 +00:00
|
|
|
|
|
|
|
switch (response) {
|
|
|
|
case GTK_RESPONSE_OK:
|
2015-03-22 06:30:57 +00:00
|
|
|
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
|
|
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (widget), &color);
|
|
|
|
g_print ("%s\n", gdk_rgba_to_string (&color));
|
2010-02-23 18:24:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-02-28 19:06:09 +00:00
|
|
|
if (response < g_strv_length(zen_data->extra_label))
|
|
|
|
printf("%s\n",zen_data->extra_label[response]);
|
2010-02-23 18:24:20 +00:00
|
|
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|