[nautilus] gedit-overlay: update from upstream



commit f0649b5bb808aa71fcab52c3e61f5e6419928432
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon May 23 18:32:32 2011 -0400

    gedit-overlay: update from upstream

 src/gedit-overlay-child.c |   90 ++++++++++++-----------
 src/gedit-overlay.c       |  178 ++++++++++++++++++++++++++++++--------------
 2 files changed, 169 insertions(+), 99 deletions(-)
---
diff --git a/src/gedit-overlay-child.c b/src/gedit-overlay-child.c
index 74d6647..7593fe1 100644
--- a/src/gedit-overlay-child.c
+++ b/src/gedit-overlay-child.c
@@ -23,8 +23,7 @@
 
 struct _GeditOverlayChildPrivate
 {
-	GtkWidget		 *widget;
-	GBinding		 *binding;
+	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,21 +116,41 @@ 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);
-        gint child_min = 0, child_nat = 0;
+	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;
-        *natural = child_nat;
+	*natural = child_nat;
+}
+
+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
@@ -139,36 +158,28 @@ 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);
-        GtkAllocation tmp;
+	GeditOverlayChild *overlay_child = GEDIT_OVERLAY_CHILD (widget);
+	GtkWidget *child;
+	GtkAllocation tmp;
+
+	tmp.width = allocation->width;
+	tmp.height = allocation->height;
+	tmp.x = tmp.y = 0;
 
-        tmp.width = allocation->width;
-        tmp.height = allocation->height;
-        tmp.x = tmp.y = 0;
-        
 	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);
@@ -231,9 +238,8 @@ gedit_overlay_child_class_init (GeditOverlayChildClass *klass)
 	                                 g_param_spec_uint ("position",
 	                                                    "Position",
 	                                                    "The Widget Position",
-                                                            0, 
+	                                                    1, GEDIT_OVERLAY_CHILD_POSITION_STATIC,
 	                                                    GEDIT_OVERLAY_CHILD_POSITION_STATIC,
-                                                            0,
 	                                                    G_PARAM_READWRITE |
 	                                                    G_PARAM_CONSTRUCT |
 	                                                    G_PARAM_STATIC_STRINGS));
diff --git a/src/gedit-overlay.c b/src/gedit-overlay.c
index 168036b..4b76a51 100644
--- a/src/gedit-overlay.c
+++ b/src/gedit-overlay.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * gedit-overlay.c
  * This file is part of gedit
@@ -27,6 +26,12 @@
 
 #define GEDIT_OVERLAY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_OVERLAY, GeditOverlayPrivate))
 
+typedef struct
+{
+	GtkWidget *child;
+	GtkWidget *original;
+} ChildContainer;
+
 struct _GeditOverlayPrivate
 {
 	GtkWidget *main_widget;
@@ -43,14 +48,62 @@ enum
 
 G_DEFINE_TYPE (GeditOverlay, gedit_overlay, GTK_TYPE_CONTAINER)
 
+static ChildContainer *
+child_container_new (GtkWidget *child,
+                     GtkWidget *original)
+{
+	ChildContainer *ret;
+
+	ret = g_slice_new (ChildContainer);
+	ret->child = child;
+	ret->original = original;
+
+	return ret;
+}
+
+static void
+child_container_free (ChildContainer *container)
+{
+	g_slice_free (ChildContainer, container);
+}
+
+static GtkWidget *
+child_container_get_child (ChildContainer *container)
+{
+	GtkWidget *child;
+
+	if (container->child != NULL)
+	{
+		child = container->child;
+	}
+	else
+	{
+		child = container->original;
+	}
+
+	return child;
+}
+
 static void
 add_toplevel_widget (GeditOverlay *overlay,
-                     GtkWidget    *child)
+                     GtkWidget    *child,
+                     GtkWidget    *original)
 {
-	gtk_widget_set_parent (child, GTK_WIDGET (overlay));
+	ChildContainer *container;
+
+	if (child != NULL)
+	{
+		gtk_widget_set_parent (child, GTK_WIDGET (overlay));
+	}
+	else
+	{
+		gtk_widget_set_parent (original, GTK_WIDGET (overlay));
+	}
+
+	container = child_container_new (child, original);
 
 	overlay->priv->children = g_slist_append (overlay->priv->children,
-	                                          child);
+	                                          container);
 }
 
 static void
@@ -84,6 +137,27 @@ gedit_overlay_get_property (GObject    *object,
 	}
 }
 
