[nautilus] floating-bar: port to GtkOverlay



commit a28a89ab8112a5207d5413e5f767f191d1d13339
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 13 11:17:05 2011 -0400

    floating-bar: port to GtkOverlay

 src/Makefile.am             |    4 -
 src/gedit-overlay.c         |  532 -------------------------------------------
 src/gedit-overlay.h         |   67 ------
 src/nautilus-floating-bar.c |  206 +++---------------
 src/nautilus-floating-bar.h |    6 +-
 src/nautilus-icon-view.c    |    1 -
 src/nautilus-list-view.c    |    1 -
 src/nautilus-window-slot.c  |   24 +--
 src/nautilus-window-slot.h  |    1 -
 9 files changed, 39 insertions(+), 803 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 060e4cc..ed938b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,10 +49,6 @@ BUILT_SOURCES = \
 	$(NULL)
 
 nautilus_SOURCES = \
-	gedit-overlay.h				\
-	gedit-overlay.c				\
-	gedit-overlay-child.h			\
-	gedit-overlay-child.c			\
 	nautilus-actions.h			\
 	nautilus-application.c			\
 	nautilus-application.h			\
diff --git a/src/nautilus-floating-bar.c b/src/nautilus-floating-bar.c
index 0d092f6..eb14dbc 100644
--- a/src/nautilus-floating-bar.c
+++ b/src/nautilus-floating-bar.c
@@ -57,7 +57,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 static guint signals[NUM_SIGNALS] = { 0, };
 
 G_DEFINE_TYPE (NautilusFloatingBar, nautilus_floating_bar,
-               GEDIT_TYPE_OVERLAY_CHILD);
+               GTK_TYPE_BOX);
 
 static void
 action_button_clicked_cb (GtkButton *button,
@@ -135,180 +135,47 @@ update_label (NautilusFloatingBar *self)
 	gtk_label_set_text (GTK_LABEL (self->priv->label_widget), self->priv->label);
 }
 
-/* this is adapted from Epiphany:
- * lib/widgets/ephy-overlay-escaping-child.c
- *
- * License: LGPL v2.1+
- * Copyright © 2011 Igalia S.L.
- */
-
-/* If the pointer leaves the window, restore the widget position */
-static gboolean
-parent_leave_notify_event (GtkWidget *widget,
-                           GdkEventMotion *event,
-                           GtkWidget *parent)
-{
-	NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
-	NautilusFloatingBarDetails *priv = self->priv;
-	GtkAllocation alloc;
-
-	gtk_widget_get_allocation (widget, &alloc);
-	alloc.y = priv->initial_allocation.y;
-	gtk_widget_size_allocate (widget, &alloc);
-
-	return FALSE;
-}
-
-/* this should be in Gdk...really */
-static gboolean
-is_point_in_rectangle (int point_x,
-                       int point_y,
-                       GdkRectangle rectangle)
-{
-	int rectangle_x_higher_bound = rectangle.x + rectangle.width;
-	int rectangle_y_higher_bound = rectangle.y + rectangle.height;
-
-	return point_x >= rectangle.x && point_x < rectangle_x_higher_bound
-		&& point_y >= rectangle.y && point_y < rectangle_y_higher_bound;
-}
-
-/* Keep the widget-pointer distance at at least
- * EphyOverlayEscapingChildPrivate::escaping_distance by sliding the widget
- * away if needed.
- */
 static gboolean
