[gtk+/composite-templates-new: 10/32] GtkInfoBar: 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: 10/32] GtkInfoBar: Define children with a GtkBuilder template
- Date: Mon, 8 Apr 2013 08:21:32 +0000 (UTC)
commit 0091e25dbe40249bb5a5ffb362806ba1d8ef1980
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Fri Mar 22 19:45:31 2013 +0900
GtkInfoBar: Define children with a GtkBuilder template
gtk/Makefile.am | 3 +-
gtk/gtk.gresource.xml | 1 +
gtk/gtkinfobar.c | 50 ++++++------------------------------------------
gtk/gtkinfobar.ui | 42 +++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 ++++++++++
po/POTFILES.in | 1 +
6 files changed, 64 insertions(+), 44 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 44ee02d..9c7046c 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1097,7 +1097,8 @@ DND_CURSORS = \
COMPOSITE_TEMPLATES = \
gtkdialog.ui \
- gtkmessagedialog.ui
+ gtkmessagedialog.ui \
+ gtkinfobar.ui
#
# rules to generate built sources
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 329f29b..cfd3025 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -12,6 +12,7 @@
<file alias="cursor/dnd-move.png">cursor_dnd_move.png</file>
<file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
<file compressed="true">gtkdialog.ui</file>
+ <file compressed="true">gtkinfobar.ui</file>
<file compressed="true">gtkmessagedialog.ui</file>
</gresource>
</gresources>
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a3a877d..c086d95 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -167,9 +167,6 @@ static void gtk_info_bar_get_preferred_height (GtkWidget *widget,
static gboolean gtk_info_bar_draw (GtkWidget *widget,
cairo_t *cr);
static void gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface);
-static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
- GtkBuilder *builder,
- const gchar *childname);
static gboolean gtk_info_bar_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
@@ -530,6 +527,12 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
+ /* Bind class to template
+ */
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkinfobar.ui");
+ gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, content_area);
+ gtk_widget_class_bind_child_internal (widget_class, GtkInfoBarPrivate, action_area);
+
g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
}
@@ -537,42 +540,19 @@ static void
gtk_info_bar_init (GtkInfoBar *info_bar)
{
GtkWidget *widget = GTK_WIDGET (info_bar);
- GtkWidget *content_area;
- GtkWidget *action_area;
-
- gtk_widget_push_composite_child ();
info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
GTK_TYPE_INFO_BAR,
GtkInfoBarPrivate);
- content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (content_area);
- gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
-
- action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
- gtk_widget_show (action_area);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
- gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
-
- gtk_widget_set_app_paintable (widget, TRUE);
gtk_widget_set_redraw_on_allocate (widget, TRUE);
- info_bar->priv->content_area = content_area;
- info_bar->priv->action_area = action_area;
-
- /* set default spacings */
- gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), ACTION_AREA_DEFAULT_SPACING);
- gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area), ACTION_AREA_DEFAULT_BORDER);
- gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_SPACING);
- gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_BORDER);
-
/* message-type is a CONSTRUCT property, so we init to a value
* different from its default to trigger its property setter
* during construction */
info_bar->priv->message_type = GTK_MESSAGE_OTHER;
- gtk_widget_pop_composite_child ();
+ gtk_widget_init_template (GTK_WIDGET (info_bar));
}
static GtkBuildableIface *parent_buildable_iface;
@@ -581,26 +561,10 @@ static void
gtk_info_bar_buildable_interface_init (GtkBuildableIface *iface)
{
parent_buildable_iface = g_type_interface_peek_parent (iface);
- iface->get_internal_child = gtk_info_bar_buildable_get_internal_child;
iface->custom_tag_start = gtk_info_bar_buildable_custom_tag_start;
iface->custom_finished = gtk_info_bar_buildable_custom_finished;
}
-static GObject *
-gtk_info_bar_buildable_get_internal_child (GtkBuildable *buildable,
- GtkBuilder *builder,
- const gchar *childname)
-{
- if (strcmp (childname, "content_area") == 0)
- return G_OBJECT (GTK_INFO_BAR (buildable)->priv->content_area);
- else if (strcmp (childname, "action_area") == 0)
- return G_OBJECT (GTK_INFO_BAR (buildable)->priv->action_area);
-
- return parent_buildable_iface->get_internal_child (buildable,
- builder,
- childname);
-}
-
static gint
get_response_for_widget (GtkInfoBar *info_bar,
GtkWidget *widget)
diff --git a/gtk/gtkinfobar.ui b/gtk/gtkinfobar.ui
new file mode 100644
index 0000000..f8a6799
--- /dev/null
+++ b/gtk/gtkinfobar.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GtkInfoBar" parent="GtkBox">
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox" id="content_area">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="spacing">16</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButtonBox" id="action_area">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 51b6579..f0d58f7 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -55,6 +55,16 @@ test_message_dialog_basic (void)
gtk_widget_destroy (dialog);
}
+static void
+test_info_bar_basic (void)
+{
+ GtkWidget *infobar;
+
+ infobar = gtk_info_bar_new ();
+ g_assert (GTK_IS_INFO_BAR (infobar));
+ gtk_widget_destroy (infobar);
+}
+
int
main (int argc, char **argv)
{
@@ -70,6 +80,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkDialog/Basic", test_dialog_basic);
g_test_add_func ("/Template/GtkDialog/OverrideProperty", test_dialog_override_property);
g_test_add_func ("/Template/GtkMessageDialog/Basic", test_message_dialog_basic);
+ g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic);
return g_test_run();
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d8add4d..bfb50a4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -275,4 +275,5 @@ modules/printbackends/lpr/gtkprintbackendlpr.c
modules/printbackends/papi/gtkprintbackendpapi.c
modules/printbackends/test/gtkprintbackendtest.c
[type: gettext/glade]gtk/gtkdialog.ui
+[type: gettext/glade]gtk/gtkinfobar.ui
[type: gettext/glade]gtk/gtkmessagedialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]