diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index dc4f8a0281..949fc625e3 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1106,6 +1106,7 @@ COMPOSITE_TEMPLATES = \
gtkfilechooserbutton.ui \
gtkfilechooserdefault.ui \
gtkfilechooserdialog.ui \
+ gtkfontbutton.ui \
gtkfontchooserdialog.ui \
gtkfontchooserwidget.ui \
gtkinfobar.ui \
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index bdc844a8d9..7def35dd73 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -21,6 +21,7 @@
gtkfilechooserbutton.ui
gtkfilechooserdefault.ui
gtkfilechooserdialog.ui
+ gtkfontbutton.ui
gtkfontchooserdialog.ui
gtkfontchooserwidget.ui
gtkinfobar.ui
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index e4d908fe8f..3576364e26 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -70,9 +70,9 @@ struct _GtkFontButtonPrivate
guint show_preview_entry : 1;
GtkWidget *font_dialog;
- GtkWidget *inside;
GtkWidget *font_label;
GtkWidget *size_label;
+ GtkWidget *font_size_box;
PangoFontDescription *font_desc;
PangoFontFamily *font_family;
@@ -123,7 +123,6 @@ static void dialog_destroy (GtkWidget *widget,
gpointer data);
/* Auxiliary functions */
-static GtkWidget *gtk_font_button_create_inside (GtkFontButton *gfs);
static void gtk_font_button_label_use_font (GtkFontButton *gfs);
static void gtk_font_button_update_font_info (GtkFontButton *gfs);
@@ -406,9 +405,11 @@ static void
gtk_font_button_class_init (GtkFontButtonClass *klass)
{
GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
GtkButtonClass *button_class;
gobject_class = (GObjectClass *) klass;
+ widget_class = (GtkWidgetClass *) klass;
button_class = (GtkButtonClass *) klass;
gobject_class->finalize = gtk_font_button_finalize;
@@ -539,6 +540,13 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
+ /* Bind class to template
+ */
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkfontbutton.ui");
+ gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, font_label);
+ gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, size_label);
+ gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, font_size_box);
g_type_class_add_private (gobject_class, sizeof (GtkFontButtonPrivate));
}
@@ -562,8 +570,7 @@ gtk_font_button_init (GtkFontButton *font_button)
font_button->priv->font_size = -1;
font_button->priv->title = g_strdup (_("Pick a Font"));
- font_button->priv->inside = gtk_font_button_create_inside (font_button);
- gtk_container_add (GTK_CONTAINER (font_button), font_button->priv->inside);
+ gtk_widget_init_template (GTK_WIDGET (font_button));
gtk_font_button_take_font_desc (font_button, NULL);
}
@@ -928,9 +935,10 @@ gtk_font_button_set_show_size (GtkFontButton *font_button,
{
font_button->priv->show_size = show_size;
- gtk_container_remove (GTK_CONTAINER (font_button), font_button->priv->inside);
- font_button->priv->inside = gtk_font_button_create_inside (font_button);
- gtk_container_add (GTK_CONTAINER (font_button), font_button->priv->inside);
+ if (font_button->priv->show_size)
+ gtk_widget_show (font_button->priv->font_size_box);
+ else
+ gtk_widget_hide (font_button->priv->font_size_box);
gtk_font_button_update_font_info (font_button);
@@ -1109,31 +1117,6 @@ dialog_destroy (GtkWidget *widget,
font_button->priv->font_dialog = NULL;
}
-static GtkWidget *
-gtk_font_button_create_inside (GtkFontButton *font_button)
-{
- GtkWidget *widget;
-
-
- widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
- font_button->priv->font_label = gtk_label_new (_("Font"));
-
- gtk_label_set_justify (GTK_LABEL (font_button->priv->font_label), GTK_JUSTIFY_LEFT);
- gtk_box_pack_start (GTK_BOX (widget), font_button->priv->font_label, TRUE, TRUE, 5);
-
- if (font_button->priv->show_size)
- {
- gtk_box_pack_start (GTK_BOX (widget), gtk_separator_new (GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0);
- font_button->priv->size_label = gtk_label_new ("14");
- gtk_box_pack_start (GTK_BOX (widget), font_button->priv->size_label, FALSE, FALSE, 5);
- }
-
- gtk_widget_show_all (widget);
-
- return widget;
-}
-
static void
gtk_font_button_label_use_font (GtkFontButton *font_button)
{
diff --git a/gtk/gtkfontbutton.ui b/gtk/gtkfontbutton.ui
new file mode 100644
index 0000000000..62658fbad5
--- /dev/null
+++ b/gtk/gtkfontbutton.ui
@@ -0,0 +1,64 @@
+
+
+
+
+ True
+ True
+
+
+
+
+
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 8816f80b2a..e666c1ce5c 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -245,6 +245,16 @@ test_file_chooser_button_basic (void)
gtk_widget_destroy (widget);
}
+static void
+test_font_button_basic (void)
+{
+ GtkWidget *widget;
+
+ widget = gtk_font_button_new ();
+ g_assert (GTK_IS_FONT_BUTTON (widget));
+ gtk_widget_destroy (widget);
+}
+
static void
test_font_chooser_widget_basic (void)
{
@@ -324,6 +334,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkFileChooserWidget/Basic", test_file_chooser_widget_basic);
g_test_add_func ("/Template/GtkFileChooserDialog/Basic", test_file_chooser_dialog_basic);
g_test_add_func ("/Template/GtkFileChooserButton/Basic", test_file_chooser_button_basic);
+ g_test_add_func ("/Template/GtkFontButton/Basic", test_font_button_basic);
g_test_add_func ("/Template/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic);
g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic);
g_test_add_func ("/Template/GtkRecentChooserWidget/Basic", test_recent_chooser_widget_basic);