-parent_motion_notify_event (GtkWidget *widget,
-                            GdkEventMotion *event,
-                            GtkWidget *parent)
+overlay_enter_notify_cb (GtkWidget        *parent,
+			 GdkEventCrossing *event,
+			 gpointer          user_data)
 {
-	NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
-	NautilusFloatingBarDetails *priv = self->priv;
-	int distance_x, distance_y;
-	GtkAllocation alloc;
+	GtkWidget *widget = user_data;
 
-	gtk_widget_get_allocation (widget, &alloc);
+	if (event->window != gtk_widget_get_window (widget)) {
+		return FALSE;
+	}
 
-	if (is_point_in_rectangle (event->x, event->y, priv->escaping_area)) {
-		gtk_widget_get_pointer (widget, &distance_x, &distance_y);
-		alloc.y += priv->escaping_distance + distance_y;
+	if (gtk_widget_get_halign (widget) == GTK_ALIGN_START) {
+		gtk_widget_set_halign (widget, GTK_ALIGN_END);
 	} else {
-		/* Put the widget at its original position if we are out of the escaping
-		 * zone. Do nothing if it is already there.
-		 */
-		if (alloc.y == priv->initial_allocation.y) {
-			return FALSE;
-		}
-
-		alloc.y = priv->initial_allocation.y;
+		gtk_widget_set_halign (widget, GTK_ALIGN_START);
 	}
 
-	gtk_widget_size_allocate (widget, &alloc);
+	gtk_widget_queue_resize (widget);
 
 	return FALSE;
 }
 
-/* When the parent overlay is resized, the child relative position is modified.
- * So we update our initial_allocation to this new value and redefine our
- * escaping area.
- */
-static void
-parent_size_allocate (GtkWidget    *widget,
-                      GdkRectangle *allocation,
-                      GtkWidget      *parent)
-{
-	NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
-	NautilusFloatingBarDetails *priv = self->priv;
-	GtkAllocation initial_allocation;
-
-	gtk_widget_get_allocation (widget, &initial_allocation);
-	priv->escaping_area = priv->initial_allocation = initial_allocation;
-
-	/* Define an escaping area around the widget.
-	 * Current implementation only handle horizontal lowerside widgets
-	 */
-	priv->escaping_area.height += priv->escaping_distance;
-	/* escape on both right and left */
-	priv->escaping_area.width += 2 * priv->escaping_distance;
-	priv->escaping_area.x -= priv->escaping_distance;
-	priv->escaping_area.y -= priv->escaping_distance;
-}
-
-/* Install listeners on our overlay parents to locate the pointer
- * and our relative position.
- */
 static void
 nautilus_floating_bar_parent_set (GtkWidget *widget,
-				  GtkWidget *previous_parent)
+				  GtkWidget *old_parent)
 {
 	GtkWidget *parent;
 
-	if (previous_parent != NULL) {
-		g_signal_handlers_disconnect_by_func (previous_parent,
-						      G_CALLBACK (parent_motion_notify_event),
-						      widget);
-		g_signal_handlers_disconnect_by_func (previous_parent,
-						      G_CALLBACK (parent_leave_notify_event),
-						      widget);
-		g_signal_handlers_disconnect_by_func (previous_parent,
-						      G_CALLBACK (parent_size_allocate),
-						      widget);
-	}
-
 	parent = gtk_widget_get_parent (widget);
 
-	if (parent == NULL) {
-		return;
+	if (old_parent != NULL) {
+		g_signal_handlers_disconnect_by_func (old_parent,
+						      overlay_enter_notify_cb, widget);
 	}
 
-	g_signal_connect_swapped (parent,
-				  "motion-notify-event",
-				  G_CALLBACK (parent_motion_notify_event),
-				  widget);
-	g_signal_connect_swapped (parent,
-				  "leave-notify-event",
-				  G_CALLBACK (parent_leave_notify_event),
-				  widget);
-	g_signal_connect_swapped (parent,
-				  "size-allocate",
-				  G_CALLBACK (parent_size_allocate),
-				  widget);
-}
-
-/* When the mouse is over us, translate the event coords and slide the widget
- * accordingly
- */
-static gboolean
-nautilus_floating_bar_motion_notify (GtkWidget *widget,
-				     GdkEventMotion *event)
-{
-	NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
-	NautilusFloatingBarDetails *priv = self->priv;
-
-	event->x += priv->initial_allocation.x;
-	event->y += priv->initial_allocation.y;
-	return parent_motion_notify_event (widget, event, gtk_widget_get_parent (widget));
-}
-
-/* Make our event window propagate mouse motion events, so we can slide the widget,
- * when hovered.
- */
-static void
-nautilus_floating_bar_realize (GtkWidget *widget)
-{
-	GdkWindow *window;
-	GdkEventMask events;
-
-	GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->realize (widget);
-
-	window = gtk_widget_get_window (widget);
-	events = gdk_window_get_events (window);
-	events |= GDK_POINTER_MOTION_MASK;
-
-	gdk_window_set_events (window, events);
+	if (parent != NULL) {
+		g_signal_connect (parent, "enter-notify-event",
+				  G_CALLBACK (overlay_enter_notify_cb), widget);
+	}
 }
 
-/* end of code adapted from Epiphany */
-
 static void
 nautilus_floating_bar_show (GtkWidget *widget)
 {
@@ -333,7 +200,7 @@ nautilus_floating_bar_hide (GtkWidget *widget)
 
 static gboolean
 nautilus_floating_bar_draw (GtkWidget *widget,
-                          cairo_t *cr)
+			    cairo_t *cr)
 {
 	  GtkStyleContext *context;
 
@@ -369,10 +236,7 @@ nautilus_floating_bar_constructed (GObject *obj)
 
 	G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->constructed (obj);
 
-	g_object_get (self,
-		      "widget", &box,
-		      NULL);
-	gtk_widget_show (box);
+	box = GTK_WIDGET (obj);
 
 	w = gtk_spinner_new ();
 	gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
@@ -393,8 +257,6 @@ nautilus_floating_bar_constructed (GObject *obj)
 		      NULL);
 	self->priv->label_widget = w;
 	gtk_widget_show (w);
-
-	g_object_unref (box);
 }
 
 static void
