[gtk+/composite-templates] Fixed composite implementation



commit 1913b6f1bd4031854a5fe834a8fd9a381901c37f
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Sat Jun 9 20:21:32 2012 -0300

    Fixed composite implementation

 gtk/gtkdialog.c        |  231 ++++++++++++++++++++++-------------------------
 gtk/gtkmessagedialog.c |   78 ++++++++--------
 2 files changed, 148 insertions(+), 161 deletions(-)
---
diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c
index 23c17b6..451e4c3 100644
--- a/gtk/gtkdialog.c
+++ b/gtk/gtkdialog.c
@@ -242,8 +242,6 @@ static const gchar *gtk_dialog_template =
   
 enum {
   PROP_0,
-  PROP_HAS_SEPARATOR,
-  PROP_SEPARATOR,
   PROP_VBOX,
   PROP_ACTION_AREA
 };
@@ -260,6 +258,102 @@ 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)
+{
+  GtkDialogPrivate *priv = dialog->priv;
+  gint content_area_border;
+  gint content_area_spacing;
+  gint button_spacing;
+  gint action_area_border;
+
+  gtk_widget_style_get (GTK_WIDGET (dialog),
+                        "content-area-border", &content_area_border,
+                        "content-area-spacing", &content_area_spacing,
+                        "button-spacing", &button_spacing,
+                        "action-area-border", &action_area_border,
+                        NULL);
+
+  
+  gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
+                                  content_area_border);
+  if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
+    {
+      gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
+      _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
+    }
+  gtk_box_set_spacing (GTK_BOX (priv->action_area), button_spacing);
+  gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
+                                  action_area_border);
+}
+
+static GObject *
+gtk_dialog_constructor (GType                  type,
+                        guint                  n_construct_properties,
+                        GObjectConstructParam *construct_properties)
+{
+  GObject *obj;
+  
+  obj = G_OBJECT_CLASS (gtk_dialog_parent_class)->constructor (type,
+                                                               n_construct_properties,
+                                                               construct_properties);
+
+  update_spacings (GTK_DIALOG (obj));
+
+  gtk_window_set_type_hint (GTK_WINDOW (obj), GDK_WINDOW_TYPE_HINT_DIALOG);
+  gtk_window_set_position (GTK_WINDOW (obj), GTK_WIN_POS_CENTER_ON_PARENT);
+
+  return obj;
+}
+
 static void
 gtk_dialog_class_init (GtkDialogClass *class)
 {
@@ -270,6 +364,10 @@ gtk_dialog_class_init (GtkDialogClass *class)
   gobject_class = G_OBJECT_CLASS (class);
   widget_class = GTK_WIDGET_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;
   widget_class->style_updated = gtk_dialog_style_updated;
 
@@ -280,21 +378,6 @@ gtk_dialog_class_init (GtkDialogClass *class)
   g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate));
 
   /**
-   * GtkDialog:separator:
-   *
-   * The separator above the action buttons.
-   * 
-   * Since: 3.0
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_SEPARATOR,
-                                   gtk_param_spec_composite ("separator",
-							     P_("Separator"),
-							     P_("The separator above the action buttons"),
-							     GTK_TYPE_SEPARATOR, 
-							     GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
-
-  /**
    * GtkDialog:vbox:
    *
    * The dialog content area.
@@ -415,45 +498,17 @@ gtk_dialog_class_init (GtkDialogClass *class)
 }
 
 static void
-update_spacings (GtkDialog *dialog)
-{
-  GtkDialogPrivate *priv = dialog->priv;
-  gint content_area_border;
-  gint content_area_spacing;
-  gint button_spacing;
-  gint action_area_border;
-
-  gtk_widget_style_get (GTK_WIDGET (dialog),
-                        "content-area-border", &content_area_border,
-                        "content-area-spacing", &content_area_spacing,
-                        "button-spacing", &button_spacing,
-                        "action-area-border", &action_area_border,
-                        NULL);
-
-  
-  gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
-                                  content_area_border);
-  if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
-    {
-      gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
-      _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
-    }
-  gtk_box_set_spacing (GTK_BOX (priv->action_area),
-                       button_spacing);
-  gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
-                                  action_area_border);
-}
-
-static void
 gtk_dialog_init (GtkDialog *dialog)
 {
   GtkDialogPrivate *priv;
+  
+  priv = dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
+                                                     GTK_TYPE_DIALOG,
+                                                     GtkDialogPrivate);
 
-  dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
-                                              GTK_TYPE_DIALOG,
-                                              GtkDialogPrivate);
-  priv = dialog->priv;
-
+  priv->vbox = NULL;
+  priv->action_area = NULL;
+  
   /* To avoid breaking old code that prevents destroy on delete event
    * by connecting a handler, we have to have the FIRST signal
    * connection on the dialog.
@@ -462,12 +517,6 @@ gtk_dialog_init (GtkDialog *dialog)
                     "delete-event",
                     G_CALLBACK (gtk_dialog_delete_event_handler),
                     NULL);
-
-  gtk_window_set_type_hint (GTK_WINDOW (dialog),
-			    GDK_WINDOW_TYPE_HINT_DIALOG);
-  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
-
-  update_spacings (dialog);
 }
 
 static GtkBuildableIface *parent_buildable_iface;
@@ -480,70 +529,6 @@ gtk_dialog_buildable_interface_init (GtkBuildableIface *iface)
   iface->custom_finished = gtk_dialog_buildable_custom_finished;
 }
 
-static void 
-gtk_dialog_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
-{
-  GtkDialog *dialog;
-  
-  dialog = GTK_DIALOG (object);
-  
-  switch (prop_id)
-    {
-    case PROP_HAS_SEPARATOR:
-      gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value));
-      break;
-
-    case PROP_SEPARATOR:
-      dialog->separator = g_value_get_object (value);
-      break;
-
-    case PROP_VBOX:
-      dialog->vbox = g_value_get_object (value);
-      break;
-
-    case PROP_ACTION_AREA:
-      dialog->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)
-{
-  GtkDialog *dialog;
-  
-  dialog = GTK_DIALOG (object);
-  
-  switch (prop_id)
-    {
-    case PROP_HAS_SEPARATOR:
-      g_value_set_boolean (value, dialog->separator != NULL);
-      break;
-
-    case PROP_VBOX:
-      g_value_set_object (value, dialog->vbox);
-      break;
-
-    case PROP_ACTION_AREA:
-      g_value_set_object (value, dialog->action_area);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
 static gboolean
 gtk_dialog_delete_event_handler (GtkWidget   *widget,
                                  GdkEventAny *event,
@@ -626,7 +611,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 3b5b60f..c3e08d6 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -100,15 +100,16 @@
 
 struct _GtkMessageDialogPrivate
 {
+  GtkWidget *label;
   GtkWidget *secondary_label;
+  GtkWidget *image;
+  GtkWidget *message_area;
   guint message_type : 3;
   guint buttons_type : 3;
   guint has_primary_markup : 1;
   guint has_secondary_text : 1;
 };
 
-static void     gtk_message_dialog_style_set    (GtkWidget             *widget,
-						 GtkStyle              *prev_style);
 static GObject *gtk_message_dialog_constructor  (GType                  type,
 						 guint                  n_construct_properties,
 						 GObjectConstructParam *construct_params);
@@ -122,6 +123,7 @@ 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\"?>"
@@ -207,7 +209,8 @@ enum {
   PROP_SECONDARY_USE_MARKUP,
   PROP_IMAGE,
   PROP_LABEL,
-  PROP_SECONDARY_LABEL
+  PROP_SECONDARY_LABEL,
+  PROP_MESSAGE_AREA
 };
 
 G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
@@ -216,6 +219,17 @@ G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
 
 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)
 {
@@ -225,17 +239,26 @@ gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
   iface->custom_finished = parent_buildable_iface->custom_finished;
 }
 
-static GObject *
-gtk_message_dialog_buildable_get_internal_child (GtkBuildable *buildable,
-                                                 GtkBuilder   *builder,
-                                                 const gchar  *childname)
+static void
+gtk_message_dialog_style_updated (GtkWidget *widget)
 {
-  if (strcmp (childname, "message_area") == 0)
-    return G_OBJECT (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (buildable)));
+  GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
+  GtkWidget *parent;
+  gint border_width;
 
-  return parent_buildable_iface->get_internal_child (buildable, builder, childname);
-}
+  parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
+
+  if (parent)
+    {
+      gtk_widget_style_get (widget, "message-border",
+                            &border_width, NULL);
+
+      gtk_container_set_border_width (GTK_CONTAINER (parent),
+                                      MAX (0, border_width - 7));
+    }
 
+  GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);
+}
 
 static void
 gtk_message_dialog_class_init (GtkMessageDialogClass *class)
@@ -519,7 +542,7 @@ gtk_message_dialog_constructor (GType                  type,
 								   construct_params);
 
   dialog = GTK_MESSAGE_DIALOG (object);
-  priv = GTK_MESSAGE_DIALOG_GET_PRIVATE (dialog);
+  priv = dialog->priv;
 
   /* Setup widget's now that they've been built */
   setup_type (dialog, priv->message_type);
