[gtk+] paned: Split size request code
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] paned: Split size request code
- Date: Wed, 1 May 2013 15:47:14 +0000 (UTC)
commit ea98c61f3c90cdd3b5e34fa57e510e8ca4715f09
Author: Benjamin Otte <otte redhat com>
Date: Mon Apr 29 19:02:28 2013 +0200
paned: Split size request code
The code is pretty different for both cases, so better split things
here.
gtk/gtkpaned.c | 133 +++++++++++++++++++++++---------------------------------
1 files changed, 55 insertions(+), 78 deletions(-)
---
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index cc1cb13..77c79ee 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -871,67 +871,53 @@ gtk_paned_finalize (GObject *object)
}
static void
-gtk_paned_compute_position (GtkPaned *paned,
- gint allocation,
- gint child1_req,
- gint child2_req,
- gint *min_pos,
- gint *max_pos,
- gint *out_pos)
+gtk_paned_get_preferred_size_for_orientation (GtkWidget *widget,
+ gint size,
+ gint *minimum,
+ gint *natural)
{
+ GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = paned->priv;
- gint min, max, pos;
-
- min = priv->child1_shrink ? 0 : child1_req;
+ gint child_min, child_nat;
- max = allocation;
- if (!priv->child2_shrink)
- max = MAX (1, max - child2_req);
- max = MAX (min, max);
+ *minimum = *natural = 0;
- if (!priv->position_set)
+ if (priv->child1 && gtk_widget_get_visible (priv->child1))
{
- if (priv->child1_resize && !priv->child2_resize)
- pos = MAX (0, allocation - child2_req);
- else if (!priv->child1_resize && priv->child2_resize)
- pos = child1_req;
- else if (child1_req + child2_req != 0)
- pos = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
+ _gtk_widget_get_preferred_size_for_size (priv->child1, priv->orientation, size, &child_min,
&child_nat, NULL, NULL);
+ if (priv->child1_shrink)
+ *minimum = 0;
else
- pos = allocation * 0.5 + 0.5;
+ *minimum = child_min;
+ *natural = child_nat;
}
- else
+
+ if (priv->child2 && gtk_widget_get_visible (priv->child2))
{
- /* If the position was set before the initial allocation.
- * (priv->last_allocation <= 0) just clamp it and leave it.
- */
- if (priv->last_allocation > 0)
- {
- if (priv->child1_resize && !priv->child2_resize)
- pos = priv->child1_size + allocation - priv->last_allocation;
- else if (!(!priv->child1_resize && priv->child2_resize))
- pos = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
- }
- else
- pos = min;
+ _gtk_widget_get_preferred_size_for_size (priv->child2, priv->orientation, size, &child_min,
&child_nat, NULL, NULL);
+
+ if (!priv->child2_shrink)
+ *minimum += child_min;
+ *natural += child_nat;
}
- pos = CLAMP (pos, min, max);
-
- if (min_pos)
- *min_pos = pos;
- if (max_pos)
- *max_pos = pos;
- if (out_pos)
- *out_pos = pos;
+ if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
+ priv->child2 && gtk_widget_get_visible (priv->child2))
+ {
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ *minimum += handle_size;
+ *natural += handle_size;
+ }
}
static void
-gtk_paned_get_preferred_size (GtkWidget *widget,
- GtkOrientation orientation,
- gint size,
- gint *minimum,
- gint *natural)
+gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget,
+ gint size,
+ gint *minimum,
+ gint *natural)
{
GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = paned->priv;
@@ -941,44 +927,35 @@ gtk_paned_get_preferred_size (GtkWidget *widget,
if (priv->child1 && gtk_widget_get_visible (priv->child1))
{
- _gtk_widget_get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat,
NULL, NULL);
- if (priv->child1_shrink && priv->orientation == orientation)
- *minimum = 0;
- else
- *minimum = child_min;
+ _gtk_widget_get_preferred_size_for_size (priv->child1, 1 - priv->orientation, size, &child_min,
&child_nat, NULL, NULL);
+
+ *minimum = child_min;
*natural = child_nat;
}
if (priv->child2 && gtk_widget_get_visible (priv->child2))
{
- _gtk_widget_get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat,
NULL, NULL);
+ _gtk_widget_get_preferred_size_for_size (priv->child2, 1 - priv->orientation, size, &child_min,
&child_nat, NULL, NULL);
- if (priv->orientation == orientation)
- {
- if (!priv->child2_shrink)
- *minimum += child_min;
- *natural += child_nat;
- }
- else
- {
- *minimum = MAX (*minimum, child_min);
- *natural = MAX (*natural, child_nat);
- }
+ *minimum = MAX (*minimum, child_min);
+ *natural = MAX (*natural, child_nat);
}
+}
- if (priv->child1 && gtk_widget_get_visible (priv->child1) &&
- priv->child2 && gtk_widget_get_visible (priv->child2))
- {
- gint handle_size;
-
- gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+static void
+gtk_paned_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint size,
+ gint *minimum,
+ gint *natural)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ GtkPanedPrivate *priv = paned->priv;
- if (priv->orientation == orientation)
- {
- *minimum += handle_size;
- *natural += handle_size;
- }
- }
+ if (orientation == priv->orientation)
+ return gtk_paned_get_preferred_size_for_orientation (widget, size, minimum, natural);
+ else
+ return gtk_paned_get_preferred_size_for_opposite_orientation (widget, size, minimum, natural);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]