summaryrefslogtreecommitdiff
path: root/gtk/gtkfontbutton.c
diff options
context:
space:
mode:
authorTristan Van Berkom <tristanvb@openismus.com>2013-03-30 17:35:54 +0900
committerTristan Van Berkom <tristanvb@openismus.com>2013-04-08 21:19:29 +0900
commit36bacc4674dc76d197f69e173eef8858c6d98853 (patch)
tree87cf6cd8e4947a2e6c5baa856af0ba1a9ed36212 /gtk/gtkfontbutton.c
parent4c81151a20b1e269b36f986fe057538d8ad85fc1 (diff)
downloadgtk+-36bacc4674dc76d197f69e173eef8858c6d98853.tar.gz
GtkFontButton: Define children with a GtkBuilder template
Diffstat (limited to 'gtk/gtkfontbutton.c')
-rw-r--r--gtk/gtkfontbutton.c47
1 files changed, 15 insertions, 32 deletions
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)
{