[gtk+/composite-templates-new: 7/7] GtkAboutDialog: 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: 7/7] GtkAboutDialog: Define children with a GtkBuilder template
- Date: Fri, 22 Mar 2013 13:17:01 +0000 (UTC)
commit 729c2d46307f911316875a76e5f98a9ae08ca851
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Fri Mar 22 21:51:40 2013 +0900
GtkAboutDialog: Define children with a GtkBuilder template
gtk/Makefile.am | 5 +-
gtk/gtk.gresource.xml | 3 +-
gtk/gtkaboutdialog.c | 147 ++++++++-----------------------
gtk/gtkaboutdialog.ui | 230 +++++++++++++++++++++++++++++++++++++++++++++++++
gtk/tests/templates.c | 11 +++
5 files changed, 285 insertions(+), 111 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0b92543..a172f0f 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1094,9 +1094,10 @@ DND_CURSORS = \
cursor_dnd_none.png
COMPOSITE_TEMPLATES = \
+ gtkaboutdialog.ui \
gtkdialog.ui \
- gtkmessagedialog.ui \
- gtkinfobar.ui
+ gtkinfobar.ui \
+ gtkmessagedialog.ui
#
# rules to generate built sources
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index df76b25..1aef6c6 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -11,8 +11,9 @@
<file alias="cursor/dnd-none.png">cursor_dnd_none.png</file>
<file alias="cursor/dnd-move.png">cursor_dnd_move.png</file>
<file alias="cursor/dnd-copy.png">cursor_dnd_copy.png</file>
+ <file>gtkaboutdialog.ui</file>
<file>gtkdialog.ui</file>
- <file>gtkmessagedialog.ui</file>
<file>gtkinfobar.ui</file>
+ <file>gtkmessagedialog.ui</file>
</gresource>
</gresources>
diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c
index f50fed0..2a85cfd 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -222,6 +222,13 @@ static void display_license_page (GtkWidget
static void close_cb (GtkAboutDialog *about);
static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about,
const gchar *uri);
+static void credits_button_clicked (GtkButton *button,
+ gpointer data);
+static void license_button_clicked (GtkButton *button,
+ gpointer data);
+static gboolean emit_activate_link (GtkAboutDialog *about,
+ const gchar *uri);
+
enum {
ACTIVATE_LINK,
@@ -238,9 +245,11 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
object_class = (GObjectClass *)klass;
widget_class = (GtkWidgetClass *)klass;
+ container_class = (GtkContainerClass *)klass;
object_class->set_property = gtk_about_dialog_set_property;
object_class->get_property = gtk_about_dialog_get_property;
@@ -535,6 +544,35 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass)
FALSE,
GTK_PARAM_READWRITE));
+ gtk_container_class_set_template (container_class,
+ GTK_TEMPLATE_SOURCE_RESOURCE,
+ "/org/gtk/libgtk/gtkaboutdialog.ui");
+ gtk_container_class_automate_child (container_class, "notebook", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, notebook));
+ gtk_container_class_automate_child (container_class, "logo_image", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, logo_image));
+ gtk_container_class_automate_child (container_class, "name_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, name_label));
+ gtk_container_class_automate_child (container_class, "version_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, version_label));
+ gtk_container_class_automate_child (container_class, "comments_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, comments_label));
+ gtk_container_class_automate_child (container_class, "copyright_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, copyright_label));
+ gtk_container_class_automate_child (container_class, "license_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, license_label));
+ gtk_container_class_automate_child (container_class, "website_label", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, website_label));
+ gtk_container_class_automate_child (container_class, "credits_button", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, credits_button));
+ gtk_container_class_automate_child (container_class, "license_button", FALSE, GTK_AUTOMATE_CHILD_PRIVATE,
+ G_STRUCT_OFFSET (GtkAboutDialogPrivate, license_button));
+
+ gtk_container_class_declare_callbacks (container_class,
+ "credits_button_clicked", (GCallback)credits_button_clicked,
+ "license_button_clicked", (GCallback)license_button_clicked,
+ "emit_activate_link", (GCallback)emit_activate_link,
+ NULL);
g_type_class_add_private (object_class, sizeof (GtkAboutDialogPrivate));
}
@@ -642,10 +680,7 @@ license_button_clicked (GtkButton *button,
static void
gtk_about_dialog_init (GtkAboutDialog *about)
{
- GtkDialog *dialog = GTK_DIALOG (about);
GtkAboutDialogPrivate *priv;
- GtkWidget *vbox, *page_vbox, *hbox, *button, *close_button, *image;
- GtkWidget *content_area, *action_area;
/* Data */
priv = GTK_ABOUT_DIALOG_GET_PRIVATE (about);
@@ -670,116 +705,12 @@ gtk_about_dialog_init (GtkAboutDialog *about)
priv->license_type = GTK_LICENSE_UNKNOWN;
- content_area = gtk_dialog_get_content_area (dialog);
- action_area = gtk_dialog_get_action_area (dialog);
-
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
- gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-
- /* Widgets */
- gtk_widget_push_composite_child ();
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
- gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
-
- priv->logo_image = gtk_image_new ();
- gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0);
-
- priv->name_label = gtk_label_new (NULL);
- gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER);
- gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0);
-
- priv->notebook = gtk_notebook_new ();
- gtk_box_pack_start (GTK_BOX (vbox), priv->notebook, TRUE, TRUE, 0);
- gtk_widget_set_size_request (priv->notebook, 400, 100);
-
- page_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
- gtk_widget_show (page_vbox);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
- gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page_vbox, NULL);
-
- priv->version_label = gtk_label_new (NULL);
- gtk_label_set_selectable (GTK_LABEL (priv->version_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (priv->version_label), GTK_JUSTIFY_CENTER);
- gtk_box_pack_start (GTK_BOX (page_vbox), priv->version_label, FALSE, FALSE, 0);
-
- priv->comments_label = gtk_label_new (NULL);
- gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER);
- gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE);
- gtk_box_pack_start (GTK_BOX (page_vbox), priv->comments_label, FALSE, FALSE, 0);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
- gtk_box_pack_start (GTK_BOX (page_vbox), hbox, FALSE, FALSE, 0);
-
- priv->website_label = button = gtk_label_new ("");
- gtk_widget_set_no_show_all (button, TRUE);
- gtk_label_set_selectable (GTK_LABEL (button), TRUE);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
- g_signal_connect_swapped (button, "activate-link",
- G_CALLBACK (emit_activate_link), about);
-
- priv->license_label = gtk_label_new (NULL);
- gtk_label_set_use_markup (GTK_LABEL (priv->license_label), TRUE);
- gtk_label_set_selectable (GTK_LABEL (priv->license_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (priv->license_label), GTK_JUSTIFY_CENTER);
- gtk_box_pack_end (GTK_BOX (page_vbox), priv->license_label, FALSE, FALSE, 0);
- gtk_label_set_line_wrap (GTK_LABEL (priv->license_label), TRUE);
-
- priv->copyright_label = gtk_label_new (NULL);
- gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER);
- gtk_box_pack_end (GTK_BOX (page_vbox), priv->copyright_label, FALSE, FALSE, 0);
-
- gtk_widget_show (vbox);
- gtk_widget_show (priv->notebook);
- gtk_widget_show (priv->logo_image);
- gtk_widget_show (priv->name_label);
- gtk_widget_show (hbox);
-
- /* Add the close button */
- close_button = gtk_dialog_add_button (GTK_DIALOG (about),
- GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL);
gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CANCEL);
- /* Add the credits button */
- button = gtk_toggle_button_new_with_mnemonic (_("C_redits"));
- gtk_widget_set_can_default (button, TRUE);
- image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_set_no_show_all (button, TRUE);
- gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
- gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
- g_signal_connect (button, "clicked",
- G_CALLBACK (credits_button_clicked), about);
- priv->credits_button = button;
- priv->credits_page = 0;
-
- /* Add the license button */
- button = gtk_toggle_button_new_with_mnemonic (_("_License"));
- gtk_widget_set_can_default (button, TRUE);
- gtk_widget_set_no_show_all (button, TRUE);
- gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
- gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area), button, TRUE);
- g_signal_connect (button, "clicked",
- G_CALLBACK (license_button_clicked), about);
- priv->license_button = button;
- priv->license_page = 0;
+ gtk_container_init_template (GTK_CONTAINER (about));
switch_page (about, 0);
- gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
-
- gtk_widget_pop_composite_child ();
-
- gtk_widget_grab_default (close_button);
- gtk_widget_grab_focus (close_button);
-
/* force defaults */
gtk_about_dialog_set_program_name (about, NULL);
gtk_about_dialog_set_logo (about, NULL);
diff --git a/gtk/gtkaboutdialog.ui b/gtk/gtkaboutdialog.ui
new file mode 100644
index 0000000..41056c7
--- /dev/null
+++ b/gtk/gtkaboutdialog.ui
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.6 -->
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="stock">gtk-about</property>
+ </object>
+ <template class="GtkAboutDialog" parent="GtkDialog">
+ <property name="border_width">5</property>
+ <property name="resizable">False</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="layout_style">end</property>
+ <property name="border_width">5</property>
+ <child>
+ <object class="GtkButton" id="credits_button">
+ <property name="label" translatable="yes">C_redits</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="no_show_all">True</property>
+ <property name="image">image1</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="credits_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ <property name="secondary">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="license_button">
+ <property name="label" translatable="yes">_License</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="no_show_all">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="license_button_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ <property name="secondary">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="close_button">
+ <property name="label">gtk-close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="is_focus">True</property>
+ <property name="has_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box">
+ <property name="visible">True</property>
+ <property name="border_width">5</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkImage" id="logo_image">
+ <property name="visible">True</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="name_label">
+ <property name="visible">True</property>
+ <property name="label">name label</property>
+ <property name="justify">center</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkNotebook" id="notebook">
+ <property name="width_request">400</property>
+ <property name="height_request">100</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="show_tabs">False</property>
+ <property name="show_border">False</property>
+ <child>
+ <object class="GtkBox" id="page_vbox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">8</property>
+ <child>
+ <object class="GtkLabel" id="version_label">
+ <property name="label">version 1.0</property>
+ <property name="justify">center</property>
+ <property name="selectable">True</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="comments_label">
+ <property name="label">comments</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="hbox">
+ <property name="visible">True</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <object class="GtkLabel" id="website_label">
+ <property name="no_show_all">True</property>
+ <property name="label">http://website.com</property>
+ <property name="selectable">True</property>
+ <signal name="activate-link" handler="emit_activate_link" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="license_label">
+ <property name="label">license</property>
+ <property name="use_markup">True</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="copyright_label">
+ <property name="label">copyright</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="tab">
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">credits_button</action-widget>
+ <action-widget response="0">license_button</action-widget>
+ <action-widget response="-6">close_button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 0c4e350..d1a197b 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -56,6 +56,16 @@ test_message_dialog_basic (void)
}
static void
+test_about_dialog_basic (void)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_about_dialog_new ();
+ g_assert (GTK_IS_ABOUT_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static void
test_info_bar_basic (void)
{
GtkWidget *infobar;
@@ -74,6 +84,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/GtkAboutDialog/Basic", test_about_dialog_basic);
g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic);
return g_test_run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]