[gedit] Use GtkBin for managing the child.



commit fb93cdd329ebc9826acf17b6a0d0a4100b726d6e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat Apr 16 18:38:37 2011 +0200

    Use GtkBin for managing the child.

 gedit/gedit-overlay-child.c |   71 +++++++++++++++++++++++-------------------
 1 files changed, 39 insertions(+), 32 deletions(-)
---
diff --git a/gedit/gedit-overlay-child.c b/gedit/gedit-overlay-child.c
index e30d6ed..7593fe1 100644
--- a/gedit/gedit-overlay-child.c
+++ b/gedit/gedit-overlay-child.c
@@ -23,7 +23,6 @@
 
 struct _GeditOverlayChildPrivate
 {
-	GtkWidget                *widget;
 	GBinding                 *binding;
 	GeditOverlayChildPosition position;
 	guint                     offset;
@@ -50,7 +49,7 @@ gedit_overlay_child_get_property (GObject    *object,
 	switch (prop_id)
 	{
 		case PROP_WIDGET:
-			g_value_set_object (value, child->priv->widget);
+			g_value_set_object (value, gtk_bin_get_child (GTK_BIN (child)));
 			break;
 		case PROP_POSITION:
 			g_value_set_uint (value, child->priv->position);
@@ -117,17 +116,29 @@ gedit_overlay_child_realize (GtkWidget *widget)
 }
 
 static void
-gedit_overlay_child_get_preferred_width (GtkWidget *widget,
-                                         gint      *minimum,
-                                         gint      *natural)
+gedit_overlay_child_get_size (GtkWidget     *widget,
+                              GtkOrientation orientation,
+                              gint          *minimum,
+                              gint          *natural)
 {
-	GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
+	GeditOverlayChild *overlay_child = GEDIT_OVERLAY_CHILD (widget);
+	GtkWidget *child;
 	gint child_min = 0, child_nat = 0;
 
-	if (child->priv->widget != NULL)
+	child = gtk_bin_get_child (GTK_BIN (overlay_child));
+
+	if (child != NULL)
 	{
-		gtk_widget_get_preferred_width (child->priv->widget,
-		                                &child_min, &child_nat);
+		if (orientation == GTK_ORIENTATION_HORIZONTAL)
+		{
+			gtk_widget_get_preferred_width (child,
+			                                &child_min, &child_nat);
+		}
+		else
+		{
+			gtk_widget_get_preferred_height (child,
+			                                 &child_min, &child_nat);
+		}
 	}
 
 	*minimum = child_min;
@@ -135,28 +146,27 @@ gedit_overlay_child_get_preferred_width (GtkWidget *widget,
 }
 
 static void
+gedit_overlay_child_get_preferred_width (GtkWidget *widget,
+                                         gint      *minimum,
+                                         gint      *natural)
+{
+	gedit_overlay_child_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
+}
+
+static void
 gedit_overlay_child_get_preferred_height (GtkWidget *widget,
                                           gint      *minimum,
                                           gint      *natural)
 {
-	GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
-	gint child_min = 0, child_nat = 0;
-
-	if (child->priv->widget != NULL)
-	{
-		gtk_widget_get_preferred_height (child->priv->widget,
-		                                 &child_min, &child_nat);
-	}
-
-	*minimum = child_min;
-	*natural = child_nat;
+	gedit_overlay_child_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
 }
 
 static void
 gedit_overlay_child_size_allocate (GtkWidget     *widget,
                                    GtkAllocation *allocation)
 {
-	GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
+	GeditOverlayChild *overlay_child = GEDIT_OVERLAY_CHILD (widget);
+	GtkWidget *child;
 	GtkAllocation tmp;
 
 	tmp.width = allocation->width;
@@ -165,10 +175,11 @@ gedit_overlay_child_size_allocate (GtkWidget     *widget,
 
 	GTK_WIDGET_CLASS (gedit_overlay_child_parent_class)->size_allocate (widget, allocation);
 
-	if (child->priv->widget != NULL)
+	child = gtk_bin_get_child (GTK_BIN (overlay_child));
+
+	if (child != NULL)
 	{
-		gtk_widget_size_allocate (child->priv->widget,
-		                          &tmp);
+		gtk_widget_size_allocate (child, &tmp);
 	}
 }
 
@@ -176,13 +187,11 @@ static void
 gedit_overlay_child_add (GtkContainer *container,
                          GtkWidget    *widget)
 {
-	GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (container);
+	GeditOverlayChild *overlay_child = GEDIT_OVERLAY_CHILD (container);
 
-	child->priv->widget = widget;
-
-	child->priv->binding = g_object_bind_property (G_OBJECT (widget), "visible",
-						       G_OBJECT (container), "visible",
-						       G_BINDING_BIDIRECTIONAL);
+	overlay_child->priv->binding = g_object_bind_property (G_OBJECT (widget), "visible",
+							       G_OBJECT (container), "visible",
+							       G_BINDING_BIDIRECTIONAL);
 
 	GTK_CONTAINER_CLASS (gedit_overlay_child_parent_class)->add (container, widget);
 }
@@ -193,8 +202,6 @@ gedit_overlay_child_remove (GtkContainer *container,
 {
 	GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (container);
 
-	child->priv->widget = NULL;
-
 	g_object_unref (child->priv->binding);
 
 	GTK_CONTAINER_CLASS (gedit_overlay_child_parent_class)->remove (container, widget);



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