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-child.c: box layout child 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
|
2010-11-10 22:00:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-10 05:42:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:st-box-layout-child
|
|
|
|
* @short_description: meta data associated with a #StBoxLayout child.
|
|
|
|
*
|
|
|
|
* #StBoxLayoutChild is a #ClutterChildMeta implementation that stores the
|
|
|
|
* child properties for children inside a #StBoxLayout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "st-box-layout-child.h"
|
|
|
|
#include "st-private.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (StBoxLayoutChild, st_box_layout_child, CLUTTER_TYPE_CHILD_META)
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_EXPAND,
|
|
|
|
PROP_X_FILL,
|
|
|
|
PROP_Y_FILL,
|
|
|
|
PROP_X_ALIGN,
|
|
|
|
PROP_Y_ALIGN
|
|
|
|
};
|
|
|
|
|
2013-07-02 21:08:10 +00:00
|
|
|
static ClutterLayoutMeta *
|
|
|
|
get_layout_meta (StBoxLayoutChild *self)
|
|
|
|
{
|
|
|
|
ClutterChildMeta *meta = CLUTTER_CHILD_META (self);
|
|
|
|
ClutterActor *actor = clutter_child_meta_get_actor (meta);
|
|
|
|
ClutterContainer *container = clutter_child_meta_get_container (meta);
|
|
|
|
ClutterLayoutManager *layout = clutter_actor_get_layout_manager (CLUTTER_ACTOR (container));
|
|
|
|
return clutter_layout_manager_get_child_meta (layout, container, actor);
|
|
|
|
}
|
|
|
|
|
2009-09-10 05:42:25 +00:00
|
|
|
static void
|
|
|
|
st_box_layout_child_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
|
2013-07-02 21:08:10 +00:00
|
|
|
GObject *meta = G_OBJECT (get_layout_meta (child));
|
|
|
|
gboolean expand, fill;
|
|
|
|
ClutterBoxAlignment layout_align;
|
|
|
|
StAlign align;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_EXPAND:
|
2013-07-02 21:08:10 +00:00
|
|
|
g_object_get (meta, "expand", &expand, NULL);
|
|
|
|
g_value_set_boolean (value, expand);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_X_FILL:
|
2013-07-02 21:08:10 +00:00
|
|
|
g_object_get (meta, "x-fill", &fill, NULL);
|
|
|
|
g_value_set_boolean (value, fill);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_Y_FILL:
|
2013-07-02 21:08:10 +00:00
|
|
|
g_object_get (meta, "y-fill", &fill, NULL);
|
|
|
|
g_value_set_boolean (value, fill);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_X_ALIGN:
|
|
|
|
case PROP_Y_ALIGN:
|
2013-07-02 21:08:10 +00:00
|
|
|
g_object_get (meta, g_param_spec_get_name (pspec), &layout_align, NULL);
|
|
|
|
switch (layout_align)
|
|
|
|
{
|
|
|
|
case CLUTTER_BOX_ALIGNMENT_START:
|
|
|
|
align = ST_ALIGN_START;
|
|
|
|
break;
|
|
|
|
case CLUTTER_BOX_ALIGNMENT_CENTER:
|
|
|
|
align = ST_ALIGN_MIDDLE;
|
|
|
|
break;
|
|
|
|
case CLUTTER_BOX_ALIGNMENT_END:
|
|
|
|
align = ST_ALIGN_END;
|
2014-05-19 22:15:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2013-07-02 21:08:10 +00:00
|
|
|
}
|
|
|
|
g_value_set_enum (value, align);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_child_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
|
2013-07-02 21:08:10 +00:00
|
|
|
GObject *meta = G_OBJECT (get_layout_meta (child));
|
|
|
|
ClutterBoxAlignment align;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_EXPAND:
|
2013-07-02 21:08:10 +00:00
|
|
|
g_object_set (meta, "expand", g_value_get_boolean (value), NULL);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_X_FILL:
|
2013-07-02 21:08:10 +00:00
|
|
|
child->x_fill_set = TRUE;
|
|
|
|
g_object_set (meta, "x-fill", g_value_get_boolean (value), NULL);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_Y_FILL:
|
2013-07-02 21:08:10 +00:00
|
|
|
child->y_fill_set = TRUE;
|
|
|
|
g_object_set (meta, "y-fill", g_value_get_boolean (value), NULL);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
case PROP_X_ALIGN:
|
|
|
|
case PROP_Y_ALIGN:
|
2013-07-02 21:08:10 +00:00
|
|
|
switch (g_value_get_enum (value))
|
|
|
|
{
|
|
|
|
case ST_ALIGN_START:
|
|
|
|
align = CLUTTER_BOX_ALIGNMENT_START;
|
|
|
|
break;
|
|
|
|
case ST_ALIGN_MIDDLE:
|
|
|
|
align = CLUTTER_BOX_ALIGNMENT_CENTER;
|
|
|
|
break;
|
|
|
|
case ST_ALIGN_END:
|
|
|
|
align = CLUTTER_BOX_ALIGNMENT_END;
|
2014-05-19 22:15:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2013-07-02 21:08:10 +00:00
|
|
|
}
|
|
|
|
g_object_set (meta, g_param_spec_get_name (pspec), align, NULL);
|
2009-09-10 05:42:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
2013-07-02 21:08:10 +00:00
|
|
|
}
|
2009-09-10 05:42:25 +00:00
|
|
|
|
2013-07-02 21:08:10 +00:00
|
|
|
static void
|
|
|
|
st_box_layout_child_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
|
|
|
|
GObject *meta = G_OBJECT (get_layout_meta (child));
|
|
|
|
|
|
|
|
if (!child->x_fill_set)
|
|
|
|
g_object_set (meta, "x-fill", TRUE, NULL);
|
|
|
|
|
|
|
|
if (!child->y_fill_set)
|
|
|
|
g_object_set (meta, "y-fill", TRUE, NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (st_box_layout_child_parent_class)->constructed (object);
|
2009-09-10 05:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_child_class_init (StBoxLayoutChildClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
object_class->get_property = st_box_layout_child_get_property;
|
|
|
|
object_class->set_property = st_box_layout_child_set_property;
|
2013-07-02 21:08:10 +00:00
|
|
|
object_class->constructed = st_box_layout_child_constructed;
|
2009-09-10 05:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
pspec = g_param_spec_boolean ("expand", "Expand",
|
|
|
|
"Allocate the child extra space",
|
|
|
|
FALSE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_EXPAND, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_boolean ("x-fill", "x-fill",
|
|
|
|
"Whether the child should receive priority "
|
|
|
|
"when the container is allocating spare space "
|
|
|
|
"on the horizontal axis",
|
|
|
|
TRUE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_X_FILL, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_boolean ("y-fill", "y-fill",
|
|
|
|
"Whether the child should receive priority "
|
|
|
|
"when the container is allocating spare space "
|
|
|
|
"on the vertical axis",
|
|
|
|
TRUE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_Y_FILL, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_enum ("x-align",
|
|
|
|
"X Alignment",
|
|
|
|
"X alignment of the widget within the cell",
|
|
|
|
ST_TYPE_ALIGN,
|
|
|
|
ST_ALIGN_MIDDLE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_X_ALIGN, pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_enum ("y-align",
|
|
|
|
"Y Alignment",
|
|
|
|
"Y alignment of the widget within the cell",
|
|
|
|
ST_TYPE_ALIGN,
|
|
|
|
ST_ALIGN_MIDDLE,
|
|
|
|
ST_PARAM_READWRITE);
|
|
|
|
g_object_class_install_property (object_class, PROP_Y_ALIGN, pspec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_box_layout_child_init (StBoxLayoutChild *self)
|
|
|
|
{
|
|
|
|
}
|