@@ -541,7 +564,7 @@ gtk_message_dialog_set_property (GObject      *object,
     {
     case PROP_MESSAGE_TYPE:
 
-      if (dialog->image)
+      if (priv->image)
 	setup_type (dialog, g_value_get_enum (value));
       else
 	/* Deffer assignment at construct time until image is built */
@@ -596,7 +619,7 @@ gtk_message_dialog_set_property (GObject      *object,
       gtk_message_dialog_set_image (dialog, g_value_get_object (value));
       break;
     case PROP_LABEL:
-      dialog->label = g_value_get_object (value);
+      priv->label = g_value_get_object (value);
       break;
     case PROP_SECONDARY_LABEL:
       priv->secondary_label = g_value_get_object (value);
@@ -818,13 +841,13 @@ gtk_message_dialog_set_image (GtkMessageDialog *dialog,
    * the image is not already in the dialog (which is
    * the case when GtkBuilder builds the image).
    */
-  if (dialog->image && dialog->image != image)
+  if (priv->image && priv->image != image)
     {
       priv->message_type = GTK_MESSAGE_OTHER;
   
-      parent = dialog->image->parent;
+      parent = gtk_widget_get_parent (priv->image);
       gtk_container_add (GTK_CONTAINER (parent), image);
-      gtk_container_remove (GTK_CONTAINER (parent), dialog->image);
+      gtk_container_remove (GTK_CONTAINER (parent), priv->image);
       gtk_box_reorder_child (GTK_BOX (parent), image, 0);
     }
 
@@ -1076,24 +1099,3 @@ gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
 
   g_object_notify (G_OBJECT (message_dialog), "buttons");
 }
-
-static void
-gtk_message_dialog_style_updated (GtkWidget *widget)
-{
-  GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
-  GtkWidget *parent;
-  gint border_width;
-
-  parent = gtk_widget_get_parent (gtk_message_dialog_get_image (dialog));
-
-  if (parent)
-    {
-      gtk_widget_style_get (widget, "message-border",
-                            &border_width, NULL);
-
-      gtk_container_set_border_width (GTK_CONTAINER (parent),
-                                      MAX (0, border_width - 7));
-    }
-
-  GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->style_updated (widget);
-}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]