@@ -419,8 +281,6 @@ nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass)
 	wclass->show = nautilus_floating_bar_show;
 	wclass->hide = nautilus_floating_bar_hide;
 	wclass->parent_set = nautilus_floating_bar_parent_set;
-	wclass->motion_notify_event = nautilus_floating_bar_motion_notify;
-	wclass->realize = nautilus_floating_bar_realize;
 
 	properties[PROP_LABEL] =
 		g_param_spec_string ("label",
@@ -490,9 +350,10 @@ nautilus_floating_bar_new (const gchar *label,
 			   gboolean show_spinner)
 {
 	return g_object_new (NAUTILUS_TYPE_FLOATING_BAR,
-			     "widget", gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8),
 			     "label", label,
 			     "show-spinner", show_spinner,
+			     "orientation", GTK_ORIENTATION_HORIZONTAL,
+			     "spacing", 8,
 			     NULL);
 }
 
@@ -501,18 +362,14 @@ nautilus_floating_bar_add_action (NautilusFloatingBar *self,
 				  const gchar *stock_id,
 				  gint action_id)
 {
-	GtkWidget *w, *button, *box;
-
-	g_object_get (self,
-		      "widget", &box,
-		      NULL);
+	GtkWidget *w, *button;
 
 	w = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
 	gtk_widget_show (w);
 
 	button = gtk_button_new ();
 	gtk_button_set_image (GTK_BUTTON (button), w);
-	gtk_box_pack_end (GTK_BOX (box), button, FALSE, FALSE, 0);
+	gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0);
 	gtk_widget_show (button);
 
 	g_object_set_data (G_OBJECT (button), "action-id",
@@ -520,22 +377,16 @@ nautilus_floating_bar_add_action (NautilusFloatingBar *self,
 
 	g_signal_connect (button, "clicked",
 			  G_CALLBACK (action_button_clicked_cb), self);
-
-	g_object_unref (box);
 }
 
 void
 nautilus_floating_bar_cleanup_actions (NautilusFloatingBar *self)
 {
-	GtkWidget *box, *widget;
+	GtkWidget *widget;
 	GList *children, *l;
 	gpointer data;
 
-	g_object_get (self,
-		      "widget", &box,
-		      NULL);
-
-	children = gtk_container_get_children (GTK_CONTAINER (box));
+	children = gtk_container_get_children (GTK_CONTAINER (self));
 	l = children;
 
 	while (l != NULL) {
@@ -549,6 +400,5 @@ nautilus_floating_bar_cleanup_actions (NautilusFloatingBar *self)
 		}
 	}
 
-	g_object_unref (box);
 	g_list_free (children);
 }
diff --git a/src/nautilus-floating-bar.h b/src/nautilus-floating-bar.h
index 99f88a5..03ea0f9 100644
--- a/src/nautilus-floating-bar.h
+++ b/src/nautilus-floating-bar.h
@@ -28,8 +28,6 @@
 
 #include <gtk/gtk.h>
 
-#include "gedit-overlay-child.h"
-
 #define NAUTILUS_FLOATING_BAR_ACTION_ID_STOP 1
 
 #define NAUTILUS_TYPE_FLOATING_BAR nautilus_floating_bar_get_type()
