2010-10-26 08:14:20 +00:00
|
|
|
/* gtkcellareabox.c
|
2010-10-23 08:01:58 +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.
|
|
|
|
*/
|
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "gtkintl.h"
|
2010-10-23 08:01:58 +00:00
|
|
|
#include "gtkorientable.h"
|
2010-10-24 11:01:04 +00:00
|
|
|
#include "gtkcelllayout.h"
|
2010-10-23 08:01:58 +00:00
|
|
|
#include "gtkcellareabox.h"
|
2010-10-26 09:22:59 +00:00
|
|
|
#include "gtkcellareaboxiter.h"
|
2010-10-26 16:01:58 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
|
|
|
|
/* GObjectClass */
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_finalize (GObject *object);
|
|
|
|
static void gtk_cell_area_box_dispose (GObject *object);
|
|
|
|
static void gtk_cell_area_box_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_cell_area_box_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
|
|
|
/* GtkCellAreaClass */
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_add (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer);
|
|
|
|
static void gtk_cell_area_box_remove (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer);
|
|
|
|
static void gtk_cell_area_box_forall (GtkCellArea *area,
|
|
|
|
GtkCellCallback callback,
|
|
|
|
gpointer callback_data);
|
|
|
|
static gint gtk_cell_area_box_event (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags);
|
|
|
|
static void gtk_cell_area_box_render (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags);
|
|
|
|
static void gtk_cell_area_box_set_cell_property (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_cell_area_box_get_cell_property (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static GtkCellAreaIter *gtk_cell_area_box_create_iter (GtkCellArea *area);
|
|
|
|
static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
|
|
|
|
static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
|
|
|
static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height);
|
|
|
|
static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height);
|
|
|
|
static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
2010-11-01 08:41:02 +00:00
|
|
|
static void gtk_cell_area_box_grab_focus (GtkCellArea *area,
|
|
|
|
GtkDirectionType direction);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
/* GtkCellLayoutIface */
|
|
|
|
static void gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface);
|
|
|
|
static void gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand);
|
|
|
|
static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand);
|
2010-10-24 11:08:21 +00:00
|
|
|
static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gint position);
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
/* CellInfo/CellGroup metadata handling and convenience functions */
|
2010-10-24 11:01:04 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
guint expand : 1; /* Whether the cell expands */
|
|
|
|
guint pack : 1; /* Whether the cell is packed from the start or end */
|
|
|
|
guint align : 1; /* Whether to align this cell's position with adjacent rows */
|
2010-10-24 11:01:04 +00:00
|
|
|
} CellInfo;
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
typedef struct {
|
|
|
|
GList *cells;
|
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
guint id : 8;
|
|
|
|
guint n_cells : 8;
|
|
|
|
guint expand_cells : 8;
|
2010-10-30 08:32:15 +00:00
|
|
|
} CellGroup;
|
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
|
|
|
gint position;
|
|
|
|
gint size;
|
|
|
|
} AllocatedCell;
|
|
|
|
|
|
|
|
static CellInfo *cell_info_new (GtkCellRenderer *renderer,
|
|
|
|
GtkPackType pack,
|
|
|
|
gboolean expand,
|
|
|
|
gboolean align);
|
|
|
|
static void cell_info_free (CellInfo *info);
|
|
|
|
static gint cell_info_find (CellInfo *info,
|
|
|
|
GtkCellRenderer *renderer);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
static AllocatedCell *allocated_cell_new (GtkCellRenderer *renderer,
|
|
|
|
gint position,
|
|
|
|
gint size);
|
|
|
|
static void allocated_cell_free (AllocatedCell *cell);
|
|
|
|
static GList *list_consecutive_cells (GtkCellAreaBox *box);
|
|
|
|
static gint count_expand_groups (GtkCellAreaBox *box);
|
|
|
|
static void iter_weak_notify (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *dead_iter);
|
|
|
|
static void flush_iters (GtkCellAreaBox *box);
|
|
|
|
static void init_iter_groups (GtkCellAreaBox *box);
|
|
|
|
static void init_iter_group (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *iter);
|
|
|
|
static GSList *get_allocated_cells (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *iter,
|
|
|
|
GtkWidget *widget);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
|
|
|
|
struct _GtkCellAreaBoxPrivate
|
|
|
|
{
|
2010-10-30 12:40:22 +00:00
|
|
|
GtkOrientation orientation;
|
|
|
|
|
|
|
|
GList *cells;
|
2010-11-02 07:51:06 +00:00
|
|
|
GArray *groups;
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
GSList *iters;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
gint spacing;
|
2010-10-23 08:01:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2010-10-26 16:01:58 +00:00
|
|
|
PROP_ORIENTATION,
|
2010-10-30 08:32:15 +00:00
|
|
|
PROP_SPACING
|
2010-10-23 08:01:58 +00:00
|
|
|
};
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
enum {
|
|
|
|
CELL_PROP_0,
|
|
|
|
CELL_PROP_EXPAND,
|
|
|
|
CELL_PROP_ALIGN,
|
|
|
|
CELL_PROP_PACK_TYPE
|
|
|
|
};
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkCellAreaBox, gtk_cell_area_box, GTK_TYPE_CELL_AREA,
|
2010-10-24 11:01:04 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
|
|
|
|
gtk_cell_area_box_cell_layout_init)
|
2010-10-23 08:01:58 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
#define OPPOSITE_ORIENTATION(orientation) \
|
|
|
|
((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
|
|
|
|
GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_init (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
|
|
|
|
box->priv = G_TYPE_INSTANCE_GET_PRIVATE (box,
|
|
|
|
GTK_TYPE_CELL_AREA_BOX,
|
|
|
|
GtkCellAreaBoxPrivate);
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
|
2010-11-02 07:51:06 +00:00
|
|
|
priv->groups = g_array_new (FALSE, TRUE, sizeof (CellGroup));
|
2010-10-24 11:01:04 +00:00
|
|
|
priv->cells = NULL;
|
2010-10-30 12:40:22 +00:00
|
|
|
priv->iters = NULL;
|
2010-10-26 16:01:58 +00:00
|
|
|
priv->spacing = 0;
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_class_init (GtkCellAreaBoxClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkCellAreaClass *area_class = GTK_CELL_AREA_CLASS (class);
|
|
|
|
|
|
|
|
/* GObjectClass */
|
|
|
|
object_class->finalize = gtk_cell_area_box_finalize;
|
|
|
|
object_class->dispose = gtk_cell_area_box_dispose;
|
|
|
|
object_class->set_property = gtk_cell_area_box_set_property;
|
|
|
|
object_class->get_property = gtk_cell_area_box_get_property;
|
|
|
|
|
|
|
|
/* GtkCellAreaClass */
|
2010-10-31 08:45:29 +00:00
|
|
|
area_class->add = gtk_cell_area_box_add;
|
|
|
|
area_class->remove = gtk_cell_area_box_remove;
|
|
|
|
area_class->forall = gtk_cell_area_box_forall;
|
|
|
|
area_class->event = gtk_cell_area_box_event;
|
|
|
|
area_class->render = gtk_cell_area_box_render;
|
|
|
|
area_class->set_cell_property = gtk_cell_area_box_set_cell_property;
|
|
|
|
area_class->get_cell_property = gtk_cell_area_box_get_cell_property;
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-26 08:14:20 +00:00
|
|
|
area_class->create_iter = gtk_cell_area_box_create_iter;
|
2010-10-23 08:01:58 +00:00
|
|
|
area_class->get_request_mode = gtk_cell_area_box_get_request_mode;
|
|
|
|
area_class->get_preferred_width = gtk_cell_area_box_get_preferred_width;
|
|
|
|
area_class->get_preferred_height = gtk_cell_area_box_get_preferred_height;
|
|
|
|
area_class->get_preferred_height_for_width = gtk_cell_area_box_get_preferred_height_for_width;
|
|
|
|
area_class->get_preferred_width_for_height = gtk_cell_area_box_get_preferred_width_for_height;
|
|
|
|
|
2010-11-01 08:41:02 +00:00
|
|
|
area_class->grab_focus = gtk_cell_area_box_grab_focus;
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
/* Properties */
|
2010-10-23 08:01:58 +00:00
|
|
|
g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
|
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_SPACING,
|
|
|
|
g_param_spec_int ("spacing",
|
|
|
|
P_("Spacing"),
|
|
|
|
P_("Space which is inserted between cells"),
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
0,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
/* Cell Properties */
|
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
|
|
|
CELL_PROP_EXPAND,
|
|
|
|
g_param_spec_boolean
|
|
|
|
("expand",
|
|
|
|
P_("Expand"),
|
|
|
|
P_("Whether the cell expands"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
|
|
|
CELL_PROP_ALIGN,
|
|
|
|
g_param_spec_boolean
|
|
|
|
("align",
|
|
|
|
P_("Align"),
|
|
|
|
P_("Whether cell should align with adjacent rows"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
|
|
|
CELL_PROP_PACK_TYPE,
|
|
|
|
g_param_spec_enum
|
|
|
|
("pack-type",
|
|
|
|
P_("Pack Type"),
|
|
|
|
P_("A GtkPackType indicating whether the cell is packed with "
|
|
|
|
"reference to the start or end of the cell area"),
|
|
|
|
GTK_TYPE_PACK_TYPE, GTK_PACK_START,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
g_type_class_add_private (object_class, sizeof (GtkCellAreaBoxPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
/*************************************************************
|
2010-10-30 12:40:22 +00:00
|
|
|
* CellInfo/CellGroup basics and convenience functions *
|
2010-10-24 11:01:04 +00:00
|
|
|
*************************************************************/
|
|
|
|
static CellInfo *
|
|
|
|
cell_info_new (GtkCellRenderer *renderer,
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkPackType pack,
|
2010-10-24 11:01:04 +00:00
|
|
|
gboolean expand,
|
2010-10-30 08:32:15 +00:00
|
|
|
gboolean align)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = g_slice_new (CellInfo);
|
|
|
|
|
|
|
|
info->renderer = g_object_ref_sink (renderer);
|
|
|
|
info->pack = pack;
|
2010-10-30 08:32:15 +00:00
|
|
|
info->expand = expand;
|
|
|
|
info->align = align;
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_info_free (CellInfo *info)
|
|
|
|
{
|
|
|
|
g_object_unref (info->renderer);
|
|
|
|
|
|
|
|
g_slice_free (CellInfo, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
cell_info_find (CellInfo *info,
|
|
|
|
GtkCellRenderer *renderer)
|
|
|
|
{
|
|
|
|
return (info->renderer == renderer) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
static AllocatedCell *
|
|
|
|
allocated_cell_new (GtkCellRenderer *renderer,
|
|
|
|
gint position,
|
|
|
|
gint size)
|
|
|
|
{
|
|
|
|
AllocatedCell *cell = g_slice_new (AllocatedCell);
|
|
|
|
|
|
|
|
cell->renderer = renderer;
|
|
|
|
cell->position = position;
|
|
|
|
cell->size = size;
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
allocated_cell_free (AllocatedCell *cell)
|
|
|
|
{
|
|
|
|
g_slice_free (AllocatedCell, cell);
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
static GList *
|
|
|
|
list_consecutive_cells (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *l, *consecutive_cells = NULL, *pack_end_cells = NULL;
|
|
|
|
CellInfo *info;
|
|
|
|
|
|
|
|
/* List cells in consecutive order taking their
|
|
|
|
* PACK_START/PACK_END options into account
|
|
|
|
*/
|
|
|
|
for (l = priv->cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
info = l->data;
|
|
|
|
|
|
|
|
if (info->pack == GTK_PACK_START)
|
|
|
|
consecutive_cells = g_list_prepend (consecutive_cells, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = priv->cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
info = l->data;
|
|
|
|
|
|
|
|
if (info->pack == GTK_PACK_END)
|
|
|
|
pack_end_cells = g_list_prepend (pack_end_cells, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
consecutive_cells = g_list_reverse (consecutive_cells);
|
|
|
|
consecutive_cells = g_list_concat (consecutive_cells, pack_end_cells);
|
|
|
|
|
|
|
|
return consecutive_cells;
|
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
static void
|
|
|
|
cell_groups_clear (GtkCellAreaBox *box)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
|
|
|
{
|
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
|
|
|
|
|
|
|
g_list_free (group->cells);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_set_size (priv->groups, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_groups_rebuild (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
CellGroup group = { 0, };
|
2010-10-30 08:32:15 +00:00
|
|
|
GList *cells, *l;
|
|
|
|
guint id = 0;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_clear (box);
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
if (!priv->cells)
|
2010-11-02 07:51:06 +00:00
|
|
|
return;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
cells = list_consecutive_cells (box);
|
|
|
|
|
|
|
|
/* First group is implied */
|
|
|
|
g_array_append_val (priv->groups, group);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
for (l = cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = l->data;
|
|
|
|
|
|
|
|
/* A new group starts with any aligned cell, the first group is implied */
|
|
|
|
if (info->align && l != cells)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
memset (&group, 0x0, sizeof (CellGroup));
|
|
|
|
group.id = ++id;
|
|
|
|
|
|
|
|
g_array_append_val (priv->groups, group);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
group.cells = g_list_prepend (group.cells, info);
|
|
|
|
group.n_cells++;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
/* A group expands if it contains any expand cells */
|
|
|
|
if (info->expand)
|
2010-11-02 07:51:06 +00:00
|
|
|
group.expand_cells++;
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (cells);
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (id = 0; id < priv->groups->len; id++)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup *group_ptr = &g_array_index (priv->groups, CellGroup, id);
|
|
|
|
|
|
|
|
group_ptr->cells = g_list_reverse (group_ptr->cells);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Iters need to be updated with the new grouping information */
|
|
|
|
init_iter_groups (box);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
count_visible_cells (CellGroup *group,
|
|
|
|
gint *expand_cells)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
gint visible_cells = 0;
|
|
|
|
gint n_expand_cells = 0;
|
|
|
|
|
|
|
|
for (l = group->cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = l->data;
|
|
|
|
|
|
|
|
if (gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
{
|
|
|
|
visible_cells++;
|
|
|
|
|
|
|
|
if (info->expand)
|
|
|
|
n_expand_cells++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expand_cells)
|
|
|
|
*expand_cells = n_expand_cells;
|
|
|
|
|
|
|
|
return visible_cells;
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
count_expand_groups (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
gint i;
|
2010-10-30 08:32:15 +00:00
|
|
|
gint expand_groups = 0;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
if (group->expand_cells > 0)
|
2010-10-30 08:32:15 +00:00
|
|
|
expand_groups++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return expand_groups;
|
|
|
|
}
|
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
static void
|
2010-10-31 04:06:10 +00:00
|
|
|
iter_weak_notify (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *dead_iter)
|
2010-10-30 12:40:22 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
|
|
|
|
priv->iters = g_slist_remove (priv->iters, dead_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-31 04:06:10 +00:00
|
|
|
init_iter_group (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *iter)
|
2010-10-30 12:40:22 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
gint *expand_groups, i;
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
expand_groups = g_new (gboolean, priv->groups->len);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
2010-10-30 12:40:22 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
expand_groups[i] = (group->expand_cells > 0);
|
2010-10-30 12:40:22 +00:00
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* This call implies flushing the request info */
|
|
|
|
gtk_cell_area_box_init_groups (iter, priv->groups->len, expand_groups);
|
2010-10-31 04:06:10 +00:00
|
|
|
g_free (expand_groups);
|
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
static void
|
|
|
|
init_iter_groups (GtkCellAreaBox *box)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-10-30 14:48:52 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
GSList *l;
|
2010-10-30 14:48:52 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
/* When the box's groups are reconstructed, iters need to
|
|
|
|
* be reinitialized.
|
|
|
|
*/
|
|
|
|
for (l = priv->iters; l; l = l->next)
|
2010-10-30 14:48:52 +00:00
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
GtkCellAreaBoxIter *iter = l->data;
|
|
|
|
|
|
|
|
init_iter_group (box, iter);
|
2010-10-30 14:48:52 +00:00
|
|
|
}
|
2010-10-31 04:06:10 +00:00
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
static void
|
|
|
|
flush_iters (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GSList *l;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
/* When the box layout changes, iters need to
|
|
|
|
* be flushed and sizes for the box get requested again
|
|
|
|
*/
|
|
|
|
for (l = priv->iters; l; l = l->next)
|
2010-10-30 14:48:52 +00:00
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
GtkCellAreaIter *iter = l->data;
|
2010-10-30 14:48:52 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
gtk_cell_area_iter_flush (iter);
|
2010-10-30 14:48:52 +00:00
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
/* Returns an allocation for each cell in the orientation of the box,
|
|
|
|
* used in ->render()/->event() implementations to get a straight-forward
|
|
|
|
* list of allocated cells to operate on.
|
|
|
|
*/
|
|
|
|
static GSList *
|
|
|
|
get_allocated_cells (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *iter,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
const GtkCellAreaBoxAllocation *group_allocs;
|
2010-10-31 13:50:53 +00:00
|
|
|
GtkCellArea *area = GTK_CELL_AREA (box);
|
2010-10-31 06:22:39 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
GList *cell_list;
|
2010-10-31 06:22:39 +00:00
|
|
|
GSList *allocated_cells = NULL;
|
|
|
|
gint i, j, n_allocs;
|
|
|
|
|
|
|
|
group_allocs = gtk_cell_area_box_iter_get_orientation_allocs (iter, &n_allocs);
|
|
|
|
if (!group_allocs)
|
|
|
|
{
|
|
|
|
g_warning ("Trying to operate on an unallocated GtkCellAreaIter, "
|
|
|
|
"GtkCellAreaBox requires that the iter be allocated at least "
|
|
|
|
"in the orientation of the box");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = 0; i < n_allocs; i++)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
/* We dont always allocate all groups, sometimes the requested group has only invisible
|
|
|
|
* cells for every row, hence the usage of group_allocs[i].group_idx here
|
|
|
|
*/
|
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, group_allocs[i].group_idx);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
/* Exception for single cell groups */
|
|
|
|
if (group->n_cells == 1)
|
|
|
|
{
|
|
|
|
CellInfo *info = group->cells->data;
|
|
|
|
AllocatedCell *cell =
|
|
|
|
allocated_cell_new (info->renderer, group_allocs[i].position, group_allocs[i].size);
|
|
|
|
|
|
|
|
allocated_cells = g_slist_prepend (allocated_cells, cell);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
GtkRequestedSize *sizes;
|
|
|
|
gint avail_size, position;
|
|
|
|
gint visible_cells, expand_cells;
|
2010-10-31 06:22:39 +00:00
|
|
|
gint extra_size, extra_extra;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
visible_cells = count_visible_cells (group, &expand_cells);
|
|
|
|
|
|
|
|
/* If this row has no visible cells in this group, just
|
|
|
|
* skip the allocation */
|
|
|
|
if (visible_cells == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Offset the allocation to the group position and allocate into
|
|
|
|
* the group's available size */
|
|
|
|
position = group_allocs[i].position;
|
|
|
|
avail_size = group_allocs[i].size;
|
|
|
|
|
|
|
|
sizes = g_new (GtkRequestedSize, visible_cells);
|
|
|
|
|
|
|
|
for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = cell_list->data;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
priv->orientation,
|
|
|
|
widget, -1,
|
|
|
|
&sizes[j].minimum_size,
|
|
|
|
&sizes[j].natural_size);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
sizes[j].data = info;
|
|
|
|
avail_size -= sizes[j].minimum_size;
|
|
|
|
|
|
|
|
j++;
|
2010-10-31 06:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Distribute cells naturally within the group */
|
2010-11-02 07:51:06 +00:00
|
|
|
avail_size -= (visible_cells - 1) * priv->spacing;
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
/* Calculate/distribute expand for cells */
|
2010-11-02 07:51:06 +00:00
|
|
|
if (expand_cells > 0)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
extra_size = avail_size / expand_cells;
|
|
|
|
extra_extra = avail_size % expand_cells;
|
2010-10-31 06:22:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
extra_size = extra_extra = 0;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Create the allocated cells (loop only over visible cells here) */
|
|
|
|
for (j = 0; j < visible_cells; j++)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellInfo *info = sizes[j].data;
|
2010-10-31 06:22:39 +00:00
|
|
|
AllocatedCell *cell;
|
|
|
|
|
|
|
|
if (info->expand)
|
|
|
|
{
|
|
|
|
sizes[j].minimum_size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
sizes[j].minimum_size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cell = allocated_cell_new (info->renderer, position, sizes[j].minimum_size);
|
|
|
|
|
|
|
|
allocated_cells = g_slist_prepend (allocated_cells, cell);
|
|
|
|
|
|
|
|
position += sizes[j].minimum_size;
|
|
|
|
position += priv->spacing;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
|
|
|
j++;
|
2010-10-31 06:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (sizes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* 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 */
|
2010-10-31 06:22:39 +00:00
|
|
|
return g_slist_reverse (allocated_cells);
|
|
|
|
}
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
/*************************************************************
|
|
|
|
* GObjectClass *
|
|
|
|
*************************************************************/
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_finalize (GObject *object)
|
|
|
|
{
|
2010-10-30 12:40:22 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GSList *l;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Unref/free the iter list */
|
2010-10-30 12:40:22 +00:00
|
|
|
for (l = priv->iters; l; l = l->next)
|
|
|
|
g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)iter_weak_notify, box);
|
|
|
|
|
|
|
|
g_slist_free (priv->iters);
|
2010-11-02 07:51:06 +00:00
|
|
|
priv->iters = NULL;
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Free the cell grouping info */
|
|
|
|
cell_groups_clear (box);
|
|
|
|
g_array_free (priv->groups, TRUE);
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (gtk_cell_area_box_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
case PROP_ORIENTATION:
|
|
|
|
box->priv->orientation = g_value_get_enum (value);
|
|
|
|
|
|
|
|
/* Notify that size needs to be requested again */
|
|
|
|
flush_iters (box);
|
|
|
|
break;
|
2010-10-30 08:32:15 +00:00
|
|
|
case PROP_SPACING:
|
|
|
|
gtk_cell_area_box_set_spacing (box, g_value_get_int (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (object);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2010-10-31 04:06:10 +00:00
|
|
|
case PROP_ORIENTATION:
|
|
|
|
g_value_set_enum (value, box->priv->orientation);
|
|
|
|
break;
|
2010-10-30 08:32:15 +00:00
|
|
|
case PROP_SPACING:
|
|
|
|
g_value_set_int (value, gtk_cell_area_box_get_spacing (box));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* GtkCellAreaClass *
|
|
|
|
*************************************************************/
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_add (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer)
|
|
|
|
{
|
2010-10-24 11:01:04 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
|
2010-10-30 08:32:15 +00:00
|
|
|
renderer, FALSE, TRUE);
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_remove (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer)
|
|
|
|
{
|
2010-10-24 11:01:04 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
CellInfo *info = node->data;
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
cell_info_free (info);
|
|
|
|
|
|
|
|
priv->cells = g_list_delete_link (priv->cells, node);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
/* Reconstruct cell groups */
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("Trying to remove a cell renderer that is not present GtkCellAreaBox");
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_forall (GtkCellArea *area,
|
|
|
|
GtkCellCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
2010-10-24 11:01:04 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = priv->cells; list; list = list->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = list->data;
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
callback (info->renderer, callback_data);
|
|
|
|
}
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2010-11-01 03:39:00 +00:00
|
|
|
gtk_cell_area_box_event (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-01 03:39:00 +00:00
|
|
|
gtk_cell_area_box_render (GtkCellArea *area,
|
|
|
|
GtkCellAreaIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
GtkCellRendererState flags)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-31 06:22:39 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-10-31 13:50:53 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-10-31 06:22:39 +00:00
|
|
|
GtkCellAreaBoxIter *box_iter = GTK_CELL_AREA_BOX_ITER (iter);
|
|
|
|
GSList *allocated_cells, *l;
|
2010-10-31 13:50:53 +00:00
|
|
|
GdkRectangle background_area, inner_area;
|
|
|
|
|
|
|
|
background_area = *cell_area;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
/* Get a list of cells with allocation sizes decided regardless
|
|
|
|
* of alignments and pack order etc. */
|
|
|
|
allocated_cells = get_allocated_cells (box, box_iter, widget);
|
|
|
|
|
|
|
|
for (l = allocated_cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
AllocatedCell *cell = l->data;
|
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
background_area.x = cell_area->x + cell->position;
|
|
|
|
background_area.width = cell->size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
background_area.y = cell_area->y + cell->position;
|
|
|
|
background_area.height = cell->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove margins from the background area to produce the cell area
|
|
|
|
*/
|
|
|
|
gtk_cell_area_inner_cell_area (area, &background_area, &inner_area);
|
|
|
|
|
2010-11-01 03:39:00 +00:00
|
|
|
/* XXX We have to do some per-cell considerations for the 'flags'
|
|
|
|
* for focus handling */
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_renderer_render (cell->renderer, cr, widget,
|
|
|
|
&background_area, &inner_area,
|
2010-11-01 03:39:00 +00:00
|
|
|
flags);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
}
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
g_slist_foreach (allocated_cells, (GFunc)allocated_cell_free, NULL);
|
|
|
|
g_slist_free (allocated_cells);
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_set_cell_property (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
|
|
|
gboolean rebuild = FALSE;
|
|
|
|
gboolean flush = FALSE;
|
|
|
|
gboolean val;
|
|
|
|
GtkPackType pack_type;
|
|
|
|
|
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info = node->data;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case CELL_PROP_EXPAND:
|
|
|
|
val = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (info->expand != val)
|
|
|
|
{
|
|
|
|
info->expand = val;
|
|
|
|
flush = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CELL_PROP_ALIGN:
|
|
|
|
val = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (info->align != val)
|
|
|
|
{
|
|
|
|
info->align = val;
|
|
|
|
flush = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CELL_PROP_PACK_TYPE:
|
|
|
|
pack_type = g_value_get_enum (value);
|
|
|
|
|
|
|
|
if (info->pack != pack_type)
|
|
|
|
{
|
|
|
|
info->pack = pack_type;
|
|
|
|
rebuild = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Groups need to be rebuilt */
|
|
|
|
if (rebuild)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-31 08:45:29 +00:00
|
|
|
}
|
|
|
|
else if (flush)
|
|
|
|
{
|
|
|
|
flush_iters (box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_cell_property (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
|
|
|
|
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info = node->data;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case CELL_PROP_EXPAND:
|
|
|
|
g_value_set_boolean (value, info->expand);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CELL_PROP_ALIGN:
|
|
|
|
g_value_set_boolean (value, info->align);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CELL_PROP_PACK_TYPE:
|
|
|
|
g_value_set_enum (value, info->pack);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GTK_CELL_AREA_WARN_INVALID_CHILD_PROPERTY_ID (area, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 08:14:20 +00:00
|
|
|
static GtkCellAreaIter *
|
|
|
|
gtk_cell_area_box_create_iter (GtkCellArea *area)
|
|
|
|
{
|
2010-10-30 12:40:22 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GtkCellAreaIter *iter =
|
|
|
|
(GtkCellAreaIter *)g_object_new (GTK_TYPE_CELL_AREA_BOX_ITER, NULL);
|
|
|
|
|
|
|
|
priv->iters = g_slist_prepend (priv->iters, iter);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (iter), (GWeakNotify)iter_weak_notify, box);
|
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
/* Tell the new group about our cell layout */
|
|
|
|
init_iter_group (box, GTK_CELL_AREA_BOX_ITER (iter));
|
|
|
|
|
2010-10-30 12:40:22 +00:00
|
|
|
return iter;
|
2010-10-26 08:14:20 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
gtk_cell_area_box_get_request_mode (GtkCellArea *area)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
|
|
|
|
return (priv->orientation) == GTK_ORIENTATION_HORIZONTAL ?
|
|
|
|
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH :
|
|
|
|
GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
static void
|
|
|
|
compute_size (GtkCellAreaBox *box,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
GtkCellAreaBoxIter *iter,
|
|
|
|
GtkWidget *widget,
|
2010-10-30 08:32:15 +00:00
|
|
|
gint for_size,
|
2010-10-26 16:01:58 +00:00
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-10-31 13:50:53 +00:00
|
|
|
GtkCellArea *area = GTK_CELL_AREA (box);
|
2010-11-02 07:51:06 +00:00
|
|
|
GList *list;
|
|
|
|
gint i;
|
2010-10-26 16:01:58 +00:00
|
|
|
gint min_size = 0;
|
|
|
|
gint nat_size = 0;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
|
|
|
gint group_min_size = 0;
|
|
|
|
gint group_nat_size = 0;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (list = group->cells; list; list = list->next)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellInfo *info = list->data;
|
|
|
|
gint renderer_min_size, renderer_nat_size;
|
|
|
|
|
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
|
|
|
|
&renderer_min_size, &renderer_nat_size);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
if (orientation == priv->orientation)
|
|
|
|
{
|
|
|
|
if (min_size > 0)
|
|
|
|
{
|
|
|
|
min_size += priv->spacing;
|
|
|
|
nat_size += priv->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group_min_size > 0)
|
|
|
|
{
|
|
|
|
group_min_size += priv->spacing;
|
|
|
|
group_nat_size += priv->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_size += renderer_min_size;
|
|
|
|
nat_size += renderer_nat_size;
|
|
|
|
group_min_size += renderer_min_size;
|
|
|
|
group_nat_size += renderer_nat_size;
|
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
else
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
|
|
|
min_size = MAX (min_size, renderer_min_size);
|
|
|
|
nat_size = MAX (nat_size, renderer_nat_size);
|
|
|
|
group_min_size = MAX (group_min_size, renderer_min_size);
|
|
|
|
group_nat_size = MAX (group_nat_size, renderer_nat_size);
|
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
if (for_size < 0)
|
|
|
|
gtk_cell_area_box_iter_push_group_width (iter, group->id, group_min_size, group_nat_size);
|
|
|
|
else
|
|
|
|
gtk_cell_area_box_iter_push_group_width_for_height (iter, group->id, for_size,
|
|
|
|
group_min_size, group_nat_size);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
if (for_size < 0)
|
|
|
|
gtk_cell_area_box_iter_push_group_height (iter, group->id, group_min_size, group_nat_size);
|
|
|
|
else
|
|
|
|
gtk_cell_area_box_iter_push_group_height_for_width (iter, group->id, for_size,
|
|
|
|
group_min_size, group_nat_size);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*minimum_size = min_size;
|
|
|
|
*natural_size = nat_size;
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkRequestedSize *
|
2010-10-31 13:50:53 +00:00
|
|
|
get_group_sizes (GtkCellArea *area,
|
|
|
|
CellGroup *group,
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkOrientation orientation,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *n_sizes)
|
|
|
|
{
|
|
|
|
GtkRequestedSize *sizes;
|
|
|
|
GList *l;
|
|
|
|
gint i;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
*n_sizes = count_visible_cells (group, NULL);
|
2010-10-30 08:32:15 +00:00
|
|
|
sizes = g_new (GtkRequestedSize, *n_sizes);
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (l = group->cells, i = 0; l; l = l->next)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = l->data;
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
sizes[i].data = info;
|
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
orientation, widget, -1,
|
|
|
|
&sizes[i].minimum_size,
|
|
|
|
&sizes[i].natural_size);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
|
|
|
i++;
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sizes;
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
static void
|
2010-10-30 08:32:15 +00:00
|
|
|
compute_group_size_for_opposing_orientation (GtkCellAreaBox *box,
|
|
|
|
CellGroup *group,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-10-31 13:50:53 +00:00
|
|
|
GtkCellArea *area = GTK_CELL_AREA (box);
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Exception for single cell groups */
|
2010-10-31 06:22:39 +00:00
|
|
|
if (group->n_cells == 1)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
CellInfo *info = group->cells->data;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
OPPOSITE_ORIENTATION (priv->orientation),
|
|
|
|
widget, for_size, minimum_size, natural_size);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkRequestedSize *orientation_sizes;
|
|
|
|
CellInfo *info;
|
|
|
|
gint n_sizes, i;
|
|
|
|
gint avail_size = for_size;
|
|
|
|
gint extra_size, extra_extra;
|
|
|
|
gint min_size = 0, nat_size = 0;
|
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
orientation_sizes = get_group_sizes (area, group, priv->orientation, widget, &n_sizes);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
/* First naturally allocate the cells in the group into the for_size */
|
|
|
|
avail_size -= (n_sizes - 1) * priv->spacing;
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
|
|
|
avail_size -= orientation_sizes[i].minimum_size;
|
|
|
|
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
|
|
|
|
|
|
|
|
/* Calculate/distribute expand for cells */
|
2010-10-31 06:22:39 +00:00
|
|
|
if (group->expand_cells > 0)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-31 06:22:39 +00:00
|
|
|
extra_size = avail_size / group->expand_cells;
|
|
|
|
extra_extra = avail_size % group->expand_cells;
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
2010-10-30 08:32:15 +00:00
|
|
|
extra_size = extra_extra = 0;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
for (i = 0; i < n_sizes; i++)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
gint cell_min, cell_nat;
|
|
|
|
|
|
|
|
info = orientation_sizes[i].data;
|
|
|
|
|
|
|
|
if (info->expand)
|
|
|
|
{
|
|
|
|
orientation_sizes[i].minimum_size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
orientation_sizes[i].minimum_size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
OPPOSITE_ORIENTATION (priv->orientation),
|
|
|
|
widget,
|
|
|
|
orientation_sizes[i].minimum_size,
|
|
|
|
&cell_min, &cell_nat);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
min_size = MAX (min_size, cell_min);
|
|
|
|
nat_size = MAX (nat_size, cell_nat);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
*minimum_size = min_size;
|
|
|
|
*natural_size = nat_size;
|
|
|
|
|
|
|
|
g_free (orientation_sizes);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
compute_size_for_opposing_orientation (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxIter *iter,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
CellGroup *group;
|
|
|
|
GtkRequestedSize *orientation_sizes;
|
|
|
|
gint n_groups, n_expand_groups, i;
|
|
|
|
gint avail_size = for_size;
|
|
|
|
gint extra_size, extra_extra;
|
|
|
|
gint min_size = 0, nat_size = 0;
|
|
|
|
|
|
|
|
n_expand_groups = count_expand_groups (box);
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-10-30 08:32:15 +00:00
|
|
|
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)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
extra_size = avail_size / n_expand_groups;
|
|
|
|
extra_extra = avail_size % n_expand_groups;
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
2010-10-30 08:32:15 +00:00
|
|
|
extra_size = extra_extra = 0;
|
|
|
|
|
|
|
|
/* Now we need to naturally allocate sizes for cells in each group
|
|
|
|
* and push the height-for-width for each group accordingly while accumulating
|
|
|
|
* the overall height-for-width for this row.
|
|
|
|
*/
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = 0; i < n_groups; i++)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
gint group_min, group_nat;
|
2010-11-02 07:51:06 +00:00
|
|
|
gint group_idx = GPOINTER_TO_INT (orientation_sizes[i].data);
|
|
|
|
|
|
|
|
group = &g_array_index (priv->groups, CellGroup, group_idx);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
if (group->expand_cells > 0)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
orientation_sizes[i].minimum_size += extra_size;
|
2010-10-30 08:32:15 +00:00
|
|
|
if (extra_extra)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
orientation_sizes[i].minimum_size++;
|
2010-10-30 08:32:15 +00:00
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we have the allocation for the group, request it's height-for-width */
|
|
|
|
compute_group_size_for_opposing_orientation (box, group, widget,
|
2010-11-02 07:51:06 +00:00
|
|
|
orientation_sizes[i].minimum_size,
|
2010-10-30 08:32:15 +00:00
|
|
|
&group_min, &group_nat);
|
|
|
|
|
|
|
|
min_size = MAX (min_size, group_min);
|
|
|
|
nat_size = MAX (nat_size, group_nat);
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
gtk_cell_area_box_iter_push_group_height_for_width (iter, group_idx, for_size,
|
2010-10-30 08:32:15 +00:00
|
|
|
group_min, group_nat);
|
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
else
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
gtk_cell_area_box_iter_push_group_width_for_height (iter, group_idx, for_size,
|
2010-10-30 08:32:15 +00:00
|
|
|
group_min, group_nat);
|
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
*minimum_size = min_size;
|
|
|
|
*natural_size = nat_size;
|
|
|
|
|
|
|
|
g_free (orientation_sizes);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
|
2010-10-26 08:14:20 +00:00
|
|
|
GtkCellAreaIter *iter,
|
2010-10-23 08:01:58 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxIter *box_iter;
|
|
|
|
gint min_width, nat_width;
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
box_iter = GTK_CELL_AREA_BOX_ITER (iter);
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Compute the size of all renderers for current row data,
|
2010-10-26 16:01:58 +00:00
|
|
|
* bumping cell alignments in the iter along the way */
|
|
|
|
compute_size (box, GTK_ORIENTATION_HORIZONTAL,
|
2010-10-30 08:32:15 +00:00
|
|
|
box_iter, widget, -1, &min_width, &nat_width);
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
if (minimum_width)
|
|
|
|
*minimum_width = min_width;
|
|
|
|
|
|
|
|
if (natural_width)
|
|
|
|
*natural_width = nat_width;
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
|
2010-10-26 08:14:20 +00:00
|
|
|
GtkCellAreaIter *iter,
|
2010-10-23 08:01:58 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxIter *box_iter;
|
|
|
|
gint min_height, nat_height;
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
box_iter = GTK_CELL_AREA_BOX_ITER (iter);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Compute the size of all renderers for current row data,
|
2010-10-26 16:01:58 +00:00
|
|
|
* bumping cell alignments in the iter along the way */
|
|
|
|
compute_size (box, GTK_ORIENTATION_VERTICAL,
|
2010-10-30 08:32:15 +00:00
|
|
|
box_iter, widget, -1, &min_height, &nat_height);
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
if (minimum_height)
|
|
|
|
*minimum_height = min_height;
|
|
|
|
|
|
|
|
if (natural_height)
|
|
|
|
*natural_height = nat_height;
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
|
2010-10-26 08:14:20 +00:00
|
|
|
GtkCellAreaIter *iter,
|
2010-10-23 08:01:58 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxIter *box_iter;
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
gint min_height, nat_height;
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
box_iter = GTK_CELL_AREA_BOX_ITER (iter);
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Add up vertical requests of height for width and push the overall
|
2010-10-26 16:01:58 +00:00
|
|
|
* cached sizes for alignments */
|
2010-10-30 08:32:15 +00:00
|
|
|
compute_size (box, priv->orientation, box_iter, widget, width, &min_height, &nat_height);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Juice: virtually allocate cells into the for_width using the
|
2010-10-26 16:01:58 +00:00
|
|
|
* alignments and then return the overall height for that width, and cache it */
|
2010-10-30 08:32:15 +00:00
|
|
|
compute_size_for_opposing_orientation (box, box_iter, widget, width, &min_height, &nat_height);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minimum_height)
|
|
|
|
*minimum_height = min_height;
|
|
|
|
|
|
|
|
if (natural_height)
|
|
|
|
*natural_height = nat_height;
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
|
2010-10-26 08:14:20 +00:00
|
|
|
GtkCellAreaIter *iter,
|
2010-10-23 08:01:58 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxIter *box_iter;
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
gint min_width, nat_width;
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_ITER (iter));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-10-26 16:01:58 +00:00
|
|
|
box_iter = GTK_CELL_AREA_BOX_ITER (iter);
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Add up horizontal requests of width for height and push the overall
|
2010-10-26 16:01:58 +00:00
|
|
|
* cached sizes for alignments */
|
2010-10-30 08:32:15 +00:00
|
|
|
compute_size (box, priv->orientation, box_iter, widget, height, &min_width, &nat_width);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
/* Juice: horizontally allocate cells into the for_height using the
|
|
|
|
* alignments and then return the overall width for that height, and cache it */
|
|
|
|
compute_size_for_opposing_orientation (box, box_iter, widget, height, &min_width, &nat_width);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minimum_width)
|
|
|
|
*minimum_width = min_width;
|
|
|
|
|
|
|
|
if (natural_width)
|
|
|
|
*natural_width = nat_width;
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 08:41:02 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_grab_focus (GtkCellArea *area,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
gboolean first_cell = FALSE;
|
2010-11-02 07:51:06 +00:00
|
|
|
gint i;
|
|
|
|
GList *list;
|
2010-11-01 08:41:02 +00:00
|
|
|
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GTK_DIR_TAB_FORWARD:
|
|
|
|
case GTK_DIR_DOWN:
|
|
|
|
case GTK_DIR_RIGHT:
|
|
|
|
first_cell = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
|
|
|
case GTK_DIR_UP:
|
|
|
|
case GTK_DIR_LEFT:
|
|
|
|
default:
|
|
|
|
first_cell = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (i = first_cell ? 0 : priv->groups->len -1;
|
|
|
|
i >= 0 && i < priv->groups->len;
|
|
|
|
i = first_cell ? i + 1 : i - 1)
|
2010-11-01 08:41:02 +00:00
|
|
|
{
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
2010-11-01 08:41:02 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
for (list = first_cell ? g_list_first (group->cells) : g_list_last (group->cells);
|
|
|
|
list; list = first_cell ? list->next : list->prev)
|
2010-11-01 08:41:02 +00:00
|
|
|
{
|
|
|
|
GtkCellRendererMode mode;
|
2010-11-02 07:51:06 +00:00
|
|
|
CellInfo *info = list->data;
|
2010-11-01 08:41:02 +00:00
|
|
|
|
|
|
|
/* XXX This does not handle cases where the cell
|
|
|
|
* is not visible as it is not row specific,
|
|
|
|
* that's a problem.
|
|
|
|
*/
|
|
|
|
g_object_get (info->renderer, "mode", &mode, NULL);
|
|
|
|
if (mode == GTK_CELL_RENDERER_MODE_EDITABLE ||
|
|
|
|
mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
|
|
|
|
{
|
|
|
|
gtk_cell_area_set_focus_cell (area, info->renderer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* GtkCellLayoutIface *
|
|
|
|
*************************************************************/
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_cell_layout_init (GtkCellLayoutIface *iface)
|
|
|
|
{
|
|
|
|
iface->pack_start = gtk_cell_area_box_layout_pack_start;
|
|
|
|
iface->pack_end = gtk_cell_area_box_layout_pack_end;
|
2010-10-24 11:08:21 +00:00
|
|
|
iface->reorder = gtk_cell_area_box_layout_reorder;
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_layout_pack_start (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand)
|
|
|
|
{
|
2010-10-30 08:32:15 +00:00
|
|
|
gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, TRUE);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
|
2010-10-24 11:08:21 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gint position)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
|
|
|
|
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
info = node->data;
|
|
|
|
|
|
|
|
priv->cells = g_list_delete_link (priv->cells, node);
|
|
|
|
priv->cells = g_list_insert (priv->cells, info, position);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-24 11:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
/*************************************************************
|
|
|
|
* API *
|
|
|
|
*************************************************************/
|
2010-10-24 11:01:04 +00:00
|
|
|
GtkCellArea *
|
|
|
|
gtk_cell_area_box_new (void)
|
|
|
|
{
|
|
|
|
return (GtkCellArea *)g_object_new (GTK_TYPE_CELL_AREA_BOX, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
|
|
|
|
GtkCellRenderer *renderer,
|
2010-10-30 08:32:15 +00:00
|
|
|
gboolean expand,
|
|
|
|
gboolean align)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
CellInfo *info;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
|
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
|
|
|
|
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
if (g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find))
|
|
|
|
{
|
|
|
|
g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
info = cell_info_new (renderer, GTK_PACK_START, expand, align);
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
priv->cells = g_list_append (priv->cells, info);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
|
|
|
|
GtkCellRenderer *renderer,
|
2010-10-30 08:32:15 +00:00
|
|
|
gboolean expand,
|
|
|
|
gboolean align)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
CellInfo *info;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
|
|
|
|
g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
|
|
|
|
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
if (g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find))
|
|
|
|
{
|
|
|
|
g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
info = cell_info_new (renderer, GTK_PACK_END, expand, align);
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
priv->cells = g_list_append (priv->cells, info);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
gint
|
|
|
|
gtk_cell_area_box_get_spacing (GtkCellAreaBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_CELL_AREA_BOX (box), 0);
|
|
|
|
|
|
|
|
return box->priv->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
|
|
|
|
gint spacing)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX (box));
|
|
|
|
|
|
|
|
priv = box->priv;
|
|
|
|
|
|
|
|
if (priv->spacing != spacing)
|
|
|
|
{
|
|
|
|
priv->spacing = spacing;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (box), "spacing");
|
2010-10-30 12:40:22 +00:00
|
|
|
|
|
|
|
/* Notify that size needs to be requested again */
|
|
|
|
flush_iters (box);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
}
|