[gtk+/composite-templates-new: 30/30] GtkFontButton: Define children with a GtkBuilder template
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates-new: 30/30] GtkFontButton: Define children with a GtkBuilder template
- Date: Sat, 30 Mar 2013 08:46:48 +0000 (UTC)
commit b67cac89ca3a2439b4a04c0c6929dfbf81d3fb1f
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Sat Mar 30 17:35:54 2013 +0900
GtkFontButton: Define children with a GtkBuilder template
gtk/Makefile.am | 1 +
gtk/gtk.gresource.xml | 1 +
gtk/gtkfontbutton.c | 47 +++++++++++------------------------
gtk/gtkfontbutton.ui | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 ++++++++
po/POTFILES.in | 1 +
6 files changed, 93 insertions(+), 32 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index d7e3dd6..fbf5e7b 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1105,6 +1105,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 f5691d3..06c2edc 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -21,6 +21,7 @@
<file>gtkfilechooserbutton.ui</file>
<file>gtkfilechooserdefault.ui</file>
<file>gtkfilechooserdialog.ui</file>
+ <file>gtkfontbutton.ui</file>
<file>gtkfontchooserdialog.ui</file>
<file>gtkfontchooserwidget.ui</file>
<file>gtkinfobar.ui</file>
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index e4d908f..3576364 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 0000000..62658fb
--- /dev/null
+++ b/gtk/gtkfontbutton.ui
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkFontButton" parent="GtkButton">
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="font_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Font</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">5</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="font_size_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="no_show_all">True</property>
+ <child>
+ <object class="GtkSeparator" id="separator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="size_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">14</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 8816f80..e666c1c 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -246,6 +246,16 @@ test_file_chooser_button_basic (void)
}
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)
{
GtkWidget *widget;
@@ -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);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0672280..ea4d669 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -284,6 +284,7 @@ modules/printbackends/test/gtkprintbackendtest.c
[type: gettext/glade]gtk/gtkfilechooserbutton.ui
[type: gettext/glade]gtk/gtkfilechooserdedault.ui
[type: gettext/glade]gtk/gtkfilechooserdialog.ui
+[type: gettext/glade]gtk/gtkfontbutton.ui
[type: gettext/glade]gtk/gtkfontchooserdialog.ui
[type: gettext/glade]gtk/gtkfontchooserwidget.ui
[type: gettext/glade]gtk/gtkinfobar.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]