[gedit] Do not special case GtkScrolledWindow.



commit 72bc702dd1246ca493990c5e268c033ed9cb046c
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Feb 16 12:09:33 2011 +0100

    Do not special case GtkScrolledWindow.
    
    Instead a relative-widget property is added. If this property is specified
    the floating widgets will be placed in relation to it.

 gedit/gedit-animated-overlay.c |   29 +++++++++++++++++++++++-
 gedit/gedit-animated-overlay.h |    3 +-
 gedit/gedit-overlay.c          |   47 ++++++++++++++++++++++++++++------------
 gedit/gedit-overlay.h          |    3 +-
 gedit/gedit-view-frame.c       |    2 +-
 5 files changed, 66 insertions(+), 18 deletions(-)
---
diff --git a/gedit/gedit-animated-overlay.c b/gedit/gedit-animated-overlay.c
index e5e508d..9b4668a 100644
--- a/gedit/gedit-animated-overlay.c
+++ b/gedit/gedit-animated-overlay.c
@@ -116,11 +116,24 @@ gedit_animated_overlay_init (GeditAnimatedOverlay *overlay)
 	                  overlay);
 }
 
+/**
+ * gedit_animated_overlay_new:
+ * @main_widget: a #GtkWidget
+ * @relative_widget: (allow-none): a #Gtkwidget
+ *
+ * Creates a new #GeditAnimatedOverlay. If @relative_widget is not %NULL the
+ * floating widgets will be placed in relation to it, if not @main_widget will
+ * be use for this purpose.
+ *
+ * Returns: a new #GeditAnimatedOverlay object.
+ */
 GtkWidget *
-gedit_animated_overlay_new (GtkWidget *main_widget)
+gedit_animated_overlay_new (GtkWidget *main_widget,
+                            GtkWidget *relative_widget)
 {
 	return g_object_new (GEDIT_TYPE_ANIMATED_OVERLAY,
 	                     "main-widget", main_widget,
+	                     "relative-widget", relative_widget,
 	                     NULL);
 }
 
@@ -174,6 +187,20 @@ get_animated_widget (GeditAnimatedOverlay *overlay,
 	return anim_widget;
 }
 
