summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2010-11-25 16:09:51 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2010-11-25 16:09:51 +0900
commit9d0c2f6b37beee6032981759b0e1f8161ccd9d72 (patch)
tree0525d3c3661463dbb20fb543bcb98c168240e90a /gtk
parent57a94bfb5364392a2469c592c4cf88536be7e061 (diff)
downloadgtk+-9d0c2f6b37beee6032981759b0e1f8161ccd9d72.tar.gz
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.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkcellareabox.c40
-rw-r--r--gtk/gtkcellareaboxcontext.c24
-rw-r--r--gtk/gtkcellareaboxcontext.h7
3 files changed, 52 insertions, 19 deletions
diff --git a/gtk/gtkcellareabox.c b/gtk/gtkcellareabox.c
index a269cf5d9a..5bfcf1e00a 100644
--- a/gtk/gtkcellareabox.c
+++ b/gtk/gtkcellareabox.c
@@ -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)
{
diff --git a/gtk/gtkcellareaboxcontext.c b/gtk/gtkcellareaboxcontext.c
index e0501e6944..caf23df071 100644
--- a/gtk/gtkcellareaboxcontext.c
+++ b/gtk/gtkcellareaboxcontext.c
@@ -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);
}
diff --git a/gtk/gtkcellareaboxcontext.h b/gtk/gtkcellareaboxcontext.h
index 4f9c02d9b1..01f7dc6cba 100644
--- a/gtk/gtkcellareaboxcontext.h
+++ b/gtk/gtkcellareaboxcontext.h
@@ -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__ */