/pidgin/main: b18fa06ff063: Use GtkFontButton and GtkColorButton...
Elliott Sales de Andrade
qulogic at pidgin.im
Wed Feb 12 19:36:21 EST 2014
Changeset: b18fa06ff063eb53863a6275890a81ea7c5c864e
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2014-02-12 19:36 -0500
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/b18fa06ff063
Description:
Use GtkFontButton and GtkColorButton widgets.
These are nicer since they show the actual setting with the user having
to attempt to change it.
diffstat:
pidgin/gtk3compat.h | 33 +++++++++++---
pidgin/gtkwhiteboard.c | 42 +++++-------------
pidgin/plugins/themeedit.c | 100 ++++++++++++++++++--------------------------
3 files changed, 79 insertions(+), 96 deletions(-)
diffs (289 lines):
diff --git a/pidgin/gtk3compat.h b/pidgin/gtk3compat.h
--- a/pidgin/gtk3compat.h
+++ b/pidgin/gtk3compat.h
@@ -38,14 +38,31 @@
#define gtk_color_chooser_dialog_new(title, parent) \
gtk_color_selection_dialog_new(title)
-#define GTK_COLOR_CHOOSER(widget) GTK_COLOR_SELECTION( \
- gtk_color_selection_dialog_get_color_selection( \
- GTK_COLOR_SELECTION_DIALOG(widget)))
-#define gtk_color_chooser_set_use_alpha(chooser, val)
-#define pidgin_color_chooser_set_rgb(chooser, color) \
- gtk_color_selection_set_current_color(chooser, color)
-#define pidgin_color_chooser_get_rgb(chooser, color) \
- gtk_color_selection_get_current_color(chooser, color)
+#define GTK_COLOR_CHOOSER(widget) (widget)
+#define gtk_color_chooser_set_use_alpha(widget, val) do { \
+ if (GTK_IS_COLOR_BUTTON(widget)) \
+ gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(widget), val); \
+} while (0)
+#define pidgin_color_chooser_set_rgb(widget, color) do { \
+ if (GTK_IS_COLOR_SELECTION_DIALOG(widget)) \
+ gtk_color_selection_set_current_color( \
+ GTK_COLOR_SELECTION( \
+ gtk_color_selection_dialog_get_color_selection( \
+ GTK_COLOR_SELECTION_DIALOG(widget))), \
+ color); \
+ else \
+ gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), color); \
+} while (0)
+#define pidgin_color_chooser_get_rgb(chooser, color) do { \
+ if (GTK_IS_COLOR_SELECTION_DIALOG(widget)) \
+ gtk_color_selection_get_current_color( \
+ GTK_COLOR_SELECTION( \
+ gtk_color_selection_dialog_get_color_selection( \
+ GTK_COLOR_SELECTION_DIALOG(widget))), \
+ color); \
+ else \
+ gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), color); \
+} while (0)
#else
diff --git a/pidgin/gtkwhiteboard.c b/pidgin/gtkwhiteboard.c
--- a/pidgin/gtkwhiteboard.c
+++ b/pidgin/gtkwhiteboard.c
@@ -113,7 +113,7 @@ static void pidgin_whiteboard_set_canvas
static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb, GdkColor *color);
-static void color_select_dialog(GtkWidget *widget, PidginWhiteboard *gtkwb);
+static void color_selected(GtkColorButton *button, PidginWhiteboard *gtkwb);
/******************************************************************************
* Globals
@@ -169,6 +169,7 @@ static void pidgin_whiteboard_create(Pur
GtkWidget *clear_button;
GtkWidget *save_button;
GtkWidget *color_button;
+ GdkColor color;
PidginWhiteboard *gtkwb = g_new0(PidginWhiteboard, 1);
gtkwb->priv = g_new0(PidginWhiteboardPrivate, 1);
@@ -272,11 +273,16 @@ static void pidgin_whiteboard_create(Pur
G_CALLBACK(pidgin_whiteboard_button_save_press), gtkwb);
/* Add a color selector */
- color_button = gtk_button_new_from_stock(GTK_STOCK_SELECT_COLOR);
+ color_button = gtk_color_button_new();
gtk_box_pack_start(GTK_BOX(vbox_controls), color_button, FALSE, FALSE, PIDGIN_HIG_BOX_SPACE);
gtk_widget_show(color_button);
- g_signal_connect(G_OBJECT(color_button), "clicked",
- G_CALLBACK(color_select_dialog), gtkwb);
+
+ gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(color_button), FALSE);
+ pidgin_whiteboard_rgb24_to_rgb48(gtkwb->brush_color, &color);
+ pidgin_color_chooser_set_rgb(GTK_COLOR_CHOOSER(color_button), &color);
+
+ g_signal_connect(G_OBJECT(color_button), "color-set",
+ G_CALLBACK(color_selected), gtkwb);
/* Make all this (window) visible */
gtk_widget_show(window);
@@ -867,20 +873,14 @@ static void pidgin_whiteboard_rgb24_to_r
}
static void
-color_selected(GtkDialog *dialog, gint response, gpointer _gtkwb)
+color_selected(GtkColorButton *button, PidginWhiteboard *gtkwb)
{
GdkColor color;
- PidginWhiteboard *gtkwb = _gtkwb;
PurpleWhiteboard *wb = gtkwb->wb;
int old_size, old_color;
int new_color;
- pidgin_color_chooser_get_rgb(GTK_COLOR_CHOOSER(dialog), &color);
- g_object_set_data(G_OBJECT(gtkwb->window), "colour-dialog", NULL);
- gtk_widget_destroy(GTK_WIDGET(dialog));
-
- if (response != GTK_RESPONSE_OK)
- return;
+ pidgin_color_chooser_get_rgb(GTK_COLOR_CHOOSER(button), &color);
new_color = (color.red & 0xFF00) << 8;
new_color |= (color.green & 0xFF00);
@@ -890,21 +890,3 @@ color_selected(GtkDialog *dialog, gint r
purple_whiteboard_send_brush(wb, old_size, new_color);
}
-static void color_select_dialog(GtkWidget *widget, PidginWhiteboard *gtkwb)
-{
- GdkColor color;
- GtkWidget *dialog;
-
- dialog = gtk_color_chooser_dialog_new(_("Select color"),
- GTK_WINDOW(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)));
- gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(dialog), FALSE);
- g_object_set_data(G_OBJECT(gtkwb->window), "colour-dialog", dialog);
-
- g_signal_connect(G_OBJECT(dialog), "response",
- G_CALLBACK(color_selected), gtkwb);
-
- pidgin_whiteboard_rgb24_to_rgb48(gtkwb->brush_color, &color);
- pidgin_color_chooser_set_rgb(GTK_COLOR_CHOOSER(dialog), &color);
-
- gtk_widget_show_all(GTK_WIDGET(dialog));
-}
diff --git a/pidgin/plugins/themeedit.c b/pidgin/plugins/themeedit.c
--- a/pidgin/plugins/themeedit.c
+++ b/pidgin/plugins/themeedit.c
@@ -60,51 +60,43 @@ close_blist_theme(GtkWidget *w, GtkWidge
}
static void
-theme_color_selected(GtkDialog *dialog, gint response, const char *prop)
+theme_color_selected(GtkColorButton *button, const char *prop)
{
- if (response == GTK_RESPONSE_OK) {
- GdkColor color;
- PidginBlistTheme *theme;
+ GdkColor color;
+ PidginBlistTheme *theme;
- pidgin_color_chooser_get_rgb(GTK_COLOR_CHOOSER(dialog), &color);
+ pidgin_color_chooser_get_rgb(GTK_COLOR_CHOOSER(button), &color);
- theme = pidgin_blist_get_theme();
+ theme = pidgin_blist_get_theme();
- if (prop_type_is_color(theme, prop)) {
- g_object_set(G_OBJECT(theme), prop, &color, NULL);
+ if (prop_type_is_color(theme, prop)) {
+ g_object_set(G_OBJECT(theme), prop, &color, NULL);
+ } else {
+ PidginThemeFont *font = NULL;
+ g_object_get(G_OBJECT(theme), prop, &font, NULL);
+ if (!font) {
+ font = pidgin_theme_font_new(NULL, &color);
+ g_object_set(G_OBJECT(theme), prop, font, NULL);
+ pidgin_theme_font_free(font);
} else {
- PidginThemeFont *font = NULL;
- g_object_get(G_OBJECT(theme), prop, &font, NULL);
- if (!font) {
- font = pidgin_theme_font_new(NULL, &color);
- g_object_set(G_OBJECT(theme), prop, font, NULL);
- pidgin_theme_font_free(font);
- } else {
- pidgin_theme_font_set_color(font, &color);
- }
+ pidgin_theme_font_set_color(font, &color);
}
- pidgin_blist_set_theme(theme);
}
-
- gtk_widget_destroy(GTK_WIDGET(dialog));
+ pidgin_blist_set_theme(theme);
}
static void
-theme_font_face_selected(GtkWidget *dialog, gint response, gpointer font)
+theme_font_face_selected(GtkFontButton *button, PidginThemeFont *font)
{
- if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) {
- const char *fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog));
- pidgin_theme_font_set_font_face(font, fontname);
- pidgin_blist_refresh(purple_blist_get_buddy_list());
- }
- gtk_widget_destroy(dialog);
+ const char *fontname = gtk_font_button_get_font_name(button);
+ pidgin_theme_font_set_font_face(font, fontname);
+ pidgin_blist_refresh(purple_blist_get_buddy_list());
}
-static void
-theme_font_select_face(GtkWidget *widget, gpointer prop)
+static GtkWidget *
+theme_font_select_face_widget(const char *prop)
{
- GtkWindow *window;
- GtkWidget *dialog;
+ GtkWidget *widget;
PidginBlistTheme *theme;
PidginThemeFont *font = NULL;
const char *face;
@@ -120,19 +112,20 @@ theme_font_select_face(GtkWidget *widget
}
face = pidgin_theme_font_get_font_face(font);
- window = GTK_WINDOW(gtk_widget_get_toplevel(widget));
- dialog = gtk_font_chooser_dialog_new(_("Select Font"), window);
+ widget = gtk_font_button_new();
+ gtk_font_button_set_title(GTK_FONT_BUTTON(widget), _("Select Font"));
if (face && *face)
- gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), face);
- g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(theme_font_face_selected),
+ gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), face);
+ g_signal_connect(G_OBJECT(widget), "font-set", G_CALLBACK(theme_font_face_selected),
font);
- gtk_widget_show_all(dialog);
+
+ return widget;
}
-static void
-theme_color_select(GtkWidget *widget, gpointer prop)
+static GtkWidget *
+theme_color_select_widget(const char *prop)
{
- GtkWidget *dialog;
+ GtkWidget *widget;
PidginBlistTheme *theme;
const GdkColor *color = NULL;
@@ -147,15 +140,15 @@ theme_color_select(GtkWidget *widget, gp
color = pidgin_theme_font_get_color(pair);
}
- dialog = gtk_color_chooser_dialog_new(_("Select Color"),
- GTK_WINDOW(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)));
- gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(dialog), FALSE);
+ widget = gtk_color_button_new();
+ gtk_color_button_set_title(GTK_COLOR_BUTTON(widget), _("Select Color"));
+ gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(widget), FALSE);
if (color)
- pidgin_color_chooser_set_rgb(GTK_COLOR_CHOOSER(dialog), color);
- g_signal_connect(G_OBJECT(dialog), "response",
- G_CALLBACK(theme_color_selected), prop);
+ pidgin_color_chooser_set_rgb(GTK_COLOR_CHOOSER(widget), color);
+ g_signal_connect(G_OBJECT(widget), "color-set",
+ G_CALLBACK(theme_color_selected), (gpointer)prop);
- gtk_widget_show_all(dialog);
+ return widget;
}
static GtkWidget *
@@ -173,10 +166,7 @@ pidgin_theme_create_color_selector(const
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text(label, blurb);
- color = pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_COLOR,
- PIDGIN_BUTTON_HORIZONTAL);
- g_signal_connect(G_OBJECT(color), "clicked", G_CALLBACK(theme_color_select),
- (gpointer)prop);
+ color = theme_color_select_widget(prop);
gtk_box_pack_start(GTK_BOX(hbox), color, FALSE, FALSE, 0);
return hbox;
@@ -197,16 +187,10 @@ pidgin_theme_create_font_selector(const
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text(label, blurb);
- font = pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_FONT,
- PIDGIN_BUTTON_HORIZONTAL);
- g_signal_connect(G_OBJECT(font), "clicked", G_CALLBACK(theme_font_select_face),
- (gpointer)prop);
+ font = theme_font_select_face_widget(prop);
gtk_box_pack_start(GTK_BOX(hbox), font, FALSE, FALSE, 0);
- color = pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_COLOR,
- PIDGIN_BUTTON_HORIZONTAL);
- g_signal_connect(G_OBJECT(color), "clicked", G_CALLBACK(theme_color_select),
- (gpointer)prop);
+ color = theme_color_select_widget(prop);
gtk_box_pack_start(GTK_BOX(hbox), color, FALSE, FALSE, 0);
return hbox;
More information about the Commits
mailing list