1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include <glib/gprintf.h>
28 #include "gtkfontchooserdialog.h"
29 #include "gtkfontchooser.h"
30 #include "gtkfontchooserwidget.h"
31 #include "gtkfontchooserutils.h"
35 #include "gtkaccessible.h"
36 #include "gtkbuildable.h"
37 #include "gtkprivate.h"
38 #include "gtkwidget.h"
40 struct _GtkFontChooserDialogPrivate
42 GtkWidget *fontchooser;
44 GtkWidget *select_button;
45 GtkWidget *cancel_button;
49 * SECTION:gtkfontchooserdialog
50 * @Short_description: A dialog for selecting fonts
51 * @Title: GtkFontChooserDialog
52 * @See_also: #GtkFontChooser, #GtkDialog
54 * The #GtkFontChooserDialog widget is a dialog for selecting a font.
55 * It implements the #GtkFontChooser interface.
57 * <refsect2 id="GtkFontChooserDialog-BUILDER-UI">
58 * <title>GtkFontChooserDialog as GtkBuildable</title>
59 * The GtkFontChooserDialog implementation of the GtkBuildable interface
60 * exposes the buttons with the names
61 * "select_button" and "cancel_button.
67 static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface);
68 static GObject *gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
70 const gchar *childname);
72 G_DEFINE_TYPE_WITH_CODE (GtkFontChooserDialog, gtk_font_chooser_dialog, GTK_TYPE_DIALOG,
73 G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
74 _gtk_font_chooser_delegate_iface_init)
75 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
76 gtk_font_chooser_dialog_buildable_interface_init))
78 static GtkBuildableIface *parent_buildable_iface;
81 gtk_font_chooser_dialog_set_property (GObject *object,
86 GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
87 GtkFontChooserDialogPrivate *priv = dialog->priv;
92 g_object_set_property (G_OBJECT (priv->fontchooser), pspec->name, value);
98 gtk_font_chooser_dialog_get_property (GObject *object,
103 GtkFontChooserDialog *dialog = GTK_FONT_CHOOSER_DIALOG (object);
104 GtkFontChooserDialogPrivate *priv = dialog->priv;
109 g_object_get_property (G_OBJECT (priv->fontchooser), pspec->name, value);
115 gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
117 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
119 gobject_class->get_property = gtk_font_chooser_dialog_get_property;
120 gobject_class->set_property = gtk_font_chooser_dialog_set_property;
122 _gtk_font_chooser_install_properties (gobject_class);
124 g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate));
128 font_activated_cb (GtkFontChooser *fontchooser,
129 const gchar *fontname,
132 GtkDialog *dialog = user_data;
134 gtk_dialog_response (dialog, GTK_RESPONSE_OK);
138 gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag)
140 GtkFontChooserDialogPrivate *priv;
141 GtkDialog *dialog = GTK_DIALOG (fontchooserdiag);
142 GtkWidget *action_area, *content_area;
144 fontchooserdiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooserdiag,
145 GTK_TYPE_FONT_CHOOSER_DIALOG,
146 GtkFontChooserDialogPrivate);
147 priv = fontchooserdiag->priv;
149 content_area = gtk_dialog_get_content_area (dialog);
150 action_area = gtk_dialog_get_action_area (dialog);
152 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
153 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
154 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
155 gtk_box_set_spacing (GTK_BOX (action_area), 6);
157 gtk_widget_push_composite_child ();
159 gtk_window_set_resizable (GTK_WINDOW (fontchooserdiag), TRUE);
161 /* Create the content area */
162 priv->fontchooser = gtk_font_chooser_widget_new ();
163 gtk_container_set_border_width (GTK_CONTAINER (priv->fontchooser), 5);
164 gtk_widget_show (priv->fontchooser);
165 gtk_box_pack_start (GTK_BOX (content_area),
166 priv->fontchooser, TRUE, TRUE, 0);
168 g_signal_connect (priv->fontchooser, "font-activated",
169 G_CALLBACK (font_activated_cb), dialog);
171 /* Create the action area */
172 priv->cancel_button = gtk_dialog_add_button (dialog,
174 GTK_RESPONSE_CANCEL);
175 priv->select_button = gtk_dialog_add_button (dialog,
178 gtk_widget_grab_default (priv->select_button);
180 gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontchooserdiag),
185 gtk_window_set_title (GTK_WINDOW (fontchooserdiag), _("Font Selection"));
187 gtk_widget_pop_composite_child ();
189 _gtk_font_chooser_set_delegate (GTK_FONT_CHOOSER (fontchooserdiag),
190 GTK_FONT_CHOOSER (priv->fontchooser));
194 * gtk_font_chooser_dialog_new:
195 * @title: (allow-none): Title of the dialog, or %NULL
196 * @parent: (allow-none): Transient parent of the dialog, or %NULL
198 * Creates a new #GtkFontChooserDialog.
200 * Return value: a new #GtkFontChooserDialog
205 gtk_font_chooser_dialog_new (const gchar *title,
208 GtkFontChooserDialog *dialog;
210 dialog = g_object_new (GTK_TYPE_FONT_CHOOSER_DIALOG,
212 "transient-for", parent,
215 return GTK_WIDGET (dialog);
219 gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface)
221 parent_buildable_iface = g_type_interface_peek_parent (iface);
222 iface->get_internal_child = gtk_font_chooser_dialog_buildable_get_internal_child;
226 gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
228 const gchar *childname)
230 GtkFontChooserDialogPrivate *priv;
232 priv = GTK_FONT_CHOOSER_DIALOG (buildable)->priv;
234 if (g_strcmp0 (childname, "select_button") == 0)
235 return G_OBJECT (priv->select_button);
236 else if (g_strcmp0 (childname, "cancel_button") == 0)
237 return G_OBJECT (priv->cancel_button);
239 return parent_buildable_iface->get_internal_child (buildable, builder, childname);