[goffice] Deprecations: switch from one colour selector to another.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Deprecations: switch from one colour selector to another.
- Date: Sun, 28 Dec 2014 22:59:26 +0000 (UTC)
commit e685ee099d4f128d521b31b2f398cca413a7bc3a
Author: Morten Welinder <terra gnome org>
Date: Sun Dec 28 17:58:54 2014 -0500
Deprecations: switch from one colour selector to another.
ChangeLog | 6 +++
NEWS | 1 +
goffice/gtk/go-color-palette.c | 76 ++++++++++++++++++++++++-------------
goffice/gtk/go-color-selector.c | 79 +++++++++++++++++++++++---------------
4 files changed, 105 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ec1367b..3b545d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-28 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.
+
2014-12-26 Morten Welinder <terra gnome org>
* goffice/gtk/go-action-combo-pixmaps.c (make_icon): Handle a
diff --git a/NEWS b/NEWS
index 1521bf6..8f8fd4d 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Jean:
Morten:
* Dead kitten salvage.
* Fix canvas issues when removing items.
+ * Switch from GtkColorSelDialog to GtkColorChooser. [#695634]
--------------------------------------------------------------------------
goffice 0.10.18:
diff --git a/goffice/gtk/go-color-palette.c b/goffice/gtk/go-color-palette.c
index f33fb4b..8bb159c 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,6 +66,8 @@ typedef struct {
#define COLOR_PREVIEW_WIDTH 12
#define COLOR_PREVIEW_HEIGHT 12
+#define CCW_KEY "GOColorPalette::ccw"
+
enum {
COLOR_CHANGED,
DISPLAY_CUSTOM_DIALOG,
@@ -153,36 +155,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 */
@@ -376,7 +394,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;
@@ -387,11 +405,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
@@ -643,7 +664,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;
@@ -657,11 +678,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);
}
/**
diff --git a/goffice/gtk/go-color-selector.c b/goffice/gtk/go-color-selector.c
index a7d0be7..36efd24 100644
--- a/goffice/gtk/go-color-selector.c
+++ b/goffice/gtk/go-color-selector.c
@@ -29,6 +29,9 @@
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
+#define COLOR_DIALOG_KEY "GOColorSelector::color-dialog"
+#define CCW_KEY "GOColorSelector::ccw"
+
typedef struct {
int n_swatches;
GOColorGroup *color_group;
@@ -50,8 +53,7 @@ get_index (int n_swatches, GOColorGroup *color_group, GOColor color)
{
int i = 0;
int index = -1;
- const GONamedColor *default_color_set =
- _go_color_palette_default_color_set ();
+ const GONamedColor *default_color_set = _go_color_palette_default_color_set ();
while (default_color_set[i].name != NULL) {
if (default_color_set[i].color == color && index < 0) {
@@ -76,8 +78,7 @@ get_index (int n_swatches, GOColorGroup *color_group, GOColor color)
static GOColor
get_color (int n_swatches, GOColorGroup *color_group, int index)
{
- const GONamedColor *default_color_set =
- _go_color_palette_default_color_set ();
+ const GONamedColor *default_color_set = _go_color_palette_default_color_set ();
if (index < 0 || index >= (n_swatches))
index = 0;
@@ -149,20 +150,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))
@@ -170,41 +169,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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]