summaryrefslogtreecommitdiff
path: root/gtk/gtkfontchooserutils.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@gnome.org>2011-09-12 01:49:26 +0200
committerChristian Persch <chpe@gnome.org>2011-09-13 12:55:21 +0200
commit5452525143ce10628080ceabf19cb1f68d5708a9 (patch)
tree33afac26fd60bd205d0a636ff516b8e7f0a9a221 /gtk/gtkfontchooserutils.c
parent291b04402864563425b34f2c00bc936642fd41f6 (diff)
downloadgtk+-5452525143ce10628080ceabf19cb1f68d5708a9.tar.gz
Make GtkFontChooser an interface
Make the GtkFontChooser API similar to the Gtk{File,Recent,App}Chooser APIs by introducing GtkFontChooser as an interface, that has a default implementation in GtkFontChooserWidget. https://bugzilla.gnome.org/show_bug.cgi?id=657627
Diffstat (limited to 'gtk/gtkfontchooserutils.c')
-rw-r--r--gtk/gtkfontchooserutils.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/gtk/gtkfontchooserutils.c b/gtk/gtkfontchooserutils.c
new file mode 100644
index 0000000000..4dbec90922
--- /dev/null
+++ b/gtk/gtkfontchooserutils.c
@@ -0,0 +1,186 @@
+/* gtkfontchooserutils.h - Private utility functions for implementing a
+ * GtkFontChooser interface
+ *
+ * Copyright (C) 2006 Emmanuele Bassi
+ *
+ * All rights reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Based on gtkfilechooserutils.c:
+ * Copyright (C) 2003 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include "gtkfontchooserutils.h"
+
+static GtkFontChooser *
+get_delegate (GtkFontChooser *receiver)
+{
+ return g_object_get_qdata (G_OBJECT (receiver),
+ GTK_FONT_CHOOSER_DELEGATE_QUARK);
+}
+
+static gchar *
+delegate_get_font_name (GtkFontChooser *chooser)
+{
+ return gtk_font_chooser_get_font_name (get_delegate (chooser));
+}
+
+static gboolean
+delegate_set_font_name (GtkFontChooser *chooser,
+ const gchar *fontname)
+{
+ return gtk_font_chooser_set_font_name (get_delegate (chooser), fontname);
+}
+
+static PangoFontFamily *
+delegate_get_font_family (GtkFontChooser *chooser)
+{
+ return gtk_font_chooser_get_family (get_delegate (chooser));
+}
+
+static PangoFontFace *
+delegate_get_font_face (GtkFontChooser *chooser)
+{
+ return gtk_font_chooser_get_face (get_delegate (chooser));
+}
+
+static int
+delegate_get_font_size (GtkFontChooser *chooser)
+{
+ return gtk_font_chooser_get_size (get_delegate (chooser));
+}
+
+static void
+delegate_set_filter_func (GtkFontChooser *chooser,
+ GtkFontFilterFunc filter_func,
+ gpointer filter_data,
+ GDestroyNotify data_destroy)
+{
+ gtk_font_chooser_set_filter_func (get_delegate (chooser),
+ filter_func,
+ filter_data,
+ data_destroy);
+}
+
+static void
+delegate_notify (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ gpointer iface;
+
+ iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
+ GTK_TYPE_FONT_CHOOSER);
+ if (g_object_interface_find_property (iface, pspec->name))
+ g_object_notify_by_pspec (user_data, pspec);
+}
+
+static void
+delegate_font_activated (GtkFontChooser *receiver,
+ const gchar *fontname,
+ GtkFontChooser *delegate)
+{
+ _gtk_font_chooser_font_activated (delegate, fontname);
+}
+
+GQuark
+_gtk_font_chooser_delegate_get_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0))
+ quark = g_quark_from_static_string ("gtk-font-chooser-delegate");
+
+ return quark;
+}
+
+/**
+ * _gtk_font_chooser_install_properties:
+ * @klass: the class structure for a type deriving from #GObject
+ *
+ * Installs the necessary properties for a class implementing
+ * #GtkFontChooser. A #GtkParamSpecOverride property is installed
+ * for each property, using the values from the #GtkFontChooserProp
+ * enumeration. The caller must make sure itself that the enumeration
+ * values don't collide with some other property values they
+ * are using.
+ */
+void
+_gtk_font_chooser_install_properties (GObjectClass *klass)
+{
+ g_object_class_override_property (klass,
+ GTK_FONT_CHOOSER_PROP_FONT_NAME,
+ "font-name");
+ g_object_class_override_property (klass,
+ GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
+ "preview-text");
+ g_object_class_override_property (klass,
+ GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
+ "show-preview-entry");
+}
+
+/**
+ * _gtk_font_chooser_delegate_iface_init:
+ * @iface: a #GtkFontChooserIface
+ *
+ * An interface-initialization function for use in cases where
+ * an object is simply delegating the methods, signals of
+ * the #GtkFontChooser interface to another object.
+ * _gtk_font_chooser_set_delegate() must be called on each
+ * instance of the object so that the delegate object can
+ * be found.
+ */
+void
+_gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
+{
+ iface->get_font_name = delegate_get_font_name;
+ iface->set_font_name = delegate_set_font_name;
+ iface->get_font_family = delegate_get_font_family;
+ iface->get_font_face = delegate_get_font_face;
+ iface->get_font_size = delegate_get_font_size;
+ iface->set_filter_func = delegate_set_filter_func;
+}
+
+/**
+ * _gtk_font_chooser_set_delegate:
+ * @receiver: a #GObject implementing #GtkFontChooser
+ * @delegate: another #GObject implementing #GtkFontChooser
+ *
+ * Establishes that calls on @receiver for #GtkFontChooser
+ * methods should be delegated to @delegate, and that
+ * #GtkFontChooser signals emitted on @delegate should be
+ * forwarded to @receiver. Must be used in conjunction with
+ * _gtk_font_chooser_delegate_iface_init().
+ */
+void
+_gtk_font_chooser_set_delegate (GtkFontChooser *receiver,
+ GtkFontChooser *delegate)
+{
+ g_return_if_fail (GTK_IS_FONT_CHOOSER (receiver));
+ g_return_if_fail (GTK_IS_FONT_CHOOSER (delegate));
+
+ g_object_set_qdata (G_OBJECT (receiver),
+ GTK_FONT_CHOOSER_DELEGATE_QUARK,
+ delegate);
+
+ g_signal_connect (delegate, "notify",
+ G_CALLBACK (delegate_notify), receiver);
+ g_signal_connect (delegate, "font-activated",
+ G_CALLBACK (delegate_font_activated), receiver);
+}