[goffice] Dead kittens: GtkColorSelDialog -> GtkColorChooser.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Dead kittens: GtkColorSelDialog -> GtkColorChooser.
- Date: Mon, 11 Mar 2013 00:28:16 +0000 (UTC)
commit 009d6d67403341a1e9a4769192d394be94b4ef73
Author: Morten Welinder <terra gnome org>
Date: Sun Mar 10 20:27:49 2013 -0400
Dead kittens: GtkColorSelDialog -> GtkColorChooser.
ChangeLog | 4 ++
NEWS | 1 +
goffice/gtk/go-color-palette.c | 82 +++++++++++++++++++++++++-------------
goffice/gtk/go-color-selector.c | 83 ++++++++++++++++++++++++---------------
4 files changed, 109 insertions(+), 61 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8636da2..3c912ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2013-03-10 Morten Welinder <terra gnome org>
+ * goffice/gtk/go-color-palette.c: Avoid GtkColorSelDialog which is
+ _gone_ from current gtk+. Use GtkColorChooserWidget instead.
+ * goffice/gtk/go-color-selector.c: Ditto.
+
* goffice/math/go-regression.c: Bring a blunt clue bat to the
attention of gtk-doc.
* goffice/math/go-cspline.c: ditto.
diff --git a/NEWS b/NEWS
index fe8429d..e850b97 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ goffice 0.10.2:
Morten:
* Fix problems with cspline boxed type. [#695550]
* Fix gtk-doc problems --without-long-double. [#695550]
+ * Switch from GtkColorSelDialog to GtkColorChooser.
--------------------------------------------------------------------------
goffice 0.10.1:
diff --git a/goffice/gtk/go-color-palette.c b/goffice/gtk/go-color-palette.c
index b143b2d..5d9b7e3 100644
--- a/goffice/gtk/go-color-palette.c
+++ b/goffice/gtk/go-color-palette.c
@@ -48,7 +48,7 @@ struct _GOColorPalette {
gboolean allow_alpha;
/* only for custom colours */
- GtkWidget *swatches [GO_COLOR_GROUP_HISTORY_SIZE];
+ GtkWidget *swatches[GO_COLOR_GROUP_HISTORY_SIZE];
/* The table with our default color names */
GONamedColor const *default_set;
@@ -66,13 +66,15 @@ typedef struct {
#define COLOR_PREVIEW_WIDTH 12
#define COLOR_PREVIEW_HEIGHT 12
+#define CCW_KEY "GOColorPalette::ccw"
+
enum {
COLOR_CHANGED,
DISPLAY_CUSTOM_DIALOG,
LAST_SIGNAL
};
-GONamedColor const default_color_set [] = {
+GONamedColor const _default_color_set[] = {
{ GO_COLOR_FROM_RGBA (0x00, 0x00, 0x00, 0xff), N_("black")},
{ GO_COLOR_FROM_RGBA (0x99, 0x33, 0x00, 0xff), N_("light brown")},
{ GO_COLOR_FROM_RGBA (0x33, 0x33, 0x00, 0xff), N_("brown gold")},
@@ -147,36 +149,52 @@ static guint go_color_palette_signals [LAST_SIGNAL] = { 0, };
static GObjectClass *go_color_palette_parent_class;
static GtkWidget *
-create_color_sel (GObject *action_proxy, GOColor c, GCallback handler, gboolean allow_alpha)
-{
- char *title = g_object_get_data (G_OBJECT (action_proxy), "title");
- GtkWidget *w = gtk_color_selection_dialog_new (title), *hb;
- GtkColorSelectionDialog *dialog = GTK_COLOR_SELECTION_DIALOG (w);
- GtkColorSelection *colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection
(dialog));
+create_color_sel (GtkWidget *parent_widget, GObject *action_proxy,
+ GOColor c, GCallback handler, gboolean allow_alpha)
+{
+ const char *title =
+ g_object_get_data (G_OBJECT (action_proxy), "title");
+ GtkWidget *toplevel = gtk_widget_get_toplevel (parent_widget);
+ GtkWidget *dialog = gtk_dialog_new_with_buttons
+ (title,
+ (gtk_widget_is_toplevel (toplevel)
+ ? GTK_WINDOW (toplevel)
+ : NULL),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+ GtkWidget *ccw = gtk_color_chooser_widget_new ();
+ GtkWidget *dca = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
GdkRGBA gdk;
- g_object_get (G_OBJECT (w), "help-button", &hb, NULL);
- gtk_widget_hide (hb);
- gtk_color_selection_set_has_opacity_control (colorsel, allow_alpha);
- gtk_color_selection_set_current_rgba (colorsel,
- go_color_to_gdk_rgba (c, &gdk));
+ g_object_set_data (G_OBJECT (dialog), CCW_KEY, ccw);
+
+ gtk_container_add (GTK_CONTAINER (dca), ccw);
+
+ go_color_to_gdk_rgba (c, &gdk);
+
+ g_object_set (G_OBJECT (ccw),
+ "use-alpha", allow_alpha,
+ "rgba", &gdk,
+ "show-editor", TRUE,
+ NULL);
g_signal_connect_object (dialog,
"response", handler, action_proxy, 0);
/* require an explicit show _after_ the custom-dialog signal fires */
- return w;
+ return dialog;
}
static gboolean
-handle_color_sel (GtkColorSelectionDialog *dialog,
+handle_color_sel (GtkDialog *dialog,
gint response_id, GOColor *res)
{
if (response_id == GTK_RESPONSE_OK) {
+ GtkColorChooser *chooser = g_object_get_data (G_OBJECT (dialog), CCW_KEY);
GdkRGBA gdk;
- GtkColorSelection *colorsel = GTK_COLOR_SELECTION
(gtk_color_selection_dialog_get_color_selection (dialog));
-
- gtk_color_selection_get_current_rgba (colorsel, &gdk);
+ gtk_color_chooser_get_rgba (chooser, &gdk);
*res = GO_COLOR_FROM_GDK_RGBA (gdk);
}
/* destroy _before_ we emit */
@@ -377,7 +395,7 @@ go_color_palette_button_new (GOColorPalette *pal, GtkGrid *grid,
}
static void
-cb_combo_custom_response (GtkColorSelectionDialog *dialog,
+cb_combo_custom_response (GtkDialog *dialog,
gint response_id, GOColorPalette *pal)
{
GOColor c;
@@ -388,11 +406,14 @@ cb_combo_custom_response (GtkColorSelectionDialog *dialog,
static void
cb_combo_custom_clicked (GtkWidget *button, GOColorPalette *pal)
{
- GtkWidget *dialog = create_color_sel (G_OBJECT (pal), pal->selection,
- G_CALLBACK (cb_combo_custom_response), pal->allow_alpha);
+ GtkWidget *dialog = create_color_sel
+ (button,
+ G_OBJECT (pal), pal->selection,
+ G_CALLBACK (cb_combo_custom_response),
+ pal->allow_alpha);
g_signal_emit (pal, go_color_palette_signals [DISPLAY_CUSTOM_DIALOG], 0,
dialog);
- gtk_widget_show (dialog);
+ gtk_widget_show_all (dialog);
}
void
@@ -530,7 +551,7 @@ go_color_palette_new (char const *no_color_label,
GOColorPalette *pal;
int const cols = 8;
int const rows = 6;
- GONamedColor const *color_names = default_color_set;
+ GONamedColor const *color_names = _default_color_set;
pal = g_object_new (GO_TYPE_COLOR_PALETTE, NULL);
@@ -644,7 +665,7 @@ cb_menu_color_activate (GtkWidget *button, GOMenuColor *menu)
color, FALSE, TRUE, FALSE);
}
static void
-cb_menu_custom_response (GtkColorSelectionDialog *dialog,
+cb_menu_custom_response (GtkDialog *dialog,
gint response_id, GOMenuColor *menu)
{
GOColor c;
@@ -658,11 +679,14 @@ cb_menu_custom_response (GtkColorSelectionDialog *dialog,
static void
cb_menu_custom_activate (GtkWidget *button, GOMenuColor *menu)
{
- GtkWidget *dialog = create_color_sel (G_OBJECT (menu), menu->selection,
- G_CALLBACK (cb_menu_custom_response), menu->allow_alpha);
- g_signal_emit (menu, go_menu_color_signals [DISPLAY_CUSTOM_DIALOG], 0,
+ GtkWidget *dialog = create_color_sel
+ (button,
+ G_OBJECT (menu), menu->selection,
+ G_CALLBACK (cb_menu_custom_response),
+ menu->allow_alpha);
+ g_signal_emit (menu, go_menu_color_signals[DISPLAY_CUSTOM_DIALOG], 0,
dialog);
- gtk_widget_show (dialog);
+ gtk_widget_show_all (dialog);
}
/**
@@ -686,7 +710,7 @@ go_color_palette_make_menu (char const *no_color_label,
int cols = 8;
int rows = 6;
int col, row, pos, table_row = 0;
- GONamedColor const *color_names = default_color_set;
+ GONamedColor const *color_names = _default_color_set;
GtkWidget *w, *submenu;
submenu = g_object_new (go_menu_color_get_type (), NULL);
diff --git a/goffice/gtk/go-color-selector.c b/goffice/gtk/go-color-selector.c
index 3951d0b..93adb24 100644
--- a/goffice/gtk/go-color-selector.c
+++ b/goffice/gtk/go-color-selector.c
@@ -29,7 +29,10 @@
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
-extern GONamedColor default_color_set [];
+#define COLOR_DIALOG_KEY "GOColorSelector::color-dialog"
+#define CCW_KEY "GOColorSelector::ccw"
+
+extern GONamedColor _default_color_set[];
typedef struct {
int n_swatches;
@@ -53,8 +56,8 @@ get_index (int n_swatches, GOColorGroup *color_group, GOColor color)
int i = 0;
int index = -1;
- while (default_color_set[i].name != NULL) {
- if (default_color_set[i].color == color && index < 0) {
+ while (_default_color_set[i].name != NULL) {
+ if (_default_color_set[i].color == color && index < 0) {
index = i;
continue;
}
@@ -80,7 +83,7 @@ get_color (int n_swatches, GOColorGroup *color_group, int index)
index = 0;
if (index < n_swatches - GO_COLOR_GROUP_HISTORY_SIZE)
- return default_color_set[index].color;
+ return _default_color_set[index].color;
else
return color_group->history[index - (n_swatches - GO_COLOR_GROUP_HISTORY_SIZE)];
}
@@ -150,20 +153,18 @@ go_color_palette_render_func (cairo_t *cr,
}
static void
-cb_color_dialog_response (GtkColorSelectionDialog *color_dialog,
+cb_color_dialog_response (GtkDialog *color_dialog,
gint response,
GOSelector *selector)
{
- GtkWidget *color_selection;
-
- color_selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG
(color_dialog));
+ GtkColorChooser *chooser =
+ g_object_get_data (G_OBJECT (color_dialog), CCW_KEY);
if (response == GTK_RESPONSE_OK) {
GdkRGBA gdk_color;
GOColor color;
- gtk_color_selection_get_current_rgba (GTK_COLOR_SELECTION (color_selection),
- &gdk_color);
+ gtk_color_chooser_get_rgba (chooser, &gdk_color);
color = GO_COLOR_FROM_GDK_RGBA (gdk_color);
if (!go_color_selector_set_color (selector, color))
@@ -171,41 +172,59 @@ cb_color_dialog_response (GtkColorSelectionDialog *color_dialog,
go_selector_activate (selector);
}
- g_object_set_data (G_OBJECT (selector), "color-dialog", NULL);
+ g_object_set_data (G_OBJECT (selector), COLOR_DIALOG_KEY, NULL);
}
static void
cb_combo_custom_activate (GOPalette *palette, GOSelector *selector)
{
GtkWidget *color_dialog;
- GtkWidget *color_selection;
+ GtkWidget *ccw, *dca;
GdkRGBA gdk_color;
- GOColor color;
GOColorSelectorState *state = go_selector_get_user_data (selector);
+ GOColor color = go_color_selector_get_color (selector, NULL);
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (selector));
+
+ go_color_to_gdk_rgba (color, &gdk_color);
- color_dialog = g_object_get_data (G_OBJECT (selector), "color-dialog");
+ color_dialog = g_object_get_data (G_OBJECT (selector), COLOR_DIALOG_KEY);
if (color_dialog != NULL) {
- color_selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG
(color_dialog));
- color = go_color_selector_get_color (selector, NULL);
- gtk_color_selection_set_current_rgba (GTK_COLOR_SELECTION (color_selection),
- go_color_to_gdk_rgba (color, &gdk_color));
+ GtkColorChooser *chooser =
+ g_object_get_data (G_OBJECT (color_dialog), CCW_KEY);
+ gtk_color_chooser_set_rgba (chooser, &gdk_color);
gtk_window_present (GTK_WINDOW (color_dialog));
return;
}
- color_dialog = gtk_color_selection_dialog_new (_("Custom color..."));
- color_selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG
(color_dialog));
- gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_selection),
state->allow_alpha);
- g_object_set_data_full (G_OBJECT (selector), "color-dialog", color_dialog,
- (GDestroyNotify) gtk_widget_destroy);
- color = go_color_selector_get_color (selector, NULL);
- gtk_color_selection_set_current_rgba (GTK_COLOR_SELECTION (color_selection),
- go_color_to_gdk_rgba (color, &gdk_color));
- if (state->allow_alpha)
- gtk_color_selection_set_current_alpha (GTK_COLOR_SELECTION (color_selection),
- GO_COLOR_UINT_A (color) * 257);
- g_signal_connect (color_dialog, "response", G_CALLBACK (cb_color_dialog_response), selector);
- gtk_widget_show (color_dialog);
+ color_dialog = gtk_dialog_new_with_buttons
+ (_("Custom color..."),
+ (gtk_widget_is_toplevel (toplevel)
+ ? GTK_WINDOW (toplevel)
+ : NULL),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+ ccw = gtk_color_chooser_widget_new ();
+ g_object_set_data (G_OBJECT (color_dialog), CCW_KEY, ccw);
+ dca = gtk_dialog_get_content_area (GTK_DIALOG (color_dialog));
+ gtk_container_add (GTK_CONTAINER (dca), ccw);
+
+ g_object_set (G_OBJECT (ccw),
+ "use-alpha", state->allow_alpha,
+ "rgba", &gdk_color,
+ "show-editor", TRUE,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (selector),
+ COLOR_DIALOG_KEY, color_dialog,
+ (GDestroyNotify)gtk_widget_destroy);
+
+ g_signal_connect (color_dialog,
+ "response", G_CALLBACK (cb_color_dialog_response),
+ selector);
+
+ gtk_widget_show_all (color_dialog);
}
static void
@@ -287,7 +306,7 @@ go_selector_new_color (GOColor initial_color,
state->default_color = default_color;
state->allow_alpha = TRUE;
- while (default_color_set[count].name != NULL) count ++;
+ while (_default_color_set[count].name != NULL) count ++;
state->n_swatches = count + GO_COLOR_GROUP_HISTORY_SIZE;
state->color_group = go_color_group_fetch (group, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]