No issues found
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3 * st-box-layout-child.c: box layout child actor
4 *
5 * Copyright 2009 Intel Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU Lesser General Public License,
9 * version 2.1, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /**
21 * SECTION:st-box-layout-child
22 * @short_description: meta data associated with a #StBoxLayout child.
23 *
24 * #StBoxLayoutChild is a #ClutterChildMeta implementation that stores the
25 * child properties for children inside a #StBoxLayout.
26 */
27
28 #include "st-box-layout-child.h"
29 #include "st-private.h"
30
31 G_DEFINE_TYPE (StBoxLayoutChild, st_box_layout_child, CLUTTER_TYPE_CHILD_META)
32
33 #define BOX_LAYOUT_CHILD_PRIVATE(o) \
34 (G_TYPE_INSTANCE_GET_PRIVATE ((o), ST_TYPE_BOX_LAYOUT_CHILD, StBoxLayoutChildPrivate))
35
36
37 enum
38 {
39 PROP_0,
40
41 PROP_EXPAND,
42 PROP_X_FILL,
43 PROP_Y_FILL,
44 PROP_X_ALIGN,
45 PROP_Y_ALIGN
46 };
47
48 static void
49 st_box_layout_child_get_property (GObject *object,
50 guint property_id,
51 GValue *value,
52 GParamSpec *pspec)
53 {
54 StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
55
56 switch (property_id)
57 {
58 case PROP_EXPAND:
59 g_value_set_boolean (value, child->expand);
60 break;
61 case PROP_X_FILL:
62 g_value_set_boolean (value, child->x_fill);
63 break;
64 case PROP_Y_FILL:
65 g_value_set_boolean (value, child->y_fill);
66 break;
67 case PROP_X_ALIGN:
68 g_value_set_enum (value, child->x_align);
69 break;
70 case PROP_Y_ALIGN:
71 g_value_set_enum (value, child->y_align);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 }
77 }
78
79 static void
80 st_box_layout_child_set_property (GObject *object,
81 guint property_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
86 StBoxLayout *box = ST_BOX_LAYOUT (CLUTTER_CHILD_META (object)->container);
87
88 switch (property_id)
89 {
90 case PROP_EXPAND:
91 child->expand = g_value_get_boolean (value);
92 break;
93 case PROP_X_FILL:
94 child->x_fill = g_value_get_boolean (value);
95 break;
96 case PROP_Y_FILL:
97 child->y_fill = g_value_get_boolean (value);
98 break;
99 case PROP_X_ALIGN:
100 child->x_align = g_value_get_enum (value);
101 break;
102 case PROP_Y_ALIGN:
103 child->y_align = g_value_get_enum (value);
104 break;
105
106 default:
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 }
109
110 clutter_actor_queue_relayout ((ClutterActor*) box);
111 }
112
113 static void
114 st_box_layout_child_dispose (GObject *object)
115 {
116 G_OBJECT_CLASS (st_box_layout_child_parent_class)->dispose (object);
117 }
118
119 static void
120 st_box_layout_child_finalize (GObject *object)
121 {
122 G_OBJECT_CLASS (st_box_layout_child_parent_class)->finalize (object);
123 }
124
125 static void
126 st_box_layout_child_class_init (StBoxLayoutChildClass *klass)
127 {
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 GParamSpec *pspec;
130
131 object_class->get_property = st_box_layout_child_get_property;
132 object_class->set_property = st_box_layout_child_set_property;
133 object_class->dispose = st_box_layout_child_dispose;
134 object_class->finalize = st_box_layout_child_finalize;
135
136
137 pspec = g_param_spec_boolean ("expand", "Expand",
138 "Allocate the child extra space",
139 FALSE,
140 ST_PARAM_READWRITE);
141 g_object_class_install_property (object_class, PROP_EXPAND, pspec);
142
143 pspec = g_param_spec_boolean ("x-fill", "x-fill",
144 "Whether the child should receive priority "
145 "when the container is allocating spare space "
146 "on the horizontal axis",
147 TRUE,
148 ST_PARAM_READWRITE);
149 g_object_class_install_property (object_class, PROP_X_FILL, pspec);
150
151 pspec = g_param_spec_boolean ("y-fill", "y-fill",
152 "Whether the child should receive priority "
153 "when the container is allocating spare space "
154 "on the vertical axis",
155 TRUE,
156 ST_PARAM_READWRITE);
157 g_object_class_install_property (object_class, PROP_Y_FILL, pspec);
158
159 pspec = g_param_spec_enum ("x-align",
160 "X Alignment",
161 "X alignment of the widget within the cell",
162 ST_TYPE_ALIGN,
163 ST_ALIGN_MIDDLE,
164 ST_PARAM_READWRITE);
165 g_object_class_install_property (object_class, PROP_X_ALIGN, pspec);
166
167 pspec = g_param_spec_enum ("y-align",
168 "Y Alignment",
169 "Y alignment of the widget within the cell",
170 ST_TYPE_ALIGN,
171 ST_ALIGN_MIDDLE,
172 ST_PARAM_READWRITE);
173 g_object_class_install_property (object_class, PROP_Y_ALIGN, pspec);
174 }
175
176 static void
177 st_box_layout_child_init (StBoxLayoutChild *self)
178 {
179 self->expand = FALSE;
180
181 self->x_fill = TRUE;
182 self->y_fill = TRUE;
183
184 self->x_align = ST_ALIGN_MIDDLE;
185 self->y_align = ST_ALIGN_MIDDLE;
186 }