Commit 3c39c388 authored by Tristan Van Berkom's avatar Tristan Van Berkom

GtkLockButton: Define children with a GtkBuilder template

parent 67a2cdb3
......@@ -1099,6 +1099,7 @@ COMPOSITE_TEMPLATES = \
gtkaboutdialog.ui \
gtkdialog.ui \
gtkinfobar.ui \
gtklockbutton.ui \
gtkmessagedialog.ui
#
......
......@@ -14,6 +14,7 @@
<file compressed="true">gtkaboutdialog.ui</file>
<file compressed="true">gtkdialog.ui</file>
<file compressed="true">gtkinfobar.ui</file>
<file compressed="true">gtklockbutton.ui</file>
<file compressed="true">gtkmessagedialog.ui</file>
</gresource>
</gresources>
......@@ -108,7 +108,6 @@ gtk_lock_button_finalize (GObject *object)
g_object_unref (priv->icon_lock);
g_object_unref (priv->icon_unlock);
g_object_unref (priv->label_group);
if (priv->cancellable != NULL)
{
......@@ -226,26 +225,7 @@ gtk_lock_button_init (GtkLockButton *button)
GTK_TYPE_LOCK_BUTTON,
GtkLockButtonPrivate);
priv->label_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_set_halign (priv->box, GTK_ALIGN_CENTER);
gtk_widget_set_valign (priv->box, GTK_ALIGN_CENTER);
gtk_widget_show (priv->box);
gtk_container_add (GTK_CONTAINER (button), priv->box);
priv->image = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (priv->box), priv->image, FALSE, FALSE, 0);
gtk_widget_show (priv->image);
priv->label_lock = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (priv->label_lock), 0, 0.5);
gtk_widget_set_no_show_all (priv->label_lock, TRUE);
gtk_widget_show (priv->label_lock);
gtk_box_pack_start (GTK_BOX (priv->box), priv->label_lock, FALSE, FALSE, 0);
gtk_size_group_add_widget (priv->label_group, priv->label_lock);
priv->label_unlock = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (priv->label_unlock), 0, 0.5);
gtk_widget_set_no_show_all (priv->label_unlock, TRUE);
gtk_box_pack_start (GTK_BOX (priv->box), priv->label_unlock, FALSE, FALSE, 0);
gtk_size_group_add_widget (priv->label_group, priv->label_unlock);
gtk_widget_init_template (GTK_WIDGET (button));
names[0] = "changes-allow-symbolic";
names[1] = "changes-allow";
......@@ -328,6 +308,15 @@ gtk_lock_button_class_init (GtkLockButtonClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/* Bind class to template
*/
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtklockbutton.ui");
gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, box);
gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, image);
gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_lock);
gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_unlock);
gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_group);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LOCK_BUTTON_ACCESSIBLE);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
<!-- interface-requires gtk+ 3.6 -->
<template class="GtkLockButton" parent="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkBox" id="box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</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="label_lock">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Lock</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_unlock">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Unlock</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</template>
<object class="GtkSizeGroup" id="label_group">
<property name="mode">both</property>
<widgets>
<widget name="label_lock"/>
<widget name="label_unlock"/>
</widgets>
</object>
</interface>
......@@ -75,6 +75,19 @@ test_info_bar_basic (void)
gtk_widget_destroy (infobar);
}
static void
test_lock_button_basic (void)
{
GtkWidget *button;
GPermission *permission;
permission = g_simple_permission_new (TRUE);
button = gtk_lock_button_new (permission);
g_assert (GTK_IS_LOCK_BUTTON (button));
gtk_widget_destroy (button);
g_object_unref (permission);
}
int
main (int argc, char **argv)
{
......@@ -92,6 +105,7 @@ main (int argc, char **argv)
g_test_add_func ("/Template/GtkMessageDialog/Basic", test_message_dialog_basic);
g_test_add_func ("/Template/GtkAboutDialog/Basic", test_about_dialog_basic);
g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic);
g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_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