[nautilus] overlay: fixup allocation in the overlay
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] overlay: fixup allocation in the overlay
- Date: Fri, 18 Feb 2011 23:29:33 +0000 (UTC)
commit 695d067571292c6475761e1ae4c453615f611a00
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Feb 18 18:25:30 2011 -0500
overlay: fixup allocation in the overlay
Give the children the right size they request, and make sure they don't
get more space allocated than the width of their parent.
src/gedit-overlay-child.c | 32 ++++++++++-----------
src/gedit-overlay.c | 68 +++-----------------------------------------
2 files changed, 20 insertions(+), 80 deletions(-)
---
diff --git a/src/gedit-overlay-child.c b/src/gedit-overlay-child.c
index c460c7f..ed52174 100644
--- a/src/gedit-overlay-child.c
+++ b/src/gedit-overlay-child.c
@@ -24,7 +24,6 @@
struct _GeditOverlayChildPrivate
{
GtkWidget *widget;
- GtkAllocation widget_alloc;
GeditOverlayChildPosition position;
guint offset;
gboolean fixed;
@@ -128,19 +127,17 @@ gedit_overlay_child_get_preferred_width (GtkWidget *widget,
gint *natural)
{
GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
- gint width;
+ gint child_min = 0, child_nat = 0;
if (child->priv->widget != NULL)
{
- gint child_min, child_nat;
gtk_widget_get_preferred_width (child->priv->widget,
&child_min, &child_nat);
- child->priv->widget_alloc.width = child_min;
}
- width = child->priv->widget_alloc.width;
- *minimum = *natural = width;
+ *minimum = child_min;
+ *natural = child_nat;
}
static void
@@ -149,19 +146,17 @@ gedit_overlay_child_get_preferred_height (GtkWidget *widget,
gint *natural)
{
GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
- gint height;
+ gint child_min = 0, child_nat = 0;
if (child->priv->widget != NULL)
- {
- gint child_min, child_nat;
+ {
gtk_widget_get_preferred_height (child->priv->widget,
&child_min, &child_nat);
- child->priv->widget_alloc.height = child_min;
}
- height = child->priv->widget_alloc.height;
- *minimum = *natural = height;
+ *minimum = child_min;
+ *natural = child_nat;
}
static void
@@ -169,15 +164,18 @@ gedit_overlay_child_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GeditOverlayChild *child = GEDIT_OVERLAY_CHILD (widget);
+ GtkAllocation tmp;
+
+ tmp.width = allocation->width;
+ tmp.height = allocation->height;
+ tmp.x = 0;
+ tmp.y = 0;
GTK_WIDGET_CLASS (gedit_overlay_child_parent_class)->size_allocate (widget, allocation);
- if (child->priv->widget != NULL &&
- child->priv->widget_alloc.height &&
- child->priv->widget_alloc.width)
+ if (child->priv->widget != NULL)
{
- gtk_widget_size_allocate (child->priv->widget,
- &child->priv->widget_alloc);
+ gtk_widget_size_allocate (child->priv->widget, &tmp);
}
}
diff --git a/src/gedit-overlay.c b/src/gedit-overlay.c
index 62fa201..d9a634a 100644
--- a/src/gedit-overlay.c
+++ b/src/gedit-overlay.c
@@ -35,8 +35,6 @@ struct _GeditOverlayPrivate
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
- glong hadjustment_signal_id;
- glong vadjustment_signal_id;
/* GtkScrollablePolicy needs to be checked when
* driving the scrollable adjustment values */
@@ -73,28 +71,6 @@ add_toplevel_widget (GeditOverlay *overlay,
}
static void
-gedit_overlay_dispose (GObject *object)
-{
- GeditOverlay *overlay = GEDIT_OVERLAY (object);
-
- if (overlay->priv->hadjustment != NULL)
- {
- g_signal_handler_disconnect (overlay->priv->hadjustment,
- overlay->priv->hadjustment_signal_id);
- overlay->priv->hadjustment = NULL;
- }
-
- if (overlay->priv->vadjustment != NULL)
- {
- g_signal_handler_disconnect (overlay->priv->vadjustment,
- overlay->priv->vadjustment_signal_id);
- overlay->priv->vadjustment = NULL;
- }
-
- G_OBJECT_CLASS (gedit_overlay_parent_class)->dispose (object);
-}
-
-static void
gedit_overlay_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -311,7 +287,7 @@ set_children_positions (GeditOverlay *overlay)
if (child == priv->main_widget)
continue;
- gtk_widget_get_preferred_size (child, &req, NULL);
+ gtk_widget_get_preferred_size (child, NULL, &req);
offset = gedit_overlay_child_get_offset (GEDIT_OVERLAY_CHILD (child));
/* FIXME: Add all the positions here */
@@ -331,8 +307,8 @@ set_children_positions (GeditOverlay *overlay)
alloc.y = priv->main_alloc.height - req.height;
break;
case GEDIT_OVERLAY_CHILD_POSITION_SOUTH_EAST:
- alloc.x = priv->main_alloc.width - req.width - offset;
- alloc.y = priv->main_alloc.height - req.height;
+ alloc.x = MAX (priv->main_alloc.x, priv->main_alloc.width - req.width - (gint) offset);
+ alloc.y = MAX (priv->main_alloc.y, priv->main_alloc.height - req.height);
break;
default:
alloc.x = 0;
@@ -345,8 +321,8 @@ set_children_positions (GeditOverlay *overlay)
alloc.y *= gtk_adjustment_get_value (priv->vadjustment);
}
- alloc.width = req.width;
- alloc.height = req.height;
+ alloc.width = MIN (priv->main_alloc.width, req.width);
+ alloc.height = MIN (priv->main_alloc.height, req.height);
gtk_widget_size_allocate (child, &alloc);
}
@@ -486,13 +462,6 @@ gedit_overlay_child_type (GtkContainer *overlay)
}
static void
-adjustment_value_changed (GtkAdjustment *adjustment,
- GeditOverlay *overlay)
-{
- set_children_positions (overlay);
-}
-
-static void
gedit_overlay_set_hadjustment (GeditOverlay *overlay,
GtkAdjustment *adjustment)
{
@@ -501,25 +470,12 @@ gedit_overlay_set_hadjustment (GeditOverlay *overlay,
if (adjustment && priv->vadjustment == adjustment)
return;
- if (priv->hadjustment != NULL)
- {
- g_signal_handler_disconnect (priv->hadjustment,
- priv->hadjustment_signal_id);
- g_object_unref (priv->hadjustment);
- }
-
if (adjustment == NULL)
{
adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
0.0, 0.0, 0.0);
}
- priv->hadjustment_signal_id =
- g_signal_connect (adjustment,
- "value-changed",
- G_CALLBACK (adjustment_value_changed),
- overlay);
-
priv->hadjustment = g_object_ref_sink (adjustment);
if (GTK_IS_SCROLLABLE (priv->main_widget))
@@ -542,25 +498,12 @@ gedit_overlay_set_vadjustment (GeditOverlay *overlay,
if (adjustment && priv->vadjustment == adjustment)
return;
- if (priv->vadjustment != NULL)
- {
- g_signal_handler_disconnect (priv->vadjustment,
- priv->vadjustment_signal_id);
- g_object_unref (priv->vadjustment);
- }
-
if (adjustment == NULL)
{
adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
0.0, 0.0, 0.0);
}
- overlay->priv->vadjustment_signal_id =
- g_signal_connect (adjustment,
- "value-changed",
- G_CALLBACK (adjustment_value_changed),
- overlay);
-
priv->vadjustment = g_object_ref_sink (adjustment);
if (GTK_IS_SCROLLABLE (priv->main_widget))
@@ -580,7 +523,6 @@ gedit_overlay_class_init (GeditOverlayClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
- object_class->dispose = gedit_overlay_dispose;
object_class->get_property = gedit_overlay_get_property;
object_class->set_property = gedit_overlay_set_property;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]