@@ -49,12 +47,12 @@ typedef struct _NautilusFloatingBarClass NautilusFloatingBarClass;
 typedef struct _NautilusFloatingBarDetails NautilusFloatingBarDetails;
 
 struct _NautilusFloatingBar {
-	GeditOverlayChild parent;
+	GtkBox parent;
 	NautilusFloatingBarDetails *priv;
 };
 
 struct _NautilusFloatingBarClass {
-	GeditOverlayChildClass parent_class;
+	GtkBoxClass parent_class;
 };
 
 /* GObject */
diff --git a/src/nautilus-icon-view.c b/src/nautilus-icon-view.c
index ff8017c..ff45911 100644
--- a/src/nautilus-icon-view.c
+++ b/src/nautilus-icon-view.c
@@ -26,7 +26,6 @@
 
 #include "nautilus-icon-view.h"
 
-#include "gedit-overlay.h"
 #include "nautilus-actions.h"
 #include "nautilus-icon-view-container.h"
 #include "nautilus-desktop-icon-view.h"
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index f1530b9..e958d2e 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -28,7 +28,6 @@
 #include <config.h>
 #include "nautilus-list-view.h"
 
-#include "gedit-overlay.h"
 #include "nautilus-list-model.h"
 #include "nautilus-error-reporting.h"
 #include "nautilus-view-dnd.h"
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 32823da..26ca81d 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -23,7 +23,6 @@
 */
 #include "nautilus-window-slot.h"
 
-#include "gedit-overlay.h"
 #include "nautilus-desktop-window.h"
 #include "nautilus-floating-bar.h"
 #include "nautilus-window-private.h"
@@ -184,17 +183,18 @@ nautilus_window_slot_init (NautilusWindowSlot *slot)
 	gtk_box_pack_start (GTK_BOX (content_box), extras_vbox, FALSE, FALSE, 0);
 	gtk_widget_show (extras_vbox);
 
-	slot->view_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-	slot->view_overlay = gedit_overlay_new (slot->view_box, NULL);
+	slot->view_overlay = gtk_overlay_new ();
+	gtk_widget_add_events (slot->view_overlay,
+			       GDK_ENTER_NOTIFY_MASK |
+			       GDK_LEAVE_NOTIFY_MASK);
 	gtk_box_pack_start (GTK_BOX (content_box), slot->view_overlay, TRUE, TRUE, 0);
 	gtk_widget_show (slot->view_overlay);
-	gtk_widget_show (slot->view_box);
 
 	slot->floating_bar = nautilus_floating_bar_new ("", FALSE);
-	gedit_overlay_add (GEDIT_OVERLAY (slot->view_overlay),
-			   slot->floating_bar,
-			   GEDIT_OVERLAY_CHILD_POSITION_SOUTH_EAST,
-			   0);
+	gtk_widget_set_halign (slot->floating_bar, GTK_ALIGN_END);
+	gtk_widget_set_valign (slot->floating_bar, GTK_ALIGN_END);
+	gtk_overlay_add_overlay (GTK_OVERLAY (slot->view_overlay),
+				 slot->floating_bar);
 
 	g_signal_connect (slot->floating_bar, "action",
 			  G_CALLBACK (floating_bar_action_cb), slot);
@@ -457,18 +457,12 @@ nautilus_window_slot_set_content_view_widget (NautilusWindowSlot *slot,
 
 	if (new_view != NULL) {
 		widget = GTK_WIDGET (new_view);
-		gtk_box_pack_start (GTK_BOX (slot->view_box), widget, 
-				    TRUE, TRUE, 0);
+		gtk_container_add (GTK_CONTAINER (slot->view_overlay), widget);
 		gtk_widget_show (widget);
 
 		slot->content_view = new_view;
 		g_object_ref (slot->content_view);
 
-		g_object_set (slot->view_overlay,
-			      "relative-widget",
-			      gtk_bin_get_child (GTK_BIN (slot->content_view)),
-			      NULL);
-
 		/* connect new view */
 		nautilus_window_connect_content_view (window, new_view);
 	}
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index 0342c62..0a2b922 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -72,7 +72,6 @@ struct NautilusWindowSlot {
  	 */
 	GtkWidget *content_box;
 	GtkWidget *extra_location_widgets;
-	GtkWidget *view_box;
 
 	GtkWidget *view_overlay;
 	GtkWidget *floating_bar;



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