Commit 9d0c2f6b authored by Tristan Van Berkom's avatar Tristan Van Berkom

Make GtkCellAreaBox handle rendering without a previous allocation in the orientation of choice.

This is so that treeviews can have some columns oriented vertically and
some horizontally, usually the column will only allocate the areas
width, having vertical columns without fixed row heights just means
it's slower to render.
parent 57a94bfb
......@@ -166,7 +166,8 @@ static void init_context_group (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context);
static GSList *get_allocated_cells (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context,
GtkWidget *widget);
GtkWidget *widget,
gint orientation_size);
struct _GtkCellAreaBoxPrivate
......@@ -570,22 +571,22 @@ flush_contexts (GtkCellAreaBox *box)
static GSList *
get_allocated_cells (GtkCellAreaBox *box,
GtkCellAreaBoxContext *context,
GtkWidget *widget)
GtkWidget *widget,
gint orientation_size)
{
const GtkCellAreaBoxAllocation *group_allocs;
GtkCellArea *area = GTK_CELL_AREA (box);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *cell_list;
GSList *allocated_cells = NULL;
gint i, j, n_allocs;
GtkCellAreaBoxAllocation *group_allocs;
GtkCellArea *area = GTK_CELL_AREA (box);
GtkCellAreaBoxPrivate *priv = box->priv;
GList *cell_list;
GSList *allocated_cells = NULL;
gint i, j, n_allocs;
gboolean free_allocs = FALSE;
group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
if (!group_allocs)
{
g_warning ("Trying to operate on an unallocated GtkCellAreaContext, "
"GtkCellAreaBox requires that the context be allocated at least "
"in the orientation of the box");
return NULL;
group_allocs = gtk_cell_area_box_context_allocate (context, orientation_size, &n_allocs);
free_allocs = TRUE;
}
for (i = 0; i < n_allocs; i++)
......@@ -685,6 +686,9 @@ get_allocated_cells (GtkCellAreaBox *box,
}
}
if (free_allocs)
g_free (group_allocs);
/* Note it might not be important to reverse the list here at all,
* we have the correct positions, no need to allocate from left to right */
return g_slist_reverse (allocated_cells);
......@@ -838,7 +842,9 @@ gtk_cell_area_box_get_cell_allocation (GtkCellArea *area,
/* Get a list of cells with allocation sizes decided regardless
* of alignments and pack order etc. */
allocated_cells = get_allocated_cells (box, box_context, widget);
allocated_cells = get_allocated_cells (box, box_context, widget,
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
cell_area->width : cell_area->height);
for (l = allocated_cells; l; l = l->next)
{
......@@ -914,7 +920,9 @@ gtk_cell_area_box_event (GtkCellArea *area,
/* Get a list of cells with allocation sizes decided regardless
* of alignments and pack order etc. */
allocated_cells = get_allocated_cells (box, box_context, widget);
allocated_cells = get_allocated_cells (box, box_context, widget,
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
cell_area->width : cell_area->height);
for (l = allocated_cells; l; l = l->next)
{
......@@ -1016,7 +1024,9 @@ gtk_cell_area_box_render (GtkCellArea *area,
/* Get a list of cells with allocation sizes decided regardless
* of alignments and pack order etc. */
allocated_cells = get_allocated_cells (box, box_context, widget);
allocated_cells = get_allocated_cells (box, box_context, widget,
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
cell_area->width : cell_area->height);
for (l = allocated_cells; l; l = l->next)
{
......
......@@ -562,8 +562,8 @@ gtk_cell_area_box_context_allocate_width (GtkCellAreaContext *context,
{
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
GtkCellArea *area;
GtkOrientation orientation;
GtkCellArea *area;
GtkOrientation orientation;
area = gtk_cell_area_context_get_area (context);
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
......@@ -604,6 +604,7 @@ gtk_cell_area_box_context_allocate_height (GtkCellAreaContext *context,
GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate_height (context, height);
}
/*************************************************************
* API *
*************************************************************/
......@@ -870,7 +871,7 @@ gtk_cell_area_box_context_get_heights (GtkCellAreaBoxContext *box_context,
return gtk_cell_area_box_context_get_requests (box_context, GTK_ORIENTATION_VERTICAL, n_heights);
}
G_CONST_RETURN GtkCellAreaBoxAllocation *
GtkCellAreaBoxAllocation *
gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
gint *n_allocs)
{
......@@ -883,4 +884,21 @@ gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context
*n_allocs = priv->n_orientation_allocs;
return priv->orientation_allocs;
}
GtkCellAreaBoxAllocation *
gtk_cell_area_box_context_allocate (GtkCellAreaBoxContext *context,
gint orientation_size,
gint *n_allocs)
{
GtkCellArea *area;
GtkOrientation orientation;
gint spacing;
area = gtk_cell_area_context_get_area (GTK_CELL_AREA_CONTEXT (context));
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
spacing = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
return allocate_for_orientation (context, orientation, spacing, orientation_size, n_allocs);
}
......@@ -125,10 +125,15 @@ typedef struct {
gint size; /* Full allocated size of the cells in this group spacing inclusive */
} GtkCellAreaBoxAllocation;
G_CONST_RETURN GtkCellAreaBoxAllocation *
GtkCellAreaBoxAllocation *
gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
gint *n_allocs);
GtkCellAreaBoxAllocation *
gtk_cell_area_box_context_allocate (GtkCellAreaBoxContext *context,
gint orientation_size,
gint *n_allocs);
G_END_DECLS
#endif /* __GTK_CELL_AREA_BOX_CONTEXT_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment