diff options
author | Tristan Van Berkom <tristanvb@openismus.com> | 2013-03-23 17:52:48 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristanvb@openismus.com> | 2013-04-08 21:19:28 +0900 |
commit | 3c39c388c9413df5e06733fa5fbd005260b0a06b (patch) | |
tree | d5e963eefa8d3a84d8a366acf5620711de3e5304 /gtk | |
parent | 67a2cdb303d640ef78a0369741453c33a975fd52 (diff) | |
download | gtk+-3c39c388c9413df5e06733fa5fbd005260b0a06b.tar.gz |
GtkLockButton: Define children with a GtkBuilder template
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 1 | ||||
-rw-r--r-- | gtk/gtk.gresource.xml | 1 | ||||
-rw-r--r-- | gtk/gtklockbutton.c | 31 | ||||
-rw-r--r-- | gtk/gtklockbutton.ui | 64 | ||||
-rw-r--r-- | gtk/tests/templates.c | 14 |
5 files changed, 90 insertions, 21 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 3209f40512..a5ab08eb39 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1099,6 +1099,7 @@ COMPOSITE_TEMPLATES = \ gtkaboutdialog.ui \ gtkdialog.ui \ gtkinfobar.ui \ + gtklockbutton.ui \ gtkmessagedialog.ui # diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml index af69aa0d47..fae2734c49 100644 --- a/gtk/gtk.gresource.xml +++ b/gtk/gtk.gresource.xml @@ -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> diff --git a/gtk/gtklockbutton.c b/gtk/gtklockbutton.c index 962b4a947d..b8a162139d 100644 --- a/gtk/gtklockbutton.c +++ b/gtk/gtklockbutton.c @@ -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); } diff --git a/gtk/gtklockbutton.ui b/gtk/gtklockbutton.ui new file mode 100644 index 0000000000..5229a38fea --- /dev/null +++ b/gtk/gtklockbutton.ui @@ -0,0 +1,64 @@ +<?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> diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c index 56d09a67bb..fb43fbcf7c 100644 --- a/gtk/tests/templates.c +++ b/gtk/tests/templates.c @@ -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(); } |