[gtk+/composite-templates] Updated GtkDialog and GtkMessageDialog implementation to new GtkContainer template API
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates] Updated GtkDialog and GtkMessageDialog implementation to new GtkContainer template API
- Date: Tue, 26 Jun 2012 21:25:23 +0000 (UTC)
commit 84d86664f4c7d99e5230b6cdf884804cba853341
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Tue Jun 26 18:24:37 2012 -0300
Updated GtkDialog and GtkMessageDialog implementation to new GtkContainer template API
gtk/gtkdialog.c | 120 +++++++-------------------------------------
gtk/gtkmessagedialog.c | 130 +++++++++++++++---------------------------------
2 files changed, 58 insertions(+), 192 deletions(-)
---
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index 451e4c3..13ed9f5 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -213,20 +213,12 @@ static const gchar *gtk_dialog_template =
"<interface>"
" <requires lib=\"gtk+\" version=\"2.20\"/>"
" <child>"
- " <object class=\"GtkVBox\" id=\"vbox\">"
+ " <object class=\"GtkBox\" id=\"vbox\">"
" <property name=\"visible\">True</property>"
+ " <property name=\"orientation\">GTK_ORIENTATION_VERTICAL</property>"
" <child>"
- " <object class=\"GtkHSeparator\" id=\"separator\">"
- " <property name=\"visible\">True</property>"
- " </object>"
- " <packing>"
- " <property name=\"expand\">False</property>"
- " <property name=\"pack_type\">end</property>"
- " <property name=\"position\">1</property>"
- " </packing>"
- " </child>"
- " <child>"
- " <object class=\"GtkHButtonBox\" id=\"action-area\">"
+ " <object class=\"GtkButtonBox\" id=\"action_area\">"
+ " <property name=\"orientation\">GTK_ORIENTATION_HORIZONTAL</property>"
" <property name=\"visible\">True</property>"
" <property name=\"layout_style\">end</property>"
" </object>"
@@ -239,12 +231,6 @@ static const gchar *gtk_dialog_template =
" </object>"
" </child>"
"</interface>";
-
-enum {
- PROP_0,
- PROP_VBOX,
- PROP_ACTION_AREA
-};
enum {
RESPONSE,
@@ -257,55 +243,6 @@ static guint dialog_signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_CODE (GtkDialog, gtk_dialog, GTK_TYPE_WINDOW,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_dialog_buildable_interface_init))
-
-static void
-gtk_dialog_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkDialogPrivate *priv = GTK_DIALOG (object)->priv;
-
- switch (prop_id)
- {
- case PROP_VBOX:
- priv->vbox = g_value_get_object (value);
- break;
-
- case PROP_ACTION_AREA:
- priv->action_area = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_dialog_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkDialogPrivate *priv = GTK_DIALOG (object)->priv;
-
- switch (prop_id)
- {
- case PROP_VBOX:
- g_value_set_object (value, priv->vbox);
- break;
-
- case PROP_ACTION_AREA:
- g_value_set_object (value, priv->action_area);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
static void
update_spacings (GtkDialog *dialog)
{
@@ -357,15 +294,15 @@ gtk_dialog_constructor (GType type,
static void
gtk_dialog_class_init (GtkDialogClass *class)
{
+ GtkContainerClass *container_class;
GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkBindingSet *binding_set;
gobject_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
+ container_class = GTK_CONTAINER_CLASS (class);
- gobject_class->set_property = gtk_dialog_set_property;
- gobject_class->get_property = gtk_dialog_get_property;
gobject_class->constructor = gtk_dialog_constructor;
widget_class->map = gtk_dialog_map;
@@ -378,36 +315,6 @@ gtk_dialog_class_init (GtkDialogClass *class)
g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate));
/**
- * GtkDialog:vbox:
- *
- * The dialog content area.
- *
- * Since: 3.0
- */
- g_object_class_install_property (gobject_class,
- PROP_VBOX,
- gtk_param_spec_composite ("vbox",
- P_("Content Area"),
- P_("The dialog content area"),
- GTK_TYPE_BOX,
- GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- /**
- * GtkDialog:action-area:
- *
- * The dialog action area.
- *
- * Since: 3.0
- */
- g_object_class_install_property (gobject_class,
- PROP_ACTION_AREA,
- gtk_param_spec_composite ("action-area",
- P_("Action Area"),
- P_("The dialog action area"),
- GTK_TYPE_BUTTON_BOX,
- GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- /**
* GtkDialog::response:
* @dialog: the object on which the signal is emitted
* @response_id: the response ID
@@ -494,7 +401,16 @@ gtk_dialog_class_init (GtkDialogClass *class)
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
- gtk_container_class_set_template (GTK_CONTAINER_CLASS (class), gtk_dialog_template);
+ gtk_container_class_set_template (GTK_CONTAINER_CLASS (class),
+ gtk_dialog_template,
+ GTK_CONTAINER_TEMPLATE_STRING);
+
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkDialogPrivate, vbox),
+ "vbox");
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkDialogPrivate, action_area),
+ "action_area");
}
static void
@@ -502,7 +418,7 @@ gtk_dialog_init (GtkDialog *dialog)
{
GtkDialogPrivate *priv;
- priv = dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
+ dialog->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_DIALOG,
GtkDialogPrivate);
@@ -611,7 +527,7 @@ static void
gtk_dialog_style_updated (GtkWidget *widget)
{
GTK_WIDGET_CLASS (gtk_dialog_parent_class)->style_updated (widget);
-g_message ("%s",__func__);
+
update_spacings (GTK_DIALOG (widget));
}
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index c3e08d6..cf40e75 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -123,20 +123,20 @@ static void gtk_message_dialog_get_property (GObject *object,
GParamSpec *pspec);
static void gtk_message_dialog_add_buttons (GtkMessageDialog *message_dialog,
GtkButtonsType buttons);
-static void gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface);
static const gchar *gtk_message_dialog_template =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<interface>"
" <requires lib=\"gtk+\" version=\"2.20\"/>"
" <child internal-child=\"vbox\">"
- " <object class=\"GtkVBox\" id=\"vbox\">"
+ " <object class=\"GtkBox\" id=\"vbox\">"
" <property name=\"spacing\">14</property>"
" <child>"
- " <object class=\"GtkHBox\" id=\"hbox1\">"
+ " <object class=\"GtkBox\" id=\"hbox1\">"
" <property name=\"visible\">True</property>"
" <property name=\"border_width\">5</property>"
" <property name=\"spacing\">12</property>"
+ " <property name=\"orientation\">GTK_ORIENTATION_HORIZONTAL</property>"
" <child>"
" <object class=\"GtkImage\" id=\"image\">"
" <property name=\"visible\">True</property>"
@@ -150,9 +150,10 @@ static const gchar *gtk_message_dialog_template =
" </packing>"
" </child>"
" <child>"
- " <object class=\"GtkVBox\" id=\"vbox1\">"
+ " <object class=\"GtkBox\" id=\"vbox1\">"
" <property name=\"visible\">True</property>"
" <property name=\"spacing\">12</property>"
+ " <property name=\"orientation\">GTK_ORIENTATION_HORIZONTAL</property>"
" <child>"
" <object class=\"GtkLabel\" id=\"label\">"
" <property name=\"visible\">True</property>"
@@ -169,7 +170,7 @@ static const gchar *gtk_message_dialog_template =
" </packing>"
" </child>"
" <child>"
- " <object class=\"GtkLabel\" id=\"secondary-label\">"
+ " <object class=\"GtkLabel\" id=\"secondary_label\">"
" <property name=\"visible\">False</property>"
" <property name=\"no_show_all\">True</property>"
" <property name=\"xalign\">0</property>"
@@ -189,12 +190,12 @@ static const gchar *gtk_message_dialog_template =
" </child>"
" </object>"
" </child>"
- " </object>"
- " </child>"
- " <child internal-child=\"action-area\">"
- " <object class=\"GtkHButtonBox\" id=\"action-area\">"
- " <property name=\"border_width\">5</property>"
- " <property name=\"spacing\">6</property>"
+ " <child internal-child=\"action_area\">"
+ " <object class=\"GtkButtonBox\" id=\"action_area\">"
+ " <property name=\"border_width\">5</property>"
+ " <property name=\"spacing\">6</property>"
+ " </object>"
+ " </child>"
" </object>"
" </child>"
"</interface>";
@@ -208,36 +209,10 @@ enum {
PROP_SECONDARY_TEXT,
PROP_SECONDARY_USE_MARKUP,
PROP_IMAGE,
- PROP_LABEL,
- PROP_SECONDARY_LABEL,
PROP_MESSAGE_AREA
};
-G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
- gtk_message_dialog_buildable_interface_init))
-
-static GtkBuildableIface *parent_buildable_iface;
-
-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_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;
-}
+G_DEFINE_TYPE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG)
static void
gtk_message_dialog_style_updated (GtkWidget *widget)
@@ -263,12 +238,14 @@ gtk_message_dialog_style_updated (GtkWidget *widget)
static void
gtk_message_dialog_class_init (GtkMessageDialogClass *class)
{
+ GtkContainerClass *container_class;
GtkWidgetClass *widget_class;
GObjectClass *gobject_class;
- widget_class = GTK_WIDGET_CLASS (class);
gobject_class = G_OBJECT_CLASS (class);
-
+ widget_class = GTK_WIDGET_CLASS (class);
+ container_class = GTK_CONTAINER_CLASS (class);
+
widget_class->style_updated = gtk_message_dialog_style_updated;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT);
@@ -382,47 +359,30 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
*/
g_object_class_install_property (gobject_class,
PROP_IMAGE,
- gtk_param_spec_composite ("image",
- P_("Image"),
- P_("The image"),
- GTK_TYPE_WIDGET,
- GTK_PARAM_READWRITE));
-
-
- /**
- * GtkMessageDialog:label:
- *
- * The message label for this dialog.
- *
- * Since: 3.0
- */
- g_object_class_install_property (gobject_class,
- PROP_LABEL,
- gtk_param_spec_composite ("label",
- P_("Label"),
- P_("The label"),
- GTK_TYPE_LABEL,
- GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
-
- /**
- * GtkMessageDialog:secondary-label:
- *
- * The secondary message label for this dialog.
- *
- * Since: 3.0
- */
- g_object_class_install_property (gobject_class,
- PROP_SECONDARY_LABEL,
- gtk_param_spec_composite ("secondary-label",
- P_("Secondary Label"),
- P_("The secondary message label"),
- GTK_TYPE_LABEL,
- GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
-
- g_type_class_add_private (gobject_class,
- sizeof (GtkMessageDialogPrivate));
+ g_param_spec_object ("image",
+ P_("Image"),
+ P_("The image"),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE));
- gtk_container_class_set_template (GTK_CONTAINER_CLASS (class), gtk_message_dialog_template);
+ g_type_class_add_private (gobject_class, sizeof (GtkMessageDialogPrivate));
+
+ gtk_container_class_set_template (GTK_CONTAINER_CLASS (class),
+ gtk_message_dialog_template,
+ GTK_CONTAINER_TEMPLATE_STRING);
+
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkMessageDialogPrivate, label),
+ "label");
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkMessageDialogPrivate, secondary_label),
+ "secondary_label");
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkMessageDialogPrivate, image),
+ "image");
+ gtk_container_class_declare_internal_child (container_class, TRUE,
+ G_STRUCT_OFFSET (GtkMessageDialogPrivate, message_area),
+ "action_area");
}
static void
@@ -618,13 +578,6 @@ gtk_message_dialog_set_property (GObject *object,
case PROP_IMAGE:
gtk_message_dialog_set_image (dialog, g_value_get_object (value));
break;
- case PROP_LABEL:
- priv->label = g_value_get_object (value);
- break;
- case PROP_SECONDARY_LABEL:
- priv->secondary_label = g_value_get_object (value);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -668,9 +621,6 @@ gtk_message_dialog_get_property (GObject *object,
case PROP_IMAGE:
g_value_set_object (value, priv->image);
break;
- case PROP_MESSAGE_AREA:
- g_value_set_object (value, priv->message_area);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]