2009-09-29 19:08:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2009-09-10 05:42:25 +00:00
|
|
|
/*
|
|
|
|
* st-box-layout.h: box layout actor
|
|
|
|
*
|
|
|
|
* Copyright 2009 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU Lesser General Public License,
|
|
|
|
* version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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 program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Written by: Thomas Wood <thomas.wood@intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-10-23 14:18:35 +00:00
|
|
|
/* Portions copied from Clutter:
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
* 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 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
/**
|
|
|
|
* SECTION:st-box-layout
|
|
|
|
* @short_description: a layout container arranging children in a single line
|
|
|
|
*
|
|
|
|
* The #StBoxLayout arranges its children along a single line, where each
|
|
|
|
* child can be allocated either its preferred size or larger if the expand
|
|
|
|
* option is set. If the fill option is set, the actor will be allocated more
|
|
|
|
* than its requested size. If the fill option is not set, but the expand option
|
|
|
|
* is enabled, then the position of the actor within the available space can
|
|
|
|
* be determined by the alignment child property.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
#include "st-box-layout.h"
|
|
|
|
|
|
|
|
#include "st-private.h"
|
|
|
|
#include "st-scrollable.h"
|
|
|
|
#include "st-box-layout-child.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void st_box_container_iface_init (ClutterContainerIface *iface);
|
|
|
|
static void st_box_scrollable_interface_init (StScrollableInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (StBoxLayout, st_box_layout, ST_TYPE_WIDGET,
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
|
|
|
|
st_box_container_iface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ST_TYPE_SCROLLABLE,
|
|
|
|
st_box_scrollable_interface_init));
|
|
|
|
|
|
|
|
#define BOX_LAYOUT_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((o), ST_TYPE_BOX_LAYOUT, StBoxLayoutPrivate))
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_VERTICAL,
|
|
|
|
PROP_PACK_START,
|
|
|
|
|
|
|
|
PROP_HADJUST,
|
|
|
|
PROP_VADJUST
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _StBoxLayoutPrivate
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
|
|
|
|
guint spacing;
|
|
|
|
|
|
|
|
guint is_vertical : 1;
|
|
|
|
guint is_pack_start : 1;
|
|
|
|
|
|
|
|
StAdjustment *hadjustment;
|
|
|
|
StAdjustment *vadjustment;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* StScrollable Interface Implementation
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adjustment_value_notify_cb (StAdjustment *adjustment,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
StBoxLayout *box)
|
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (box));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scrollable_set_adjustments (StScrollable *scrollable,
|
|
|
|
StAdjustment *hadjustment,
|
|
|
|
StAdjustment *vadjustment)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (scrollable)->priv;
|
|
|
|
|
2010-03-10 23:32:10 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (scrollable));
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
if (hadjustment != priv->hadjustment)
|
|
|
|
{
|
|
|
|
if (priv->hadjustment)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->hadjustment,
|
|
|
|
adjustment_value_notify_cb,
|
|
|
|
scrollable);
|
|
|
|
g_object_unref (priv->hadjustment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hadjustment)
|
|
|
|
{
|
|
|
|
g_object_ref (hadjustment);
|
|
|
|
g_signal_connect (hadjustment, "notify::value",
|
|
|
|
G_CALLBACK (adjustment_value_notify_cb),
|
|
|
|
scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->hadjustment = hadjustment;
|
2010-03-10 23:32:10 +00:00
|
|
|
g_object_notify (G_OBJECT (scrollable), "hadjustment");
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vadjustment != priv->vadjustment)
|
|
|
|
{
|
|
|
|
if (priv->vadjustment)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->vadjustment,
|
|
|
|
adjustment_value_notify_cb,
|
|
|
|
scrollable);
|
|
|
|
g_object_unref (priv->vadjustment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vadjustment)
|
|
|
|
{
|
|
|
|
g_object_ref (vadjustment);
|
|
|
|
g_signal_connect (vadjustment, "notify::value",
|
|
|
|
G_CALLBACK (adjustment_value_notify_cb),
|
|
|
|
scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->vadjustment = vadjustment;
|
2010-03-10 23:32:10 +00:00
|
|
|
g_object_notify (G_OBJECT (scrollable), "vadjustment");
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2010-03-10 23:32:10 +00:00
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (scrollable));
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scrollable_get_adjustments (StScrollable *scrollable,
|
|
|
|
StAdjustment **hadjustment,
|
|
|
|
StAdjustment **vadjustment)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv;
|
|
|
|
|
|
|
|
priv = (ST_BOX_LAYOUT (scrollable))->priv;
|
|
|
|
|
2010-03-10 23:32:10 +00:00
|
|
|
if (priv->hadjustment)
|
|
|
|
*hadjustment = priv->hadjustment;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (vadjustment)
|
2010-03-10 23:32:10 +00:00
|
|
|
*vadjustment = priv->vadjustment;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_scrollable_interface_init (StScrollableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->set_adjustments = scrollable_set_adjustments;
|
|
|
|
iface->get_adjustments = scrollable_get_adjustments;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ClutterContainer Implementation
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
st_box_container_add_actor (ClutterContainer *container,
|
|
|
|
ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
2010-03-02 20:05:14 +00:00
|
|
|
_st_container_add_actor (container, actor, &priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_remove_actor (ClutterContainer *container,
|
|
|
|
ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
2010-03-02 20:05:14 +00:00
|
|
|
_st_container_remove_actor (container, actor, &priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_foreach (ClutterContainer *container,
|
|
|
|
ClutterCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
2010-03-02 20:05:14 +00:00
|
|
|
_st_container_foreach (container, callback, callback_data,
|
|
|
|
&priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_lower (ClutterContainer *container,
|
|
|
|
ClutterActor *actor,
|
|
|
|
ClutterActor *sibling)
|
|
|
|
{
|
2009-10-23 14:18:35 +00:00
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
2010-03-02 20:05:14 +00:00
|
|
|
_st_container_lower (container, actor, sibling, &priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_raise (ClutterContainer *container,
|
|
|
|
ClutterActor *actor,
|
|
|
|
ClutterActor *sibling)
|
|
|
|
{
|
2009-10-23 14:18:35 +00:00
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
2010-03-02 20:05:14 +00:00
|
|
|
_st_container_raise (container, actor, sibling, &priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_sort_depth_order (ClutterContainer *container)
|
|
|
|
{
|
2010-03-02 20:05:14 +00:00
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
|
|
|
|
|
|
|
_st_container_sort_depth_order (container, &priv->children);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_container_iface_init (ClutterContainerIface *iface)
|
|
|
|
{
|
|
|
|
iface->add = st_box_container_add_actor;
|
|
|
|
iface->remove = st_box_container_remove_actor;
|
|
|
|
iface->foreach = st_box_container_foreach;
|
|
|
|
iface->lower = st_box_container_lower;
|
|
|
|
iface->raise = st_box_container_raise;
|
|
|
|
iface->sort_depth_order = st_box_container_sort_depth_order;
|
|
|
|
|
|
|
|
iface->child_meta_type = ST_TYPE_BOX_LAYOUT_CHILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (object)->priv;
|
|
|
|
StAdjustment *adjustment;
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VERTICAL:
|
|
|
|
g_value_set_boolean (value, priv->is_vertical);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PACK_START:
|
|
|
|
g_value_set_boolean (value, priv->is_pack_start);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_HADJUST:
|
|
|
|
scrollable_get_adjustments (ST_SCROLLABLE (object), &adjustment, NULL);
|
|
|
|
g_value_set_object (value, adjustment);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VADJUST:
|
|
|
|
scrollable_get_adjustments (ST_SCROLLABLE (object), NULL, &adjustment);
|
|
|
|
g_value_set_object (value, adjustment);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StBoxLayout *box = ST_BOX_LAYOUT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VERTICAL:
|
|
|
|
st_box_layout_set_vertical (box, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PACK_START:
|
|
|
|
st_box_layout_set_pack_start (box, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_HADJUST:
|
|
|
|
scrollable_set_adjustments (ST_SCROLLABLE (object),
|
|
|
|
g_value_get_object (value),
|
|
|
|
box->priv->vadjustment);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_VADJUST:
|
|
|
|
scrollable_set_adjustments (ST_SCROLLABLE (object),
|
|
|
|
box->priv->hadjustment,
|
|
|
|
g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (object)->priv;
|
|
|
|
|
|
|
|
while (priv->children)
|
2009-10-08 18:53:46 +00:00
|
|
|
clutter_actor_destroy (priv->children->data);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (priv->hadjustment)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->hadjustment);
|
|
|
|
priv->hadjustment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->vadjustment)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->vadjustment);
|
|
|
|
priv->vadjustment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (st_box_layout_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-20 17:41:13 +00:00
|
|
|
get_content_preferred_width (StBoxLayout *self,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-09-20 17:41:13 +00:00
|
|
|
StBoxLayoutPrivate *priv = self->priv;
|
2009-09-10 05:42:25 +00:00
|
|
|
gint n_children = 0;
|
2009-10-15 18:45:54 +00:00
|
|
|
gint n_fixed = 0;
|
2009-09-20 17:41:13 +00:00
|
|
|
gfloat min_width, natural_width;
|
2009-09-10 05:42:25 +00:00
|
|
|
GList *l;
|
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
min_width = 0;
|
|
|
|
natural_width = 0;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
for (l = priv->children; l; l = g_list_next (l))
|
|
|
|
{
|
2009-10-15 18:25:01 +00:00
|
|
|
ClutterActor *child = l->data;
|
2009-09-10 05:42:25 +00:00
|
|
|
gfloat child_min = 0, child_nat = 0;
|
2010-02-13 16:24:25 +00:00
|
|
|
gboolean child_fill;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-10-15 18:25:01 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
2009-09-10 05:42:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
n_children++;
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (clutter_actor_get_fixed_position_set (child))
|
|
|
|
{
|
|
|
|
n_fixed++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
if (priv->is_vertical)
|
|
|
|
{
|
2010-02-13 16:24:25 +00:00
|
|
|
_st_actor_get_preferred_width (child, -1, FALSE,
|
|
|
|
&child_min, &child_nat);
|
2009-09-20 17:41:13 +00:00
|
|
|
min_width = MAX (child_min, min_width);
|
|
|
|
natural_width = MAX (child_nat, natural_width);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-13 16:24:25 +00:00
|
|
|
clutter_container_child_get ((ClutterContainer*) self, child,
|
|
|
|
"y-fill", &child_fill,
|
|
|
|
NULL);
|
|
|
|
_st_actor_get_preferred_width (child, for_height, child_fill,
|
|
|
|
&child_min, &child_nat);
|
2009-09-20 17:41:13 +00:00
|
|
|
min_width += child_min;
|
|
|
|
natural_width += child_nat;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (!priv->is_vertical && (n_children - n_fixed) > 1)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-10-15 18:45:54 +00:00
|
|
|
min_width += priv->spacing * (n_children - n_fixed - 1);
|
|
|
|
natural_width += priv->spacing * (n_children - n_fixed - 1);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2009-09-20 17:41:13 +00:00
|
|
|
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = min_width;
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = natural_width;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-20 17:41:13 +00:00
|
|
|
st_box_layout_get_preferred_width (ClutterActor *actor,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-09-20 17:41:13 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
get_content_preferred_width (ST_BOX_LAYOUT (actor), for_height,
|
|
|
|
min_width_p, natural_width_p);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
st_theme_node_adjust_preferred_width (theme_node,
|
|
|
|
min_width_p, natural_width_p);
|
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
static void
|
|
|
|
get_content_preferred_height (StBoxLayout *self,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = self->priv;
|
|
|
|
gint n_children = 0;
|
2009-10-15 18:45:54 +00:00
|
|
|
gint n_fixed = 0;
|
2009-09-20 17:41:13 +00:00
|
|
|
gfloat min_height, natural_height;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
min_height = 0;
|
|
|
|
natural_height = 0;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
for (l = priv->children; l; l = g_list_next (l))
|
|
|
|
{
|
2009-10-15 18:25:01 +00:00
|
|
|
ClutterActor *child = l->data;
|
2009-09-10 05:42:25 +00:00
|
|
|
gfloat child_min = 0, child_nat = 0;
|
2010-02-13 16:24:25 +00:00
|
|
|
gboolean child_fill = FALSE;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-10-15 18:25:01 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
2009-09-10 05:42:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
n_children++;
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (clutter_actor_get_fixed_position_set (child))
|
|
|
|
{
|
|
|
|
n_fixed++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-13 16:24:25 +00:00
|
|
|
if (priv->is_vertical)
|
|
|
|
{
|
|
|
|
clutter_container_child_get ((ClutterContainer*) self, child,
|
|
|
|
"x-fill", &child_fill,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
_st_actor_get_preferred_height (child,
|
|
|
|
(priv->is_vertical) ? for_width : -1,
|
|
|
|
child_fill,
|
|
|
|
&child_min,
|
|
|
|
&child_nat);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (!priv->is_vertical)
|
|
|
|
{
|
2009-09-20 17:41:13 +00:00
|
|
|
min_height = MAX (child_min, min_height);
|
|
|
|
natural_height = MAX (child_nat, natural_height);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-20 17:41:13 +00:00
|
|
|
min_height += child_min;
|
|
|
|
natural_height += child_nat;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (priv->is_vertical && (n_children - n_fixed) > 1)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-10-15 18:45:54 +00:00
|
|
|
min_height += priv->spacing * (n_children - n_fixed - 1);
|
|
|
|
natural_height += priv->spacing * (n_children - n_fixed - 1);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2009-09-20 17:41:13 +00:00
|
|
|
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = min_height;
|
|
|
|
|
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = natural_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_get_preferred_height (ClutterActor *actor,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
2010-03-05 22:20:56 +00:00
|
|
|
StBoxLayout *self = ST_BOX_LAYOUT (actor);
|
|
|
|
StBoxLayoutPrivate *priv = self->priv;
|
2009-09-20 17:41:13 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
|
|
|
|
|
|
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
|
|
|
|
2010-03-05 22:20:56 +00:00
|
|
|
if (priv->hadjustment)
|
|
|
|
{
|
|
|
|
/* If we're scrolled, the parent calls us with the width that
|
|
|
|
* we'll actually get, which can be smaller than the minimum
|
|
|
|
* width that we give our contents.
|
|
|
|
*/
|
|
|
|
gfloat min_width;
|
|
|
|
|
|
|
|
get_content_preferred_width (self, -1, &min_width, NULL);
|
|
|
|
for_width = MAX (for_width, min_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
get_content_preferred_height (self, for_width,
|
2009-09-20 17:41:13 +00:00
|
|
|
min_height_p, natural_height_p);
|
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_height (theme_node,
|
|
|
|
min_height_p, natural_height_p);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
typedef struct {
|
|
|
|
int child_index;
|
|
|
|
gfloat shrink_amount;
|
|
|
|
} BoxChildShrink;
|
|
|
|
|
|
|
|
/* Sort with the greatest shrink amount first */
|
|
|
|
static int
|
|
|
|
compare_by_shrink_amount (const void *a,
|
|
|
|
const void *b)
|
|
|
|
{
|
|
|
|
float diff = ((const BoxChildShrink *)a)->shrink_amount - ((const BoxChildShrink *)b)->shrink_amount;
|
|
|
|
return diff < 0 ? 1 : (diff == 0 ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort in ascending order by child index */
|
|
|
|
static int
|
|
|
|
compare_by_child_index (const void *a,
|
|
|
|
const void *b)
|
|
|
|
{
|
|
|
|
return ((const BoxChildShrink *)a)->child_index - ((const BoxChildShrink *)b)->child_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BoxChildShrink *
|
|
|
|
compute_shrinks (StBoxLayout *self,
|
|
|
|
gfloat for_length,
|
|
|
|
gfloat total_shrink)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = self->priv;
|
|
|
|
int n_children = g_list_length (priv->children);
|
|
|
|
BoxChildShrink *shrinks = g_new0 (BoxChildShrink, n_children);
|
|
|
|
gfloat shrink_so_far, base_shrink;
|
|
|
|
int n_shrink_children;
|
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* The effect that we want is that all the children get an equal chance
|
|
|
|
* to expand from their minimum size up to the natural size. Or to put
|
|
|
|
* it a different way, we want to start by shrinking only the child that
|
|
|
|
* can shrink most, then shrink that and the next most shrinkable child,
|
|
|
|
* to the point where we are shrinking everything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find the amount of possible shrink for each child */
|
2009-10-15 18:45:54 +00:00
|
|
|
int n_possible_shrink_children = 0;
|
2009-09-21 22:01:17 +00:00
|
|
|
for (l = priv->children, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
2009-10-15 18:25:01 +00:00
|
|
|
ClutterActor *child = l->data;
|
2009-09-21 22:01:17 +00:00
|
|
|
gfloat child_min, child_nat;
|
2010-02-13 16:24:25 +00:00
|
|
|
gboolean child_fill;
|
2009-10-15 18:45:54 +00:00
|
|
|
gboolean fixed;
|
|
|
|
|
|
|
|
child = (ClutterActor*) l->data;
|
|
|
|
fixed = clutter_actor_get_fixed_position_set (child);
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
shrinks[i].child_index = i;
|
2009-10-15 18:45:54 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (child) && !fixed)
|
2009-09-21 22:01:17 +00:00
|
|
|
{
|
|
|
|
if (priv->is_vertical)
|
2010-02-13 16:24:25 +00:00
|
|
|
{
|
|
|
|
clutter_container_child_get ((ClutterContainer*) self, child,
|
|
|
|
"x-fill", &child_fill,
|
|
|
|
NULL);
|
|
|
|
_st_actor_get_preferred_height (child,
|
|
|
|
for_length, child_fill,
|
|
|
|
&child_min, &child_nat);
|
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
else
|
2010-02-13 16:24:25 +00:00
|
|
|
{
|
|
|
|
clutter_container_child_get ((ClutterContainer*) self, child,
|
|
|
|
"y-fill", &child_fill,
|
|
|
|
NULL);
|
|
|
|
_st_actor_get_preferred_width (child,
|
|
|
|
for_length, child_fill,
|
|
|
|
&child_min, &child_nat);
|
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
shrinks[i].shrink_amount = MAX (0., child_nat - child_min);
|
2009-10-15 18:45:54 +00:00
|
|
|
n_possible_shrink_children++;
|
2009-09-21 22:01:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shrinks[i].shrink_amount = -1.;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to process children starting from the child with the maximum available
|
|
|
|
* shrink, so sort in this order; !visible children end up at the end */
|
|
|
|
qsort (shrinks, n_children, sizeof (BoxChildShrink), compare_by_shrink_amount);
|
|
|
|
|
|
|
|
/* +--+
|
|
|
|
* | |
|
|
|
|
* | | +--
|
|
|
|
* | | | |
|
|
|
|
* | | | | +-+
|
|
|
|
* --+--+-+-+-+-+----------
|
|
|
|
* | | | | | | +-+ +-+
|
|
|
|
* | | | | | | | | | |
|
|
|
|
* --+--+-+-+-+-+-+-+------
|
|
|
|
*
|
|
|
|
* We are trying to find the correct position for the upper line the "water mark"
|
|
|
|
* so that total of the portion of the bars above the line is equal to the total
|
|
|
|
* amount we want to shrink.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Start by moving the line downward, top-of-bar by top-of-bar */
|
|
|
|
shrink_so_far = 0;
|
2009-10-15 18:45:54 +00:00
|
|
|
for (n_shrink_children = 1; n_shrink_children <= n_possible_shrink_children; n_shrink_children++)
|
2009-09-21 22:01:17 +00:00
|
|
|
{
|
2009-10-15 18:45:54 +00:00
|
|
|
if (n_shrink_children < n_possible_shrink_children)
|
2009-09-21 22:01:17 +00:00
|
|
|
base_shrink = shrinks[n_shrink_children].shrink_amount;
|
|
|
|
else
|
|
|
|
base_shrink = 0;
|
|
|
|
shrink_so_far += n_shrink_children * (shrinks[n_shrink_children - 1].shrink_amount - base_shrink);
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (shrink_so_far >= total_shrink || n_shrink_children == n_possible_shrink_children)
|
2009-09-21 22:01:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we found enough shrinkage, move it back upwards to the right position */
|
|
|
|
base_shrink += (shrink_so_far - total_shrink) / n_shrink_children;
|
|
|
|
if (base_shrink < 0) /* can't shrink that much, probably round-off error */
|
|
|
|
base_shrink = 0;
|
|
|
|
|
|
|
|
/* Assign the portion above the base shrink line to the shrink_amount */
|
|
|
|
for (i = 0; i < n_shrink_children; i++)
|
|
|
|
shrinks[i].shrink_amount -= base_shrink;
|
|
|
|
for (; i < n_children; i++)
|
|
|
|
shrinks[i].shrink_amount = 0;
|
|
|
|
|
|
|
|
/* And sort back to their original order */
|
|
|
|
qsort (shrinks, n_children, sizeof (BoxChildShrink), compare_by_child_index);
|
|
|
|
|
|
|
|
return shrinks;
|
|
|
|
}
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
static void
|
|
|
|
st_box_layout_allocate (ClutterActor *actor,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (actor)->priv;
|
2009-09-20 17:41:13 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
|
|
|
ClutterActorBox content_box;
|
2009-09-21 22:01:17 +00:00
|
|
|
gfloat avail_width, avail_height, min_width, natural_width, min_height, natural_height;
|
|
|
|
gfloat position, next_position;
|
2009-09-10 05:42:25 +00:00
|
|
|
GList *l;
|
2009-09-21 22:01:17 +00:00
|
|
|
gint n_expand_children = 0, i;
|
|
|
|
gfloat expand_amount, shrink_amount;
|
|
|
|
BoxChildShrink *shrinks = NULL;
|
2009-11-14 17:22:36 +00:00
|
|
|
gboolean flip = (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL)
|
|
|
|
&& (!priv->is_vertical);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->allocate (actor, box,
|
|
|
|
flags);
|
|
|
|
|
|
|
|
if (priv->children == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
|
|
|
|
|
|
|
avail_width = content_box.x2 - content_box.x1;
|
|
|
|
avail_height = content_box.y2 - content_box.y1;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
get_content_preferred_width (ST_BOX_LAYOUT (actor), avail_height,
|
2009-09-21 22:01:17 +00:00
|
|
|
&min_width, &natural_width);
|
2010-03-05 22:20:56 +00:00
|
|
|
get_content_preferred_height (ST_BOX_LAYOUT (actor), MAX (avail_width, min_width),
|
|
|
|
&min_height, &natural_height);
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
/* update adjustments for scrolling */
|
|
|
|
if (priv->vadjustment)
|
|
|
|
{
|
|
|
|
gdouble prev_value;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (priv->vadjustment),
|
|
|
|
"lower", 0.0,
|
2010-03-10 18:57:05 +00:00
|
|
|
"upper", MAX (min_height, avail_height),
|
2009-09-10 05:42:25 +00:00
|
|
|
"page-size", avail_height,
|
|
|
|
"step-increment", avail_height / 6,
|
2010-03-10 18:57:05 +00:00
|
|
|
"page-increment", avail_height - avail_height / 6,
|
2009-09-10 05:42:25 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
prev_value = st_adjustment_get_value (priv->vadjustment);
|
|
|
|
st_adjustment_set_value (priv->vadjustment, prev_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->hadjustment)
|
|
|
|
{
|
|
|
|
gdouble prev_value;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (priv->hadjustment),
|
|
|
|
"lower", 0.0,
|
2010-03-10 18:57:05 +00:00
|
|
|
"upper", MAX (min_width, avail_width),
|
2009-09-10 05:42:25 +00:00
|
|
|
"page-size", avail_width,
|
|
|
|
"step-increment", avail_width / 6,
|
2010-03-10 18:57:05 +00:00
|
|
|
"page-increment", avail_width - avail_width / 6,
|
2009-09-10 05:42:25 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
prev_value = st_adjustment_get_value (priv->hadjustment);
|
|
|
|
st_adjustment_set_value (priv->hadjustment, prev_value);
|
|
|
|
}
|
|
|
|
|
2010-03-05 22:20:56 +00:00
|
|
|
if (avail_height < min_height)
|
|
|
|
{
|
|
|
|
avail_height = min_height;
|
|
|
|
content_box.y2 = content_box.y1 + avail_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avail_width < min_width)
|
|
|
|
{
|
|
|
|
avail_width = min_width;
|
|
|
|
content_box.x2 = content_box.x1 + avail_width;
|
|
|
|
}
|
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
if (priv->is_vertical)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-09-21 22:01:17 +00:00
|
|
|
expand_amount = MAX (0, avail_height - natural_height);
|
2010-03-10 16:56:04 +00:00
|
|
|
shrink_amount = MAX (0, natural_height - avail_height);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
else
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-09-21 22:01:17 +00:00
|
|
|
expand_amount = MAX (0, avail_width - natural_width);
|
2010-03-10 16:56:04 +00:00
|
|
|
shrink_amount = MAX (0, natural_width - avail_width);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
if (expand_amount > 0)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
2009-09-21 22:01:17 +00:00
|
|
|
/* count the number of children with expand set to TRUE */
|
|
|
|
n_expand_children = 0;
|
|
|
|
for (l = priv->children; l; l = l->next)
|
|
|
|
{
|
2009-10-15 18:25:01 +00:00
|
|
|
ClutterActor *child = l->data;
|
2009-09-21 22:01:17 +00:00
|
|
|
gboolean expand;
|
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child) ||
|
|
|
|
clutter_actor_get_fixed_position_set (child))
|
2009-09-21 22:01:17 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
clutter_container_child_get ((ClutterContainer *) actor,
|
2009-10-15 18:25:01 +00:00
|
|
|
child,
|
2009-09-21 22:01:17 +00:00
|
|
|
"expand", &expand,
|
|
|
|
NULL);
|
|
|
|
if (expand)
|
|
|
|
n_expand_children++;
|
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
if (n_expand_children == 0)
|
|
|
|
expand_amount = 0;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
else if (shrink_amount > 0)
|
|
|
|
{
|
|
|
|
shrinks = compute_shrinks (ST_BOX_LAYOUT (actor),
|
|
|
|
priv->is_vertical ? avail_width : avail_height,
|
|
|
|
shrink_amount);
|
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (priv->is_vertical)
|
2009-09-20 17:41:13 +00:00
|
|
|
position = content_box.y1;
|
2009-11-14 17:22:36 +00:00
|
|
|
else if (flip)
|
|
|
|
position = content_box.x2;
|
2009-09-10 05:42:25 +00:00
|
|
|
else
|
2009-09-20 17:41:13 +00:00
|
|
|
position = content_box.x1;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (priv->is_pack_start)
|
2009-09-21 22:01:17 +00:00
|
|
|
{
|
|
|
|
l = g_list_last (priv->children);
|
|
|
|
i = g_list_length (priv->children);
|
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
else
|
2009-09-21 22:01:17 +00:00
|
|
|
{
|
|
|
|
l = priv->children;
|
|
|
|
i = 0;
|
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
while (l)
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
|
|
|
ClutterActor *child = (ClutterActor*) l->data;
|
|
|
|
ClutterActorBox child_box;
|
2009-09-21 22:01:17 +00:00
|
|
|
gfloat child_min, child_nat, child_allocated;
|
2009-10-15 18:45:54 +00:00
|
|
|
gboolean xfill, yfill, expand, fixed;
|
2009-09-10 05:42:25 +00:00
|
|
|
StAlign xalign, yalign;
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
2009-09-21 22:01:17 +00:00
|
|
|
goto next_child;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-10-15 18:45:54 +00:00
|
|
|
fixed = clutter_actor_get_fixed_position_set (child);
|
|
|
|
if (fixed)
|
|
|
|
{
|
|
|
|
clutter_actor_allocate_preferred_size (child, flags);
|
|
|
|
goto next_child;
|
|
|
|
}
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
clutter_container_child_get ((ClutterContainer*) actor, child,
|
|
|
|
"x-fill", &xfill,
|
|
|
|
"y-fill", &yfill,
|
|
|
|
"x-align", &xalign,
|
|
|
|
"y-align", &yalign,
|
|
|
|
"expand", &expand,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (priv->is_vertical)
|
|
|
|
{
|
2010-02-13 16:24:25 +00:00
|
|
|
_st_actor_get_preferred_height (child, avail_width, xfill,
|
|
|
|
&child_min, &child_nat);
|
2009-09-21 22:01:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-13 16:24:25 +00:00
|
|
|
_st_actor_get_preferred_width (child, avail_height, yfill,
|
|
|
|
&child_min, &child_nat);
|
2009-09-21 22:01:17 +00:00
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-21 22:01:17 +00:00
|
|
|
child_allocated = child_nat;
|
|
|
|
if (expand_amount > 0 && expand)
|
|
|
|
child_allocated += expand_amount / n_expand_children;
|
|
|
|
else if (shrink_amount > 0)
|
|
|
|
child_allocated -= shrinks[i].shrink_amount;
|
|
|
|
|
2009-11-14 17:22:36 +00:00
|
|
|
if (flip)
|
|
|
|
next_position = position - child_allocated;
|
|
|
|
else
|
|
|
|
next_position = position + child_allocated;
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
if (priv->is_vertical)
|
|
|
|
{
|
|
|
|
child_box.y1 = (int)(0.5 + position);
|
|
|
|
child_box.y2 = (int)(0.5 + next_position);
|
2009-09-20 17:41:13 +00:00
|
|
|
child_box.x1 = content_box.x1;
|
2010-03-05 22:20:56 +00:00
|
|
|
child_box.x2 = content_box.x2;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2010-02-13 16:24:25 +00:00
|
|
|
_st_allocate_fill (ST_WIDGET (actor), child, &child_box,
|
|
|
|
xalign, yalign, xfill, yfill);
|
2009-09-10 05:42:25 +00:00
|
|
|
clutter_actor_allocate (child, &child_box, flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-14 17:22:36 +00:00
|
|
|
if (flip)
|
|
|
|
{
|
|
|
|
child_box.x1 = (int)(0.5 + next_position);
|
|
|
|
child_box.x2 = (int)(0.5 + position);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child_box.x1 = (int)(0.5 + position);
|
|
|
|
child_box.x2 = (int)(0.5 + next_position);
|
|
|
|
}
|
|
|
|
|
2009-09-20 17:41:13 +00:00
|
|
|
child_box.y1 = content_box.y1;
|
2010-03-05 22:20:56 +00:00
|
|
|
child_box.y2 = content_box.y2;
|
2009-09-21 22:01:17 +00:00
|
|
|
|
2010-02-13 16:24:25 +00:00
|
|
|
_st_allocate_fill (ST_WIDGET (actor), child, &child_box,
|
|
|
|
xalign, yalign, xfill, yfill);
|
2009-09-10 05:42:25 +00:00
|
|
|
clutter_actor_allocate (child, &child_box, flags);
|
2009-09-21 22:01:17 +00:00
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-11-14 17:22:36 +00:00
|
|
|
if (flip)
|
|
|
|
position = next_position - priv->spacing;
|
|
|
|
else
|
|
|
|
position = next_position + priv->spacing;
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
next_child:
|
|
|
|
if (priv->is_pack_start)
|
|
|
|
{
|
|
|
|
l = l->prev;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
l = l->next;
|
|
|
|
i++;
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-21 22:01:17 +00:00
|
|
|
|
|
|
|
if (shrinks)
|
|
|
|
g_free (shrinks);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_apply_transform (ClutterActor *a,
|
|
|
|
CoglMatrix *m)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (a)->priv;
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->apply_transform (a, m);
|
|
|
|
|
|
|
|
if (priv->hadjustment)
|
|
|
|
x = st_adjustment_get_value (priv->hadjustment);
|
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
if (priv->vadjustment)
|
|
|
|
y = st_adjustment_get_value (priv->vadjustment);
|
|
|
|
else
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
cogl_matrix_translate (m, (int) -x, (int) -y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_paint (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (actor)->priv;
|
2009-09-21 23:11:09 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 05:42:25 +00:00
|
|
|
GList *l;
|
|
|
|
gdouble x, y;
|
2009-09-21 23:11:09 +00:00
|
|
|
ClutterActorBox child_box;
|
|
|
|
ClutterActorBox allocation_box;
|
|
|
|
ClutterActorBox content_box;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (priv->hadjustment)
|
|
|
|
x = st_adjustment_get_value (priv->hadjustment);
|
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
if (priv->vadjustment)
|
|
|
|
y = st_adjustment_get_value (priv->vadjustment);
|
|
|
|
else
|
|
|
|
y = 0;
|
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
/* If we are translated, then we need to translate back before chaining
|
|
|
|
* up or the background and borders will be drawn in the wrong place */
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
{
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate ((int)x, (int)y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->paint (actor);
|
|
|
|
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
{
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->children == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (actor, &allocation_box);
|
|
|
|
st_theme_node_get_content_box (theme_node, &allocation_box, &content_box);
|
|
|
|
|
|
|
|
content_box.x1 += x;
|
|
|
|
content_box.y1 += y;
|
|
|
|
content_box.x2 += x;
|
|
|
|
content_box.y2 += y;
|
|
|
|
|
|
|
|
/* The content area forms the viewport into the scrolled contents, while
|
|
|
|
* the borders and background stay in place; after drawing the borders and
|
|
|
|
* background, we clip to the content area */
|
|
|
|
if (priv->hadjustment || priv->vadjustment)
|
2010-02-11 20:24:13 +00:00
|
|
|
cogl_clip_push_rectangle ((int)content_box.x1,
|
|
|
|
(int)content_box.y1,
|
|
|
|
(int)content_box.x2,
|
|
|
|
(int)content_box.y2);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
for (l = priv->children; l; l = g_list_next (l))
|
|
|
|
{
|
|
|
|
ClutterActor *child = (ClutterActor*) l->data;
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
clutter_actor_get_allocation_box (child, &child_box);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
if ((child_box.x1 < content_box.x2) &&
|
|
|
|
(child_box.x2 > content_box.x1) &&
|
|
|
|
(child_box.y1 < content_box.y2) &&
|
|
|
|
(child_box.y2 > content_box.y1))
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
|
|
|
clutter_actor_paint (child);
|
|
|
|
}
|
|
|
|
}
|
2009-09-21 23:11:09 +00:00
|
|
|
|
|
|
|
if (priv->hadjustment || priv->vadjustment)
|
|
|
|
cogl_clip_pop ();
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (actor)->priv;
|
2009-09-21 23:11:09 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 05:42:25 +00:00
|
|
|
GList *l;
|
|
|
|
gdouble x, y;
|
2009-09-21 23:11:09 +00:00
|
|
|
ClutterActorBox child_box;
|
|
|
|
ClutterActorBox allocation_box;
|
|
|
|
ClutterActorBox content_box;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
if (priv->hadjustment)
|
|
|
|
x = st_adjustment_get_value (priv->hadjustment);
|
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
if (priv->vadjustment)
|
|
|
|
y = st_adjustment_get_value (priv->vadjustment);
|
|
|
|
else
|
|
|
|
y = 0;
|
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
if (x != 0 || y != 0)
|
|
|
|
{
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_translate ((int)x, (int)y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->pick (actor, color);
|
|
|
|
|
|
|
|
if (x != 0 || y != 0)
|
|
|
|
{
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->children == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (actor, &allocation_box);
|
|
|
|
st_theme_node_get_content_box (theme_node, &allocation_box, &content_box);
|
|
|
|
|
|
|
|
content_box.x1 += x;
|
|
|
|
content_box.y1 += y;
|
|
|
|
content_box.x2 += x;
|
|
|
|
content_box.y2 += y;
|
|
|
|
|
|
|
|
if (priv->hadjustment || priv->vadjustment)
|
2010-02-11 20:24:13 +00:00
|
|
|
cogl_clip_push_rectangle ((int)content_box.x1,
|
|
|
|
(int)content_box.y1,
|
|
|
|
(int)content_box.x2,
|
|
|
|
(int)content_box.y2);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
for (l = priv->children; l; l = g_list_next (l))
|
|
|
|
{
|
|
|
|
ClutterActor *child = (ClutterActor*) l->data;
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
|
|
|
|
continue;
|
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
clutter_actor_get_allocation_box (child, &child_box);
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2009-09-21 23:11:09 +00:00
|
|
|
if ((child_box.x1 < content_box.x2) &&
|
|
|
|
(child_box.x2 > content_box.x1) &&
|
|
|
|
(child_box.y1 < content_box.y2) &&
|
|
|
|
(child_box.y2 > content_box.y1))
|
2009-09-10 05:42:25 +00:00
|
|
|
{
|
|
|
|
clutter_actor_paint (child);
|
|
|
|
}
|
|
|
|
}
|
2009-09-21 23:11:09 +00:00
|
|
|
|
|
|
|
if (priv->hadjustment || priv->vadjustment)
|
|
|
|
cogl_clip_pop ();
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-30 03:03:41 +00:00
|
|
|
static void
|
|
|
|
st_box_layout_style_changed (StWidget *self)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
|
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (self);
|
|
|
|
int old_spacing = priv->spacing;
|
|
|
|
double spacing = 0;
|
|
|
|
|
|
|
|
st_theme_node_get_length (theme_node, "spacing", FALSE, &spacing);
|
|
|
|
priv->spacing = (int)(spacing + 0.5);
|
|
|
|
if (priv->spacing != old_spacing)
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
|
|
|
|
|
|
|
|
ST_WIDGET_CLASS (st_box_layout_parent_class)->style_changed (self);
|
|
|
|
}
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
static void
|
|
|
|
st_box_layout_class_init (StBoxLayoutClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2009-09-30 03:03:41 +00:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2009-09-10 05:42:25 +00:00
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (StBoxLayoutPrivate));
|
|
|
|
|
|
|
|
object_class->get_property = st_box_layout_get_property;
|
|
|
|
object_class->set_property = st_box_layout_set_property;
|
|
|
|
object_class->dispose = st_box_layout_dispose;
|
|
|
|
|
|
|
|
actor_class->allocate = st_box_layout_allocate;
|
|
|
|
actor_class->get_preferred_width = st_box_layout_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = st_box_layout_get_preferred_height;
|
|
|
|
actor_class->apply_transform = st_box_layout_apply_transform;
|
|
|
|
|
|
|
|
actor_class->paint = st_box_layout_paint;
|
|
|
|
actor_class->pick = st_box_layout_pick;
|
|
|
|
|
2009-09-30 03:03:41 +00:00
|
|
|
widget_class->style_changed = st_box_layout_style_changed;
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
pspec = g_param_spec_boolean ("vertical",
|
|
|
|
"Vertical",
|
|
|
|
"Whether the layout should be vertical, rather"
|
|
|
|
"than horizontal",
|
|
|
|
FALSE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_VERTICAL, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_boolean ("pack-start",
|
|
|
|
"Pack Start",
|
|
|
|
"Whether to pack items at the start of the box",
|
|
|
|
FALSE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_PACK_START, pspec);
|
|
|
|
|
|
|
|
/* StScrollable properties */
|
|
|
|
g_object_class_override_property (object_class,
|
|
|
|
PROP_HADJUST,
|
|
|
|
"hadjustment");
|
|
|
|
|
|
|
|
g_object_class_override_property (object_class,
|
|
|
|
PROP_VADJUST,
|
|
|
|
"vadjustment");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_init (StBoxLayout *self)
|
|
|
|
{
|
|
|
|
self->priv = BOX_LAYOUT_PRIVATE (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_new:
|
|
|
|
*
|
|
|
|
* Create a new #StBoxLayout.
|
|
|
|
*
|
|
|
|
* Returns: a newly allocated #StBoxLayout
|
|
|
|
*/
|
|
|
|
StWidget *
|
|
|
|
st_box_layout_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (ST_TYPE_BOX_LAYOUT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_set_vertical:
|
|
|
|
* @box: A #StBoxLayout
|
2010-03-23 23:56:10 +00:00
|
|
|
* @vertical: %TRUE if the layout should be vertical
|
2009-09-10 05:42:25 +00:00
|
|
|
*
|
|
|
|
* Set the value of the #StBoxLayout::vertical property
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_box_layout_set_vertical (StBoxLayout *box,
|
|
|
|
gboolean vertical)
|
|
|
|
{
|
|
|
|
g_return_if_fail (ST_IS_BOX_LAYOUT (box));
|
|
|
|
|
|
|
|
if (box->priv->is_vertical != vertical)
|
|
|
|
{
|
|
|
|
box->priv->is_vertical = vertical;
|
|
|
|
clutter_actor_queue_relayout ((ClutterActor*) box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (box), "vertical");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_get_vertical:
|
|
|
|
* @box: A #StBoxLayout
|
|
|
|
*
|
|
|
|
* Get the value of the #StBoxLayout::vertical property.
|
|
|
|
*
|
2010-03-23 23:56:10 +00:00
|
|
|
* Returns: %TRUE if the layout is vertical
|
2009-09-10 05:42:25 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
st_box_layout_get_vertical (StBoxLayout *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_BOX_LAYOUT (box), FALSE);
|
|
|
|
|
|
|
|
return box->priv->is_vertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_set_pack_start:
|
|
|
|
* @box: A #StBoxLayout
|
2010-03-23 23:56:10 +00:00
|
|
|
* @pack_start: %TRUE if the layout should use pack-start
|
2009-09-10 05:42:25 +00:00
|
|
|
*
|
|
|
|
* Set the value of the #StBoxLayout::pack-start property.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_box_layout_set_pack_start (StBoxLayout *box,
|
|
|
|
gboolean pack_start)
|
|
|
|
{
|
|
|
|
g_return_if_fail (ST_IS_BOX_LAYOUT (box));
|
|
|
|
|
|
|
|
if (box->priv->is_pack_start != pack_start)
|
|
|
|
{
|
|
|
|
box->priv->is_pack_start = pack_start;
|
|
|
|
clutter_actor_queue_relayout ((ClutterActor*) box);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (box), "pack-start");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_get_pack_start:
|
|
|
|
* @box: A #StBoxLayout
|
|
|
|
*
|
|
|
|
* Get the value of the #StBoxLayout::pack-start property.
|
|
|
|
*
|
2010-03-23 23:56:10 +00:00
|
|
|
* Returns: %TRUE if pack-start is enabled
|
2009-09-10 05:42:25 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
st_box_layout_get_pack_start (StBoxLayout *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_BOX_LAYOUT (box), FALSE);
|
|
|
|
|
|
|
|
return box->priv->is_pack_start;
|
|
|
|
}
|
2009-11-10 19:25:41 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_internal_remove_all (StBoxLayout *self,
|
|
|
|
gboolean destroy)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
|
|
|
|
ClutterActor *child;
|
|
|
|
|
|
|
|
while (priv->children)
|
|
|
|
{
|
|
|
|
child = priv->children->data;
|
|
|
|
|
|
|
|
g_object_ref (child);
|
|
|
|
priv->children = g_list_delete_link (priv->children, priv->children);
|
|
|
|
clutter_actor_unparent (child);
|
|
|
|
g_signal_emit_by_name (self, "actor-removed", child);
|
|
|
|
if (destroy)
|
|
|
|
clutter_actor_destroy (child);
|
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_queue_relayout ((ClutterActor*) self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_remove_all:
|
|
|
|
* @self:
|
|
|
|
*
|
|
|
|
* Efficiently unparent all children currently in this box.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_box_layout_remove_all (StBoxLayout *self)
|
|
|
|
{
|
|
|
|
st_box_layout_internal_remove_all (self, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_destroy_children:
|
|
|
|
* @self:
|
|
|
|
*
|
|
|
|
* Efficiently unparent and destroy all children currently in this box.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_box_layout_destroy_children (StBoxLayout *self)
|
|
|
|
{
|
|
|
|
st_box_layout_internal_remove_all (self, TRUE);
|
|
|
|
}
|
2009-11-10 20:46:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* st_box_layout_get_n_children:
|
|
|
|
* @self: a #StBoxLayout
|
|
|
|
*
|
|
|
|
* Returns the number of children in this box.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
st_box_layout_get_n_children (StBoxLayout *self)
|
|
|
|
{
|
|
|
|
return g_list_length (self->priv->children);
|
|
|
|
}
|
2010-01-13 20:03:26 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
st_box_layout_move_child (StBoxLayout *self,
|
|
|
|
ClutterActor *actor,
|
|
|
|
int pos)
|
|
|
|
{
|
|
|
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
|
|
|
|
|
|
|
|
GList *item = NULL;
|
|
|
|
|
|
|
|
item = g_list_find (priv->children, actor);
|
|
|
|
|
|
|
|
if (item == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Actor of type '%s' is not a child of the StBoxLayout container",
|
|
|
|
g_type_name (G_OBJECT_TYPE (actor)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->children = g_list_delete_link (priv->children, item);
|
|
|
|
priv->children = g_list_insert (priv->children, actor, pos);
|
|
|
|
clutter_actor_queue_relayout ((ClutterActor*) self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
st_box_layout_insert_actor (StBoxLayout *self,
|
|
|
|
ClutterActor *actor,
|
|
|
|
int pos)
|
|
|
|
{
|
|
|
|
clutter_container_add_actor((ClutterContainer*) self, actor);
|
|
|
|
st_box_layout_move_child(self, actor, pos);
|
|
|
|
}
|
|
|
|
|