[gtk+/grid-widget] Cosmetics
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/grid-widget] Cosmetics
- Date: Sun, 10 Oct 2010 06:11:34 +0000 (UTC)
commit 78ed0fc79bc1c30bae24cf82e5f2dddab379523d
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 10 02:10:14 2010 -0400
Cosmetics
gtk/gtkgrid.c | 284 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 138 insertions(+), 146 deletions(-)
---
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index 957e20e..1782e12 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -64,9 +64,10 @@ struct _GtkGridLine
gint minimum;
gint natural;
gint allocation;
- gboolean need_expand;
- gboolean expand;
- gboolean empty;
+
+ guint need_expand : 1;
+ guint expand : 1;
+ guint empty : 1;
};
/* A GtkGridLines struct represents all the rows or columns of
@@ -78,7 +79,7 @@ struct _GtkGridLines
GtkGridLine *lines;
gint min, max;
gint16 spacing;
- gboolean homogeneous;
+ guint homogeneous : 1;
};
struct _GtkGridPrivate
@@ -155,19 +156,19 @@ gtk_grid_get_property (GObject *object,
break;
case PROP_ROW_SPACING:
- g_value_set_int (value, ROWS(priv)->spacing);
+ g_value_set_int (value, ROWS (priv)->spacing);
break;
case PROP_COLUMN_SPACING:
- g_value_set_int (value, COLUMNS(priv)->spacing);
+ g_value_set_int (value, COLUMNS (priv)->spacing);
break;
case PROP_ROW_HOMOGENEOUS:
- g_value_set_boolean (value, ROWS(priv)->homogeneous);
+ g_value_set_boolean (value, ROWS (priv)->homogeneous);
break;
case PROP_COLUMN_HOMOGENEOUS:
- g_value_set_boolean (value, COLUMNS(priv)->homogeneous);
+ g_value_set_boolean (value, COLUMNS (priv)->homogeneous);
break;
default:
@@ -195,24 +196,24 @@ gtk_grid_set_orientation (GtkGrid *grid,
{
child = list->data;
- left = CHILD_LEFT(child);
- top = CHILD_TOP(child);
- width = CHILD_WIDTH(child);
- height = CHILD_HEIGHT(child);
+ left = CHILD_LEFT (child);
+ top = CHILD_TOP (child);
+ width = CHILD_WIDTH (child);
+ height = CHILD_HEIGHT (child);
if (orientation == GTK_ORIENTATION_VERTICAL)
{
- CHILD_LEFT(child) = - (top + height);
- CHILD_TOP(child) = left;
- CHILD_WIDTH(child) = height;
- CHILD_HEIGHT(child) = width;
+ CHILD_LEFT (child) = - (top + height);
+ CHILD_TOP (child) = left;
+ CHILD_WIDTH (child) = height;
+ CHILD_HEIGHT (child) = width;
}
else
{
- CHILD_LEFT(child) = top;
- CHILD_TOP(child) = - (left + width);
- CHILD_WIDTH(child) = height;
- CHILD_HEIGHT(child) = width;
+ CHILD_LEFT (child) = top;
+ CHILD_TOP (child) = - (left + width);
+ CHILD_WIDTH (child) = height;
+ CHILD_HEIGHT (child) = width;
}
gtk_widget_child_notify (child->widget, "left-attach");
gtk_widget_child_notify (child->widget, "top-attach");
@@ -303,27 +304,27 @@ gtk_grid_get_child_property (GtkContainer *container,
switch (property_id)
{
case CHILD_PROP_LEFT_ATTACH:
- g_value_set_int (value, CHILD_LEFT(grid_child));
+ g_value_set_int (value, CHILD_LEFT (grid_child));
break;
case CHILD_PROP_TOP_ATTACH:
- g_value_set_int (value, CHILD_TOP(grid_child));
+ g_value_set_int (value, CHILD_TOP (grid_child));
break;
case CHILD_PROP_WIDTH:
- g_value_set_int (value, CHILD_WIDTH(grid_child));
+ g_value_set_int (value, CHILD_WIDTH (grid_child));
break;
case CHILD_PROP_HEIGHT:
- g_value_set_int (value, CHILD_HEIGHT(grid_child));
+ g_value_set_int (value, CHILD_HEIGHT (grid_child));
break;
case CHILD_PROP_HEXPAND:
- g_value_set_boolean (value, CHILD_HEXPAND(grid_child));
+ g_value_set_boolean (value, CHILD_HEXPAND (grid_child));
break;
case CHILD_PROP_VEXPAND:
- g_value_set_boolean (value, CHILD_VEXPAND(grid_child));
+ g_value_set_boolean (value, CHILD_VEXPAND (grid_child));
break;
default:
@@ -353,32 +354,32 @@ gtk_grid_set_child_property (GtkContainer *container,
switch (property_id)
{
case CHILD_PROP_LEFT_ATTACH:
- CHILD_LEFT(grid_child) = g_value_get_int (value);
+ CHILD_LEFT (grid_child) = g_value_get_int (value);
gtk_grid_free_lines (grid, GTK_ORIENTATION_HORIZONTAL);
break;
case CHILD_PROP_TOP_ATTACH:
- CHILD_TOP(grid_child) = g_value_get_int (value);
+ CHILD_TOP (grid_child) = g_value_get_int (value);
gtk_grid_free_lines (grid, GTK_ORIENTATION_VERTICAL);
break;
case CHILD_PROP_WIDTH:
- CHILD_WIDTH(grid_child) = g_value_get_int (value);
+ CHILD_WIDTH (grid_child) = g_value_get_int (value);
gtk_grid_free_lines (grid, GTK_ORIENTATION_HORIZONTAL);
break;
case CHILD_PROP_HEIGHT:
- CHILD_HEIGHT(grid_child) = g_value_get_int (value);
+ CHILD_HEIGHT (grid_child) = g_value_get_int (value);
gtk_grid_free_lines (grid, GTK_ORIENTATION_VERTICAL);
break;
case CHILD_PROP_HEXPAND:
- CHILD_HEXPAND(grid_child) = g_value_get_boolean (value);
+ CHILD_HEXPAND (grid_child) = g_value_get_boolean (value);
gtk_widget_queue_resize (GTK_WIDGET (grid));
break;
case CHILD_PROP_VEXPAND:
- CHILD_VEXPAND(grid_child) = g_value_get_boolean (value);
+ CHILD_VEXPAND (grid_child) = g_value_get_boolean (value);
gtk_widget_queue_resize (GTK_WIDGET (grid));
break;
@@ -512,6 +513,17 @@ gtk_grid_child_type (GtkContainer *container)
return GTK_TYPE_WIDGET;
}
+static GtkSizeRequestMode
+gtk_grid_get_request_mode (GtkWidget *widget)
+{
+ GtkGridPrivate *priv = GTK_GRID (widget)->priv;
+
+ if (priv->orientation == GTK_ORIENTATION_VERTICAL)
+ return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
+ else
+ return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
static void
gtk_grid_ensure_lines (GtkGrid *grid,
GtkOrientation orientation)
@@ -602,11 +614,42 @@ compute_allocation_for_span (GtkGrid *grid,
return size;
}
+static void
+compute_request_for_child (GtkGrid *grid,
+ GtkOrientation orientation,
+ GtkGridChild *child,
+ gboolean contextual,
+ gint *minimum,
+ gint *natural)
+{
+ if (contextual)
+ {
+ gint size;
+
+ size = compute_allocation_for_span (grid, 1 - orientation, child);
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_widget_get_preferred_width_for_height (child->widget,
+ size,
+ minimum, natural);
+ else
+ gtk_widget_get_preferred_height_for_width (child->widget,
+ size,
+ minimum, natural);
+ }
+ else
+ {
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_widget_get_preferred_width (child->widget, minimum, natural);
+ else
+ gtk_widget_get_preferred_height (child->widget, minimum, natural);
+ }
+}
+
/* set requisition to max of non-spanning children */
static void
gtk_grid_request_non_spanning (GtkGrid *grid,
GtkOrientation orientation,
- gboolean for_size)
+ gboolean contextual)
{
GtkGridPrivate *priv = grid->priv;
GtkGridChild *child;
@@ -631,25 +674,7 @@ gtk_grid_request_non_spanning (GtkGrid *grid,
if (attach->span != 1)
continue;
- if (for_size)
- {
- size = compute_allocation_for_span (grid, 1 - orientation, child);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_preferred_width_for_height (child->widget,
- size,
- &minimum, &natural);
- else
- gtk_widget_get_preferred_height_for_width (child->widget,
- size,
- &minimum, &natural);
- }
- else
- {
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_preferred_width (child->widget, &minimum, &natural);
- else
- gtk_widget_get_preferred_height (child->widget, &minimum, &natural);
- }
+ compute_request_for_child (grid, orientation, child, contextual, &minimum, &natural);
line = &lines->lines[attach->pos - lines->min];
line->minimum = MAX (line->minimum, minimum);
@@ -692,7 +717,7 @@ gtk_grid_request_homogeneous (GtkGrid *grid,
static void
gtk_grid_request_spanning (GtkGrid *grid,
GtkOrientation orientation,
- gboolean for_size)
+ gboolean contextual)
{
GtkGridPrivate *priv = grid->priv;
GList *list;
@@ -700,18 +725,16 @@ gtk_grid_request_spanning (GtkGrid *grid,
GtkGridChildAttach *attach;
GtkGridLines *lines;
GtkGridLine *line;
- gint child_minimum;
- gint child_natural;
+ gint minimum;
+ gint natural;
gint span_minimum;
gint span_natural;
gint span_expand;
- gint minimum;
- gint natural;
+ gboolean force_expand;
+ gint extra;
gint expand;
- gboolean force;
+ gint line_extra;
gint i;
- gint extra;
- gint size;
lines = &priv->lines[orientation];
@@ -726,9 +749,12 @@ gtk_grid_request_spanning (GtkGrid *grid,
if (attach->span == 1)
continue;
+ compute_request_for_child (grid, orientation, child, contextual, &minimum, &natural);
+
span_minimum = (attach->span - 1) * lines->spacing;
span_natural = (attach->span - 1) * lines->spacing;
span_expand = 0;
+ force_expand = FALSE;
for (i = 0; i < attach->span; i++)
{
line = &lines->lines[attach->pos - lines->min + i];
@@ -737,72 +763,45 @@ gtk_grid_request_spanning (GtkGrid *grid,
if (line->expand)
span_expand += 1;
}
-
- if (for_size)
+ if (span_expand == 0)
{
- size = compute_allocation_for_span (grid, 1 - orientation, child);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_preferred_width_for_height (child->widget,
- size,
- &child_minimum, &child_natural);
- else
- gtk_widget_get_preferred_height_for_width (child->widget,
- size,
- &child_minimum, &child_natural);
- }
- else
- {
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_preferred_width (child->widget, &child_minimum, &child_natural);
- else
- gtk_widget_get_preferred_height (child->widget, &child_minimum, &child_natural);
+ span_expand = attach->span;
+ force_expand = TRUE;
}
/* If we need to request more space for this child to fill
* its requisition, then divide up the needed space amongst the
- * columns it spans, favoring expandable columns if any.
+ * lines it spans, favoring expandable lines if any.
*/
- if (span_minimum < child_minimum)
+ if (span_minimum < minimum)
{
- force = FALSE;
- minimum = child_minimum - span_minimum;
+ extra = minimum - span_minimum;
expand = span_expand;
- if (expand == 0)
- {
- expand = attach->span;
- force = TRUE;
- }
for (i = 0; i < attach->span; i++)
{
line = &lines->lines[attach->pos - lines->min + i];
- if (force || line->expand)
+ if (force_expand || line->expand)
{
- extra = minimum / expand;
- line->minimum += extra;
- minimum -= extra;
+ line_extra = extra / expand;
+ line->minimum += line_extra;
+ extra -= line_extra;
expand -= 1;
}
}
}
- if (span_natural < child_natural)
+ if (span_natural < natural)
{
- force = FALSE;
- natural = child_natural - span_natural;
+ extra = natural - span_natural;
expand = span_expand;
- if (expand == 0)
- {
- expand = attach->span;
- force = TRUE;
- }
for (i = 0; i < attach->span; i++)
{
line = &lines->lines[attach->pos - lines->min + i];
- if (force || line->expand)
+ if (force_expand || line->expand)
{
- extra = natural / expand;
- line->natural += extra;
- natural -= extra;
+ line_extra = extra / expand;
+ line->natural += line_extra;
+ extra -= line_extra;
expand -= 1;
}
}
@@ -1090,27 +1089,18 @@ gtk_grid_get_preferred_height (GtkWidget *widget,
gtk_grid_get_size (GTK_GRID (widget), GTK_ORIENTATION_VERTICAL, minimum, natural);
}
-static GtkSizeRequestMode
-gtk_grid_get_request_mode (GtkWidget *widget)
-{
- GtkGridPrivate *priv = GTK_GRID (widget)->priv;
-
- if (priv->orientation == GTK_ORIENTATION_VERTICAL)
- return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
- else
- return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
-}
-
static void
gtk_grid_get_preferred_width_for_height (GtkWidget *widget,
gint height,
gint *minimum,
gint *natural)
{
- if (gtk_grid_get_request_mode (GTK_GRID (widget)) != GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
- gtk_grid_get_preferred_height (widget, &height, NULL);
+ GtkGrid *grid = GTK_GRID (widget);
+
+ if (gtk_grid_get_request_mode (widget) != GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+ gtk_grid_get_size (grid, GTK_ORIENTATION_VERTICAL, &height, NULL);
- gtk_grid_get_size_for_orientation (GTK_GRID (widget), GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
+ gtk_grid_get_size_for_orientation (grid, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
}
static void
@@ -1119,10 +1109,12 @@ gtk_grid_get_preferred_height_for_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
- if (gtk_grid_get_request_mode (GTK_GRID (widget)) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
- gtk_grid_get_preferred_width (widget, &width, NULL);
+ GtkGrid *grid = GTK_GRID (widget);
+
+ if (gtk_grid_get_request_mode (widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ gtk_grid_get_size (grid, GTK_ORIENTATION_HORIZONTAL, &width, NULL);
- gtk_grid_get_size_for_orientation (GTK_GRID (widget), GTK_ORIENTATION_VERTICAL, width, minimum, natural);
+ gtk_grid_get_size_for_orientation (grid, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
}
static void
@@ -1335,12 +1327,12 @@ grid_attach (GtkGrid *grid,
child = g_new (GtkGridChild, 1);
child->widget = widget;
- CHILD_LEFT(child) = left;
- CHILD_TOP(child) = top;
- CHILD_WIDTH(child) = width;
- CHILD_HEIGHT(child) = height;
- CHILD_HEXPAND(child) = FALSE;
- CHILD_VEXPAND(child) = FALSE;
+ CHILD_LEFT (child) = left;
+ CHILD_TOP (child) = top;
+ CHILD_WIDTH (child) = width;
+ CHILD_HEIGHT (child) = height;
+ CHILD_HEXPAND (child) = FALSE;
+ CHILD_VEXPAND (child) = FALSE;
priv->children = g_list_prepend (priv->children, child);
@@ -1390,20 +1382,20 @@ gtk_grid_attach_next_to (GtkGrid *grid,
switch (side)
{
case GTK_POS_LEFT:
- left = CHILD_LEFT(grid_sibling) - width;
- top = CHILD_TOP(grid_sibling);
+ left = CHILD_LEFT (grid_sibling) - width;
+ top = CHILD_TOP (grid_sibling);
break;
case GTK_POS_RIGHT:
- left = CHILD_LEFT(grid_sibling) + CHILD_WIDTH(grid_sibling);
- top = CHILD_TOP(grid_sibling);
+ left = CHILD_LEFT (grid_sibling) + CHILD_WIDTH (grid_sibling);
+ top = CHILD_TOP (grid_sibling);
break;
case GTK_POS_TOP:
- left = CHILD_LEFT(grid_sibling);
- top = CHILD_TOP(grid_sibling) - height;
+ left = CHILD_LEFT (grid_sibling);
+ top = CHILD_TOP (grid_sibling) - height;
break;
case GTK_POS_BOTTOM:
- left = CHILD_LEFT(grid_sibling);
- top = CHILD_TOP(grid_sibling) + CHILD_HEIGHT(grid_sibling);
+ left = CHILD_LEFT (grid_sibling);
+ top = CHILD_TOP (grid_sibling) + CHILD_HEIGHT (grid_sibling);
break;
default:
g_assert_not_reached ();
@@ -1421,9 +1413,9 @@ gtk_grid_set_row_homogeneous (GtkGrid *grid,
priv = grid->priv;
- if (ROWS(priv)->homogeneous != homogeneous)
+ if (ROWS (priv)->homogeneous != homogeneous)
{
- ROWS(priv)->homogeneous = homogeneous;
+ ROWS (priv)->homogeneous = homogeneous;
if (gtk_widget_get_visible (GTK_WIDGET (grid)))
gtk_widget_queue_resize (GTK_WIDGET (grid));
@@ -1440,7 +1432,7 @@ gtk_grid_get_row_homogeneous (GtkGrid *grid)
priv = grid->priv;
- return ROWS(priv)->homogeneous;
+ return ROWS (priv)->homogeneous;
}
void
@@ -1452,9 +1444,9 @@ gtk_grid_set_column_homogeneous (GtkGrid *grid,
priv = grid->priv;
- if (COLUMNS(priv)->homogeneous != homogeneous)
+ if (COLUMNS (priv)->homogeneous != homogeneous)
{
- COLUMNS(priv)->homogeneous = homogeneous;
+ COLUMNS (priv)->homogeneous = homogeneous;
if (gtk_widget_get_visible (GTK_WIDGET (grid)))
gtk_widget_queue_resize (GTK_WIDGET (grid));
@@ -1471,7 +1463,7 @@ gtk_grid_get_column_homogeneous (GtkGrid *grid)
priv = grid->priv;
- return COLUMNS(priv)->homogeneous;
+ return COLUMNS (priv)->homogeneous;
}
void
@@ -1484,9 +1476,9 @@ gtk_grid_set_row_spacing (GtkGrid *grid,
priv = grid->priv;
- if (ROWS(priv)->spacing != spacing)
+ if (ROWS (priv)->spacing != spacing)
{
- ROWS(priv)->spacing = spacing;
+ ROWS (priv)->spacing = spacing;
if (gtk_widget_get_visible (GTK_WIDGET (grid)))
gtk_widget_queue_resize (GTK_WIDGET (grid));
@@ -1503,7 +1495,7 @@ gtk_grid_get_row_spacing (GtkGrid *grid)
priv = grid->priv;
- return ROWS(priv)->spacing;
+ return ROWS (priv)->spacing;
}
void
@@ -1516,9 +1508,9 @@ gtk_grid_set_column_spacing (GtkGrid *grid,
priv = grid->priv;
- if (COLUMNS(priv)->spacing != spacing)
+ if (COLUMNS (priv)->spacing != spacing)
{
- COLUMNS(priv)->spacing = spacing;
+ COLUMNS (priv)->spacing = spacing;
if (gtk_widget_get_visible (GTK_WIDGET (grid)))
gtk_widget_queue_resize (GTK_WIDGET (grid));
@@ -1536,5 +1528,5 @@ gtk_grid_get_column_spacing (GtkGrid *grid)
priv = grid->priv;
- return COLUMNS(priv)->spacing;
+ return COLUMNS (priv)->spacing;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]