Commit 56167944 authored by Tristan Van Berkom's avatar Tristan Van Berkom

GtkInfoBar: Define children with a GtkBuilder template

parent 671871b4
......@@ -1097,7 +1097,8 @@ DND_CURSORS = \
COMPOSITE_TEMPLATES = \
gtkdialog.ui \
gtkmessagedialog.ui
gtkmessagedialog.ui \
gtkinfobar.ui
#
# rules to generate built sources
......
......@@ -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>
......@@ -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)
......
<?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>
......@@ -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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment