Commit 671871b4 authored by Tristan Van Berkom's avatar Tristan Van Berkom

GtkMessageDialog: Define children with a GtkBuilder template

parent 33f6195d
......@@ -1095,8 +1095,9 @@ DND_CURSORS = \
cursor_dnd_move.png \
cursor_dnd_none.png
COMPOSITE_TEMPLATES = \
gtkdialog.ui
COMPOSITE_TEMPLATES = \
gtkdialog.ui \
gtkmessagedialog.ui
#
# rules to generate built sources
......
......@@ -12,5 +12,6 @@
<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">gtkmessagedialog.ui</file>
</gresource>
</gresources>
......@@ -123,10 +123,6 @@ static void gtk_message_dialog_get_property (GObject *object,
static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
GtkButtonsType buttons);
static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
static GObject * gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *childname);
enum {
PROP_0,
......@@ -150,23 +146,10 @@ static void
gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
{
parent_buildable_iface = g_type_interface_peek_parent (iface);
iface->get_internal_child = gtk_message_dialog_buildable_get_internal_child;
iface->custom_tag_start = parent_buildable_iface->custom_tag_start;
iface->custom_finished = parent_buildable_iface->custom_finished;
}
static GObject *
gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *childname)
{
if (strcmp (childname, "message_area") == 0)
return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
}
static void
gtk_message_dialog_class_init (GtkMessageDialogClass *class)
{
......@@ -311,15 +294,19 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
GTK_TYPE_WIDGET,
GTK_PARAM_READABLE));
/* Setup Composite data */
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkmessagedialog.ui");
gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, image);
gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, label);
gtk_widget_class_bind_child (widget_class, GtkMessageDialogPrivate, secondary_label);
gtk_widget_class_bind_child_internal (widget_class, GtkMessageDialogPrivate, message_area);
g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
}
static void
gtk_message_dialog_init (GtkMessageDialog *dialog)
{
GtkWidget *hbox;
GtkDialog *message_dialog = GTK_DIALOG (dialog);
GtkWidget *action_area, *content_area;
GtkMessageDialogPrivate *priv;
dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
......@@ -327,65 +314,13 @@ gtk_message_dialog_init (GtkMessageDialog *dialog)
GtkMessageDialogPrivate);
priv = dialog->priv;
content_area = gtk_dialog_get_content_area (message_dialog);
action_area = gtk_dialog_get_action_area (message_dialog);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_window_set_title (GTK_WINDOW (dialog), "");
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
priv->has_primary_markup = FALSE;
priv->has_secondary_text = FALSE;
priv->secondary_label = gtk_label_new (NULL);
gtk_widget_set_no_show_all (priv->secondary_label, TRUE);
priv->label = gtk_label_new (NULL);
priv->image = gtk_image_new_from_stock (NULL, GTK_ICON_SIZE_DIALOG);
g_object_set (priv->image, "use-fallback", TRUE, NULL);
gtk_widget_set_halign (priv->image, GTK_ALIGN_CENTER);
gtk_widget_set_valign (priv->image, GTK_ALIGN_START);
gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
gtk_widget_set_valign (priv->label, GTK_ALIGN_START);
gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
gtk_widget_set_halign (priv->secondary_label, GTK_ALIGN_START);
gtk_widget_set_valign (priv->secondary_label, GTK_ALIGN_START);
gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.0);
gtk_misc_set_alignment (GTK_MISC (priv->secondary_label), 0.0, 0.0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
priv->message_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_box_pack_start (GTK_BOX (priv->message_area), priv->label,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (priv->message_area), priv->secondary_label,
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), priv->image,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), priv->message_area,
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (content_area),
hbox,
FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
gtk_box_set_spacing (GTK_BOX (action_area), 6);
priv->has_primary_markup = FALSE;
priv->has_secondary_text = FALSE;
gtk_widget_init_template (GTK_WIDGET (dialog));
gtk_message_dialog_style_updated (GTK_WIDGET (dialog));
gtk_widget_show_all (hbox);
}
static void
......
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
<!-- interface-requires gtk+ 3.10 -->
<template class="GtkMessageDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes"> </property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">14</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</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="can_focus">False</property>
<property name="border_width">5</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage" id="image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<property name="stock">gtk-missing-image</property>
<property name="use_fallback">True</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="message_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="xalign">0</property>
<property name="yalign">0</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">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="secondary_label">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="wrap">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
......@@ -42,6 +42,19 @@ test_dialog_override_property (void)
gtk_widget_destroy (dialog);
}
static void
test_message_dialog_basic (void)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"Do it hard !");
g_assert (GTK_IS_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
int
main (int argc, char **argv)
{
......@@ -56,6 +69,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);
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