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-12-03 08:13:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkcellareabox
|
2010-12-18 00:14:35 +00:00
|
|
|
* @Short_Description: A cell area that renders GtkCellRenderers
|
|
|
|
* into a row or a column
|
2010-12-03 08:13:31 +00:00
|
|
|
* @Title: GtkCellAreaBox
|
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* The #GtkCellAreaBox renders cell renderers into a row or a column
|
|
|
|
* depending on its #GtkOrientation.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* GtkCellAreaBox uses a notion of <emphasis>packing</emphasis>. Packing
|
2010-12-18 00:14:35 +00:00
|
|
|
* refers to adding cell renderers with reference to a particular position
|
2010-12-03 08:13:31 +00:00
|
|
|
* in a #GtkCellAreaBox. There are two reference positions: the
|
|
|
|
* <emphasis>start</emphasis> and the <emphasis>end</emphasis> of the box.
|
2010-12-18 00:14:35 +00:00
|
|
|
* When the #GtkCellAreaBox is oriented in the %GTK_ORIENTATION_VERTICAL
|
|
|
|
* orientation, the start is defined as the top of the box and the end is
|
|
|
|
* defined as the bottom. In the %GTK_ORIENTATION_HORIZONTAL orientation
|
|
|
|
* start is defined as the left side and the end is defined as the right
|
|
|
|
* side.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* Alignments of #GtkCellRenderers rendered in adjacent rows can be
|
|
|
|
* configured by configuring the #GtkCellAreaBox:align child cell property
|
|
|
|
* with gtk_cell_area_cell_set_property() or by specifying the "align"
|
|
|
|
* argument to gtk_cell_area_box_pack_start() and gtk_cell_area_box_pack_end().
|
2010-12-03 08:13:31 +00:00
|
|
|
*/
|
|
|
|
|
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"
|
2011-01-11 15:04:00 +00:00
|
|
|
#include "gtkcellareaboxcontextprivate.h"
|
2011-01-04 17:05:05 +00:00
|
|
|
#include "gtktypebuiltins.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,
|
2010-12-18 00:14:35 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_get_property (GObject *object,
|
2010-12-18 00:14:35 +00:00
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_remove (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer);
|
2010-12-06 03:41:38 +00:00
|
|
|
static void gtk_cell_area_box_foreach (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellCallback callback,
|
|
|
|
gpointer callback_data);
|
2010-12-06 05:11:28 +00:00
|
|
|
static void gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
const GdkRectangle *background_area,
|
|
|
|
GtkCellAllocCallback callback,
|
|
|
|
gpointer callback_data);
|
2010-12-21 12:11:01 +00:00
|
|
|
static void gtk_cell_area_box_apply_attributes (GtkCellArea *area,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gboolean is_expander,
|
|
|
|
gboolean is_expanded);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_set_cell_property (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_get_cell_property (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2010-11-13 07:23:01 +00:00
|
|
|
static GtkCellAreaContext *gtk_cell_area_box_create_context (GtkCellArea *area);
|
2010-12-12 15:18:00 +00:00
|
|
|
static GtkCellAreaContext *gtk_cell_area_box_copy_context (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context);
|
2010-11-01 03:39:00 +00:00
|
|
|
static GtkSizeRequestMode gtk_cell_area_box_get_request_mode (GtkCellArea *area);
|
|
|
|
static void gtk_cell_area_box_get_preferred_width (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_get_preferred_height (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_get_preferred_height_for_width (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height);
|
2010-11-01 03:39:00 +00:00
|
|
|
static void gtk_cell_area_box_get_preferred_width_for_height (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
2010-11-10 10:17:06 +00:00
|
|
|
static gboolean gtk_cell_area_box_focus (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand);
|
2010-10-24 11:01:04 +00:00
|
|
|
static void gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand);
|
2010-10-24 11:08:21 +00:00
|
|
|
static void gtk_cell_area_box_layout_reorder (GtkCellLayout *cell_layout,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gint position);
|
2010-12-09 09:20:39 +00:00
|
|
|
static void gtk_cell_area_box_focus_changed (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkCellAreaBox *box);
|
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 */
|
2010-12-18 00:14:35 +00:00
|
|
|
guint pack : 1; /* Whether it is packed from the start or end */
|
|
|
|
guint align : 1; /* Whether to align its position with adjacent rows */
|
2010-12-21 12:11:01 +00:00
|
|
|
guint fixed : 1; /* Whether to require the same size for all 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-12-21 12:11:01 +00:00
|
|
|
guint align : 1;
|
|
|
|
guint visible : 1;
|
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;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
static CellInfo *cell_info_new (GtkCellRenderer *renderer,
|
|
|
|
GtkPackType pack,
|
|
|
|
gboolean expand,
|
2010-12-21 12:11:01 +00:00
|
|
|
gboolean align,
|
|
|
|
gboolean fixed);
|
2010-11-13 07:23:01 +00:00
|
|
|
static void cell_info_free (CellInfo *info);
|
|
|
|
static gint cell_info_find (CellInfo *info,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer);
|
2010-11-13 07:23:01 +00:00
|
|
|
|
|
|
|
static AllocatedCell *allocated_cell_new (GtkCellRenderer *renderer,
|
2010-12-18 00:14:35 +00:00
|
|
|
gint position,
|
|
|
|
gint size);
|
2010-11-13 07:23:01 +00:00
|
|
|
static void allocated_cell_free (AllocatedCell *cell);
|
|
|
|
static GList *list_consecutive_cells (GtkCellAreaBox *box);
|
|
|
|
static gint count_expand_groups (GtkCellAreaBox *box);
|
|
|
|
static void context_weak_notify (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *dead_context);
|
2010-11-27 07:05:14 +00:00
|
|
|
static void reset_contexts (GtkCellAreaBox *box);
|
2010-11-13 07:23:01 +00:00
|
|
|
static void init_context_groups (GtkCellAreaBox *box);
|
|
|
|
static void init_context_group (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *context);
|
2010-11-13 07:23:01 +00:00
|
|
|
static GSList *get_allocated_cells (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
|
|
|
|
struct _GtkCellAreaBoxPrivate
|
|
|
|
{
|
2010-12-09 09:20:39 +00:00
|
|
|
/* We hold on to the previously focused cell when navigating
|
|
|
|
* up and down in a horizontal box (or left and right on a vertical one)
|
2010-12-18 00:14:35 +00:00
|
|
|
* this way we always re-enter the last focused cell.
|
|
|
|
*/
|
2010-12-09 09:20:39 +00:00
|
|
|
GtkCellRenderer *last_focus_cell;
|
|
|
|
gulong focus_cell_id;
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-12-09 09:20:39 +00:00
|
|
|
GList *cells;
|
|
|
|
GArray *groups;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-12-09 09:20:39 +00:00
|
|
|
GSList *contexts;
|
|
|
|
|
2011-04-12 16:25:53 +00:00
|
|
|
GtkOrientation orientation;
|
2010-12-09 09:20:39 +00:00
|
|
|
gint spacing;
|
2010-12-05 06:20:46 +00:00
|
|
|
|
|
|
|
/* We hold on to the rtl state from a widget we are requested for
|
2010-12-18 00:14:35 +00:00
|
|
|
* so that we can navigate focus correctly
|
|
|
|
*/
|
2010-12-09 09:20:39 +00:00
|
|
|
gboolean rtl;
|
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,
|
2010-12-21 12:11:01 +00:00
|
|
|
CELL_PROP_FIXED_SIZE,
|
2010-10-31 08:45:29 +00:00
|
|
|
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-12-18 00:14:35 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
|
|
|
|
gtk_cell_area_box_cell_layout_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
#define OPPOSITE_ORIENTATION(orientation) \
|
|
|
|
((orientation) == GTK_ORIENTATION_HORIZONTAL ? \
|
2010-10-30 08:32:15 +00:00
|
|
|
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-11-13 07:23:01 +00:00
|
|
|
priv->contexts = NULL;
|
2010-10-26 16:01:58 +00:00
|
|
|
priv->spacing = 0;
|
2010-12-05 06:20:46 +00:00
|
|
|
priv->rtl = FALSE;
|
2010-12-09 09:20:39 +00:00
|
|
|
|
|
|
|
/* Watch whenever focus is given to a cell, even if it's not with keynav,
|
2010-12-18 00:14:35 +00:00
|
|
|
* this way we remember upon entry of the area where focus was last time
|
|
|
|
* around
|
|
|
|
*/
|
|
|
|
priv->focus_cell_id = g_signal_connect (box, "notify::focus-cell",
|
|
|
|
G_CALLBACK (gtk_cell_area_box_focus_changed), box);
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
static void
|
2010-10-23 08:01:58 +00:00
|
|
|
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-11-05 13:16:32 +00:00
|
|
|
area_class->add = gtk_cell_area_box_add;
|
|
|
|
area_class->remove = gtk_cell_area_box_remove;
|
2010-12-06 03:41:38 +00:00
|
|
|
area_class->foreach = gtk_cell_area_box_foreach;
|
2010-12-06 05:11:28 +00:00
|
|
|
area_class->foreach_alloc = gtk_cell_area_box_foreach_alloc;
|
2010-12-21 12:11:01 +00:00
|
|
|
area_class->apply_attributes = gtk_cell_area_box_apply_attributes;
|
2010-11-05 13:16:32 +00:00
|
|
|
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-12-18 00:14:35 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
area_class->create_context = gtk_cell_area_box_create_context;
|
2010-12-12 15:18:00 +00:00
|
|
|
area_class->copy_context = gtk_cell_area_box_copy_context;
|
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-10 10:17:06 +00:00
|
|
|
area_class->focus = gtk_cell_area_box_focus;
|
2010-11-01 08:41:02 +00:00
|
|
|
|
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-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* GtkCellAreaBox:spacing:
|
|
|
|
*
|
|
|
|
* The amount of space to reserve between cells.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-26 16:01:58 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_SPACING,
|
|
|
|
g_param_spec_int ("spacing",
|
2010-12-18 00:14:35 +00:00
|
|
|
P_("Spacing"),
|
|
|
|
P_("Space which is inserted between cells"),
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
0,
|
|
|
|
GTK_PARAM_READWRITE));
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
/* Cell Properties */
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* GtkCellAreaBox:expand:
|
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* Whether the cell renderer should receive extra space
|
|
|
|
* when the area receives more than its natural size.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-31 08:45:29 +00:00
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
2010-12-18 00:14:35 +00:00
|
|
|
CELL_PROP_EXPAND,
|
|
|
|
g_param_spec_boolean
|
|
|
|
("expand",
|
|
|
|
P_("Expand"),
|
|
|
|
P_("Whether the cell expands"),
|
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* GtkCellAreaBox:align:
|
|
|
|
*
|
|
|
|
* Whether the cell renderer should be aligned in adjacent rows.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-31 08:45:29 +00:00
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
2010-12-18 00:14:35 +00:00
|
|
|
CELL_PROP_ALIGN,
|
|
|
|
g_param_spec_boolean
|
|
|
|
("align",
|
|
|
|
P_("Align"),
|
|
|
|
P_("Whether cell should align with adjacent rows"),
|
2010-12-21 12:11:01 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkCellAreaBox:fixed-size:
|
|
|
|
*
|
|
|
|
* Whether the cell renderer should require the same size
|
|
|
|
* for all rows for which it was requested.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
|
|
|
CELL_PROP_FIXED_SIZE,
|
|
|
|
g_param_spec_boolean
|
|
|
|
("fixed-size",
|
|
|
|
P_("Fixed Size"),
|
|
|
|
P_("Whether cells should be the same size in all rows"),
|
2010-12-18 00:14:35 +00:00
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE));
|
2010-10-31 08:45:29 +00:00
|
|
|
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* GtkCellAreaBox:pack-type:
|
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* A GtkPackType indicating whether the cell renderer is packed
|
|
|
|
* with reference to the start or end of the area.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-31 08:45:29 +00:00
|
|
|
gtk_cell_area_class_install_cell_property (area_class,
|
2010-12-18 00:14:35 +00:00
|
|
|
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-31 08:45:29 +00:00
|
|
|
|
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 *
|
2010-12-18 00:14:35 +00:00
|
|
|
cell_info_new (GtkCellRenderer *renderer,
|
|
|
|
GtkPackType pack,
|
|
|
|
gboolean expand,
|
2010-12-21 12:11:01 +00:00
|
|
|
gboolean align,
|
|
|
|
gboolean fixed)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = g_slice_new (CellInfo);
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-24 11:01:04 +00:00
|
|
|
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-12-21 12:11:01 +00:00
|
|
|
info->fixed = fixed;
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
return (info->renderer == renderer) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2010-10-31 06:22:39 +00:00
|
|
|
static AllocatedCell *
|
|
|
|
allocated_cell_new (GtkCellRenderer *renderer,
|
2010-12-18 00:14:35 +00:00
|
|
|
gint position,
|
|
|
|
gint size)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* List cells in consecutive order taking their
|
|
|
|
* PACK_START/PACK_END options into account
|
2010-10-30 08:32:15 +00:00
|
|
|
*/
|
|
|
|
for (l = priv->cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
info = l->data;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
if (info->pack == GTK_PACK_START)
|
2010-12-18 00:14:35 +00:00
|
|
|
consecutive_cells = g_list_prepend (consecutive_cells, info);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (l = priv->cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
info = l->data;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
if (info->pack == GTK_PACK_END)
|
2010-12-18 00:14:35 +00:00
|
|
|
pack_end_cells = g_list_prepend (pack_end_cells, info);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2010-12-18 00:14:35 +00:00
|
|
|
cell_groups_clear (GtkCellAreaBox *box)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-02 07:51:06 +00:00
|
|
|
CellGroup group = { 0, };
|
2010-11-08 08:43:27 +00:00
|
|
|
CellGroup *group_ptr;
|
2010-10-30 08:32:15 +00:00
|
|
|
GList *cells, *l;
|
|
|
|
guint id = 0;
|
2010-12-21 12:11:01 +00:00
|
|
|
gboolean last_cell_fixed = FALSE;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
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-11-08 08:43:27 +00:00
|
|
|
group_ptr = &g_array_index (priv->groups, CellGroup, id);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
for (l = cells; l; l = l->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = l->data;
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
/* A new group starts with any aligned cell, or
|
|
|
|
* at the beginning and end of a fixed size cell.
|
|
|
|
* the first group is implied */
|
|
|
|
if ((info->align || info->fixed || last_cell_fixed) && l != cells)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
memset (&group, 0x0, sizeof (CellGroup));
|
|
|
|
group.id = ++id;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
g_array_append_val (priv->groups, group);
|
|
|
|
group_ptr = &g_array_index (priv->groups, CellGroup, id);
|
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-08 08:43:27 +00:00
|
|
|
group_ptr->cells = g_list_prepend (group_ptr->cells, info);
|
|
|
|
group_ptr->n_cells++;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
/* Not every group is aligned, some are floating
|
|
|
|
* fixed size cells */
|
|
|
|
if (info->align)
|
|
|
|
group_ptr->align = TRUE;
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
/* A group expands if it contains any expand cells */
|
|
|
|
if (info->expand)
|
2010-12-18 00:14:35 +00:00
|
|
|
group_ptr->expand_cells++;
|
2010-12-21 12:11:01 +00:00
|
|
|
|
|
|
|
last_cell_fixed = info->fixed;
|
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-08 08:43:27 +00:00
|
|
|
group_ptr = &g_array_index (priv->groups, CellGroup, id);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
|
|
|
group_ptr->cells = g_list_reverse (group_ptr->cells);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
/* Contexts need to be updated with the new grouping information */
|
|
|
|
init_context_groups (box);
|
2010-11-02 07:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2010-12-18 00:14:35 +00:00
|
|
|
count_visible_cells (CellGroup *group,
|
|
|
|
gint *expand_cells)
|
2010-11-02 07:51:06 +00:00
|
|
|
{
|
|
|
|
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))
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
visible_cells++;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (info->expand)
|
|
|
|
n_expand_cells++;
|
|
|
|
}
|
2010-11-02 07:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-18 00:14:35 +00:00
|
|
|
expand_groups++;
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return expand_groups;
|
|
|
|
}
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
context_weak_notify (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *dead_context)
|
2010-10-30 12:40:22 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv->contexts = g_slist_remove (priv->contexts, dead_context);
|
2010-10-30 12:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
init_context_group (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *context)
|
2010-10-30 12:40:22 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-12-21 12:11:01 +00:00
|
|
|
gint *expand_groups, *align_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-12-21 12:11:01 +00:00
|
|
|
align_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-12-21 12:11:01 +00:00
|
|
|
align_groups[i] = group->align;
|
2010-10-30 12:40:22 +00:00
|
|
|
}
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2011-02-09 04:18:22 +00:00
|
|
|
/* This call implies resetting the request info */
|
|
|
|
_gtk_cell_area_box_init_groups (context, priv->groups->len, expand_groups, align_groups);
|
2010-10-31 04:06:10 +00:00
|
|
|
g_free (expand_groups);
|
2010-12-21 12:11:01 +00:00
|
|
|
g_free (align_groups);
|
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
|
2010-11-13 07:23:01 +00:00
|
|
|
init_context_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-12-18 00:14:35 +00:00
|
|
|
/* When the box's groups are reconstructed,
|
|
|
|
* contexts need to be reinitialized.
|
2010-10-31 04:06:10 +00:00
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
for (l = priv->contexts; l; l = l->next)
|
2010-10-30 14:48:52 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *context = l->data;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
init_context_group (box, context);
|
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
|
2010-11-27 07:05:14 +00:00
|
|
|
reset_contexts (GtkCellAreaBox *box)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GSList *l;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
/* When the box layout changes, contexts need to
|
2010-11-27 07:05:14 +00:00
|
|
|
* be reset and sizes for the box get requested again
|
2010-10-31 04:06:10 +00:00
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
for (l = priv->contexts; l; l = l->next)
|
2010-10-30 14:48:52 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaContext *context = l->data;
|
2010-10-30 14:48:52 +00:00
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
gtk_cell_area_context_reset (context);
|
2010-10-30 14:48:52 +00:00
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
/* Fall back on a completely unaligned dynamic allocation of cells
|
|
|
|
* when not allocated for the said orientation, alignment of cells
|
|
|
|
* is not done when each area gets a different size in the orientation
|
|
|
|
* of the box.
|
|
|
|
*/
|
|
|
|
static GSList *
|
|
|
|
allocate_cells_manually (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2010-11-26 12:26:24 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *cells, *l;
|
|
|
|
GSList *allocated_cells = NULL;
|
|
|
|
GtkRequestedSize *sizes;
|
|
|
|
gint i;
|
|
|
|
gint nvisible = 0, nexpand = 0, group_expand;
|
2010-12-05 06:20:46 +00:00
|
|
|
gint avail_size, extra_size, extra_extra, full_size;
|
2010-11-26 14:41:39 +00:00
|
|
|
gint position = 0, for_size;
|
2010-12-05 06:20:46 +00:00
|
|
|
gboolean rtl;
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
if (!priv->cells)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* For vertical oriented boxes, we just let the cell renderers
|
|
|
|
* realign themselves for rtl
|
|
|
|
*/
|
2010-12-05 06:20:46 +00:00
|
|
|
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
2010-12-05 06:20:46 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
cells = list_consecutive_cells (box);
|
|
|
|
|
|
|
|
/* Count the visible and expand cells */
|
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
|
|
|
{
|
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
|
|
|
|
|
|
|
nvisible += count_visible_cells (group, &group_expand);
|
|
|
|
nexpand += group_expand;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvisible <= 0)
|
|
|
|
{
|
|
|
|
g_list_free (cells);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-11-26 14:41:39 +00:00
|
|
|
{
|
2010-12-05 06:20:46 +00:00
|
|
|
full_size = avail_size = width;
|
|
|
|
for_size = height;
|
2010-11-26 14:41:39 +00:00
|
|
|
}
|
2010-11-26 12:26:24 +00:00
|
|
|
else
|
2010-11-26 14:41:39 +00:00
|
|
|
{
|
2010-12-05 06:20:46 +00:00
|
|
|
full_size = avail_size = height;
|
|
|
|
for_size = width;
|
2010-11-26 14:41:39 +00:00
|
|
|
}
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
/* Go ahead and collect the requests on the fly */
|
|
|
|
sizes = g_new0 (GtkRequestedSize, nvisible);
|
|
|
|
for (l = cells, i = 0; l; l = l->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = l->data;
|
|
|
|
|
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
2010-12-18 00:14:35 +00:00
|
|
|
continue;
|
2010-11-26 12:26:24 +00:00
|
|
|
|
2010-11-26 14:41:39 +00:00
|
|
|
gtk_cell_area_request_renderer (GTK_CELL_AREA (box), info->renderer,
|
2010-12-18 00:14:35 +00:00
|
|
|
priv->orientation,
|
|
|
|
widget, for_size,
|
|
|
|
&sizes[i].minimum_size,
|
|
|
|
&sizes[i].natural_size);
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
avail_size -= sizes[i].minimum_size;
|
|
|
|
|
|
|
|
sizes[i].data = info;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Naturally distribute the allocation */
|
|
|
|
avail_size -= (nvisible - 1) * priv->spacing;
|
2010-12-06 07:29:40 +00:00
|
|
|
if (avail_size > 0)
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, nvisible, sizes);
|
|
|
|
else
|
|
|
|
avail_size = 0;
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
/* Calculate/distribute expand for cells */
|
|
|
|
if (nexpand > 0)
|
|
|
|
{
|
|
|
|
extra_size = avail_size / nexpand;
|
|
|
|
extra_extra = avail_size % nexpand;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
extra_size = extra_extra = 0;
|
|
|
|
|
|
|
|
/* Create the allocated cells */
|
|
|
|
for (i = 0; i < nvisible; i++)
|
|
|
|
{
|
|
|
|
CellInfo *info = sizes[i].data;
|
|
|
|
AllocatedCell *cell;
|
|
|
|
|
|
|
|
if (info->expand)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
sizes[i].minimum_size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
sizes[i].minimum_size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-05 06:20:46 +00:00
|
|
|
if (rtl)
|
2010-12-18 00:14:35 +00:00
|
|
|
cell = allocated_cell_new (info->renderer,
|
|
|
|
full_size - (position + sizes[i].minimum_size),
|
|
|
|
sizes[i].minimum_size);
|
2010-12-05 06:20:46 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
cell = allocated_cell_new (info->renderer, position, sizes[i].minimum_size);
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
allocated_cells = g_slist_prepend (allocated_cells, cell);
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
position += sizes[i].minimum_size;
|
|
|
|
position += priv->spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (sizes);
|
|
|
|
g_list_free (cells);
|
|
|
|
|
|
|
|
/* Note it might not be important to reverse the list here at all,
|
2010-12-18 00:14:35 +00:00
|
|
|
* we have the correct positions, no need to allocate from left to right
|
|
|
|
*/
|
2010-11-26 12:26:24 +00:00
|
|
|
return g_slist_reverse (allocated_cells);
|
|
|
|
}
|
|
|
|
|
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 *
|
2010-11-13 07:23:01 +00:00
|
|
|
get_allocated_cells (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
2010-11-25 07:09:51 +00:00
|
|
|
GtkCellAreaBoxAllocation *group_allocs;
|
|
|
|
GtkCellArea *area = GTK_CELL_AREA (box);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *cell_list;
|
|
|
|
GSList *allocated_cells = NULL;
|
2010-12-21 12:11:01 +00:00
|
|
|
gint i, j, n_allocs, position;
|
2010-12-05 06:20:46 +00:00
|
|
|
gint for_size, full_size;
|
|
|
|
gboolean rtl;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
group_allocs = _gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
|
2010-10-31 06:22:39 +00:00
|
|
|
if (!group_allocs)
|
2010-11-26 12:26:24 +00:00
|
|
|
return allocate_cells_manually (box, widget, width, height);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-11-26 14:41:39 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-05 06:20:46 +00:00
|
|
|
{
|
|
|
|
full_size = width;
|
|
|
|
for_size = height;
|
|
|
|
}
|
2010-11-26 14:41:39 +00:00
|
|
|
else
|
2010-12-05 06:20:46 +00:00
|
|
|
{
|
|
|
|
full_size = height;
|
|
|
|
for_size = width;
|
|
|
|
}
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* For vertical oriented boxes, we just let the cell renderers
|
|
|
|
* realign themselves for rtl
|
|
|
|
*/
|
2010-12-05 06:20:46 +00:00
|
|
|
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
2010-11-26 14:41:39 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
for (position = 0, i = 0; i < n_allocs; i++)
|
2010-10-31 06:22:39 +00:00
|
|
|
{
|
2010-12-18 00:14:35 +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
|
2010-11-02 07:51:06 +00:00
|
|
|
*/
|
|
|
|
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)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = group->cells->data;
|
|
|
|
AllocatedCell *cell;
|
2010-12-21 12:11:01 +00:00
|
|
|
gint cell_position, cell_size;
|
|
|
|
|
2011-01-10 09:46:51 +00:00
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
/* If were not aligned, place the cell after the last cell */
|
|
|
|
if (info->align)
|
|
|
|
position = cell_position = group_allocs[i].position;
|
|
|
|
else
|
|
|
|
cell_position = position;
|
|
|
|
|
|
|
|
/* If not a fixed size, use only the requested size for this row */
|
|
|
|
if (info->fixed)
|
|
|
|
cell_size = group_allocs[i].size;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint dummy;
|
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
priv->orientation,
|
|
|
|
widget, for_size,
|
|
|
|
&dummy,
|
|
|
|
&cell_size);
|
|
|
|
cell_size = MIN (cell_size, group_allocs[i].size);
|
|
|
|
}
|
2010-12-18 00:14:35 +00:00
|
|
|
|
|
|
|
if (rtl)
|
|
|
|
cell = allocated_cell_new (info->renderer,
|
2010-12-21 12:11:01 +00:00
|
|
|
full_size - (cell_position + cell_size), cell_size);
|
2010-12-18 00:14:35 +00:00
|
|
|
else
|
2010-12-21 12:11:01 +00:00
|
|
|
cell = allocated_cell_new (info->renderer, cell_position, cell_size);
|
|
|
|
|
|
|
|
position += cell_size;
|
|
|
|
position += priv->spacing;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
|
|
|
allocated_cells = g_slist_prepend (allocated_cells, cell);
|
|
|
|
}
|
2010-10-31 06:22:39 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
GtkRequestedSize *sizes;
|
2010-12-21 12:11:01 +00:00
|
|
|
gint avail_size, cell_position;
|
2010-12-18 00:14:35 +00:00
|
|
|
gint visible_cells, expand_cells;
|
|
|
|
gint extra_size, extra_extra;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
visible_cells = count_visible_cells (group, &expand_cells);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* If this row has no visible cells in this group, just
|
|
|
|
* skip the allocation
|
|
|
|
*/
|
|
|
|
if (visible_cells == 0)
|
|
|
|
continue;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
/* If were not aligned, place the cell after the last cell
|
|
|
|
* and eat up the extra space
|
|
|
|
*/
|
|
|
|
if (group->align)
|
|
|
|
{
|
|
|
|
avail_size = group_allocs[i].size;
|
|
|
|
position = cell_position = group_allocs[i].position;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
avail_size = group_allocs[i].size + (group_allocs[i].position - position);
|
|
|
|
cell_position = position;
|
|
|
|
}
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
sizes = g_new (GtkRequestedSize, visible_cells);
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
for (j = 0, cell_list = group->cells; cell_list; cell_list = cell_list->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = cell_list->data;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
priv->orientation,
|
|
|
|
widget, for_size,
|
|
|
|
&sizes[j].minimum_size,
|
|
|
|
&sizes[j].natural_size);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
sizes[j].data = info;
|
|
|
|
avail_size -= sizes[j].minimum_size;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
j++;
|
|
|
|
}
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Distribute cells naturally within the group */
|
|
|
|
avail_size -= (visible_cells - 1) * priv->spacing;
|
2010-11-14 09:43:00 +00:00
|
|
|
if (avail_size > 0)
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, visible_cells, sizes);
|
|
|
|
else
|
|
|
|
avail_size = 0;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Calculate/distribute expand for cells */
|
|
|
|
if (expand_cells > 0)
|
|
|
|
{
|
|
|
|
extra_size = avail_size / expand_cells;
|
|
|
|
extra_extra = avail_size % expand_cells;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
extra_size = extra_extra = 0;
|
|
|
|
|
|
|
|
/* Create the allocated cells (loop only over visible cells here) */
|
|
|
|
for (j = 0; j < visible_cells; j++)
|
|
|
|
{
|
|
|
|
CellInfo *info = sizes[j].data;
|
|
|
|
AllocatedCell *cell;
|
|
|
|
|
|
|
|
if (info->expand)
|
|
|
|
{
|
|
|
|
sizes[j].minimum_size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
sizes[j].minimum_size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtl)
|
|
|
|
cell = allocated_cell_new (info->renderer,
|
2010-12-21 12:11:01 +00:00
|
|
|
full_size - (cell_position + sizes[j].minimum_size),
|
2010-12-18 00:14:35 +00:00
|
|
|
sizes[j].minimum_size);
|
|
|
|
else
|
2010-12-21 12:11:01 +00:00
|
|
|
cell = allocated_cell_new (info->renderer, cell_position, sizes[j].minimum_size);
|
2010-12-18 00:14:35 +00:00
|
|
|
|
|
|
|
allocated_cells = g_slist_prepend (allocated_cells, cell);
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
cell_position += sizes[j].minimum_size;
|
|
|
|
cell_position += priv->spacing;
|
2010-12-18 00:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (sizes);
|
2010-12-21 12:11:01 +00:00
|
|
|
|
|
|
|
position = cell_position;
|
2010-12-18 00:14:35 +00:00
|
|
|
}
|
2010-10-31 06:22:39 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
g_free (group_allocs);
|
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
/* Note it might not be important to reverse the list here at all,
|
2010-12-18 00:14:35 +00:00
|
|
|
* 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-12-09 09:20:39 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_focus_changed (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkCellAreaBox *box)
|
2010-12-09 09:20:39 +00:00
|
|
|
{
|
|
|
|
if (gtk_cell_area_get_focus_cell (area))
|
|
|
|
box->priv->last_focus_cell = gtk_cell_area_get_focus_cell (area);
|
|
|
|
}
|
|
|
|
|
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-13 07:23:01 +00:00
|
|
|
/* Unref/free the context list */
|
|
|
|
for (l = priv->contexts; l; l = l->next)
|
|
|
|
g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify)context_weak_notify, box);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_slist_free (priv->contexts);
|
|
|
|
priv->contexts = 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-12-18 00:14:35 +00:00
|
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
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 */
|
2010-11-27 07:05:14 +00:00
|
|
|
reset_contexts (box);
|
2011-01-12 21:28:43 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
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 *
|
|
|
|
*************************************************************/
|
2010-12-18 00:14:35 +00:00
|
|
|
static void
|
2010-10-23 08:01:58 +00:00
|
|
|
gtk_cell_area_box_add (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-24 11:01:04 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (area),
|
2010-12-21 12:11:01 +00:00
|
|
|
renderer, FALSE, FALSE, TRUE);
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_remove (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-24 11:01:04 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
|
2010-12-09 09:20:39 +00:00
|
|
|
if (priv->last_focus_cell == renderer)
|
|
|
|
priv->last_focus_cell = NULL;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
2010-10-24 11:01:04 +00:00
|
|
|
|
|
|
|
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
|
2010-12-06 03:41:38 +00:00
|
|
|
gtk_cell_area_box_foreach (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellCallback callback,
|
|
|
|
gpointer callback_data)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
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-12-06 03:41:38 +00:00
|
|
|
if (callback (info->renderer, callback_data))
|
2010-12-18 00:14:35 +00:00
|
|
|
break;
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
2010-10-23 08:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 13:16:32 +00:00
|
|
|
static void
|
2010-12-06 05:11:28 +00:00
|
|
|
gtk_cell_area_box_foreach_alloc (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *cell_area,
|
|
|
|
const GdkRectangle *background_area,
|
|
|
|
GtkCellAllocCallback callback,
|
|
|
|
gpointer callback_data)
|
2010-11-05 13:16:32 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
2010-11-05 13:16:32 +00:00
|
|
|
GSList *allocated_cells, *l;
|
2010-12-08 12:18:05 +00:00
|
|
|
GdkRectangle cell_alloc, cell_background;
|
2010-12-05 06:20:46 +00:00
|
|
|
gboolean rtl;
|
|
|
|
|
|
|
|
rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-12-08 12:18:05 +00:00
|
|
|
cell_alloc = *cell_area;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
/* Get a list of cells with allocation sizes decided regardless
|
2010-12-18 00:14:35 +00:00
|
|
|
* of alignments and pack order etc.
|
|
|
|
*/
|
|
|
|
allocated_cells = get_allocated_cells (box, box_context, widget,
|
|
|
|
cell_area->width, cell_area->height);
|
2010-10-31 06:22:39 +00:00
|
|
|
|
|
|
|
for (l = allocated_cells; l; l = l->next)
|
|
|
|
{
|
2010-12-08 12:18:05 +00:00
|
|
|
AllocatedCell *cell = l->data;
|
2010-10-31 06:22:39 +00:00
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
cell_alloc.x = cell_area->x + cell->position;
|
|
|
|
cell_alloc.width = cell->size;
|
|
|
|
}
|
2010-10-31 13:50:53 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
cell_alloc.y = cell_area->y + cell->position;
|
|
|
|
cell_alloc.height = cell->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop iterating over cells if they flow out of the render
|
|
|
|
* area, this can happen because the render area can actually
|
|
|
|
* be smaller than the requested area (treeview columns can
|
2010-12-01 13:42:54 +00:00
|
|
|
* be user resizable and can be resized to be smaller than
|
2010-12-18 00:14:35 +00:00
|
|
|
* the actual requested area).
|
|
|
|
*/
|
2010-12-08 12:18:05 +00:00
|
|
|
if (cell_alloc.x > cell_area->x + cell_area->width ||
|
2010-12-18 00:14:35 +00:00
|
|
|
cell_alloc.x + cell_alloc.width < cell_area->x ||
|
|
|
|
cell_alloc.y > cell_area->y + cell_area->height)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Special case for the last cell (or first cell in rtl)...
|
|
|
|
* let the last cell consume the remaining space in the area
|
|
|
|
* (the last cell is allowed to consume the remaining space if
|
|
|
|
* the space given for rendering is actually larger than allocation,
|
|
|
|
* this can happen in the expander GtkTreeViewColumn where only the
|
|
|
|
* deepest depth column receives the allocation... shallow columns
|
|
|
|
* receive more width). */
|
2010-12-01 13:42:54 +00:00
|
|
|
if (!l->next)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
if (rtl)
|
|
|
|
{
|
|
|
|
/* Fill the leading space for the first cell in the area
|
|
|
|
* (still last in the list)
|
|
|
|
*/
|
|
|
|
cell_alloc.width = (cell_alloc.x - cell_area->x) + cell_alloc.width;
|
|
|
|
cell_alloc.x = cell_area->x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
|
|
|
|
cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
|
|
|
|
}
|
|
|
|
}
|
2010-12-01 13:42:54 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
/* If the cell we are rendering doesnt fit into the remaining space,
|
|
|
|
* clip it so that the underlying renderer has a chance to deal with
|
|
|
|
* it (for instance text renderers get a chance to ellipsize).
|
|
|
|
*/
|
|
|
|
if (cell_alloc.x + cell_alloc.width > cell_area->x + cell_area->width)
|
|
|
|
cell_alloc.width = cell_area->x + cell_area->width - cell_alloc.x;
|
|
|
|
|
|
|
|
if (cell_alloc.y + cell_alloc.height > cell_area->y + cell_area->height)
|
|
|
|
cell_alloc.height = cell_area->y + cell_area->height - cell_alloc.y;
|
|
|
|
}
|
2010-12-01 13:42:54 +00:00
|
|
|
|
2010-12-08 12:18:05 +00:00
|
|
|
/* Add portions of the background_area to the cell_alloc
|
2010-12-18 00:14:35 +00:00
|
|
|
* to create the cell_background
|
|
|
|
*/
|
2010-12-08 12:18:05 +00:00
|
|
|
cell_background = cell_alloc;
|
2010-11-12 10:25:07 +00:00
|
|
|
|
2010-11-12 05:06:00 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
if (l == allocated_cells)
|
|
|
|
{
|
2010-12-16 11:26:18 +00:00
|
|
|
/* Add the depth to the first cell */
|
|
|
|
if (rtl)
|
|
|
|
{
|
|
|
|
cell_background.width += background_area->width - cell_area->width;
|
|
|
|
cell_background.x = background_area->x + background_area->width - cell_background.width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell_background.width += cell_area->x - background_area->x;
|
|
|
|
cell_background.x = background_area->x;
|
|
|
|
}
|
2010-12-18 00:14:35 +00:00
|
|
|
}
|
2010-11-12 05:06:00 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (l->next == NULL)
|
2010-12-16 11:26:18 +00:00
|
|
|
{
|
|
|
|
/* Grant this cell the remaining space */
|
|
|
|
int remain = cell_background.x - background_area->x;
|
|
|
|
|
|
|
|
if (rtl)
|
|
|
|
cell_background.x -= remain;
|
|
|
|
else
|
|
|
|
cell_background.width = background_area->width - remain;
|
|
|
|
}
|
2010-11-12 05:06:00 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
cell_background.y = background_area->y;
|
|
|
|
cell_background.height = background_area->height;
|
|
|
|
}
|
2010-11-12 05:06:00 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
if (l == allocated_cells)
|
|
|
|
{
|
|
|
|
cell_background.height += cell_background.y - background_area->y;
|
|
|
|
cell_background.y = background_area->y;
|
|
|
|
}
|
2010-11-12 05:06:00 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (l->next == NULL)
|
|
|
|
cell_background.height =
|
|
|
|
background_area->height - (cell_background.y - background_area->y);
|
2010-11-11 07:13:06 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
cell_background.x = background_area->x;
|
|
|
|
cell_background.width = background_area->width;
|
|
|
|
}
|
2010-10-31 13:50:53 +00:00
|
|
|
|
2010-12-08 12:18:05 +00:00
|
|
|
if (callback (cell->renderer, &cell_alloc, &cell_background, callback_data))
|
2010-12-18 00:14:35 +00:00
|
|
|
break;
|
2010-11-11 07:13:06 +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-12-21 12:11:01 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_apply_attributes (GtkCellArea *area,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gboolean is_expander,
|
|
|
|
gboolean is_expanded)
|
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* Call the parent class to apply the attributes */
|
|
|
|
GTK_CELL_AREA_CLASS
|
|
|
|
(gtk_cell_area_box_parent_class)->apply_attributes (area, tree_model, iter,
|
|
|
|
is_expander, is_expanded);
|
|
|
|
|
|
|
|
/* Update visible state for cell groups */
|
|
|
|
for (i = 0; i < priv->groups->len; i++)
|
|
|
|
{
|
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
group->visible = FALSE;
|
|
|
|
|
|
|
|
for (list = group->cells; list && group->visible == FALSE; list = list->next)
|
|
|
|
{
|
|
|
|
CellInfo *info = list->data;
|
|
|
|
|
|
|
|
if (gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
group->visible = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
static void
|
|
|
|
gtk_cell_area_box_set_cell_property (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-10-31 08:45:29 +00:00
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-10-31 08:45:29 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
|
|
|
gboolean rebuild = FALSE;
|
|
|
|
gboolean val;
|
|
|
|
GtkPackType pack_type;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
2010-10-31 08:45:29 +00:00
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info = node->data;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case CELL_PROP_EXPAND:
|
|
|
|
val = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (info->expand != val)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
info->expand = val;
|
|
|
|
rebuild = TRUE;
|
|
|
|
}
|
2010-10-31 08:45:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CELL_PROP_ALIGN:
|
|
|
|
val = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (info->align != val)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
info->align = val;
|
|
|
|
rebuild = TRUE;
|
|
|
|
}
|
2010-10-31 08:45:29 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
case CELL_PROP_FIXED_SIZE:
|
|
|
|
val = g_value_get_boolean (value);
|
|
|
|
|
|
|
|
if (info->fixed != val)
|
|
|
|
{
|
|
|
|
info->fixed = val;
|
|
|
|
rebuild = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
case CELL_PROP_PACK_TYPE:
|
|
|
|
pack_type = g_value_get_enum (value);
|
|
|
|
|
|
|
|
if (info->pack != pack_type)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
info->pack = pack_type;
|
|
|
|
rebuild = TRUE;
|
|
|
|
}
|
2010-10-31 08:45:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-12-04 11:52:03 +00:00
|
|
|
GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
|
2010-10-31 08:45:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Groups need to be rebuilt */
|
|
|
|
if (rebuild)
|
2010-11-09 04:50:30 +00:00
|
|
|
cell_groups_rebuild (box);
|
2010-10-31 08:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_get_cell_property (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-10-31 08:45:29 +00:00
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-10-31 08:45:29 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
2010-10-31 08:45:29 +00:00
|
|
|
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;
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
case CELL_PROP_FIXED_SIZE:
|
|
|
|
g_value_set_boolean (value, info->fixed);
|
|
|
|
break;
|
|
|
|
|
2010-10-31 08:45:29 +00:00
|
|
|
case CELL_PROP_PACK_TYPE:
|
|
|
|
g_value_set_enum (value, info->pack);
|
|
|
|
break;
|
|
|
|
default:
|
2010-12-04 11:52:03 +00:00
|
|
|
GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID (area, prop_id, pspec);
|
2010-10-31 08:45:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
static GtkCellAreaContext *
|
|
|
|
gtk_cell_area_box_create_context (GtkCellArea *area)
|
2010-10-26 08:14:20 +00:00
|
|
|
{
|
2010-10-30 12:40:22 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaContext *context =
|
2010-12-18 00:14:35 +00:00
|
|
|
(GtkCellAreaContext *)g_object_new (GTK_TYPE_CELL_AREA_BOX_CONTEXT,
|
|
|
|
"area", area, NULL);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv->contexts = g_slist_prepend (priv->contexts, context);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (context), (GWeakNotify)context_weak_notify, box);
|
2010-10-30 12:40:22 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
/* Tell the new group about our cell layout */
|
2010-11-13 07:23:01 +00:00
|
|
|
init_context_group (box, GTK_CELL_AREA_BOX_CONTEXT (context));
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
return context;
|
2010-10-26 08:14:20 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 15:18:00 +00:00
|
|
|
static GtkCellAreaContext *
|
|
|
|
gtk_cell_area_box_copy_context (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *copy =
|
2011-01-11 15:40:35 +00:00
|
|
|
(GtkCellAreaContext *)_gtk_cell_area_box_context_copy (GTK_CELL_AREA_BOX (area),
|
2010-12-18 00:14:35 +00:00
|
|
|
GTK_CELL_AREA_BOX_CONTEXT (context));
|
2010-12-12 15:18:00 +00:00
|
|
|
|
|
|
|
priv->contexts = g_slist_prepend (priv->contexts, copy);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (copy), (GWeakNotify)context_weak_notify, box);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
static GtkSizeRequestMode
|
2010-10-23 08:01:58 +00:00
|
|
|
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
|
2010-11-13 07:23:01 +00:00
|
|
|
compute_size (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkOrientation orientation,
|
|
|
|
GtkCellAreaBoxContext *context,
|
|
|
|
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-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-12-18 00:14:35 +00:00
|
|
|
|
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);
|
2010-11-26 04:23:01 +00:00
|
|
|
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-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
CellInfo *info = list->data;
|
|
|
|
gint renderer_min_size, renderer_nat_size;
|
|
|
|
|
|
|
|
if (!gtk_cell_renderer_get_visible (info->renderer))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gtk_cell_area_request_renderer (area, info->renderer, orientation, widget, for_size,
|
|
|
|
&renderer_min_size, &renderer_nat_size);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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-11-26 04:23:01 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
if (for_size < 0)
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_width (context, group->id, group_min_size, group_nat_size);
|
2010-12-18 00:14:35 +00:00
|
|
|
else
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_width_for_height (context, group->id, for_size,
|
2010-12-18 00:14:35 +00:00
|
|
|
group_min_size, group_nat_size);
|
|
|
|
}
|
2010-11-26 04:23:01 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
if (for_size < 0)
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_height (context, group->id, group_min_size, group_nat_size);
|
2010-12-18 00:14:35 +00:00
|
|
|
else
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_height_for_width (context, group->id, for_size,
|
2010-12-18 00:14:35 +00:00
|
|
|
group_min_size, group_nat_size);
|
|
|
|
}
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*minimum_size = min_size;
|
|
|
|
*natural_size = nat_size;
|
2010-12-05 06:20:46 +00:00
|
|
|
|
|
|
|
/* Update rtl state for focus navigation to work */
|
|
|
|
priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 04:45:21 +00:00
|
|
|
static GtkRequestedSize *
|
2010-10-31 13:50:53 +00:00
|
|
|
get_group_sizes (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
CellGroup *group,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *n_sizes)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
|
|
|
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))
|
2010-12-18 00:14:35 +00:00
|
|
|
continue;
|
2010-11-02 07:51:06 +00:00
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
sizes[i].data = info;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-31 13:50:53 +00:00
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
2010-12-18 00:14:35 +00:00
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
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++)
|
2010-12-18 00:14:35 +00:00
|
|
|
avail_size -= orientation_sizes[i].minimum_size;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
2010-11-14 09:43:00 +00:00
|
|
|
if (avail_size > 0)
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, n_sizes, orientation_sizes);
|
|
|
|
else
|
|
|
|
avail_size = 0;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
/* Calculate/distribute expand for cells */
|
2010-10-31 06:22:39 +00:00
|
|
|
if (group->expand_cells > 0)
|
2010-12-18 00:14:35 +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-12-18 00:14:35 +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-12-18 00:14:35 +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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_cell_area_request_renderer (area, info->renderer,
|
|
|
|
OPPOSITE_ORIENTATION (priv->orientation),
|
|
|
|
widget,
|
|
|
|
orientation_sizes[i].minimum_size,
|
|
|
|
&cell_min, &cell_nat);
|
|
|
|
|
|
|
|
min_size = MAX (min_size, cell_min);
|
|
|
|
nat_size = MAX (nat_size, cell_nat);
|
|
|
|
}
|
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
|
2010-12-18 00:14:35 +00:00
|
|
|
compute_size_for_opposing_orientation (GtkCellAreaBox *box,
|
|
|
|
GtkCellAreaBoxContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
|
|
|
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)
|
2011-01-11 15:40:35 +00:00
|
|
|
orientation_sizes = _gtk_cell_area_box_context_get_widths (context, &n_groups);
|
2010-10-30 08:32:15 +00:00
|
|
|
else
|
2011-01-11 15:40:35 +00:00
|
|
|
orientation_sizes = _gtk_cell_area_box_context_get_heights (context, &n_groups);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-11-14 09:43:00 +00:00
|
|
|
if (avail_size > 0)
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, orientation_sizes);
|
|
|
|
else
|
|
|
|
avail_size = 0;
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
/* 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
|
2010-12-18 00:14:35 +00:00
|
|
|
* and push the height-for-width for each group accordingly while
|
|
|
|
* accumulating the overall height-for-width for this row.
|
2010-10-30 08:32:15 +00:00
|
|
|
*/
|
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);
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-11-02 07:51:06 +00:00
|
|
|
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-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
orientation_sizes[i].minimum_size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
orientation_sizes[i].minimum_size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we have the allocation for the group,
|
2011-02-23 09:26:21 +00:00
|
|
|
* request its height-for-width
|
2010-12-18 00:14:35 +00:00
|
|
|
*/
|
2010-10-30 08:32:15 +00:00
|
|
|
compute_group_size_for_opposing_orientation (box, group, widget,
|
2010-12-18 00:14:35 +00:00
|
|
|
orientation_sizes[i].minimum_size,
|
|
|
|
&group_min, &group_nat);
|
2010-10-30 08:32:15 +00:00
|
|
|
|
|
|
|
min_size = MAX (min_size, group_min);
|
|
|
|
nat_size = MAX (nat_size, group_nat);
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_height_for_width (context, group_idx, for_size,
|
2010-12-18 00:14:35 +00:00
|
|
|
group_min, group_nat);
|
|
|
|
}
|
2010-11-26 04:23:01 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_width_for_height (context, group_idx, for_size,
|
2010-12-18 00:14:35 +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-12-05 06:20:46 +00:00
|
|
|
|
|
|
|
/* Update rtl state for focus navigation to work */
|
|
|
|
priv->rtl = (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
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-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context;
|
2010-10-26 16:01:58 +00:00
|
|
|
gint min_width, nat_width;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
2010-10-26 16:01:58 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Compute the size of all renderers for current row data,
|
|
|
|
* bumping cell alignments in the context along the way
|
|
|
|
*/
|
2010-10-26 16:01:58 +00:00
|
|
|
compute_size (box, GTK_ORIENTATION_HORIZONTAL,
|
2010-12-18 00:14:35 +00:00
|
|
|
box_context, 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-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context;
|
2010-10-26 16:01:58 +00:00
|
|
|
gint min_height, nat_height;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Compute the size of all renderers for current row data,
|
|
|
|
* bumping cell alignments in the context along the way
|
|
|
|
*/
|
2010-10-26 16:01:58 +00:00
|
|
|
compute_size (box, GTK_ORIENTATION_VERTICAL,
|
2010-12-18 00:14:35 +00:00
|
|
|
box_context, 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-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context;
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
gint min_height, nat_height;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
priv = box->priv;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
|
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Add up vertical requests of height for width and push
|
|
|
|
* the overall cached sizes for alignments
|
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
compute_size (box, priv->orientation, box_context, widget, width, &min_height, &nat_height);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Juice: virtually allocate cells into the for_width using the
|
|
|
|
* alignments and then return the overall height for that width,
|
|
|
|
* and cache it
|
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
compute_size_for_opposing_orientation (box, box_context, 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-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaContext *context,
|
|
|
|
GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2010-10-23 08:01:58 +00:00
|
|
|
{
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context;
|
2010-10-26 16:01:58 +00:00
|
|
|
GtkCellAreaBoxPrivate *priv;
|
|
|
|
gint min_width, nat_width;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (context));
|
2010-10-23 08:01:58 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
priv = box->priv;
|
2010-10-26 16:01:58 +00:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Add up horizontal requests of width for height and push
|
|
|
|
* the overall cached sizes for alignments
|
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
compute_size (box, priv->orientation, box_context, widget, height, &min_width, &nat_width);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-18 00:14:35 +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
|
|
|
|
*/
|
2010-11-13 07:23:01 +00:00
|
|
|
compute_size_for_opposing_orientation (box, box_context, 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-12-06 05:11:28 +00:00
|
|
|
enum {
|
|
|
|
FOCUS_NONE,
|
|
|
|
FOCUS_PREV,
|
2010-12-09 09:20:39 +00:00
|
|
|
FOCUS_NEXT,
|
|
|
|
FOCUS_LAST_CELL
|
2010-12-06 05:11:28 +00:00
|
|
|
};
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_cell_area_box_focus (GtkCellArea *area,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkDirectionType direction)
|
2010-11-01 08:41:02 +00:00
|
|
|
{
|
2010-11-10 10:17:06 +00:00
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (area);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
gint cycle = FOCUS_NONE;
|
|
|
|
gboolean cycled_focus = FALSE;
|
|
|
|
GtkCellRenderer *focus_cell;
|
2010-11-01 08:41:02 +00:00
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
focus_cell = gtk_cell_area_get_focus_cell (area);
|
2010-11-01 08:41:02 +00:00
|
|
|
|
2010-12-01 06:18:40 +00:00
|
|
|
/* Special case, when there is no activatable cell, focus
|
|
|
|
* is painted around the entire area... in this case we
|
|
|
|
* let focus leave the area directly.
|
|
|
|
*/
|
|
|
|
if (focus_cell && !gtk_cell_area_is_activatable (area))
|
|
|
|
{
|
|
|
|
gtk_cell_area_set_focus_cell (area, NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-01 08:41:02 +00:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GTK_DIR_TAB_FORWARD:
|
2010-12-05 06:20:46 +00:00
|
|
|
cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
|
2010-11-01 08:41:02 +00:00
|
|
|
break;
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
2010-12-05 06:20:46 +00:00
|
|
|
cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
2010-12-18 00:14:35 +00:00
|
|
|
case GTK_DIR_UP:
|
2010-12-09 09:29:36 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_PREV;
|
2010-12-09 09:20:39 +00:00
|
|
|
else if (!focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_LAST_CELL;
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
|
|
|
case GTK_DIR_DOWN:
|
2010-12-09 09:29:36 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_VERTICAL || !priv->last_focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_NEXT;
|
2010-12-09 09:20:39 +00:00
|
|
|
else if (!focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_LAST_CELL;
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
2010-11-01 08:41:02 +00:00
|
|
|
case GTK_DIR_LEFT:
|
2010-12-09 09:29:36 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = priv->rtl ? FOCUS_NEXT : FOCUS_PREV;
|
2010-12-09 09:20:39 +00:00
|
|
|
else if (!focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_LAST_CELL;
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
|
|
|
case GTK_DIR_RIGHT:
|
2010-12-09 09:29:36 +00:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL || !priv->last_focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = priv->rtl ? FOCUS_PREV : FOCUS_NEXT;
|
2010-12-09 09:20:39 +00:00
|
|
|
else if (!focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
cycle = FOCUS_LAST_CELL;
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
2010-11-01 08:41:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-09 09:20:39 +00:00
|
|
|
if (cycle == FOCUS_LAST_CELL)
|
|
|
|
{
|
|
|
|
gtk_cell_area_set_focus_cell (area, priv->last_focus_cell);
|
|
|
|
cycled_focus = TRUE;
|
|
|
|
}
|
|
|
|
else if (cycle != FOCUS_NONE)
|
2010-11-01 08:41:02 +00:00
|
|
|
{
|
2010-11-10 10:17:06 +00:00
|
|
|
gboolean found_cell = FALSE;
|
|
|
|
GList *list;
|
|
|
|
gint i;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* If there is no focused cell, focus on the first (or last) one */
|
2010-11-10 10:17:06 +00:00
|
|
|
if (!focus_cell)
|
2010-12-18 00:14:35 +00:00
|
|
|
found_cell = TRUE;
|
|
|
|
|
|
|
|
for (i = (cycle == FOCUS_NEXT) ? 0 : priv->groups->len -1;
|
|
|
|
cycled_focus == FALSE && i >= 0 && i < priv->groups->len;
|
|
|
|
i = (cycle == FOCUS_NEXT) ? i + 1 : i - 1)
|
|
|
|
{
|
|
|
|
CellGroup *group = &g_array_index (priv->groups, CellGroup, i);
|
|
|
|
|
|
|
|
for (list = (cycle == FOCUS_NEXT) ? g_list_first (group->cells) : g_list_last (group->cells);
|
|
|
|
cycled_focus == FALSE && list; list = (cycle == FOCUS_NEXT) ? list->next : list->prev)
|
|
|
|
{
|
|
|
|
CellInfo *info = list->data;
|
|
|
|
|
|
|
|
if (info->renderer == focus_cell)
|
|
|
|
found_cell = TRUE;
|
|
|
|
else if (found_cell && /* Dont give focus to cells that are siblings to a focus cell */
|
|
|
|
gtk_cell_area_get_focus_from_sibling (area, info->renderer) == NULL)
|
|
|
|
{
|
2010-11-28 17:52:18 +00:00
|
|
|
gtk_cell_area_set_focus_cell (area, info->renderer);
|
|
|
|
cycled_focus = TRUE;
|
2010-12-18 00:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-01 08:41:02 +00:00
|
|
|
}
|
2010-11-10 13:25:13 +00:00
|
|
|
|
|
|
|
if (!cycled_focus)
|
|
|
|
gtk_cell_area_set_focus_cell (area, NULL);
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
return cycled_focus;
|
2010-11-01 08:41:02 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_start (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, FALSE, TRUE);
|
2010-10-24 11:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_cell_area_box_layout_pack_end (GtkCellLayout *cell_layout,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand)
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_box_pack_end (GTK_CELL_AREA_BOX (cell_layout), renderer, expand, FALSE, 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,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gint position)
|
2010-10-24 11:08:21 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBox *box = GTK_CELL_AREA_BOX (cell_layout);
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
GList *node;
|
|
|
|
CellInfo *info;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
|
|
|
node = g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find);
|
2010-10-24 11:08:21 +00:00
|
|
|
|
|
|
|
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-12-21 12:11:01 +00:00
|
|
|
/*************************************************************
|
|
|
|
* Private interaction with GtkCellAreaBoxContext *
|
|
|
|
*************************************************************/
|
|
|
|
gboolean
|
|
|
|
_gtk_cell_area_box_group_visible (GtkCellAreaBox *box,
|
|
|
|
gint group_idx)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxPrivate *priv = box->priv;
|
|
|
|
CellGroup *group;
|
|
|
|
|
|
|
|
g_assert (group_idx >= 0 && group_idx < priv->groups->len);
|
|
|
|
|
|
|
|
group = &g_array_index (priv->groups, CellGroup, group_idx);
|
|
|
|
|
|
|
|
return group->visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-23 08:01:58 +00:00
|
|
|
/*************************************************************
|
|
|
|
* API *
|
|
|
|
*************************************************************/
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_cell_area_box_new:
|
2010-12-18 00:14:35 +00:00
|
|
|
*
|
2010-12-03 08:13:31 +00:00
|
|
|
* Creates a new #GtkCellAreaBox.
|
|
|
|
*
|
|
|
|
* Return value: a newly created #GtkCellAreaBox
|
2010-12-18 00:14:35 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2010-12-03 08:13:31 +00:00
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_cell_area_box_pack_start:
|
|
|
|
* @box: a #GtkCellAreaBox
|
|
|
|
* @renderer: the #GtkCellRenderer to add
|
|
|
|
* @expand: whether @renderer should receive extra space when the area receives
|
|
|
|
* more than its natural size
|
2010-12-18 00:14:35 +00:00
|
|
|
* @align: whether @renderer should be aligned in adjacent rows
|
2010-12-21 12:11:01 +00:00
|
|
|
* @fixed: whether @renderer should have the same size in all rows
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Adds @renderer to @box, packed with reference to the start of @box.
|
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* The @renderer is packed after any other #GtkCellRenderer packed
|
|
|
|
* with reference to the start of @box.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-24 11:01:04 +00:00
|
|
|
void
|
|
|
|
gtk_cell_area_box_pack_start (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand,
|
2010-12-21 12:11:01 +00:00
|
|
|
gboolean align,
|
|
|
|
gboolean fixed)
|
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;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find))
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
g_warning ("Refusing to add the same cell renderer to a GtkCellAreaBox twice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
info = cell_info_new (renderer, GTK_PACK_START, expand, align, fixed);
|
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-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_cell_area_box_pack_end:
|
|
|
|
* @box: a #GtkCellAreaBox
|
|
|
|
* @renderer: the #GtkCellRenderer to add
|
|
|
|
* @expand: whether @renderer should receive extra space when the area receives
|
|
|
|
* more than its natural size
|
2010-12-18 00:14:35 +00:00
|
|
|
* @align: whether @renderer should be aligned in adjacent rows
|
2010-12-21 12:11:01 +00:00
|
|
|
* @fixed: whether @renderer should have the same size in all rows
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Adds @renderer to @box, packed with reference to the end of @box.
|
|
|
|
*
|
2010-12-18 00:14:35 +00:00
|
|
|
* The @renderer is packed after (away from end of) any other
|
|
|
|
* #GtkCellRenderer packed with reference to the end of @box.
|
2010-12-03 08:13:31 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-24 11:01:04 +00:00
|
|
|
void
|
|
|
|
gtk_cell_area_box_pack_end (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
gboolean expand,
|
2010-12-21 12:11:01 +00:00
|
|
|
gboolean align,
|
|
|
|
gboolean fixed)
|
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;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (g_list_find_custom (priv->cells, renderer,
|
|
|
|
(GCompareFunc)cell_info_find))
|
2010-10-24 11:01:04 +00:00
|
|
|
{
|
|
|
|
g_warning ("Refusing to add the same cell renderer to a GtkCellArea twice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
info = cell_info_new (renderer, GTK_PACK_END, expand, align, fixed);
|
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
|
|
|
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_cell_area_box_get_spacing:
|
|
|
|
* @box: a #GtkCellAreaBox
|
|
|
|
*
|
|
|
|
* Gets the spacing added between cell renderers.
|
|
|
|
*
|
|
|
|
* Return value: the space added between cell renderers in @box.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-03 08:13:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_cell_area_box_set_spacing:
|
|
|
|
* @box: a #GtkCellAreaBox
|
|
|
|
* @spacing: the space to add between #GtkCellRenderers
|
|
|
|
*
|
|
|
|
* Sets the spacing to add between cell renderers in @box.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-10-26 16:01:58 +00:00
|
|
|
void
|
|
|
|
gtk_cell_area_box_set_spacing (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
gint spacing)
|
2010-10-26 16:01:58 +00:00
|
|
|
{
|
|
|
|
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 */
|
2010-11-27 07:05:14 +00:00
|
|
|
reset_contexts (box);
|
2010-10-26 16:01:58 +00:00
|
|
|
}
|
|
|
|
}
|