2015-12-23 03:09:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkboxgadgetprivate.h"
|
|
|
|
|
|
|
|
#include "gtkcssnodeprivate.h"
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtksizerequest.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
|
|
|
|
2016-01-13 04:57:35 +00:00
|
|
|
/* GtkBoxGadget is a container gadget implementation that arranges its
|
|
|
|
* children in a row, either horizontally or vertically. Children can
|
|
|
|
* be either widgets or gadgets, and can be set to expand horizontally
|
|
|
|
* or vertically, or both.
|
|
|
|
*/
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
typedef struct _GtkBoxGadgetPrivate GtkBoxGadgetPrivate;
|
|
|
|
struct _GtkBoxGadgetPrivate {
|
|
|
|
GtkOrientation orientation;
|
|
|
|
GArray *children;
|
2016-02-27 02:56:07 +00:00
|
|
|
|
2016-04-29 01:27:02 +00:00
|
|
|
guint draw_focus : 1;
|
|
|
|
guint draw_reverse : 1;
|
2016-03-04 02:24:20 +00:00
|
|
|
guint allocate_reverse : 1;
|
2016-04-29 01:27:02 +00:00
|
|
|
guint align_reverse : 1;
|
2015-12-23 03:09:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
|
|
|
|
|
|
|
|
typedef struct _GtkBoxGadgetChild GtkBoxGadgetChild;
|
|
|
|
struct _GtkBoxGadgetChild {
|
|
|
|
GObject *object;
|
2016-04-29 01:55:52 +00:00
|
|
|
gboolean expand;
|
2016-01-15 11:47:31 +00:00
|
|
|
GtkAlign align;
|
2015-12-23 03:09:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkBoxGadget, gtk_box_gadget, GTK_TYPE_CSS_GADGET,
|
|
|
|
G_ADD_PRIVATE (GtkBoxGadget))
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_box_gadget_child_is_visible (GObject *child)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
return gtk_widget_get_visible (GTK_WIDGET (child));
|
|
|
|
else
|
|
|
|
return gtk_css_gadget_get_visible (GTK_CSS_GADGET (child));
|
|
|
|
}
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_box_gadget_child_compute_expand (GtkBoxGadget *gadget,
|
|
|
|
GtkBoxGadgetChild *child)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
|
|
|
|
if (child->expand)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (child->object))
|
|
|
|
return gtk_widget_compute_expand (GTK_WIDGET (child->object), priv->orientation);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-01-15 11:47:31 +00:00
|
|
|
static GtkAlign
|
|
|
|
gtk_box_gadget_child_get_align (GtkBoxGadget *gadget,
|
|
|
|
GtkBoxGadgetChild *child)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
GtkAlign align;
|
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (child->object))
|
|
|
|
{
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
g_object_get (child->object, "valign", &align, NULL);
|
|
|
|
else
|
|
|
|
g_object_get (child->object, "halign", &align, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
align = child->align;
|
|
|
|
|
|
|
|
return align;
|
|
|
|
}
|
|
|
|
|
2016-04-29 01:27:02 +00:00
|
|
|
static GtkAlign
|
|
|
|
effective_align (GtkAlign align,
|
|
|
|
gboolean reverse)
|
|
|
|
{
|
|
|
|
switch (align)
|
|
|
|
{
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
return reverse ? GTK_ALIGN_END : GTK_ALIGN_START;
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
return reverse ? GTK_ALIGN_START : GTK_ALIGN_END;
|
|
|
|
default:
|
|
|
|
return align;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
static void
|
|
|
|
gtk_box_gadget_measure_child (GObject *child,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
{
|
2016-10-22 14:06:14 +00:00
|
|
|
gtk_widget_measure (GTK_WIDGET (child),
|
|
|
|
orientation,
|
|
|
|
for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_css_gadget_get_preferred_size (GTK_CSS_GADGET (child),
|
|
|
|
orientation,
|
|
|
|
for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_distribute (GtkBoxGadget *gadget,
|
2016-01-22 22:10:41 +00:00
|
|
|
gint for_size,
|
2015-12-23 03:09:30 +00:00
|
|
|
gint size,
|
|
|
|
GtkRequestedSize *sizes)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
guint i, n_expand;
|
|
|
|
|
|
|
|
n_expand = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < priv->children->len; i++)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
|
|
|
|
gtk_box_gadget_measure_child (child->object,
|
|
|
|
priv->orientation,
|
2016-01-22 22:10:41 +00:00
|
|
|
for_size,
|
2015-12-23 03:09:30 +00:00
|
|
|
&sizes[i].minimum_size, &sizes[i].natural_size,
|
|
|
|
NULL, NULL);
|
|
|
|
if (gtk_box_gadget_child_is_visible (child->object) &&
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_child_compute_expand (gadget, child))
|
2015-12-23 03:09:30 +00:00
|
|
|
n_expand++;
|
|
|
|
size -= sizes[i].minimum_size;
|
|
|
|
}
|
|
|
|
|
2016-01-27 03:11:54 +00:00
|
|
|
if G_UNLIKELY (size < 0)
|
|
|
|
{
|
|
|
|
g_critical ("%s: assertion 'size >= 0' failed in %s", G_STRFUNC, G_OBJECT_TYPE_NAME (gtk_css_gadget_get_owner (GTK_CSS_GADGET (gadget))));
|
|
|
|
return;
|
|
|
|
}
|
2015-12-23 03:09:30 +00:00
|
|
|
|
|
|
|
size = gtk_distribute_natural_allocation (size, priv->children->len, sizes);
|
|
|
|
|
|
|
|
if (size <= 0 || n_expand == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0 ; i < priv->children->len; i++)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
|
|
|
|
if (!gtk_box_gadget_child_is_visible (child->object) ||
|
2016-04-29 01:55:52 +00:00
|
|
|
!gtk_box_gadget_child_compute_expand (gadget, child))
|
2015-12-23 03:09:30 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sizes[i].minimum_size += size / n_expand;
|
|
|
|
/* distribute all pixels, even if there's a remainder */
|
|
|
|
size -= size / n_expand;
|
|
|
|
n_expand--;
|
|
|
|
}
|
2016-01-22 22:10:41 +00:00
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_measure_orientation (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
gint child_min, child_nat;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
*minimum = 0;
|
|
|
|
*natural = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < priv->children->len; i++)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
|
|
|
|
gtk_box_gadget_measure_child (child->object,
|
|
|
|
orientation,
|
|
|
|
for_size,
|
|
|
|
&child_min, &child_nat,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
*minimum += child_min;
|
|
|
|
*natural += child_nat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_measure_opposite (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
int child_min, child_nat, child_min_baseline, child_nat_baseline;
|
|
|
|
int total_min, above_min, below_min, total_nat, above_nat, below_nat;
|
|
|
|
GtkRequestedSize *sizes;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (for_size >= 0)
|
|
|
|
{
|
|
|
|
sizes = g_newa (GtkRequestedSize, priv->children->len);
|
2016-01-22 22:10:41 +00:00
|
|
|
gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), -1, for_size, sizes);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
above_min = below_min = above_nat = below_nat = -1;
|
|
|
|
total_min = total_nat = 0;
|
|
|
|
|
|
|
|
for (i = 0 ; i < priv->children->len; i++)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
|
|
|
|
gtk_box_gadget_measure_child (child->object,
|
|
|
|
orientation,
|
2016-01-23 03:08:38 +00:00
|
|
|
for_size >= 0 ? sizes[i].minimum_size : -1,
|
2015-12-23 03:09:30 +00:00
|
|
|
&child_min, &child_nat,
|
|
|
|
&child_min_baseline, &child_nat_baseline);
|
|
|
|
|
|
|
|
if (child_min_baseline >= 0)
|
|
|
|
{
|
2016-01-23 03:47:47 +00:00
|
|
|
below_min = MAX (below_min, child_min - child_min_baseline);
|
|
|
|
above_min = MAX (above_min, child_min_baseline);
|
|
|
|
below_nat = MAX (below_nat, child_nat - child_nat_baseline);
|
|
|
|
above_nat = MAX (above_nat, child_nat_baseline);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
total_min = MAX (total_min, child_min);
|
|
|
|
total_nat = MAX (total_nat, child_nat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (above_min >= 0)
|
|
|
|
{
|
|
|
|
total_min = MAX (total_min, above_min + below_min);
|
|
|
|
total_nat = MAX (total_nat, above_nat + below_nat);
|
|
|
|
/* assume GTK_BASELINE_POSITION_CENTER for now */
|
2016-01-18 00:48:40 +00:00
|
|
|
if (minimum_baseline)
|
|
|
|
*minimum_baseline = above_min + (total_min - (above_min + below_min)) / 2;
|
|
|
|
if (natural_baseline)
|
|
|
|
*natural_baseline = above_nat + (total_nat - (above_nat + below_nat)) / 2;
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*minimum = total_min;
|
|
|
|
*natural = total_nat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_get_preferred_size (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
|
|
|
|
if (priv->orientation == orientation)
|
|
|
|
gtk_box_gadget_measure_orientation (gadget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline);
|
|
|
|
else
|
|
|
|
gtk_box_gadget_measure_opposite (gadget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_allocate_child (GObject *child,
|
2016-01-23 03:08:38 +00:00
|
|
|
GtkOrientation box_orientation,
|
|
|
|
GtkAlign child_align,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
{
|
2016-01-23 03:08:38 +00:00
|
|
|
gtk_widget_size_allocate_with_baseline (GTK_WIDGET (child), allocation, baseline);
|
2015-12-23 03:09:30 +00:00
|
|
|
gtk_widget_get_clip (GTK_WIDGET (child), out_clip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-23 03:08:38 +00:00
|
|
|
GtkAllocation child_allocation;
|
|
|
|
int minimum, natural;
|
|
|
|
int minimum_baseline, natural_baseline;
|
|
|
|
|
|
|
|
if (box_orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
child_allocation.width = allocation->width;
|
|
|
|
child_allocation.x = allocation->x;
|
|
|
|
|
|
|
|
gtk_css_gadget_get_preferred_size (GTK_CSS_GADGET (child),
|
|
|
|
GTK_ORIENTATION_VERTICAL,
|
|
|
|
allocation->width,
|
|
|
|
&minimum, &natural,
|
|
|
|
&minimum_baseline, &natural_baseline);
|
2016-04-29 01:27:02 +00:00
|
|
|
|
2016-01-23 03:08:38 +00:00
|
|
|
switch (child_align)
|
|
|
|
{
|
|
|
|
case GTK_ALIGN_FILL:
|
|
|
|
child_allocation.height = allocation->height;
|
|
|
|
child_allocation.y = allocation->y;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
child_allocation.height = MIN(natural, allocation->height);
|
|
|
|
child_allocation.y = allocation->y;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
child_allocation.height = MIN(natural, allocation->height);
|
|
|
|
child_allocation.y = allocation->y + allocation->height - child_allocation.height;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_BASELINE:
|
|
|
|
if (minimum_baseline >= 0 && baseline >= 0)
|
|
|
|
{
|
|
|
|
child_allocation.height = MIN(natural, allocation->height);
|
2016-01-23 03:49:01 +00:00
|
|
|
child_allocation.y = allocation->y + MAX(0, baseline - minimum_baseline);
|
2016-01-23 03:08:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GTK_ALIGN_CENTER:
|
|
|
|
child_allocation.height = MIN(natural, allocation->height);
|
|
|
|
child_allocation.y = allocation->y + (allocation->height - child_allocation.height) / 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child_allocation.height = allocation->height;
|
|
|
|
child_allocation.y = allocation->y;
|
|
|
|
|
|
|
|
gtk_css_gadget_get_preferred_size (GTK_CSS_GADGET (child),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
allocation->height,
|
|
|
|
&minimum, &natural,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
switch (child_align)
|
|
|
|
{
|
|
|
|
case GTK_ALIGN_FILL:
|
|
|
|
child_allocation.width = allocation->width;
|
|
|
|
child_allocation.x = allocation->x;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
child_allocation.width = MIN(natural, allocation->width);
|
|
|
|
child_allocation.x = allocation->x;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
child_allocation.width = MIN(natural, allocation->width);
|
|
|
|
child_allocation.x = allocation->x + allocation->width - child_allocation.width;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_BASELINE:
|
|
|
|
case GTK_ALIGN_CENTER:
|
|
|
|
child_allocation.width = MIN(natural, allocation->width);
|
|
|
|
child_allocation.x = allocation->x + (allocation->width - child_allocation.width) / 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_css_gadget_allocate (GTK_CSS_GADGET (child), &child_allocation, baseline, out_clip);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_allocate (GtkCssGadget *gadget,
|
|
|
|
const GtkAllocation *allocation,
|
|
|
|
int baseline,
|
|
|
|
GtkAllocation *out_clip)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
GtkRequestedSize *sizes;
|
|
|
|
GtkAllocation child_allocation, child_clip;
|
2016-01-23 03:08:38 +00:00
|
|
|
GtkAlign child_align;
|
2015-12-23 03:09:30 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
child_allocation = *allocation;
|
|
|
|
sizes = g_newa (GtkRequestedSize, priv->children->len);
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2016-01-22 22:10:41 +00:00
|
|
|
gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->height, allocation->width, sizes);
|
2016-01-15 11:47:31 +00:00
|
|
|
|
2016-03-04 02:24:20 +00:00
|
|
|
if (priv->allocate_reverse)
|
|
|
|
child_allocation.x = allocation->x + allocation->width;
|
|
|
|
|
2016-01-15 11:47:31 +00:00
|
|
|
for (i = 0; i < priv->children->len; i++)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
2016-03-04 02:24:20 +00:00
|
|
|
guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
|
|
|
|
child_allocation.width = sizes[idx].minimum_size;
|
2016-01-23 03:08:38 +00:00
|
|
|
child_allocation.height = allocation->height;
|
|
|
|
child_allocation.y = allocation->y;
|
2016-03-04 02:24:20 +00:00
|
|
|
if (priv->allocate_reverse)
|
|
|
|
child_allocation.x -= child_allocation.width;
|
2016-01-23 03:08:38 +00:00
|
|
|
|
|
|
|
child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
|
|
|
|
gtk_box_gadget_allocate_child (child->object,
|
|
|
|
priv->orientation,
|
2016-04-29 01:27:02 +00:00
|
|
|
effective_align (child_align, priv->align_reverse),
|
2016-01-23 03:08:38 +00:00
|
|
|
&child_allocation,
|
|
|
|
baseline,
|
|
|
|
&child_clip);
|
2016-01-15 11:47:31 +00:00
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
if (i == 0)
|
|
|
|
*out_clip = child_clip;
|
|
|
|
else
|
|
|
|
gdk_rectangle_union (out_clip, &child_clip, out_clip);
|
2016-01-23 03:08:38 +00:00
|
|
|
|
2016-03-04 02:24:20 +00:00
|
|
|
if (!priv->allocate_reverse)
|
|
|
|
child_allocation.x += sizes[idx].minimum_size;
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-22 22:10:41 +00:00
|
|
|
gtk_box_gadget_distribute (GTK_BOX_GADGET (gadget), allocation->width, allocation->height, sizes);
|
2016-01-15 11:47:31 +00:00
|
|
|
|
2016-03-04 02:24:20 +00:00
|
|
|
if (priv->allocate_reverse)
|
|
|
|
child_allocation.y = allocation->y + allocation->height;
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
for (i = 0 ; i < priv->children->len; i++)
|
|
|
|
{
|
2016-03-04 02:24:20 +00:00
|
|
|
guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i;
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, idx);
|
|
|
|
child_allocation.height = sizes[idx].minimum_size;
|
2016-01-23 03:08:38 +00:00
|
|
|
child_allocation.width = allocation->width;
|
|
|
|
child_allocation.x = allocation->x;
|
2016-03-04 02:24:20 +00:00
|
|
|
if (priv->allocate_reverse)
|
|
|
|
child_allocation.y -= child_allocation.height;
|
2016-01-15 11:47:31 +00:00
|
|
|
|
2016-01-23 03:08:38 +00:00
|
|
|
child_align = gtk_box_gadget_child_get_align (GTK_BOX_GADGET (gadget), child);
|
|
|
|
gtk_box_gadget_allocate_child (child->object,
|
|
|
|
priv->orientation,
|
2016-04-29 01:27:02 +00:00
|
|
|
effective_align (child_align, priv->align_reverse),
|
2016-01-23 03:08:38 +00:00
|
|
|
&child_allocation,
|
|
|
|
-1,
|
|
|
|
&child_clip);
|
2016-01-15 11:47:31 +00:00
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
if (i == 0)
|
|
|
|
*out_clip = child_clip;
|
|
|
|
else
|
|
|
|
gdk_rectangle_union (out_clip, &child_clip, out_clip);
|
2016-01-23 03:08:38 +00:00
|
|
|
|
2016-03-04 02:24:20 +00:00
|
|
|
if (!priv->allocate_reverse)
|
|
|
|
child_allocation.y += sizes[idx].minimum_size;
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_box_gadget_draw (GtkCssGadget *gadget,
|
|
|
|
cairo_t *cr,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
2016-02-20 15:43:54 +00:00
|
|
|
GtkWidget *owner = gtk_css_gadget_get_owner (gadget);
|
2015-12-23 03:09:30 +00:00
|
|
|
guint i;
|
|
|
|
|
2016-02-27 02:56:07 +00:00
|
|
|
for (i = 0; i < priv->children->len; i++)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
2016-02-27 02:56:07 +00:00
|
|
|
guint draw_index = priv->draw_reverse ? priv->children->len - 1 - i : i;
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index);
|
2015-12-23 03:09:30 +00:00
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (child->object))
|
2016-02-20 15:43:54 +00:00
|
|
|
gtk_container_propagate_draw (GTK_CONTAINER (owner), GTK_WIDGET (child->object), cr);
|
2015-12-23 03:09:30 +00:00
|
|
|
else
|
2016-02-20 15:43:54 +00:00
|
|
|
gtk_css_gadget_draw (GTK_CSS_GADGET (child->object), cr);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
2016-02-20 15:43:54 +00:00
|
|
|
if (priv->draw_focus && gtk_widget_has_visible_focus (owner))
|
|
|
|
return TRUE;
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-06 23:33:47 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_box_gadget_has_content (GtkCssGadget *gadget)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
static void
|
|
|
|
gtk_box_gadget_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (object));
|
|
|
|
|
|
|
|
g_array_free (priv->children, TRUE);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_box_gadget_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_class_init (GtkBoxGadgetClass *klass)
|
|
|
|
{
|
|
|
|
GtkCssGadgetClass *gadget_class = GTK_CSS_GADGET_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_box_gadget_finalize;
|
|
|
|
|
|
|
|
gadget_class->get_preferred_size = gtk_box_gadget_get_preferred_size;
|
|
|
|
gadget_class->allocate = gtk_box_gadget_allocate;
|
|
|
|
gadget_class->draw = gtk_box_gadget_draw;
|
2016-08-06 23:33:47 +00:00
|
|
|
gadget_class->has_content = gtk_box_gadget_has_content;
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_clear_child (gpointer data)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = data;
|
|
|
|
|
|
|
|
g_object_unref (child->object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_init (GtkBoxGadget *gadget)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->children = g_array_new (FALSE, FALSE, sizeof (GtkBoxGadgetChild));
|
|
|
|
g_array_set_clear_func (priv->children, gtk_box_gadget_clear_child);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssGadget *
|
|
|
|
gtk_box_gadget_new_for_node (GtkCssNode *node,
|
|
|
|
GtkWidget *owner)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_BOX_GADGET,
|
|
|
|
"node", node,
|
|
|
|
"owner", owner,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssGadget *
|
|
|
|
gtk_box_gadget_new (const char *name,
|
2016-01-13 04:57:35 +00:00
|
|
|
GtkWidget *owner,
|
|
|
|
GtkCssGadget *parent,
|
|
|
|
GtkCssGadget *next_sibling)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
|
|
|
GtkCssNode *node;
|
|
|
|
GtkCssGadget *result;
|
|
|
|
|
|
|
|
node = gtk_css_node_new ();
|
|
|
|
gtk_css_node_set_name (node, g_intern_string (name));
|
|
|
|
if (parent)
|
|
|
|
gtk_css_node_insert_before (gtk_css_gadget_get_node (parent),
|
|
|
|
node,
|
|
|
|
next_sibling ? gtk_css_gadget_get_node (next_sibling) : NULL);
|
|
|
|
|
|
|
|
result = gtk_box_gadget_new_for_node (node, owner);
|
|
|
|
|
|
|
|
g_object_unref (node);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_set_orientation (GtkBoxGadget *gadget,
|
|
|
|
GtkOrientation orientation)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->orientation = orientation;
|
|
|
|
}
|
|
|
|
|
2016-02-20 15:43:54 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_set_draw_focus (GtkBoxGadget *gadget,
|
|
|
|
gboolean draw_focus)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->draw_focus = draw_focus;
|
|
|
|
}
|
|
|
|
|
2016-02-27 02:56:07 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_set_draw_reverse (GtkBoxGadget *gadget,
|
|
|
|
gboolean draw_reverse)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->draw_reverse = draw_reverse;
|
|
|
|
}
|
|
|
|
|
2016-03-04 02:24:20 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_set_allocate_reverse (GtkBoxGadget *gadget,
|
|
|
|
gboolean allocate_reverse)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->allocate_reverse = allocate_reverse;
|
|
|
|
}
|
|
|
|
|
2016-04-29 01:27:02 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_set_align_reverse (GtkBoxGadget *gadget,
|
|
|
|
gboolean align_reverse)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
|
|
|
|
priv->align_reverse = align_reverse;
|
|
|
|
}
|
|
|
|
|
2015-12-25 00:19:31 +00:00
|
|
|
static GtkCssNode *
|
|
|
|
get_css_node (GObject *child)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
return gtk_widget_get_css_node (GTK_WIDGET (child));
|
|
|
|
else
|
|
|
|
return gtk_css_gadget_get_node (GTK_CSS_GADGET (child));
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
static void
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_object (GtkBoxGadget *gadget,
|
|
|
|
int pos,
|
|
|
|
GObject *object,
|
|
|
|
gboolean expand,
|
|
|
|
GtkAlign align)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
GtkBoxGadgetChild child;
|
|
|
|
|
|
|
|
child.object = g_object_ref (object);
|
2016-04-29 01:55:52 +00:00
|
|
|
child.expand = expand;
|
2016-01-15 11:47:31 +00:00
|
|
|
child.align = align;
|
2015-12-23 03:09:30 +00:00
|
|
|
|
|
|
|
if (pos < 0 || pos >= priv->children->len)
|
2015-12-25 00:19:31 +00:00
|
|
|
{
|
|
|
|
g_array_append_val (priv->children, child);
|
|
|
|
gtk_css_node_insert_before (gtk_css_gadget_get_node (GTK_CSS_GADGET (gadget)),
|
|
|
|
get_css_node (object),
|
|
|
|
NULL);
|
|
|
|
}
|
2015-12-23 03:09:30 +00:00
|
|
|
else
|
2015-12-25 00:19:31 +00:00
|
|
|
{
|
|
|
|
g_array_insert_val (priv->children, pos, child);
|
|
|
|
gtk_css_node_insert_before (gtk_css_gadget_get_node (GTK_CSS_GADGET (gadget)),
|
|
|
|
get_css_node (object),
|
|
|
|
get_css_node (g_array_index (priv->children, GtkBoxGadgetChild, pos + 1).object));
|
|
|
|
}
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_widget (GtkBoxGadget *gadget,
|
|
|
|
int pos,
|
|
|
|
GtkWidget *widget)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_object (gadget, pos, G_OBJECT (widget), FALSE, GTK_ALIGN_FILL);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 18:34:15 +00:00
|
|
|
static GtkBoxGadgetChild *
|
|
|
|
gtk_box_gadget_find_object (GtkBoxGadget *gadget,
|
|
|
|
GObject *object,
|
|
|
|
int *position)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->children->len; i++)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
|
|
|
|
if (child->object == object)
|
|
|
|
{
|
2016-02-24 18:34:15 +00:00
|
|
|
if (position)
|
|
|
|
*position = i;
|
|
|
|
return child;
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-24 18:34:15 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_box_gadget_remove_object (GtkBoxGadget *gadget,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
|
|
|
|
GtkBoxGadgetChild *child;
|
|
|
|
int position;
|
|
|
|
|
|
|
|
child = gtk_box_gadget_find_object (gadget, object, &position);
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
gtk_css_node_set_parent (get_css_node (child->object), NULL);
|
|
|
|
g_array_remove_index (priv->children, position);
|
|
|
|
}
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_remove_widget (GtkBoxGadget *gadget,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_box_gadget_remove_object (gadget, G_OBJECT (widget));
|
|
|
|
}
|
|
|
|
|
2016-02-24 20:00:46 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_insert_gadget_before (GtkBoxGadget *gadget,
|
|
|
|
GtkCssGadget *sibling,
|
|
|
|
GtkCssGadget *cssgadget,
|
2016-04-29 01:55:52 +00:00
|
|
|
gboolean expand,
|
2016-02-24 20:00:46 +00:00
|
|
|
GtkAlign align)
|
|
|
|
{
|
|
|
|
/* Insert at the end if no sibling specified */
|
|
|
|
int pos = -1;
|
|
|
|
|
|
|
|
if (sibling)
|
|
|
|
gtk_box_gadget_find_object (gadget, G_OBJECT (sibling), &pos);
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_gadget (gadget, pos, cssgadget, expand, align);
|
2016-02-24 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_insert_gadget_after (GtkBoxGadget *gadget,
|
|
|
|
GtkCssGadget *sibling,
|
|
|
|
GtkCssGadget *cssgadget,
|
2016-04-29 01:55:52 +00:00
|
|
|
gboolean expand,
|
2016-02-24 20:00:46 +00:00
|
|
|
GtkAlign align)
|
|
|
|
{
|
|
|
|
/* Insert at the beginning if no sibling specified */
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
if (sibling && gtk_box_gadget_find_object (gadget, G_OBJECT (sibling), &pos))
|
|
|
|
pos++;
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_gadget (gadget, pos, cssgadget, expand, align);
|
2016-02-24 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 03:09:30 +00:00
|
|
|
void
|
|
|
|
gtk_box_gadget_insert_gadget (GtkBoxGadget *gadget,
|
|
|
|
int pos,
|
|
|
|
GtkCssGadget *cssgadget,
|
2016-04-29 01:55:52 +00:00
|
|
|
gboolean expand,
|
2016-01-15 11:47:31 +00:00
|
|
|
GtkAlign align)
|
2015-12-23 03:09:30 +00:00
|
|
|
{
|
2016-04-29 01:55:52 +00:00
|
|
|
gtk_box_gadget_insert_object (gadget, pos, G_OBJECT (cssgadget), expand, align);
|
2015-12-23 03:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_remove_gadget (GtkBoxGadget *gadget,
|
|
|
|
GtkCssGadget *cssgadget)
|
|
|
|
{
|
|
|
|
gtk_box_gadget_remove_object (gadget, G_OBJECT (cssgadget));
|
|
|
|
}
|
2016-01-18 05:03:39 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_reverse_children (GtkBoxGadget *gadget)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (GTK_BOX_GADGET (gadget));
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
gtk_css_node_reverse_children (gtk_css_gadget_get_node (GTK_CSS_GADGET (gadget)));
|
|
|
|
|
|
|
|
for (i = 0, j = priv->children->len - 1; i < j; i++, j--)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child1 = &g_array_index (priv->children, GtkBoxGadgetChild, i);
|
|
|
|
GtkBoxGadgetChild *child2 = &g_array_index (priv->children, GtkBoxGadgetChild, j);
|
|
|
|
GtkBoxGadgetChild tmp;
|
|
|
|
|
|
|
|
tmp = *child1;
|
|
|
|
*child1 = *child2;
|
|
|
|
*child2 = tmp;
|
|
|
|
}
|
|
|
|
}
|
2016-02-24 18:34:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_set_gadget_expand (GtkBoxGadget *gadget,
|
2016-04-29 01:55:52 +00:00
|
|
|
GObject *object,
|
|
|
|
gboolean expand)
|
2016-02-24 18:34:15 +00:00
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child;
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
child = gtk_box_gadget_find_object (gadget, object, NULL);
|
2016-02-24 18:34:15 +00:00
|
|
|
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
if (child->expand == expand)
|
2016-02-24 18:34:15 +00:00
|
|
|
return;
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
child->expand = expand;
|
2016-02-24 18:34:15 +00:00
|
|
|
gtk_css_gadget_queue_resize (GTK_CSS_GADGET (gadget));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_box_gadget_set_gadget_align (GtkBoxGadget *gadget,
|
2016-04-29 01:55:52 +00:00
|
|
|
GObject *object,
|
2016-02-24 18:34:15 +00:00
|
|
|
GtkAlign align)
|
|
|
|
{
|
|
|
|
GtkBoxGadgetChild *child;
|
|
|
|
|
2016-04-29 01:55:52 +00:00
|
|
|
child = gtk_box_gadget_find_object (gadget, object, NULL);
|
2016-02-24 18:34:15 +00:00
|
|
|
|
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (child->align == align)
|
|
|
|
return;
|
|
|
|
|
|
|
|
child->align = align;
|
|
|
|
gtk_css_gadget_queue_resize (GTK_CSS_GADGET (gadget));
|
|
|
|
}
|