/pidgin/main: 8da9d2ec671d: Use new GtkFontChooser where available.
Elliott Sales de Andrade
qulogic at pidgin.im
Thu Aug 16 02:29:05 EDT 2012
Changeset: 8da9d2ec671d1d32221a2254a163dedf0816ed33
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-08-16 02:17 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/8da9d2ec671d
Description:
Use new GtkFontChooser where available.
This currently ignores the font size, even though it's still visible, but
I think that may change in the future.
diffstat:
pidgin/gtk3compat.h | 9 ++++++
pidgin/gtkwebviewtoolbar.c | 67 +++++++++++++++++++--------------------------
pidgin/plugins/pidginrc.c | 10 ++++--
pidgin/plugins/themeedit.c | 9 +++--
4 files changed, 50 insertions(+), 45 deletions(-)
diffs (258 lines):
diff --git a/pidgin/gtk3compat.h b/pidgin/gtk3compat.h
--- a/pidgin/gtk3compat.h
+++ b/pidgin/gtk3compat.h
@@ -25,6 +25,13 @@
* Also, any public API should not depend on this file.
*/
+#if !GTK_CHECK_VERSION(3,2,0)
+
+#define GTK_FONT_CHOOSER GTK_FONT_SELECTION_DIALOG
+#define gtk_font_chooser_dialog_new(x,y) gtk_font_selection_dialog_new(x)
+#define gtk_font_chooser_get_font gtk_font_selection_dialog_get_font_name
+#define gtk_font_chooser_set_font gtk_font_selection_dialog_set_font_name
+
#if !GTK_CHECK_VERSION(3,0,0)
#define gdk_x11_window_get_xid GDK_WINDOW_XWINDOW
@@ -169,5 +176,7 @@ static inline gint gdk_window_get_height
#endif /* 3.0.0 */
+#endif /* 3.2.0 */
+
#endif /* _PIDGINGTK3COMPAT_H_ */
diff --git a/pidgin/gtkwebviewtoolbar.c b/pidgin/gtkwebviewtoolbar.c
--- a/pidgin/gtkwebviewtoolbar.c
+++ b/pidgin/gtkwebviewtoolbar.c
@@ -43,6 +43,8 @@
#include <gdk/gdkkeysyms.h>
+#include "gtk3compat.h"
+
#define GTK_WEBVIEWTOOLBAR_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GTK_TYPE_WEBVIEWTOOLBAR, GtkWebViewToolbarPriv))
@@ -160,27 +162,22 @@ do_big(GtkAction *large, GtkWebViewToolb
gtk_widget_grab_focus(toolbar->webview);
}
-static gboolean
-destroy_toolbar_font(GtkWidget *widget, GdkEvent *event,
- GtkWebViewToolbar *toolbar)
+static void
+destroy_toolbar_font(GtkWebViewToolbar *toolbar)
{
GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
- if (widget != NULL)
- gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview), "");
-
if (priv->font_dialog != NULL)
{
gtk_widget_destroy(priv->font_dialog);
priv->font_dialog = NULL;
}
-
- return FALSE;
}
static void
realize_toolbar_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
{
+#if !GTK_CHECK_VERSION(3,2,0)
GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
GtkFontSelection *sel;
@@ -193,40 +190,38 @@ realize_toolbar_font(GtkWidget *widget,
gtk_font_selection_get_family_list(sel)));
gtk_widget_show(gtk_widget_get_parent(gtk_widget_get_parent(
gtk_font_selection_get_family_list(sel))));
+#endif
}
static void
-cancel_toolbar_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
-{
- destroy_toolbar_font(widget, NULL, toolbar);
-}
-
-static void
-apply_font(GtkWidget *widget, GtkWebViewToolbar *toolbar)
+apply_font(GtkDialog *dialog, gint response, GtkWebViewToolbar *toolbar)
{
/* this could be expanded to include font size, weight, etc.
but for now only works with font face */
- GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
- GtkFontSelectionDialog *fontsel = GTK_FONT_SELECTION_DIALOG(priv->font_dialog);
- gchar *fontname = gtk_font_selection_dialog_get_font_name(fontsel);
+ gchar *fontname = NULL;
+
+ if (response == GTK_RESPONSE_OK)
+ fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog));
if (fontname) {
- const gchar *family_name = NULL;
- PangoFontDescription *desc = NULL;
+ PangoFontDescription *desc;
+ const gchar *family_name;
desc = pango_font_description_from_string(fontname);
family_name = pango_font_description_get_family(desc);
if (family_name) {
gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview),
- family_name);
+ family_name);
}
pango_font_description_free(desc);
g_free(fontname);
+ } else {
+ gtk_webview_toggle_fontface(GTK_WEBVIEW(toolbar->webview), "");
}
- cancel_toolbar_font(NULL, toolbar);
+ destroy_toolbar_font(toolbar);
}
static void
@@ -238,35 +233,31 @@ toggle_font(GtkAction *font, GtkWebViewT
char *fontname = gtk_webview_get_current_fontface(GTK_WEBVIEW(toolbar->webview));
if (!priv->font_dialog) {
- priv->font_dialog = gtk_font_selection_dialog_new(_("Select Font"));
+ GtkWindow *window;
+ window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbar)));
+ priv->font_dialog = gtk_font_chooser_dialog_new(_("Select Font"), window);
if (fontname) {
char *fonttif = g_strdup_printf("%s 12", fontname);
- gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(priv->font_dialog),
- fonttif);
+ gtk_font_chooser_set_font(GTK_FONT_CHOOSER(priv->font_dialog),
+ fonttif);
g_free(fonttif);
} else {
- gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(priv->font_dialog),
- DEFAULT_FONT_FACE);
+ gtk_font_chooser_set_font(GTK_FONT_CHOOSER(priv->font_dialog),
+ DEFAULT_FONT_FACE);
}
- g_signal_connect(G_OBJECT(priv->font_dialog), "delete_event",
- G_CALLBACK(destroy_toolbar_font), toolbar);
- g_signal_connect(G_OBJECT(
- gtk_font_selection_dialog_get_ok_button(GTK_FONT_SELECTION_DIALOG(priv->font_dialog))),
- "clicked", G_CALLBACK(apply_font), toolbar);
- g_signal_connect(G_OBJECT(
- gtk_font_selection_dialog_get_cancel_button(GTK_FONT_SELECTION_DIALOG(priv->font_dialog))),
- "clicked", G_CALLBACK(cancel_toolbar_font), toolbar);
+ g_signal_connect(G_OBJECT(priv->font_dialog), "response",
+ G_CALLBACK(apply_font), toolbar);
g_signal_connect_after(G_OBJECT(priv->font_dialog), "realize",
- G_CALLBACK(realize_toolbar_font), toolbar);
+ G_CALLBACK(realize_toolbar_font), toolbar);
}
gtk_window_present(GTK_WINDOW(priv->font_dialog));
g_free(fontname);
} else {
- cancel_toolbar_font(GTK_WIDGET(toolbar), toolbar);
+ destroy_toolbar_font(toolbar);
}
gtk_widget_grab_focus(toolbar->webview);
@@ -1263,7 +1254,7 @@ gtk_webviewtoolbar_finalize(GObject *obj
priv->image_dialog = NULL;
}
- destroy_toolbar_font(NULL, NULL, toolbar);
+ destroy_toolbar_font(toolbar);
if (priv->smiley_dialog != NULL) {
#if 0
g_signal_handlers_disconnect_by_func(G_OBJECT(priv->smiley_dialog), close_smiley_dialog, toolbar);
diff --git a/pidgin/plugins/pidginrc.c b/pidgin/plugins/pidginrc.c
--- a/pidgin/plugins/pidginrc.c
+++ b/pidgin/plugins/pidginrc.c
@@ -31,6 +31,8 @@
#include "util.h"
#include "version.h"
+#include "gtk3compat.h"
+
static guint pref_callback;
static const gchar *color_prefs[] = {
@@ -306,7 +308,7 @@ purplerc_font_response(GtkDialog *font_d
prefpath = font_prefs[subscript];
}
- fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(font_dialog));
+ fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(font_dialog));
purple_prefs_set_string(prefpath, fontname);
g_free(fontname);
@@ -318,6 +320,7 @@ static void
purplerc_set_font(GtkWidget *widget, gpointer data)
{
gchar title[128];
+ GtkWindow *window;
GtkWidget *font_dialog = NULL;
gint subscript = GPOINTER_TO_INT(data);
const gchar *pref = NULL, *prefpath = NULL;
@@ -331,14 +334,15 @@ purplerc_set_font(GtkWidget *widget, gpo
prefpath = font_prefs[subscript];
}
- font_dialog = gtk_font_selection_dialog_new(title);
+ window = GTK_WINDOW(gtk_widget_get_toplevel(widget));
+ font_dialog = gtk_font_chooser_dialog_new(title, window);
g_signal_connect(G_OBJECT(font_dialog), "response",
G_CALLBACK(purplerc_font_response), data);
pref = purple_prefs_get_string(prefpath);
if (pref != NULL && strcmp(pref, "")) {
- gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(font_dialog), pref);
+ gtk_font_chooser_set_font(GTK_FONT_CHOOSER(font_dialog), pref);
}
gtk_window_present(GTK_WINDOW(font_dialog));
diff --git a/pidgin/plugins/themeedit.c b/pidgin/plugins/themeedit.c
--- a/pidgin/plugins/themeedit.c
+++ b/pidgin/plugins/themeedit.c
@@ -98,7 +98,7 @@ static void
theme_font_face_selected(GtkWidget *dialog, gint response, gpointer font)
{
if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) {
- const char *fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
+ const char *fontname = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog));
pidgin_theme_font_set_font_face(font, fontname);
pidgin_blist_refresh(purple_get_blist());
}
@@ -108,6 +108,7 @@ theme_font_face_selected(GtkWidget *dial
static void
theme_font_select_face(GtkWidget *widget, gpointer prop)
{
+ GtkWindow *window;
GtkWidget *dialog;
PidginBlistTheme *theme;
PidginThemeFont *font = NULL;
@@ -124,10 +125,10 @@ theme_font_select_face(GtkWidget *widget
}
face = pidgin_theme_font_get_font_face(font);
- dialog = gtk_font_selection_dialog_new(_("Select Font"));
+ window = GTK_WINDOW(gtk_widget_get_toplevel(widget));
+ dialog = gtk_font_chooser_dialog_new(_("Select Font"), window);
if (face && *face)
- gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog),
- face);
+ gtk_font_chooser_set_font(GTK_FONT_CHOOSER(dialog), face);
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(theme_font_face_selected),
font);
gtk_widget_show_all(dialog);
More information about the Commits
mailing list