Adding GtkCellAreaIter arg to GtkCellArea->render/->event

This commit is contained in:
Tristan Van Berkom 2010-10-30 23:48:52 +09:00
parent 972e077966
commit b12e7a8115
3 changed files with 81 additions and 8 deletions

View File

@ -23,6 +23,7 @@
#include "gtkcelllayout.h"
#include "gtkcellarea.h"
#include "gtkcellareaiter.h"
/* GObjectClass */
static void gtk_cell_area_dispose (GObject *object);
@ -481,6 +482,7 @@ gtk_cell_area_forall (GtkCellArea *area,
gint
gtk_cell_area_event (GtkCellArea *area,
GtkCellAreaIter *iter,
GtkWidget *widget,
GdkEvent *event,
const GdkRectangle *cell_area)
@ -488,6 +490,7 @@ gtk_cell_area_event (GtkCellArea *area,
GtkCellAreaClass *class;
g_return_val_if_fail (GTK_IS_CELL_AREA (area), 0);
g_return_val_if_fail (GTK_IS_CELL_AREA_ITER (iter), 0);
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
g_return_val_if_fail (event != NULL, 0);
g_return_val_if_fail (cell_area != NULL, 0);
@ -495,7 +498,7 @@ gtk_cell_area_event (GtkCellArea *area,
class = GTK_CELL_AREA_GET_CLASS (area);
if (class->event)
return class->event (area, widget, event, cell_area);
return class->event (area, iter, widget, event, cell_area);
g_warning ("GtkCellAreaClass::event not implemented for `%s'",
g_type_name (G_TYPE_FROM_INSTANCE (area)));
@ -504,21 +507,23 @@ gtk_cell_area_event (GtkCellArea *area,
void
gtk_cell_area_render (GtkCellArea *area,
cairo_t *cr,
GtkCellAreaIter *iter,
GtkWidget *widget,
cairo_t *cr,
const GdkRectangle *cell_area)
{
GtkCellAreaClass *class;
g_return_if_fail (GTK_IS_CELL_AREA (area));
g_return_if_fail (cr != NULL);
g_return_if_fail (GTK_IS_CELL_AREA_ITER (iter));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL);
g_return_if_fail (cell_area != NULL);
class = GTK_CELL_AREA_GET_CLASS (area);
if (class->render)
class->render (area, cr, widget, cell_area);
class->render (area, iter, widget, cr, cell_area);
else
g_warning ("GtkCellAreaClass::render not implemented for `%s'",
g_type_name (G_TYPE_FROM_INSTANCE (area)));

View File

@ -80,12 +80,14 @@ struct _GtkCellAreaClass
GtkCellCallback callback,
gpointer callback_data);
gint (* event) (GtkCellArea *area,
GtkCellAreaIter *iter,
GtkWidget *widget,
GdkEvent *event,
const GdkRectangle *cell_area);
void (* render) (GtkCellArea *area,
cairo_t *cr,
GtkCellAreaIter *iter,
GtkWidget *widget,
cairo_t *cr,
const GdkRectangle *cell_area);
/* Geometry */
@ -137,12 +139,14 @@ void gtk_cell_area_forall (GtkCellArea
GtkCellCallback callback,
gpointer callback_data);
gint gtk_cell_area_event (GtkCellArea *area,
GtkCellAreaIter *iter,
GtkWidget *widget,
GdkEvent *event,
const GdkRectangle *cell_area);
void gtk_cell_area_render (GtkCellArea *area,
cairo_t *cr,
GtkCellAreaIter *iter,
GtkWidget *widget,
cairo_t *cr,
const GdkRectangle *cell_area);
/* Geometry */

View File

@ -51,12 +51,14 @@ static void gtk_cell_area_box_forall (GtkCellArea
GtkCellCallback callback,
gpointer callback_data);
static gint gtk_cell_area_box_event (GtkCellArea *area,
GtkCellAreaIter *iter,
GtkWidget *widget,
GdkEvent *event,
const GdkRectangle *cell_area);
static void gtk_cell_area_box_render (GtkCellArea *area,
cairo_t *cr,
GtkCellAreaIter *iter,
GtkWidget *widget,
cairo_t *cr,
const GdkRectangle *cell_area);
static GtkCellAreaIter *gtk_cell_area_box_create_iter (GtkCellArea *area);
@ -418,8 +420,68 @@ gtk_cell_area_box_allocate (GtkCellAreaBox *box,
gint size,
gint *n_allocs)
{
GtkCellAreaBoxPrivate *priv = box->priv;
CellGroup *group;
GList *group_list;
GtkRequestedSize *orientation_sizes;
gint n_groups, n_expand_groups, i;
gint avail_size = size;
gint extra_size, extra_extra;
gint position;
GtkCellAreaBoxAllocation *allocs;
n_expand_groups = count_expand_groups (box);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
orientation_sizes = gtk_cell_area_box_iter_get_widths (iter, &n_groups);
else
orientation_sizes = gtk_cell_area_box_iter_get_heights (iter, &n_groups);
/* First start by naturally allocating space among groups of cells */
avail_size -= (n_groups - 1) * priv->spacing;
for (i = 0; i < n_groups; i++)
avail_size -= orientation_sizes[i].minimum_size;
avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
/* Calculate/distribute expand for groups */
if (n_expand_groups > 0)
{
extra_size = avail_size / n_expand_groups;
extra_extra = avail_size % n_expand_groups;
}
else
extra_size = extra_extra = 0;
allocs = g_new (GtkCellAreaBoxAllocation, n_groups);
for (position = 0, group_list = priv->groups; group_list; group_list = group_list->next)
{
group = group_list->data;
allocs[group->id].position = position;
allocs[group->id].size = orientation_sizes[group->id].minimum_size;
if (group->expand)
{
allocs[group->id].size += extra_size;
if (extra_extra)
{
allocs[group->id].size++;
extra_extra--;
}
}
position += allocs[group->id].size;
position += priv->spacing;
}
g_free (orientation_sizes);
if (n_allocs)
*n_allocs = n_groups;
return allocs;
}
@ -546,6 +608,7 @@ gtk_cell_area_box_forall (GtkCellArea *area,
static gint
gtk_cell_area_box_event (GtkCellArea *area,
GtkCellAreaIter *iter,
GtkWidget *widget,
GdkEvent *event,
const GdkRectangle *cell_area)
@ -557,8 +620,9 @@ gtk_cell_area_box_event (GtkCellArea *area,
static void
gtk_cell_area_box_render (GtkCellArea *area,
cairo_t *cr,
GtkCellAreaIter *iter,
GtkWidget *widget,
cairo_t *cr,
const GdkRectangle *cell_area)
{