+/**
+ * gedit_animated_overlay_slide:
+ * @overlay: a #GeditAnimatedOverlay
+ * @widget: a #GtkWidget to add to @overlay
+ * @position: a #GeditOverlayChildPosition
+ * @offset: offset for @widget
+ * @duration: the duration of the animation
+ * @easing: a #GeditTheatricsChoreographerEasing
+ * @blocking: a #GeditTheatricsChoreographerBlocking
+ * @orientation: the orientation of the animation
+ * @in: if %TRUE slide in if %FALSE slide out
+ *
+ * Adds @widget in @overlay with a slide in/out animation depending on @in.
+ */
 void
 gedit_animated_overlay_slide (GeditAnimatedOverlay               *overlay,
                               GtkWidget                          *widget,
diff --git a/gedit/gedit-animated-overlay.h b/gedit/gedit-animated-overlay.h
index f1d8700..f9a2fb3 100644
--- a/gedit/gedit-animated-overlay.h
+++ b/gedit/gedit-animated-overlay.h
@@ -53,7 +53,8 @@ struct _GeditAnimatedOverlayClass
 
 GType gedit_animated_overlay_get_type (void) G_GNUC_CONST;
 
-GtkWidget *gedit_animated_overlay_new (GtkWidget *main_widget);
+GtkWidget *gedit_animated_overlay_new (GtkWidget *main_widget,
+                                       GtkWidget *relative_widget);
 
 void gedit_animated_overlay_slide (GeditAnimatedOverlay               *overlay,
                                    GtkWidget                          *widget,
diff --git a/gedit/gedit-overlay.c b/gedit/gedit-overlay.c
index 13649a2..16ee8cf 100644
--- a/gedit/gedit-overlay.c
+++ b/gedit/gedit-overlay.c
@@ -29,13 +29,15 @@
 struct _GeditOverlayPrivate
 {
 	GtkWidget *main_widget;
+	GtkWidget *relative_widget;
 	GSList    *children;
 };
 
 enum
 {
 	PROP_0,
-	PROP_MAIN_WIDGET
+	PROP_MAIN_WIDGET,
+	PROP_RELATIVE_WIDGET
 };
 
 G_DEFINE_TYPE (GeditOverlay, gedit_overlay, GTK_TYPE_CONTAINER)
@@ -71,6 +73,10 @@ gedit_overlay_get_property (GObject    *object,
 			g_value_set_object (value, priv->main_widget);
 			break;
 
+		case PROP_RELATIVE_WIDGET:
+			g_value_set_object (value, priv->relative_widget);
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 			break;
@@ -93,6 +99,10 @@ gedit_overlay_set_property (GObject      *object,
 			add_toplevel_widget (overlay, priv->main_widget);
 			break;
 
+		case PROP_RELATIVE_WIDGET:
+			priv->relative_widget = g_value_get_object (value);
+			break;
+
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 			break;
@@ -193,6 +203,7 @@ gedit_overlay_size_allocate (GtkWidget     *widget,
                              GtkAllocation *allocation)
 {
 	GeditOverlay *overlay = GEDIT_OVERLAY (widget);
+	GeditOverlayPrivate *priv = overlay->priv;
 	GtkAllocation main_alloc;
 	GSList *l;
 
@@ -204,22 +215,16 @@ gedit_overlay_size_allocate (GtkWidget     *widget,
 	main_alloc.width = allocation->width;
 	main_alloc.height = allocation->height;
 
-	gtk_widget_size_allocate (overlay->priv->main_widget,
-	                          &main_alloc);
+	gtk_widget_size_allocate (overlay->priv->main_widget, &main_alloc);
 
-	/* we special case the scrolled window to put the floating widgets
-	   in relation to the scrolled window child */
-	if (GTK_IS_SCROLLED_WINDOW (overlay->priv->main_widget))
+	/* if a relative widget exists place the floating widgets in relation to it */
+	if (priv->relative_widget)
 	{
-		GtkWidget *child;
-
-		child = gtk_bin_get_child (GTK_BIN (overlay->priv->main_widget));
-		gtk_widget_get_allocation (child, &main_alloc);
+		gtk_widget_get_allocation (priv->relative_widget, &main_alloc);
 	}
 
-	for (l = overlay->priv->children; l != NULL; l = g_slist_next (l))
+	for (l = priv->children; l != NULL; l = g_slist_next (l))
 	{
-		GeditOverlayPrivate *priv = overlay->priv;
 		GtkWidget *child = GTK_WIDGET (l->data);
 		GtkRequisition req;
 		GtkAllocation alloc;
@@ -406,6 +411,15 @@ gedit_overlay_class_init (GeditOverlayClass *klass)
 	                                                      G_PARAM_CONSTRUCT_ONLY |
 	                                                      G_PARAM_STATIC_STRINGS));
 
+	g_object_class_install_property (object_class, PROP_RELATIVE_WIDGET,
+	                                 g_param_spec_object ("relative-widget",
+	                                                      "Relative Widget",
+	                                                      "Widget on which the floating widgets are placed",
+	                                                      GTK_TYPE_WIDGET,
+	                                                      G_PARAM_READWRITE |
+	                                                      G_PARAM_CONSTRUCT_ONLY |
+	                                                      G_PARAM_STATIC_STRINGS));
+
 	g_type_class_add_private (object_class, sizeof (GeditOverlayPrivate));
 }
 
@@ -418,18 +432,23 @@ gedit_overlay_init (GeditOverlay *overlay)
 /**
  * gedit_overlay_new:
  * @main_widget: a #GtkWidget
+ * @relative_widget: (allow-none): a #Gtkwidget
  *
- * Creates a new #GeditOverlay
+ * Creates a new #GeditOverlay. If @relative_widget is not %NULL the floating
+ * widgets will be placed in relation to it, if not @main_widget will be use
+ * for this purpose.
  *
  * Returns: a new #GeditOverlay object.
  */
 GtkWidget *
-gedit_overlay_new (GtkWidget *main_widget)
+gedit_overlay_new (GtkWidget *main_widget,
+                   GtkWidget *relative_widget)
 {
 	g_return_val_if_fail (GTK_IS_WIDGET (main_widget), NULL);
 
 	return GTK_WIDGET (g_object_new (GEDIT_TYPE_OVERLAY,
 	                                 "main-widget", main_widget,
+	                                 "relative-widget", relative_widget,
 	                                 NULL));
 }
 
diff --git a/gedit/gedit-overlay.h b/gedit/gedit-overlay.h
index f0d696f..9e1c769 100644
--- a/gedit/gedit-overlay.h
+++ b/gedit/gedit-overlay.h
@@ -54,7 +54,8 @@ struct _GeditOverlayClass
 
 GType		 gedit_overlay_get_type			(void) G_GNUC_CONST;
 
-GtkWidget	*gedit_overlay_new			(GtkWidget *main_widget);
+GtkWidget	*gedit_overlay_new			(GtkWidget *main_widget,
+                                                         GtkWidget *relative_widget);
 
 void		 gedit_overlay_add			(GeditOverlay             *overlay,
 							 GtkWidget                *widget,
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 2ed050a..42ce01f 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -1446,7 +1446,7 @@ gedit_view_frame_init (GeditViewFrame *frame)
 					     GTK_SHADOW_IN);
 	gtk_widget_show (sw);
 
-	frame->priv->overlay = gedit_animated_overlay_new (sw);
+	frame->priv->overlay = gedit_animated_overlay_new (sw, frame->priv->view);
 	gtk_widget_show (frame->priv->overlay);
 
 	gtk_box_pack_start (GTK_BOX (frame), frame->priv->overlay, TRUE, TRUE, 0);



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