2010-11-13 07:23:01 +00:00
|
|
|
/* gtkcellareaboxcontext.c
|
2010-10-26 09:22:59 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Openismus GmbH
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Tristan Van Berkom <tristanvb@openismus.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gtkintl.h"
|
2010-10-30 08:32:15 +00:00
|
|
|
#include "gtkcellareabox.h"
|
2010-11-13 07:23:01 +00:00
|
|
|
#include "gtkcellareaboxcontext.h"
|
2010-10-30 14:06:26 +00:00
|
|
|
#include "gtkorientable.h"
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
/* GObjectClass */
|
2010-11-13 07:23:01 +00:00
|
|
|
static void gtk_cell_area_box_context_finalize (GObject *object);
|
|
|
|
|
|
|
|
/* GtkCellAreaContextClass */
|
|
|
|
static void gtk_cell_area_box_context_flush_preferred_width (GtkCellAreaContext *context);
|
|
|
|
static void gtk_cell_area_box_context_flush_preferred_height (GtkCellAreaContext *context);
|
|
|
|
static void gtk_cell_area_box_context_flush_allocation (GtkCellAreaContext *context);
|
|
|
|
static void gtk_cell_area_box_context_sum_preferred_width (GtkCellAreaContext *context);
|
|
|
|
static void gtk_cell_area_box_context_sum_preferred_height (GtkCellAreaContext *context);
|
|
|
|
static void gtk_cell_area_box_context_allocate_width (GtkCellAreaContext *context,
|
|
|
|
gint width);
|
|
|
|
static void gtk_cell_area_box_context_allocate_height (GtkCellAreaContext *context,
|
|
|
|
gint height);
|
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
typedef struct {
|
|
|
|
gint min_size;
|
|
|
|
gint nat_size;
|
|
|
|
gboolean expand;
|
|
|
|
} BaseSize;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
struct _GtkCellAreaBoxContextPrivate
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
|
|
|
/* Table of per renderer CachedSizes */
|
2010-10-31 04:06:10 +00:00
|
|
|
GArray *base_widths;
|
|
|
|
GArray *base_heights;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
/* Allocation info for this context if any */
|
2010-10-30 14:06:26 +00:00
|
|
|
gint alloc_width;
|
|
|
|
gint alloc_height;
|
|
|
|
gint n_orientation_allocs;
|
|
|
|
GtkCellAreaBoxAllocation *orientation_allocs;
|
2010-10-26 09:22:59 +00:00
|
|
|
};
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
G_DEFINE_TYPE (GtkCellAreaBoxContext, gtk_cell_area_box_context, GTK_TYPE_CELL_AREA_CONTEXT);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_init (GtkCellAreaBoxContext *box_context)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
box_context->priv = G_TYPE_INSTANCE_GET_PRIVATE (box_context,
|
|
|
|
GTK_TYPE_CELL_AREA_BOX_CONTEXT,
|
|
|
|
GtkCellAreaBoxContextPrivate);
|
|
|
|
priv = box_context->priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
priv->base_widths = g_array_new (FALSE, TRUE, sizeof (BaseSize));
|
|
|
|
priv->base_heights = g_array_new (FALSE, TRUE, sizeof (BaseSize));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-30 14:06:26 +00:00
|
|
|
priv->alloc_width = 0;
|
|
|
|
priv->alloc_height = 0;
|
|
|
|
priv->orientation_allocs = NULL;
|
|
|
|
priv->n_orientation_allocs = 0;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_class_init (GtkCellAreaBoxContextClass *class)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkCellAreaContextClass *context_class = GTK_CELL_AREA_CONTEXT_CLASS (class);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
/* GObjectClass */
|
2010-11-13 07:23:01 +00:00
|
|
|
object_class->finalize = gtk_cell_area_box_context_finalize;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
context_class->flush_preferred_width = gtk_cell_area_box_context_flush_preferred_width;
|
|
|
|
context_class->flush_preferred_height = gtk_cell_area_box_context_flush_preferred_height;
|
|
|
|
context_class->flush_allocation = gtk_cell_area_box_context_flush_allocation;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
context_class->sum_preferred_width = gtk_cell_area_box_context_sum_preferred_width;
|
|
|
|
context_class->sum_preferred_height = gtk_cell_area_box_context_sum_preferred_height;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
context_class->allocate_width = gtk_cell_area_box_context_allocate_width;
|
|
|
|
context_class->allocate_height = gtk_cell_area_box_context_allocate_height;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxContextPrivate));
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* GObjectClass *
|
|
|
|
*************************************************************/
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_finalize (GObject *object)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (object);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
g_array_free (priv->base_widths, TRUE);
|
|
|
|
g_array_free (priv->base_heights, TRUE);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-30 14:06:26 +00:00
|
|
|
g_free (priv->orientation_allocs);
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
G_OBJECT_CLASS (gtk_cell_area_box_context_parent_class)->finalize (object);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
2010-11-13 07:23:01 +00:00
|
|
|
* GtkCellAreaContextClass *
|
2010-10-26 09:22:59 +00:00
|
|
|
*************************************************************/
|
2010-10-30 14:06:26 +00:00
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_flush_preferred_width (GtkCellAreaContext *context)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
gint i;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < priv->base_widths->len; i++)
|
|
|
|
{
|
|
|
|
BaseSize *size = &g_array_index (priv->base_widths, BaseSize, i);
|
|
|
|
|
|
|
|
size->min_size = 0;
|
|
|
|
size->nat_size = 0;
|
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
GTK_CELL_AREA_CONTEXT_CLASS
|
|
|
|
(gtk_cell_area_box_context_parent_class)->flush_preferred_width (context);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_flush_preferred_height (GtkCellAreaContext *context)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
gint i;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < priv->base_heights->len; i++)
|
|
|
|
{
|
|
|
|
BaseSize *size = &g_array_index (priv->base_heights, BaseSize, i);
|
|
|
|
|
|
|
|
size->min_size = 0;
|
|
|
|
size->nat_size = 0;
|
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
GTK_CELL_AREA_CONTEXT_CLASS
|
|
|
|
(gtk_cell_area_box_context_parent_class)->flush_preferred_height (context);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_flush_allocation (GtkCellAreaContext *context)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
|
|
|
g_free (priv->orientation_allocs);
|
|
|
|
priv->orientation_allocs = NULL;
|
|
|
|
priv->n_orientation_allocs = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_sum_preferred_width (GtkCellAreaContext *context)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
GtkCellArea *area;
|
|
|
|
GtkOrientation orientation;
|
|
|
|
gint spacing, i;
|
|
|
|
gint min_size = 0, nat_size = 0;
|
|
|
|
|
|
|
|
area = gtk_cell_area_context_get_area (context);
|
2010-10-31 04:06:10 +00:00
|
|
|
spacing = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
|
|
|
|
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
|
|
|
|
|
|
|
for (i = 0; i < priv->base_widths->len; i++)
|
|
|
|
{
|
|
|
|
BaseSize *size = &g_array_index (priv->base_widths, BaseSize, i);
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Dont add spacing for 0 size groups, they can be 0 size because
|
|
|
|
* they contain only invisible cells for this round of requests
|
|
|
|
*/
|
|
|
|
if (min_size > 0 && size->nat_size > 0)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
|
|
|
min_size += spacing;
|
|
|
|
nat_size += spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_size += size->min_size;
|
|
|
|
nat_size += size->nat_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_size = MAX (min_size, size->min_size);
|
|
|
|
nat_size = MAX (nat_size, size->nat_size);
|
|
|
|
}
|
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_context_push_preferred_width (context, min_size, nat_size);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_sum_preferred_height (GtkCellAreaContext *context)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
GtkCellArea *area;
|
|
|
|
GtkOrientation orientation;
|
|
|
|
gint spacing, i;
|
|
|
|
gint min_size = 0, nat_size = 0;
|
|
|
|
|
|
|
|
area = gtk_cell_area_context_get_area (context);
|
2010-10-31 04:06:10 +00:00
|
|
|
spacing = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
|
|
|
|
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
for (i = 0; i < priv->base_heights->len; i++)
|
|
|
|
{
|
|
|
|
BaseSize *size = &g_array_index (priv->base_heights, BaseSize, i);
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Dont add spacing for 0 size groups, they can be 0 size because
|
|
|
|
* they contain only invisible cells for this round of requests
|
|
|
|
*/
|
|
|
|
if (min_size > 0 && size->nat_size > 0)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
|
|
|
min_size += spacing;
|
|
|
|
nat_size += spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_size += size->min_size;
|
|
|
|
nat_size += size->nat_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_size = MAX (min_size, size->min_size);
|
|
|
|
nat_size = MAX (nat_size, size->nat_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_context_push_preferred_height (context, min_size, nat_size);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
static GtkRequestedSize *
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_requests (GtkCellAreaBoxContext *box_context,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint *n_requests)
|
2010-11-02 07:51:06 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
GtkRequestedSize *requests;
|
|
|
|
GArray *base_array;
|
|
|
|
BaseSize *size;
|
|
|
|
gint visible_groups = 0;
|
|
|
|
gint i, j;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context), NULL);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
base_array = priv->base_widths;
|
|
|
|
else
|
|
|
|
base_array = priv->base_heights;
|
|
|
|
|
|
|
|
for (i = 0; i < base_array->len; i++)
|
|
|
|
{
|
|
|
|
size = &g_array_index (base_array, BaseSize, i);
|
|
|
|
|
|
|
|
if (size->nat_size > 0)
|
|
|
|
visible_groups++;
|
|
|
|
}
|
|
|
|
|
|
|
|
requests = g_new (GtkRequestedSize, visible_groups);
|
|
|
|
|
|
|
|
for (j = 0, i = 0; i < base_array->len; i++)
|
|
|
|
{
|
|
|
|
size = &g_array_index (base_array, BaseSize, i);
|
|
|
|
|
|
|
|
if (size->nat_size > 0)
|
|
|
|
{
|
|
|
|
requests[j].data = GINT_TO_POINTER (i);
|
|
|
|
requests[j].minimum_size = size->min_size;
|
|
|
|
requests[j].natural_size = size->nat_size;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_requests)
|
|
|
|
*n_requests = visible_groups;
|
|
|
|
|
|
|
|
return requests;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
static GtkCellAreaBoxAllocation *
|
2010-11-13 07:23:01 +00:00
|
|
|
allocate_for_orientation (GtkCellAreaBoxContext *context,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint spacing,
|
|
|
|
gint size,
|
|
|
|
gint *n_allocs)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
GtkRequestedSize *orientation_sizes;
|
|
|
|
GtkCellAreaBoxAllocation *allocs;
|
|
|
|
gint n_expand_groups = 0;
|
|
|
|
gint i, n_groups, position;
|
|
|
|
gint extra_size, extra_extra;
|
|
|
|
gint avail_size = size;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
orientation_sizes =
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_requests (context, orientation, &n_groups);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
/* Count groups that expand */
|
|
|
|
for (i = 0; i < n_groups; i++)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
BaseSize *size;
|
|
|
|
gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
size = &g_array_index (priv->base_widths, BaseSize, group_idx);
|
|
|
|
else
|
|
|
|
size = &g_array_index (priv->base_heights, BaseSize, group_idx);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
if (size->expand)
|
|
|
|
n_expand_groups++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First start by naturally allocating space among groups */
|
|
|
|
avail_size -= (n_groups - 1) * 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, i = 0; i < n_groups; i++)
|
|
|
|
{
|
|
|
|
BaseSize *base_size = &g_array_index (priv->base_widths, BaseSize, i);
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
allocs[i].group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
|
|
|
|
allocs[i].position = position;
|
|
|
|
allocs[i].size = orientation_sizes[i].minimum_size;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
if (base_size->expand)
|
|
|
|
{
|
|
|
|
allocs[i].size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
allocs[i].size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
position += allocs[i].size;
|
|
|
|
position += spacing;
|
|
|
|
}
|
|
|
|
|
2010-11-08 08:43:27 +00:00
|
|
|
if (n_allocs)
|
|
|
|
*n_allocs = n_groups;
|
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
g_free (orientation_sizes);
|
|
|
|
|
|
|
|
return allocs;
|
|
|
|
}
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_allocate_width (GtkCellAreaContext *context,
|
|
|
|
gint width)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
2010-11-25 07:09:51 +00:00
|
|
|
GtkCellArea *area;
|
|
|
|
GtkOrientation orientation;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
area = gtk_cell_area_context_get_area (context);
|
2010-10-30 14:06:26 +00:00
|
|
|
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-30 14:06:26 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
gint spacing = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
g_free (priv->orientation_allocs);
|
2010-11-13 07:23:01 +00:00
|
|
|
priv->orientation_allocs = allocate_for_orientation (box_context, orientation, spacing, width,
|
2010-11-08 08:43:27 +00:00
|
|
|
&priv->n_orientation_allocs);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate_width (context, width);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_allocate_height (GtkCellAreaContext *context,
|
|
|
|
gint height)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
GtkCellArea *area;
|
|
|
|
GtkOrientation orientation;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
area = gtk_cell_area_context_get_area (context);
|
2010-10-30 14:06:26 +00:00
|
|
|
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-30 14:06:26 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
gint spacing = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
g_free (priv->orientation_allocs);
|
2010-11-13 07:23:01 +00:00
|
|
|
priv->orientation_allocs = allocate_for_orientation (box_context, orientation, spacing, height,
|
2010-11-08 08:43:27 +00:00
|
|
|
&priv->n_orientation_allocs);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate_height (context, height);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 07:09:51 +00:00
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
/*************************************************************
|
|
|
|
* API *
|
|
|
|
*************************************************************/
|
2010-10-31 04:06:10 +00:00
|
|
|
void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_init_groups (GtkCellAreaBoxContext *box_context,
|
|
|
|
guint n_groups,
|
|
|
|
gboolean *expand_groups)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
gint i;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-11-08 08:43:27 +00:00
|
|
|
g_return_if_fail (n_groups == 0 || expand_groups != NULL);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
/* When the group dimensions change, all info must be flushed
|
|
|
|
* Note this already clears the min/nat values on the BaseSizes
|
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_context_flush (GTK_CELL_AREA_CONTEXT (box_context));
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_array_set_size (priv->base_widths, n_groups);
|
|
|
|
g_array_set_size (priv->base_heights, n_groups);
|
|
|
|
|
|
|
|
/* Now set the expand info */
|
|
|
|
for (i = 0; i < n_groups; i++)
|
|
|
|
{
|
|
|
|
BaseSize *base_width = &g_array_index (priv->base_widths, BaseSize, i);
|
|
|
|
BaseSize *base_height = &g_array_index (priv->base_heights, BaseSize, i);
|
|
|
|
|
|
|
|
base_width->expand = expand_groups[i];
|
|
|
|
base_height->expand = expand_groups[i];
|
|
|
|
}
|
|
|
|
}
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_push_group_width (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint group_idx,
|
|
|
|
gint minimum_width,
|
|
|
|
gint natural_width)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
BaseSize *size;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
size = &g_array_index (priv->base_widths, BaseSize, group_idx);
|
|
|
|
size->min_size = MAX (size->min_size, minimum_width);
|
|
|
|
size->nat_size = MAX (size->nat_size, natural_width);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_push_group_height (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint group_idx,
|
|
|
|
gint minimum_height,
|
|
|
|
gint natural_height)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
BaseSize *size;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_heights->len);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
size = &g_array_index (priv->base_heights, BaseSize, group_idx);
|
|
|
|
size->min_size = MAX (size->min_size, minimum_height);
|
|
|
|
size->nat_size = MAX (size->nat_size, natural_height);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_group_width (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint group_idx,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
BaseSize *size;
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
size = &g_array_index (priv->base_widths, BaseSize, group_idx);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (minimum_width)
|
|
|
|
*minimum_width = size->min_size;
|
|
|
|
|
|
|
|
if (natural_width)
|
|
|
|
*natural_width = size->nat_size;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_group_height (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint group_idx,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
BaseSize *size;
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_heights->len);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
size = &g_array_index (priv->base_heights, BaseSize, group_idx);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (minimum_height)
|
|
|
|
*minimum_height = size->min_size;
|
|
|
|
|
|
|
|
if (natural_height)
|
|
|
|
*natural_height = size->nat_size;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkRequestedSize *
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_widths (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint *n_widths)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
return gtk_cell_area_box_context_get_requests (box_context, GTK_ORIENTATION_HORIZONTAL, n_widths);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkRequestedSize *
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_heights (GtkCellAreaBoxContext *box_context,
|
|
|
|
gint *n_heights)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
return gtk_cell_area_box_context_get_requests (box_context, GTK_ORIENTATION_VERTICAL, n_heights);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-25 07:09:51 +00:00
|
|
|
GtkCellAreaBoxAllocation *
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
|
|
|
|
gint *n_allocs)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context), NULL);
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = context->priv;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
|
|
|
*n_allocs = priv->n_orientation_allocs;
|
|
|
|
|
|
|
|
return priv->orientation_allocs;
|
2010-11-25 07:09:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|