+static GtkWidget *
+wrap_child_if_needed (GtkWidget *widget)
+{
+	GtkWidget *child;
+
+	if (GEDIT_IS_OVERLAY_CHILD (widget))
+	{
+		return widget;
+	}
+
+	child = GTK_WIDGET (gedit_overlay_child_new (widget));
+	gtk_widget_show (child);
+
+	g_signal_connect_swapped (widget,
+	                          "destroy",
+	                          G_CALLBACK (gtk_widget_destroy),
+	                          child);
+
+	return child;
+}
+
 static void
 gedit_overlay_set_property (GObject      *object,
                             guint         prop_id,
@@ -96,10 +170,14 @@ gedit_overlay_set_property (GObject      *object,
 	switch (prop_id)
 	{
 		case PROP_MAIN_WIDGET:
+		{
 			priv->main_widget = g_value_get_object (value);
-			add_toplevel_widget (overlay, priv->main_widget);
-			break;
 
+			add_toplevel_widget (overlay,
+			                     NULL,
+			                     priv->main_widget);
+			break;
+		}
 		case PROP_RELATIVE_WIDGET:
 			priv->relative_widget = g_value_get_object (value);
 			break;
@@ -131,9 +209,9 @@ gedit_overlay_realize (GtkWidget *widget)
 	attributes.wclass = GDK_INPUT_OUTPUT;
 	attributes.visual = gtk_widget_get_visual (widget);
 	attributes.event_mask = gtk_widget_get_events (widget);
-	attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
+	attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK;
 
-	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+	attributes_mask = GDK_WA_X | GDK_WA_Y;
 
 	window = gdk_window_new (gtk_widget_get_parent_window (widget),
 	                         &attributes, attributes_mask);
@@ -204,11 +282,14 @@ gedit_overlay_size_allocate (GtkWidget     *widget,
 
 	for (l = priv->children; l != NULL; l = g_slist_next (l))
 	{
-		GtkWidget *child = GTK_WIDGET (l->data);
+		ChildContainer *container = l->data;
+		GtkWidget *child;
 		GtkRequisition req;
 		GtkAllocation alloc;
 		guint offset;
 
+		child = child_container_get_child (container);
+
 		if (child == priv->main_widget)
 			continue;
 
@@ -251,43 +332,20 @@ static GeditOverlayChild *
 get_overlay_child (GeditOverlay *overlay,
                    GtkWidget    *widget)
 {
-	GeditOverlayChild *overlay_child = NULL;
 	GSList *l;
 
 	for (l = overlay->priv->children; l != NULL; l = g_slist_next (l))
 	{
-		GtkWidget *child = GTK_WIDGET (l->data);
-
-		/* skip the main widget as it is not a OverlayChild */
-		if (child == overlay->priv->main_widget)
-			continue;
+		ChildContainer *container = l->data;
 
-		if (child == widget)
+		if (container->original == widget &&
+		    GEDIT_IS_OVERLAY_CHILD (container->child))
 		{
-			overlay_child = GEDIT_OVERLAY_CHILD (child);
-			break;
-		}
-		else
-		{
-			GtkWidget *in_widget;
-
-			/* let's try also with the internal widget */
-			g_object_get (child, "widget", &in_widget, NULL);
-			g_assert (in_widget != NULL);
-
-			if (in_widget == widget)
-			{
-				overlay_child = GEDIT_OVERLAY_CHILD (child);
-				g_object_unref (in_widget);
-
-				break;
-			}
-
-			g_object_unref (in_widget);
+			return GEDIT_OVERLAY_CHILD (container->child);
 		}
 	}
 
-	return overlay_child;
+	return NULL;
 }
 
 static void
@@ -301,20 +359,9 @@ overlay_add (GtkContainer *overlay,
 
 	if (child == NULL)
 	{
-		if (GEDIT_IS_OVERLAY_CHILD (widget))
-		{
-			child = GEDIT_OVERLAY_CHILD (widget);
-		}
-		else
-		{
-			child = gedit_overlay_child_new (widget);
-			gtk_widget_show (GTK_WIDGET (child));
-
-			g_signal_connect_swapped (widget, "destroy",
-			                          G_CALLBACK (gtk_widget_destroy), child);
-		}
-
-		add_toplevel_widget (GEDIT_OVERLAY (overlay), GTK_WIDGET (child));
+		add_toplevel_widget (GEDIT_OVERLAY (overlay),
+		                     wrap_child_if_needed (widget),
+		                     widget);
 	}
 }
 
@@ -327,15 +374,27 @@ gedit_overlay_remove (GtkContainer *overlay,
 
 	for (l = priv->children; l != NULL; l = g_slist_next (l))
 	{
-		GtkWidget *child = l->data;
+		ChildContainer *container = l->data;
+		GtkWidget *original = container->original;
 
-		if (child == widget)
+		if (original == widget)
 		{
 			gtk_widget_unparent (widget);
-			priv->children = g_slist_remove_link (priv->children,
+
+			if (container->child != NULL &&
+			    original != container->child)
+			{
+				g_signal_handlers_disconnect_by_func (original,
+				                                      gtk_widget_destroy,
+				                                      container->child);
+
+				gtk_widget_destroy (container->child);
+			}
+
+			child_container_free (container);
+			priv->children = g_slist_delete_link (priv->children,
 			                                      l);
 
-			g_slist_free (l);
 			break;
 		}
 	}
@@ -351,10 +410,14 @@ gedit_overlay_forall (GtkContainer *overlay,
 	GSList *children;
 
 	children = priv->children;
+
 	while (children)
 	{
-		GtkWidget *child = GTK_WIDGET (children->data);
+		ChildContainer *container = children->data;
 		children = children->next;
+		GtkWidget *child;
+
+		child = child_container_get_child (container);
 
 		(* callback) (child, callback_data);
 	}
@@ -366,7 +429,6 @@ gedit_overlay_child_type (GtkContainer *overlay)
 	return GTK_TYPE_WIDGET;
 }
 
-
 static void
 gedit_overlay_class_init (GeditOverlayClass *klass)
 {
@@ -412,6 +474,8 @@ static void
 gedit_overlay_init (GeditOverlay *overlay)
 {
 	overlay->priv = GEDIT_OVERLAY_GET_PRIVATE (overlay);
+
+        gtk_widget_set_app_paintable (GTK_WIDGET (overlay), TRUE);
 }
 
 /**



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