1 /* AbiWord
2 * Copyright (C) 2013 Hubert Figuiere
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA.
17 */
18
19
20 #include "xap_UnixDlg_ColorChooser.h"
21 #include "xap_Gtk2Compat.h"
22
23
XAP_UnixDlg_RunColorChooser(GtkWindow * parent,GtkColorButton * colorbtn)24 std::auto_ptr<UT_RGBColor> XAP_UnixDlg_RunColorChooser(GtkWindow* parent,
25 GtkColorButton* colorbtn)
26 {
27 GtkWidget *colordlg = gtk_color_chooser_dialog_new ("", parent);
28 GtkColorChooser *colorsel = NULL;
29 #if GTK_CHECK_VERSION(3,4,0)
30 // GtkCholorChooser is an interface now.
31 // TODO remove this when we are Gtk 3.4 only
32 colorsel = GTK_COLOR_CHOOSER(colordlg);
33 #else
34 colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG (colordlg)));
35 gtk_color_selection_set_has_palette (colorsel, TRUE);
36 #endif
37
38 GdkRGBA initialColor;
39 XAP_gtk_color_button_get_rgba(colorbtn, &initialColor);
40 gtk_color_chooser_set_rgba(colorsel, &initialColor);
41
42 UT_RGBColor* rgb = NULL;
43
44 gint result = gtk_dialog_run (GTK_DIALOG (colordlg));
45 if (result == GTK_RESPONSE_OK) {
46 // update button
47 GdkRGBA color;
48 gtk_color_chooser_get_rgba (colorsel, &color);
49 XAP_gtk_color_button_set_rgba (colorbtn, &color);
50
51 // update dialog
52 rgb = UT_UnixGdkColorToRGBColor (color);
53 }
54
55 // do not propagate further
56 gtk_widget_destroy (colordlg);
57 return std::auto_ptr<UT_RGBColor>(rgb);
58 }
59