2010-11-13 07:23:01 +00:00
|
|
|
/* gtkcellareaboxcontext.c
|
2010-10-26 09:22:59 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Openismus GmbH
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Tristan Van Berkom <tristanvb@openismus.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-10-26 09:22:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2010-10-30 08:32:15 +00:00
|
|
|
#include "gtkcellareabox.h"
|
2011-01-11 15:04:00 +00:00
|
|
|
#include "gtkcellareaboxcontextprivate.h"
|
2010-10-30 14:06:26 +00:00
|
|
|
#include "gtkorientable.h"
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2021-02-04 19:20:10 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
2022-10-07 21:47:28 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
/* GObjectClass */
|
2011-01-11 15:40:35 +00:00
|
|
|
static void _gtk_cell_area_box_context_finalize (GObject *object);
|
2010-11-13 07:23:01 +00:00
|
|
|
|
|
|
|
/* GtkCellAreaContextClass */
|
2011-01-11 15:40:35 +00:00
|
|
|
static void _gtk_cell_area_box_context_reset (GtkCellAreaContext *context);
|
|
|
|
static void _gtk_cell_area_box_context_get_preferred_height_for_width (GtkCellAreaContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int width,
|
|
|
|
int *minimum_height,
|
|
|
|
int *natural_height);
|
2011-01-11 15:40:35 +00:00
|
|
|
static void _gtk_cell_area_box_context_get_preferred_width_for_height (GtkCellAreaContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int height,
|
|
|
|
int *minimum_width,
|
|
|
|
int *natural_width);
|
2010-12-12 15:18:00 +00:00
|
|
|
|
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
|
|
|
|
/* Internal functions */
|
2011-01-11 15:40:35 +00:00
|
|
|
static void _gtk_cell_area_box_context_sum (GtkCellAreaBoxContext *context,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int for_size,
|
|
|
|
int *minimum_size,
|
|
|
|
int *natural_size);
|
2010-11-27 07:05:14 +00:00
|
|
|
static void free_cache_array (GArray *array);
|
|
|
|
static GArray *group_array_new (GtkCellAreaBoxContext *context);
|
|
|
|
static GArray *get_array (GtkCellAreaBoxContext *context,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int for_size);
|
2010-11-27 07:05:14 +00:00
|
|
|
static gboolean group_expands (GtkCellAreaBoxContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx);
|
|
|
|
static int count_expand_groups (GtkCellAreaBoxContext *context);
|
2010-11-26 12:26:24 +00:00
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
/* CachedSize management */
|
|
|
|
typedef struct {
|
2020-07-24 13:54:49 +00:00
|
|
|
int min_size;
|
|
|
|
int nat_size;
|
2010-11-26 04:23:01 +00:00
|
|
|
} CachedSize;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
struct _GtkCellAreaBoxContextPrivate
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
|
|
|
/* Table of per renderer CachedSizes */
|
2010-10-31 04:06:10 +00:00
|
|
|
GArray *base_widths;
|
|
|
|
GArray *base_heights;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
/* Table of per height/width hash tables of per renderer CachedSizes */
|
|
|
|
GHashTable *widths;
|
|
|
|
GHashTable *heights;
|
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
/* Whether each group expands */
|
|
|
|
gboolean *expand;
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
/* Whether each group is aligned */
|
|
|
|
gboolean *align;
|
2010-10-26 09:22:59 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkCellAreaBoxContext, _gtk_cell_area_box_context, GTK_TYPE_CELL_AREA_CONTEXT)
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
static void
|
|
|
|
free_cache_array (GArray *array)
|
|
|
|
{
|
|
|
|
g_array_free (array, TRUE);
|
|
|
|
}
|
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
static GArray *
|
|
|
|
group_array_new (GtkCellAreaBoxContext *context)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
GArray *group_array;
|
|
|
|
|
|
|
|
group_array = g_array_new (FALSE, TRUE, sizeof (CachedSize));
|
|
|
|
g_array_set_size (group_array, priv->base_widths->len);
|
|
|
|
|
|
|
|
return group_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *
|
|
|
|
get_array (GtkCellAreaBoxContext *context,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int for_size)
|
2010-11-26 12:26:24 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
GArray *array;
|
|
|
|
|
|
|
|
if (for_size < 0)
|
|
|
|
{
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
array = priv->base_widths;
|
2010-11-26 12:26:24 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
array = priv->base_heights;
|
2010-11-26 12:26:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
array = g_hash_table_lookup (priv->widths, GINT_TO_POINTER (for_size));
|
2010-11-26 12:26:24 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (!array)
|
|
|
|
array = priv->base_widths;
|
|
|
|
}
|
2010-11-26 12:26:24 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
array = g_hash_table_lookup (priv->heights, GINT_TO_POINTER (for_size));
|
2010-11-26 12:26:24 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
if (!array)
|
|
|
|
array = priv->base_heights;
|
|
|
|
}
|
2010-11-26 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:13 +00:00
|
|
|
static gboolean
|
2010-11-26 12:26:24 +00:00
|
|
|
group_expands (GtkCellAreaBoxContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx)
|
2010-11-26 12:26:24 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
|
|
|
|
g_assert (group_idx >= 0 && group_idx < priv->base_widths->len);
|
|
|
|
|
|
|
|
return priv->expand[group_idx];
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
static int
|
2010-11-26 12:26:24 +00:00
|
|
|
count_expand_groups (GtkCellAreaBoxContext *context)
|
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i, expand = 0;
|
2010-11-26 12:26:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < priv->base_widths->len; i++)
|
|
|
|
{
|
|
|
|
if (priv->expand[i])
|
2010-12-18 00:14:35 +00:00
|
|
|
expand++;
|
2010-11-26 12:26:24 +00:00
|
|
|
}
|
2022-10-20 11:23:13 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
return expand;
|
|
|
|
}
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_init (GtkCellAreaBoxContext *box_context)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
box_context->priv = _gtk_cell_area_box_context_get_instance_private (box_context);
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
priv->base_widths = g_array_new (FALSE, TRUE, sizeof (CachedSize));
|
|
|
|
priv->base_heights = g_array_new (FALSE, TRUE, sizeof (CachedSize));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
priv->widths = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
2010-12-18 00:14:35 +00:00
|
|
|
NULL, (GDestroyNotify)free_cache_array);
|
2010-11-26 04:23:01 +00:00
|
|
|
priv->heights = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
2010-12-18 00:14:35 +00:00
|
|
|
NULL, (GDestroyNotify)free_cache_array);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:13 +00:00
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_class_init (GtkCellAreaBoxContextClass *class)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkCellAreaContextClass *context_class = GTK_CELL_AREA_CONTEXT_CLASS (class);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
/* GObjectClass */
|
2011-01-11 15:40:35 +00:00
|
|
|
object_class->finalize = _gtk_cell_area_box_context_finalize;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
context_class->reset = _gtk_cell_area_box_context_reset;
|
|
|
|
context_class->get_preferred_height_for_width = _gtk_cell_area_box_context_get_preferred_height_for_width;
|
|
|
|
context_class->get_preferred_width_for_height = _gtk_cell_area_box_context_get_preferred_width_for_height;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* GObjectClass *
|
|
|
|
*************************************************************/
|
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_finalize (GObject *object)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (object);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
g_array_free (priv->base_widths, TRUE);
|
|
|
|
g_array_free (priv->base_heights, TRUE);
|
2010-11-26 04:23:01 +00:00
|
|
|
g_hash_table_destroy (priv->widths);
|
|
|
|
g_hash_table_destroy (priv->heights);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
g_free (priv->expand);
|
2010-12-21 12:11:01 +00:00
|
|
|
g_free (priv->align);
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
G_OBJECT_CLASS (_gtk_cell_area_box_context_parent_class)->finalize (object);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
2010-12-18 00:14:35 +00:00
|
|
|
* GtkCellAreaContextClass *
|
2010-10-26 09:22:59 +00:00
|
|
|
*************************************************************/
|
2010-10-30 14:06:26 +00:00
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_reset (GtkCellAreaContext *context)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContext *box_context = GTK_CELL_AREA_BOX_CONTEXT (context);
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
2010-11-27 07:05:14 +00:00
|
|
|
CachedSize *size;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < priv->base_widths->len; i++)
|
|
|
|
{
|
2010-11-27 07:05:14 +00:00
|
|
|
size = &g_array_index (priv->base_widths, CachedSize, i);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
size->min_size = 0;
|
|
|
|
size->nat_size = 0;
|
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
size = &g_array_index (priv->base_heights, CachedSize, i);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
|
|
|
size->min_size = 0;
|
|
|
|
size->nat_size = 0;
|
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
/* Reset context sizes as well */
|
|
|
|
g_hash_table_remove_all (priv->widths);
|
2010-11-26 12:26:24 +00:00
|
|
|
g_hash_table_remove_all (priv->heights);
|
2010-11-26 04:23:01 +00:00
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
GTK_CELL_AREA_CONTEXT_CLASS
|
2011-01-11 15:40:35 +00:00
|
|
|
(_gtk_cell_area_box_context_parent_class)->reset (context);
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-28 09:52:08 +00:00
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_sum (GtkCellAreaBoxContext *context,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int for_size,
|
|
|
|
int *minimum_size,
|
|
|
|
int *natural_size)
|
2010-11-28 09:52:08 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
GtkCellAreaBox *area;
|
2010-12-02 08:09:44 +00:00
|
|
|
GtkOrientation box_orientation;
|
|
|
|
GArray *array;
|
2020-07-24 13:54:49 +00:00
|
|
|
int spacing, i, last_aligned_group_idx;
|
|
|
|
int min_size = 0, nat_size = 0;
|
2010-11-28 09:52:08 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
area = (GtkCellAreaBox *)gtk_cell_area_context_get_area (GTK_CELL_AREA_CONTEXT (context));
|
|
|
|
spacing = gtk_cell_area_box_get_spacing (area);
|
2010-11-28 09:52:08 +00:00
|
|
|
box_orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
2010-12-12 15:18:00 +00:00
|
|
|
array = get_array (context, orientation, for_size);
|
2010-11-28 09:52:08 +00:00
|
|
|
|
2022-10-20 11:23:13 +00:00
|
|
|
/* Get the last visible aligned group
|
2010-12-21 12:11:01 +00:00
|
|
|
* (we need to get space at least up till this group) */
|
|
|
|
for (i = array->len - 1; i >= 0; i--)
|
|
|
|
{
|
2022-10-20 11:23:13 +00:00
|
|
|
if (priv->align[i] &&
|
2011-02-09 04:18:22 +00:00
|
|
|
_gtk_cell_area_box_group_visible (area, i))
|
|
|
|
break;
|
2010-12-21 12:11:01 +00:00
|
|
|
}
|
|
|
|
last_aligned_group_idx = i >= 0 ? i : 0;
|
|
|
|
|
2010-11-28 09:52:08 +00:00
|
|
|
for (i = 0; i < array->len; i++)
|
|
|
|
{
|
2010-12-02 04:19:37 +00:00
|
|
|
CachedSize *size = &g_array_index (array, CachedSize, i);
|
2010-11-28 09:52:08 +00:00
|
|
|
|
2010-12-02 04:19:37 +00:00
|
|
|
if (box_orientation == orientation)
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
2011-02-09 04:18:22 +00:00
|
|
|
if (i > last_aligned_group_idx &&
|
|
|
|
!_gtk_cell_area_box_group_visible (area, i))
|
|
|
|
continue;
|
2010-12-21 12:11:01 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* Dont add spacing for 0 size groups, they can be 0 size because
|
|
|
|
* they contain only invisible cells for this round of requests
|
|
|
|
*/
|
|
|
|
if (min_size > 0 && size->nat_size > 0)
|
|
|
|
{
|
|
|
|
min_size += spacing;
|
|
|
|
nat_size += spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_size += size->min_size;
|
|
|
|
nat_size += size->nat_size;
|
|
|
|
}
|
2010-11-28 09:52:08 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
{
|
|
|
|
min_size = MAX (min_size, size->min_size);
|
|
|
|
nat_size = MAX (nat_size, size->nat_size);
|
|
|
|
}
|
2010-11-28 09:52:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 15:18:00 +00:00
|
|
|
if (for_size < 0)
|
|
|
|
{
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_cell_area_context_push_preferred_width (GTK_CELL_AREA_CONTEXT (context), min_size, nat_size);
|
2010-12-12 15:18:00 +00:00
|
|
|
else
|
2010-12-18 00:14:35 +00:00
|
|
|
gtk_cell_area_context_push_preferred_height (GTK_CELL_AREA_CONTEXT (context), min_size, nat_size);
|
2010-12-12 15:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minimum_size)
|
|
|
|
*minimum_size = min_size;
|
|
|
|
if (natural_size)
|
|
|
|
*natural_size = nat_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_preferred_height_for_width (GtkCellAreaContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int width,
|
|
|
|
int *minimum_height,
|
|
|
|
int *natural_height)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
2022-10-20 11:23:13 +00:00
|
|
|
_gtk_cell_area_box_context_sum (GTK_CELL_AREA_BOX_CONTEXT (context), GTK_ORIENTATION_VERTICAL,
|
2010-12-18 00:14:35 +00:00
|
|
|
width, minimum_height, natural_height);
|
2010-12-12 15:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_preferred_width_for_height (GtkCellAreaContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int height,
|
|
|
|
int *minimum_width,
|
|
|
|
int *natural_width)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
2022-10-20 11:23:13 +00:00
|
|
|
_gtk_cell_area_box_context_sum (GTK_CELL_AREA_BOX_CONTEXT (context), GTK_ORIENTATION_HORIZONTAL,
|
2010-12-18 00:14:35 +00:00
|
|
|
height, minimum_width, natural_width);
|
2010-11-28 09:52:08 +00:00
|
|
|
}
|
2010-11-25 07:09:51 +00:00
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
/*************************************************************
|
|
|
|
* API *
|
|
|
|
*************************************************************/
|
2010-12-12 15:18:00 +00:00
|
|
|
static void
|
|
|
|
copy_size_array (GArray *src_array,
|
2010-12-18 00:14:35 +00:00
|
|
|
GArray *dest_array)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2010-12-12 15:18:00 +00:00
|
|
|
|
|
|
|
for (i = 0; i < src_array->len; i++)
|
|
|
|
{
|
|
|
|
CachedSize *src = &g_array_index (src_array, CachedSize, i);
|
|
|
|
CachedSize *dest = &g_array_index (dest_array, CachedSize, i);
|
|
|
|
|
|
|
|
memcpy (dest, src, sizeof (CachedSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
for_size_copy (gpointer key,
|
2010-12-18 00:14:35 +00:00
|
|
|
GArray *size_array,
|
|
|
|
GHashTable *dest_hash)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
|
|
|
GArray *new_array;
|
|
|
|
|
|
|
|
new_array = g_array_new (FALSE, TRUE, sizeof (CachedSize));
|
|
|
|
g_array_set_size (new_array, size_array->len);
|
|
|
|
|
|
|
|
copy_size_array (size_array, new_array);
|
|
|
|
|
|
|
|
g_hash_table_insert (dest_hash, key, new_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCellAreaBoxContext *
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_copy (GtkCellAreaBox *box,
|
2010-12-18 00:14:35 +00:00
|
|
|
GtkCellAreaBoxContext *context)
|
2010-12-12 15:18:00 +00:00
|
|
|
{
|
2010-12-13 06:37:12 +00:00
|
|
|
GtkCellAreaBoxContext *copy;
|
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
copy = g_object_new (GTK_TYPE_CELL_AREA_BOX_CONTEXT,
|
|
|
|
"area", box, NULL);
|
2010-12-13 06:37:12 +00:00
|
|
|
|
2011-02-09 04:18:22 +00:00
|
|
|
_gtk_cell_area_box_init_groups (copy,
|
|
|
|
context->priv->base_widths->len,
|
|
|
|
context->priv->expand,
|
|
|
|
context->priv->align);
|
2010-12-13 06:37:12 +00:00
|
|
|
|
|
|
|
/* Copy the base arrays */
|
2010-12-18 00:14:35 +00:00
|
|
|
copy_size_array (context->priv->base_widths,
|
|
|
|
copy->priv->base_widths);
|
|
|
|
copy_size_array (context->priv->base_heights,
|
|
|
|
copy->priv->base_heights);
|
2010-12-13 06:37:12 +00:00
|
|
|
|
|
|
|
/* Copy each for size */
|
|
|
|
g_hash_table_foreach (context->priv->heights,
|
2010-12-18 00:14:35 +00:00
|
|
|
(GHFunc)for_size_copy, copy->priv->heights);
|
2010-12-13 06:37:12 +00:00
|
|
|
g_hash_table_foreach (context->priv->widths,
|
2010-12-18 00:14:35 +00:00
|
|
|
(GHFunc)for_size_copy, copy->priv->widths);
|
2010-12-13 06:37:12 +00:00
|
|
|
|
2010-12-12 15:18:00 +00:00
|
|
|
|
2010-12-13 07:27:36 +00:00
|
|
|
return copy;
|
2010-12-12 15:18:00 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
void
|
2011-02-09 04:18:22 +00:00
|
|
|
_gtk_cell_area_box_init_groups (GtkCellAreaBoxContext *box_context,
|
|
|
|
guint n_groups,
|
|
|
|
gboolean *expand_groups,
|
|
|
|
gboolean *align_groups)
|
2010-10-31 04:06:10 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2021-02-04 19:20:10 +00:00
|
|
|
gsize groups_size;
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-11-08 08:43:27 +00:00
|
|
|
g_return_if_fail (n_groups == 0 || expand_groups != NULL);
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-12-18 00:14:35 +00:00
|
|
|
/* When the group dimensions change, all info must be reset
|
2010-11-26 12:26:24 +00:00
|
|
|
* Note this already clears the min/nat values on the CachedSizes
|
2010-10-31 04:06:10 +00:00
|
|
|
*/
|
2010-11-27 07:05:14 +00:00
|
|
|
gtk_cell_area_context_reset (GTK_CELL_AREA_CONTEXT (box_context));
|
2010-10-31 04:06:10 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_array_set_size (priv->base_widths, n_groups);
|
|
|
|
g_array_set_size (priv->base_heights, n_groups);
|
|
|
|
|
2021-02-04 19:20:10 +00:00
|
|
|
groups_size = n_groups * sizeof (gboolean);
|
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
g_free (priv->expand);
|
2021-02-04 19:20:10 +00:00
|
|
|
priv->expand = g_memdup2 (expand_groups, groups_size);
|
2010-12-21 12:11:01 +00:00
|
|
|
|
|
|
|
g_free (priv->align);
|
2021-02-04 19:20:10 +00:00
|
|
|
priv->align = g_memdup2 (align_groups, groups_size);
|
2010-10-31 04:06:10 +00:00
|
|
|
}
|
2010-10-26 09:22:59 +00:00
|
|
|
|
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_width (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int minimum_width,
|
|
|
|
int natural_width)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-11-26 12:26:24 +00:00
|
|
|
CachedSize *size;
|
2010-11-28 09:52:08 +00:00
|
|
|
gboolean grew = FALSE;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
size = &g_array_index (priv->base_widths, CachedSize, group_idx);
|
2010-11-28 09:52:08 +00:00
|
|
|
if (minimum_width > size->min_size)
|
|
|
|
{
|
|
|
|
size->min_size = minimum_width;
|
|
|
|
grew = TRUE;
|
|
|
|
}
|
|
|
|
if (natural_width > size->nat_size)
|
|
|
|
{
|
|
|
|
size->nat_size = natural_width;
|
|
|
|
grew = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grew)
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_sum (box_context, GTK_ORIENTATION_HORIZONTAL, -1, NULL, NULL);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_height_for_width (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int for_width,
|
|
|
|
int minimum_height,
|
|
|
|
int natural_height)
|
2010-11-26 04:23:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
GArray *group_array;
|
|
|
|
CachedSize *size;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
|
|
|
|
|
|
|
priv = box_context->priv;
|
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
|
|
|
|
|
|
|
group_array = g_hash_table_lookup (priv->heights, GINT_TO_POINTER (for_width));
|
|
|
|
if (!group_array)
|
|
|
|
{
|
2010-11-26 12:26:24 +00:00
|
|
|
group_array = group_array_new (box_context);
|
2010-11-26 04:23:01 +00:00
|
|
|
g_hash_table_insert (priv->heights, GINT_TO_POINTER (for_width), group_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = &g_array_index (group_array, CachedSize, group_idx);
|
|
|
|
size->min_size = MAX (size->min_size, minimum_height);
|
|
|
|
size->nat_size = MAX (size->nat_size, natural_height);
|
|
|
|
}
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_height (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int minimum_height,
|
|
|
|
int natural_height)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-11-26 12:26:24 +00:00
|
|
|
CachedSize *size;
|
2010-11-28 09:52:08 +00:00
|
|
|
gboolean grew = FALSE;
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_heights->len);
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
size = &g_array_index (priv->base_heights, CachedSize, group_idx);
|
2010-11-28 09:52:08 +00:00
|
|
|
if (minimum_height > size->min_size)
|
|
|
|
{
|
|
|
|
size->min_size = minimum_height;
|
|
|
|
grew = TRUE;
|
|
|
|
}
|
|
|
|
if (natural_height > size->nat_size)
|
|
|
|
{
|
|
|
|
size->nat_size = natural_height;
|
|
|
|
grew = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grew)
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_sum (box_context, GTK_ORIENTATION_VERTICAL, -1, NULL, NULL);
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_push_group_width_for_height (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int for_height,
|
|
|
|
int minimum_width,
|
|
|
|
int natural_width)
|
2010-11-26 04:23:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-11-26 12:26:24 +00:00
|
|
|
GArray *group_array;
|
|
|
|
CachedSize *size;
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
|
|
|
|
|
|
|
priv = box_context->priv;
|
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
|
|
|
|
|
|
|
group_array = g_hash_table_lookup (priv->widths, GINT_TO_POINTER (for_height));
|
|
|
|
if (!group_array)
|
|
|
|
{
|
2010-11-26 12:26:24 +00:00
|
|
|
group_array = group_array_new (box_context);
|
2010-11-26 04:23:01 +00:00
|
|
|
g_hash_table_insert (priv->widths, GINT_TO_POINTER (for_height), group_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = &g_array_index (group_array, CachedSize, group_idx);
|
|
|
|
size->min_size = MAX (size->min_size, minimum_width);
|
|
|
|
size->nat_size = MAX (size->nat_size, natural_width);
|
|
|
|
}
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_group_width (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int *minimum_width,
|
|
|
|
int *natural_width)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-11-26 12:26:24 +00:00
|
|
|
CachedSize *size;
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
size = &g_array_index (priv->base_widths, CachedSize, group_idx);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (minimum_width)
|
|
|
|
*minimum_width = size->min_size;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (natural_width)
|
|
|
|
*natural_width = size->nat_size;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_group_height_for_width (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int for_width,
|
|
|
|
int *minimum_height,
|
|
|
|
int *natural_height)
|
2010-11-26 04:23:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
GArray *group_array;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
|
|
|
|
|
|
|
priv = box_context->priv;
|
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
|
|
|
|
|
|
|
group_array = g_hash_table_lookup (priv->heights, GINT_TO_POINTER (for_width));
|
|
|
|
|
|
|
|
if (group_array)
|
|
|
|
{
|
|
|
|
CachedSize *size = &g_array_index (group_array, CachedSize, group_idx);
|
|
|
|
|
|
|
|
if (minimum_height)
|
2010-12-18 00:14:35 +00:00
|
|
|
*minimum_height = size->min_size;
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
if (natural_height)
|
2010-12-18 00:14:35 +00:00
|
|
|
*natural_height = size->nat_size;
|
2010-11-26 04:23:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (minimum_height)
|
2010-12-18 00:14:35 +00:00
|
|
|
*minimum_height = -1;
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
if (natural_height)
|
2010-12-18 00:14:35 +00:00
|
|
|
*natural_height = -1;
|
2010-11-26 04:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 09:22:59 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_group_height (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int *minimum_height,
|
|
|
|
int *natural_height)
|
2010-10-26 09:22:59 +00:00
|
|
|
{
|
2010-11-13 07:23:01 +00:00
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
2010-11-26 12:26:24 +00:00
|
|
|
CachedSize *size;
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
2010-10-26 09:22:59 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv = box_context->priv;
|
2010-10-31 04:06:10 +00:00
|
|
|
g_return_if_fail (group_idx < priv->base_heights->len);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-11-26 12:26:24 +00:00
|
|
|
size = &g_array_index (priv->base_heights, CachedSize, group_idx);
|
2010-10-26 14:01:17 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (minimum_height)
|
|
|
|
*minimum_height = size->min_size;
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-10-31 04:06:10 +00:00
|
|
|
if (natural_height)
|
|
|
|
*natural_height = size->nat_size;
|
2010-10-26 09:22:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 04:23:01 +00:00
|
|
|
void
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_group_width_for_height (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int group_idx,
|
|
|
|
int for_height,
|
|
|
|
int *minimum_width,
|
|
|
|
int *natural_width)
|
2010-11-26 04:23:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv;
|
|
|
|
GArray *group_array;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CELL_AREA_BOX_CONTEXT (box_context));
|
|
|
|
|
|
|
|
priv = box_context->priv;
|
|
|
|
g_return_if_fail (group_idx < priv->base_widths->len);
|
|
|
|
|
|
|
|
group_array = g_hash_table_lookup (priv->widths, GINT_TO_POINTER (for_height));
|
|
|
|
|
|
|
|
if (group_array)
|
|
|
|
{
|
|
|
|
CachedSize *size = &g_array_index (group_array, CachedSize, group_idx);
|
|
|
|
|
|
|
|
if (minimum_width)
|
2010-12-18 00:14:35 +00:00
|
|
|
*minimum_width = size->min_size;
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
if (natural_width)
|
2010-12-18 00:14:35 +00:00
|
|
|
*natural_width = size->nat_size;
|
2010-11-26 04:23:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (minimum_width)
|
2010-12-18 00:14:35 +00:00
|
|
|
*minimum_width = -1;
|
2010-11-26 04:23:01 +00:00
|
|
|
|
|
|
|
if (natural_width)
|
2010-12-18 00:14:35 +00:00
|
|
|
*natural_width = -1;
|
2010-11-26 04:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
static GtkRequestedSize *
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_requests (GtkCellAreaBoxContext *box_context,
|
2011-02-09 04:18:22 +00:00
|
|
|
GtkCellAreaBox *area,
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int for_size,
|
|
|
|
int *n_requests)
|
2010-12-21 12:11:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = box_context->priv;
|
|
|
|
GtkRequestedSize *requests;
|
|
|
|
GArray *array;
|
|
|
|
CachedSize *size;
|
2020-07-24 13:54:49 +00:00
|
|
|
int visible_groups = 0;
|
|
|
|
int last_aligned_group_idx = 0;
|
|
|
|
int i, j;
|
2010-12-21 12:11:01 +00:00
|
|
|
|
2022-10-20 11:23:13 +00:00
|
|
|
/* Get the last visible aligned group
|
2010-12-21 12:11:01 +00:00
|
|
|
* (we need to get space at least up till this group) */
|
|
|
|
for (i = priv->base_widths->len - 1; i >= 0; i--)
|
|
|
|
{
|
2022-10-20 11:23:13 +00:00
|
|
|
if (priv->align[i] &&
|
2011-02-09 04:18:22 +00:00
|
|
|
_gtk_cell_area_box_group_visible (area, i))
|
|
|
|
break;
|
2010-12-21 12:11:01 +00:00
|
|
|
}
|
|
|
|
last_aligned_group_idx = i >= 0 ? i : 0;
|
|
|
|
|
|
|
|
priv = box_context->priv;
|
|
|
|
array = get_array (box_context, orientation, for_size);
|
|
|
|
|
|
|
|
for (i = 0; i < array->len; i++)
|
|
|
|
{
|
|
|
|
size = &g_array_index (array, CachedSize, i);
|
|
|
|
|
|
|
|
if (size->nat_size > 0 &&
|
2011-02-09 04:18:22 +00:00
|
|
|
(i <= last_aligned_group_idx ||
|
|
|
|
_gtk_cell_area_box_group_visible (area, i)))
|
|
|
|
visible_groups++;
|
2010-12-21 12:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requests = g_new (GtkRequestedSize, visible_groups);
|
|
|
|
|
|
|
|
for (j = 0, i = 0; i < array->len; i++)
|
|
|
|
{
|
|
|
|
size = &g_array_index (array, CachedSize, i);
|
|
|
|
|
|
|
|
if (size->nat_size > 0 &&
|
2011-02-09 04:18:22 +00:00
|
|
|
(i <= last_aligned_group_idx ||
|
|
|
|
_gtk_cell_area_box_group_visible (area, i)))
|
2010-12-21 12:11:01 +00:00
|
|
|
{
|
|
|
|
requests[j].data = GINT_TO_POINTER (i);
|
|
|
|
requests[j].minimum_size = size->min_size;
|
|
|
|
requests[j].natural_size = size->nat_size;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_requests)
|
|
|
|
*n_requests = visible_groups;
|
|
|
|
|
|
|
|
return requests;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCellAreaBoxAllocation *
|
|
|
|
allocate_for_orientation (GtkCellAreaBoxContext *context,
|
2011-02-09 04:18:22 +00:00
|
|
|
GtkCellAreaBox *area,
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkOrientation orientation,
|
2020-07-24 13:54:49 +00:00
|
|
|
int spacing,
|
|
|
|
int size,
|
|
|
|
int for_size,
|
|
|
|
int *n_allocs)
|
2010-12-21 12:11:01 +00:00
|
|
|
{
|
|
|
|
GtkCellAreaBoxContextPrivate *priv = context->priv;
|
|
|
|
GtkCellAreaBoxAllocation *allocs;
|
|
|
|
GtkRequestedSize *sizes;
|
2020-07-24 13:54:49 +00:00
|
|
|
int n_expand_groups = 0;
|
|
|
|
int i, n_groups, position, vis_position;
|
|
|
|
int extra_size, extra_extra;
|
|
|
|
int avail_size = size;
|
2010-12-21 12:11:01 +00:00
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
sizes = _gtk_cell_area_box_context_get_requests (context, area, orientation, for_size, &n_groups);
|
2010-12-21 12:11:01 +00:00
|
|
|
n_expand_groups = count_expand_groups (context);
|
|
|
|
|
|
|
|
/* First start by naturally allocating space among groups */
|
|
|
|
avail_size -= (n_groups - 1) * spacing;
|
|
|
|
for (i = 0; i < n_groups; i++)
|
|
|
|
avail_size -= sizes[i].minimum_size;
|
|
|
|
|
|
|
|
if (avail_size > 0)
|
|
|
|
avail_size = gtk_distribute_natural_allocation (avail_size, n_groups, sizes);
|
|
|
|
else
|
|
|
|
avail_size = 0;
|
|
|
|
|
|
|
|
/* Calculate/distribute expand for groups */
|
|
|
|
if (n_expand_groups > 0)
|
|
|
|
{
|
|
|
|
extra_size = avail_size / n_expand_groups;
|
|
|
|
extra_extra = avail_size % n_expand_groups;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
extra_size = extra_extra = 0;
|
|
|
|
|
|
|
|
allocs = g_new (GtkCellAreaBoxAllocation, n_groups);
|
|
|
|
|
|
|
|
for (vis_position = 0, position = 0, i = 0; i < n_groups; i++)
|
|
|
|
{
|
|
|
|
allocs[i].group_idx = GPOINTER_TO_INT (sizes[i].data);
|
|
|
|
|
|
|
|
if (priv->align[allocs[i].group_idx])
|
2011-02-09 04:18:22 +00:00
|
|
|
vis_position = position;
|
2010-12-21 12:11:01 +00:00
|
|
|
|
|
|
|
allocs[i].position = vis_position;
|
|
|
|
allocs[i].size = sizes[i].minimum_size;
|
|
|
|
|
|
|
|
if (group_expands (context, allocs[i].group_idx))
|
|
|
|
{
|
|
|
|
allocs[i].size += extra_size;
|
|
|
|
if (extra_extra)
|
|
|
|
{
|
|
|
|
allocs[i].size++;
|
|
|
|
extra_extra--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
position += allocs[i].size;
|
|
|
|
position += spacing;
|
|
|
|
|
|
|
|
if (_gtk_cell_area_box_group_visible (area, allocs[i].group_idx))
|
2011-02-09 04:18:22 +00:00
|
|
|
{
|
|
|
|
vis_position += allocs[i].size;
|
|
|
|
vis_position += spacing;
|
|
|
|
}
|
2010-12-21 12:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n_allocs)
|
|
|
|
*n_allocs = n_groups;
|
|
|
|
|
|
|
|
g_free (sizes);
|
|
|
|
|
|
|
|
return allocs;
|
|
|
|
}
|
|
|
|
|
2010-10-30 08:32:15 +00:00
|
|
|
GtkRequestedSize *
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_widths (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *n_widths)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkCellAreaBox *area = (GtkCellAreaBox *)gtk_cell_area_context_get_area (GTK_CELL_AREA_CONTEXT (box_context));
|
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
return _gtk_cell_area_box_context_get_requests (box_context, area, GTK_ORIENTATION_HORIZONTAL, -1, n_widths);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkRequestedSize *
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_heights (GtkCellAreaBoxContext *box_context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *n_heights)
|
2010-10-30 08:32:15 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkCellAreaBox *area = (GtkCellAreaBox *)gtk_cell_area_context_get_area (GTK_CELL_AREA_CONTEXT (box_context));
|
|
|
|
|
2011-01-11 15:40:35 +00:00
|
|
|
return _gtk_cell_area_box_context_get_requests (box_context, area, GTK_ORIENTATION_VERTICAL, -1, n_heights);
|
2010-10-30 08:32:15 +00:00
|
|
|
}
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-11-25 07:09:51 +00:00
|
|
|
GtkCellAreaBoxAllocation *
|
2011-01-11 15:40:35 +00:00
|
|
|
_gtk_cell_area_box_context_get_orientation_allocs (GtkCellAreaBoxContext *context,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *n_allocs)
|
2010-10-30 14:06:26 +00:00
|
|
|
{
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkCellAreaContext *ctx = GTK_CELL_AREA_CONTEXT (context);
|
|
|
|
GtkCellAreaBox *area;
|
|
|
|
GtkOrientation orientation;
|
2020-07-24 13:54:49 +00:00
|
|
|
int spacing, width, height, alloc_count = 0;
|
2010-12-21 12:11:01 +00:00
|
|
|
GtkCellAreaBoxAllocation *allocs = NULL;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
area = (GtkCellAreaBox *)gtk_cell_area_context_get_area (ctx);
|
|
|
|
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
|
|
|
|
spacing = gtk_cell_area_box_get_spacing (area);
|
2010-12-18 00:14:35 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
gtk_cell_area_context_get_allocation (ctx, &width, &height);
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL && width > 0)
|
2022-10-20 11:23:13 +00:00
|
|
|
allocs = allocate_for_orientation (context, area, orientation,
|
2011-02-09 04:18:22 +00:00
|
|
|
spacing, width, height,
|
|
|
|
&alloc_count);
|
2010-12-21 12:11:01 +00:00
|
|
|
else if (orientation == GTK_ORIENTATION_VERTICAL && height > 0)
|
2022-10-20 11:23:13 +00:00
|
|
|
allocs = allocate_for_orientation (context, area, orientation,
|
2011-02-09 04:18:22 +00:00
|
|
|
spacing, height, width,
|
|
|
|
&alloc_count);
|
2010-12-21 12:11:01 +00:00
|
|
|
|
|
|
|
*n_allocs = alloc_count;
|
2010-10-30 14:06:26 +00:00
|
|
|
|
2010-12-21 12:11:01 +00:00
|
|
|
return allocs;
|
2010-10-30 14:06:26 +00:00
|
|
|
}
|