File: | ctk/ctkboxgadget.c |
Warning: | line 190, column 37 Division by zero |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright © 2015 Red Hat Inc. | |||
3 | * | |||
4 | * This library is free software; you can redistribute it and/or | |||
5 | * modify it under the terms of the GNU Lesser General Public | |||
6 | * License as published by the Free Software Foundation; either | |||
7 | * version 2.1 of the License, or (at your option) any later version. | |||
8 | * | |||
9 | * This library is distributed in the hope that it will be useful, | |||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
12 | * Lesser General Public License for more details. | |||
13 | * | |||
14 | * You should have received a copy of the GNU Lesser General Public | |||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
16 | * | |||
17 | * Authors: Benjamin Otte <otte@gnome.org> | |||
18 | */ | |||
19 | ||||
20 | #include "config.h" | |||
21 | ||||
22 | #include "ctkboxgadgetprivate.h" | |||
23 | ||||
24 | #include "ctkcssnodeprivate.h" | |||
25 | #include "ctkmain.h" | |||
26 | #include "ctkprivate.h" | |||
27 | #include "ctksizerequest.h" | |||
28 | #include "ctkwidgetprivate.h" | |||
29 | ||||
30 | /* CtkBoxGadget is a container gadget implementation that arranges its | |||
31 | * children in a row, either horizontally or vertically. Children can | |||
32 | * be either widgets or gadgets, and can be set to expand horizontally | |||
33 | * or vertically, or both. | |||
34 | */ | |||
35 | ||||
36 | typedef struct _CtkBoxGadgetPrivate CtkBoxGadgetPrivate; | |||
37 | struct _CtkBoxGadgetPrivate { | |||
38 | CtkOrientation orientation; | |||
39 | GArray *children; | |||
40 | ||||
41 | guint draw_focus : 1; | |||
42 | guint draw_reverse : 1; | |||
43 | guint allocate_reverse : 1; | |||
44 | guint align_reverse : 1; | |||
45 | }; | |||
46 | ||||
47 | typedef gboolean (* ComputeExpandFunc) (GObject *object, CtkOrientation orientation); | |||
48 | ||||
49 | typedef struct _CtkBoxGadgetChild CtkBoxGadgetChild; | |||
50 | struct _CtkBoxGadgetChild { | |||
51 | GObject *object; | |||
52 | gboolean expand; | |||
53 | CtkAlign align; | |||
54 | }; | |||
55 | ||||
56 | G_DEFINE_TYPE_WITH_CODE (CtkBoxGadget, ctk_box_gadget, CTK_TYPE_CSS_GADGET,static void ctk_box_gadget_init (CtkBoxGadget *self); static void ctk_box_gadget_class_init (CtkBoxGadgetClass *klass); static GType ctk_box_gadget_get_type_once (void); static gpointer ctk_box_gadget_parent_class = ((void*)0); static gint CtkBoxGadget_private_offset; static void ctk_box_gadget_class_intern_init (gpointer klass) { ctk_box_gadget_parent_class = g_type_class_peek_parent (klass); if (CtkBoxGadget_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkBoxGadget_private_offset ); ctk_box_gadget_class_init ((CtkBoxGadgetClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_box_gadget_get_instance_private (CtkBoxGadget *self) { return (((gpointer) ((guint8*) (self) + (glong) (CtkBoxGadget_private_offset)))); } GType ctk_box_gadget_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_box_gadget_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_box_gadget_get_type_once (void ) { GType g_define_type_id = g_type_register_static_simple (( ctk_css_gadget_get_type ()), g_intern_static_string ("CtkBoxGadget" ), sizeof (CtkBoxGadgetClass), (GClassInitFunc)(void (*)(void )) ctk_box_gadget_class_intern_init, sizeof (CtkBoxGadget), ( GInstanceInitFunc)(void (*)(void)) ctk_box_gadget_init, (GTypeFlags ) 0); { {{ CtkBoxGadget_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkBoxGadgetPrivate)); };} } return g_define_type_id; } | |||
57 | G_ADD_PRIVATE (CtkBoxGadget))static void ctk_box_gadget_init (CtkBoxGadget *self); static void ctk_box_gadget_class_init (CtkBoxGadgetClass *klass); static GType ctk_box_gadget_get_type_once (void); static gpointer ctk_box_gadget_parent_class = ((void*)0); static gint CtkBoxGadget_private_offset; static void ctk_box_gadget_class_intern_init (gpointer klass) { ctk_box_gadget_parent_class = g_type_class_peek_parent (klass); if (CtkBoxGadget_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkBoxGadget_private_offset ); ctk_box_gadget_class_init ((CtkBoxGadgetClass*) klass); } __attribute__ ((__unused__)) static inline gpointer ctk_box_gadget_get_instance_private (CtkBoxGadget *self) { return (((gpointer) ((guint8*) (self) + (glong) (CtkBoxGadget_private_offset)))); } GType ctk_box_gadget_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_box_gadget_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_box_gadget_get_type_once (void ) { GType g_define_type_id = g_type_register_static_simple (( ctk_css_gadget_get_type ()), g_intern_static_string ("CtkBoxGadget" ), sizeof (CtkBoxGadgetClass), (GClassInitFunc)(void (*)(void )) ctk_box_gadget_class_intern_init, sizeof (CtkBoxGadget), ( GInstanceInitFunc)(void (*)(void)) ctk_box_gadget_init, (GTypeFlags ) 0); { {{ CtkBoxGadget_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkBoxGadgetPrivate)); };} } return g_define_type_id; } | |||
58 | ||||
59 | static gboolean | |||
60 | ctk_box_gadget_child_is_visible (GObject *child) | |||
61 | { | |||
62 | if (CTK_IS_WIDGET (child)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
63 | return ctk_widget_get_visible (CTK_WIDGET (child)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child)), ((ctk_widget_get_type ()))))))); | |||
64 | else | |||
65 | return ctk_css_gadget_get_visible (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ()))))))); | |||
66 | } | |||
67 | ||||
68 | static gboolean | |||
69 | ctk_box_gadget_child_compute_expand (CtkBoxGadget *gadget, | |||
70 | CtkBoxGadgetChild *child) | |||
71 | { | |||
72 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
73 | ||||
74 | if (child->expand) | |||
75 | return TRUE(!(0)); | |||
76 | ||||
77 | if (CTK_IS_WIDGET (child->object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child->object)); GType __t = ((ctk_widget_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
78 | return ctk_widget_compute_expand (CTK_WIDGET (child->object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child->object)), ((ctk_widget_get_type ())))))), priv->orientation); | |||
79 | ||||
80 | return FALSE(0); | |||
81 | } | |||
82 | ||||
83 | static CtkAlign | |||
84 | ctk_box_gadget_child_get_align (CtkBoxGadget *gadget, | |||
85 | CtkBoxGadgetChild *child) | |||
86 | { | |||
87 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
88 | CtkAlign align; | |||
89 | ||||
90 | if (CTK_IS_WIDGET (child->object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child->object)); GType __t = ((ctk_widget_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
91 | { | |||
92 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
93 | g_object_get (child->object, "valign", &align, NULL((void*)0)); | |||
94 | else | |||
95 | g_object_get (child->object, "halign", &align, NULL((void*)0)); | |||
96 | } | |||
97 | else | |||
98 | align = child->align; | |||
99 | ||||
100 | return align; | |||
101 | } | |||
102 | ||||
103 | static CtkAlign | |||
104 | effective_align (CtkAlign align, | |||
105 | gboolean reverse) | |||
106 | { | |||
107 | switch (align) | |||
108 | { | |||
109 | case CTK_ALIGN_START: | |||
110 | return reverse ? CTK_ALIGN_END : CTK_ALIGN_START; | |||
111 | case CTK_ALIGN_END: | |||
112 | return reverse ? CTK_ALIGN_START : CTK_ALIGN_END; | |||
113 | default: | |||
114 | return align; | |||
115 | } | |||
116 | } | |||
117 | ||||
118 | static void | |||
119 | ctk_box_gadget_measure_child (GObject *child, | |||
120 | CtkOrientation orientation, | |||
121 | gint for_size, | |||
122 | gint *minimum, | |||
123 | gint *natural, | |||
124 | gint *minimum_baseline, | |||
125 | gint *natural_baseline) | |||
126 | { | |||
127 | if (CTK_IS_WIDGET (child)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
128 | { | |||
129 | _ctk_widget_get_preferred_size_for_size (CTK_WIDGET (child)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child)), ((ctk_widget_get_type ())))))), | |||
130 | orientation, | |||
131 | for_size, | |||
132 | minimum, natural, | |||
133 | minimum_baseline, natural_baseline); | |||
134 | } | |||
135 | else | |||
136 | { | |||
137 | ctk_css_gadget_get_preferred_size (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ())))))), | |||
138 | orientation, | |||
139 | for_size, | |||
140 | minimum, natural, | |||
141 | minimum_baseline, natural_baseline); | |||
142 | } | |||
143 | } | |||
144 | ||||
145 | static void | |||
146 | ctk_box_gadget_distribute (CtkBoxGadget *gadget, | |||
147 | gint for_size, | |||
148 | gint size, | |||
149 | CtkRequestedSize *sizes) | |||
150 | { | |||
151 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
152 | guint i, n_expand; | |||
153 | ||||
154 | n_expand = 0; | |||
155 | ||||
156 | for (i = 0 ; i < priv->children->len; i++) | |||
157 | { | |||
158 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
159 | ||||
160 | ctk_box_gadget_measure_child (child->object, | |||
161 | priv->orientation, | |||
162 | for_size, | |||
163 | &sizes[i].minimum_size, &sizes[i].natural_size, | |||
164 | NULL((void*)0), NULL((void*)0)); | |||
165 | if (ctk_box_gadget_child_is_visible (child->object) && | |||
166 | ctk_box_gadget_child_compute_expand (gadget, child)) | |||
167 | n_expand++; | |||
168 | size -= sizes[i].minimum_size; | |||
169 | } | |||
170 | ||||
171 | if G_UNLIKELY (size < 0)(size < 0) | |||
172 | { | |||
173 | g_critical ("%s: assertion 'size >= 0' failed in %s", G_STRFUNC((const char*) (__func__)), G_OBJECT_TYPE_NAME (ctk_css_gadget_get_owner (CTK_CSS_GADGET (gadget)))(g_type_name ((((((GTypeClass*) (((GTypeInstance*) (ctk_css_gadget_get_owner (((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ())))))))))->g_class ))->g_type)))))); | |||
174 | return; | |||
175 | } | |||
176 | ||||
177 | size = ctk_distribute_natural_allocation (size, priv->children->len, sizes); | |||
178 | ||||
179 | if (size <= 0 || n_expand
| |||
180 | return; | |||
181 | ||||
182 | for (i = 0 ; i < priv->children->len; i++) | |||
183 | { | |||
184 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
185 | ||||
186 | if (!ctk_box_gadget_child_is_visible (child->object) || | |||
187 | !ctk_box_gadget_child_compute_expand (gadget, child)) | |||
188 | continue; | |||
189 | ||||
190 | sizes[i].minimum_size += size / n_expand; | |||
| ||||
191 | /* distribute all pixels, even if there's a remainder */ | |||
192 | size -= size / n_expand; | |||
193 | n_expand--; | |||
194 | } | |||
195 | ||||
196 | } | |||
197 | ||||
198 | static void | |||
199 | ctk_box_gadget_measure_orientation (CtkCssGadget *gadget, | |||
200 | CtkOrientation orientation, | |||
201 | gint for_size, | |||
202 | gint *minimum, | |||
203 | gint *natural, | |||
204 | gint *minimum_baseline G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
205 | gint *natural_baseline G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
206 | { | |||
207 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
208 | gint child_min, child_nat; | |||
209 | guint i; | |||
210 | ||||
211 | *minimum = 0; | |||
212 | *natural = 0; | |||
213 | ||||
214 | for (i = 0 ; i < priv->children->len; i++) | |||
215 | { | |||
216 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
217 | ||||
218 | ctk_box_gadget_measure_child (child->object, | |||
219 | orientation, | |||
220 | for_size, | |||
221 | &child_min, &child_nat, | |||
222 | NULL((void*)0), NULL((void*)0)); | |||
223 | ||||
224 | *minimum += child_min; | |||
225 | *natural += child_nat; | |||
226 | } | |||
227 | } | |||
228 | ||||
229 | static void | |||
230 | ctk_box_gadget_measure_opposite (CtkCssGadget *gadget, | |||
231 | CtkOrientation orientation, | |||
232 | gint for_size, | |||
233 | gint *minimum, | |||
234 | gint *natural, | |||
235 | gint *minimum_baseline, | |||
236 | gint *natural_baseline) | |||
237 | { | |||
238 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
239 | int child_min, child_nat, child_min_baseline, child_nat_baseline; | |||
240 | int total_min, above_min, below_min, total_nat, above_nat, below_nat; | |||
241 | CtkRequestedSize *sizes; | |||
242 | guint i; | |||
243 | ||||
244 | if (for_size >= 0) | |||
245 | { | |||
246 | sizes = g_newa (CtkRequestedSize, priv->children->len)((CtkRequestedSize*) __builtin_alloca (sizeof (CtkRequestedSize ) * (gsize) (priv->children->len))); | |||
247 | ctk_box_gadget_distribute (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ())))))), -1, for_size, sizes); | |||
248 | } | |||
249 | ||||
250 | above_min = below_min = above_nat = below_nat = -1; | |||
251 | total_min = total_nat = 0; | |||
252 | ||||
253 | for (i = 0 ; i < priv->children->len; i++) | |||
254 | { | |||
255 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
256 | ||||
257 | ctk_box_gadget_measure_child (child->object, | |||
258 | orientation, | |||
259 | for_size >= 0 ? sizes[i].minimum_size : -1, | |||
260 | &child_min, &child_nat, | |||
261 | &child_min_baseline, &child_nat_baseline); | |||
262 | ||||
263 | if (child_min_baseline >= 0) | |||
264 | { | |||
265 | below_min = MAX (below_min, child_min - child_min_baseline)(((below_min) > (child_min - child_min_baseline)) ? (below_min ) : (child_min - child_min_baseline)); | |||
266 | above_min = MAX (above_min, child_min_baseline)(((above_min) > (child_min_baseline)) ? (above_min) : (child_min_baseline )); | |||
267 | below_nat = MAX (below_nat, child_nat - child_nat_baseline)(((below_nat) > (child_nat - child_nat_baseline)) ? (below_nat ) : (child_nat - child_nat_baseline)); | |||
268 | above_nat = MAX (above_nat, child_nat_baseline)(((above_nat) > (child_nat_baseline)) ? (above_nat) : (child_nat_baseline )); | |||
269 | } | |||
270 | else | |||
271 | { | |||
272 | total_min = MAX (total_min, child_min)(((total_min) > (child_min)) ? (total_min) : (child_min)); | |||
273 | total_nat = MAX (total_nat, child_nat)(((total_nat) > (child_nat)) ? (total_nat) : (child_nat)); | |||
274 | } | |||
275 | } | |||
276 | ||||
277 | if (above_min >= 0) | |||
278 | { | |||
279 | total_min = MAX (total_min, above_min + below_min)(((total_min) > (above_min + below_min)) ? (total_min) : ( above_min + below_min)); | |||
280 | total_nat = MAX (total_nat, above_nat + below_nat)(((total_nat) > (above_nat + below_nat)) ? (total_nat) : ( above_nat + below_nat)); | |||
281 | /* assume CTK_BASELINE_POSITION_CENTER for now */ | |||
282 | if (minimum_baseline) | |||
283 | *minimum_baseline = above_min + (total_min - (above_min + below_min)) / 2; | |||
284 | if (natural_baseline) | |||
285 | *natural_baseline = above_nat + (total_nat - (above_nat + below_nat)) / 2; | |||
286 | } | |||
287 | ||||
288 | *minimum = total_min; | |||
289 | *natural = total_nat; | |||
290 | } | |||
291 | ||||
292 | static void | |||
293 | ctk_box_gadget_get_preferred_size (CtkCssGadget *gadget, | |||
294 | CtkOrientation orientation, | |||
295 | gint for_size, | |||
296 | gint *minimum, | |||
297 | gint *natural, | |||
298 | gint *minimum_baseline, | |||
299 | gint *natural_baseline) | |||
300 | { | |||
301 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
302 | ||||
303 | if (priv->orientation == orientation) | |||
| ||||
304 | ctk_box_gadget_measure_orientation (gadget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline); | |||
305 | else | |||
306 | ctk_box_gadget_measure_opposite (gadget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline); | |||
307 | } | |||
308 | ||||
309 | static void | |||
310 | ctk_box_gadget_allocate_child (GObject *child, | |||
311 | CtkOrientation box_orientation, | |||
312 | CtkAlign child_align, | |||
313 | CtkAllocation *allocation, | |||
314 | int baseline, | |||
315 | CtkAllocation *out_clip) | |||
316 | { | |||
317 | if (CTK_IS_WIDGET (child)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
318 | { | |||
319 | ctk_widget_size_allocate_with_baseline (CTK_WIDGET (child)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child)), ((ctk_widget_get_type ())))))), allocation, baseline); | |||
320 | ctk_widget_get_clip (CTK_WIDGET (child)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child)), ((ctk_widget_get_type ())))))), out_clip); | |||
321 | } | |||
322 | else | |||
323 | { | |||
324 | CtkAllocation child_allocation; | |||
325 | int minimum, natural; | |||
326 | int minimum_baseline, natural_baseline; | |||
327 | ||||
328 | if (box_orientation == CTK_ORIENTATION_HORIZONTAL) | |||
329 | { | |||
330 | child_allocation.width = allocation->width; | |||
331 | child_allocation.x = allocation->x; | |||
332 | ||||
333 | ctk_css_gadget_get_preferred_size (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ())))))), | |||
334 | CTK_ORIENTATION_VERTICAL, | |||
335 | allocation->width, | |||
336 | &minimum, &natural, | |||
337 | &minimum_baseline, &natural_baseline); | |||
338 | ||||
339 | switch (child_align) | |||
340 | { | |||
341 | case CTK_ALIGN_FILL: | |||
342 | child_allocation.height = allocation->height; | |||
343 | child_allocation.y = allocation->y; | |||
344 | break; | |||
345 | case CTK_ALIGN_START: | |||
346 | child_allocation.height = MIN(natural, allocation->height)(((natural) < (allocation->height)) ? (natural) : (allocation ->height)); | |||
347 | child_allocation.y = allocation->y; | |||
348 | break; | |||
349 | case CTK_ALIGN_END: | |||
350 | child_allocation.height = MIN(natural, allocation->height)(((natural) < (allocation->height)) ? (natural) : (allocation ->height)); | |||
351 | child_allocation.y = allocation->y + allocation->height - child_allocation.height; | |||
352 | break; | |||
353 | case CTK_ALIGN_BASELINE: | |||
354 | if (minimum_baseline >= 0 && baseline >= 0) | |||
355 | { | |||
356 | child_allocation.height = MIN(natural, allocation->height)(((natural) < (allocation->height)) ? (natural) : (allocation ->height)); | |||
357 | child_allocation.y = allocation->y + MAX(0, baseline - minimum_baseline)(((0) > (baseline - minimum_baseline)) ? (0) : (baseline - minimum_baseline)); | |||
358 | break; | |||
359 | } | |||
360 | case CTK_ALIGN_CENTER: | |||
361 | child_allocation.height = MIN(natural, allocation->height)(((natural) < (allocation->height)) ? (natural) : (allocation ->height)); | |||
362 | child_allocation.y = allocation->y + (allocation->height - child_allocation.height) / 2; | |||
363 | break; | |||
364 | default: | |||
365 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctkboxgadget.c", 365, ( (const char*) (__func__)), ((void*)0)); } while (0); | |||
366 | } | |||
367 | } | |||
368 | else | |||
369 | { | |||
370 | child_allocation.height = allocation->height; | |||
371 | child_allocation.y = allocation->y; | |||
372 | ||||
373 | ctk_css_gadget_get_preferred_size (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ())))))), | |||
374 | CTK_ORIENTATION_HORIZONTAL, | |||
375 | allocation->height, | |||
376 | &minimum, &natural, | |||
377 | NULL((void*)0), NULL((void*)0)); | |||
378 | ||||
379 | switch (child_align) | |||
380 | { | |||
381 | case CTK_ALIGN_FILL: | |||
382 | child_allocation.width = allocation->width; | |||
383 | child_allocation.x = allocation->x; | |||
384 | break; | |||
385 | case CTK_ALIGN_START: | |||
386 | child_allocation.width = MIN(natural, allocation->width)(((natural) < (allocation->width)) ? (natural) : (allocation ->width)); | |||
387 | child_allocation.x = allocation->x; | |||
388 | break; | |||
389 | case CTK_ALIGN_END: | |||
390 | child_allocation.width = MIN(natural, allocation->width)(((natural) < (allocation->width)) ? (natural) : (allocation ->width)); | |||
391 | child_allocation.x = allocation->x + allocation->width - child_allocation.width; | |||
392 | break; | |||
393 | case CTK_ALIGN_BASELINE: | |||
394 | case CTK_ALIGN_CENTER: | |||
395 | child_allocation.width = MIN(natural, allocation->width)(((natural) < (allocation->width)) ? (natural) : (allocation ->width)); | |||
396 | child_allocation.x = allocation->x + (allocation->width - child_allocation.width) / 2; | |||
397 | break; | |||
398 | default: | |||
399 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctkboxgadget.c", 399, ( (const char*) (__func__)), ((void*)0)); } while (0); | |||
400 | } | |||
401 | } | |||
402 | ||||
403 | ctk_css_gadget_allocate (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ())))))), &child_allocation, baseline, out_clip); | |||
404 | } | |||
405 | } | |||
406 | ||||
407 | static void | |||
408 | ctk_box_gadget_allocate (CtkCssGadget *gadget, | |||
409 | const CtkAllocation *allocation, | |||
410 | int baseline, | |||
411 | CtkAllocation *out_clip) | |||
412 | { | |||
413 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
414 | CtkRequestedSize *sizes; | |||
415 | CtkAllocation child_allocation, child_clip; | |||
416 | CtkAlign child_align; | |||
417 | guint i; | |||
418 | ||||
419 | child_allocation = *allocation; | |||
420 | sizes = g_newa (CtkRequestedSize, priv->children->len)((CtkRequestedSize*) __builtin_alloca (sizeof (CtkRequestedSize ) * (gsize) (priv->children->len))); | |||
421 | ||||
422 | if (priv->orientation == CTK_ORIENTATION_HORIZONTAL) | |||
423 | { | |||
424 | ctk_box_gadget_distribute (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ())))))), allocation->height, allocation->width, sizes); | |||
425 | ||||
426 | if (priv->allocate_reverse) | |||
427 | child_allocation.x = allocation->x + allocation->width; | |||
428 | ||||
429 | for (i = 0; i < priv->children->len; i++) | |||
430 | { | |||
431 | guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i; | |||
432 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, idx)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(idx)]); | |||
433 | child_allocation.width = sizes[idx].minimum_size; | |||
434 | child_allocation.height = allocation->height; | |||
435 | child_allocation.y = allocation->y; | |||
436 | if (priv->allocate_reverse) | |||
437 | child_allocation.x -= child_allocation.width; | |||
438 | ||||
439 | child_align = ctk_box_gadget_child_get_align (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ())))))), child); | |||
440 | ctk_box_gadget_allocate_child (child->object, | |||
441 | priv->orientation, | |||
442 | effective_align (child_align, priv->align_reverse), | |||
443 | &child_allocation, | |||
444 | baseline, | |||
445 | &child_clip); | |||
446 | ||||
447 | if (i == 0) | |||
448 | *out_clip = child_clip; | |||
449 | else | |||
450 | cdk_rectangle_union (out_clip, &child_clip, out_clip); | |||
451 | ||||
452 | if (!priv->allocate_reverse) | |||
453 | child_allocation.x += sizes[idx].minimum_size; | |||
454 | } | |||
455 | } | |||
456 | else | |||
457 | { | |||
458 | ctk_box_gadget_distribute (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ())))))), allocation->width, allocation->height, sizes); | |||
459 | ||||
460 | if (priv->allocate_reverse) | |||
461 | child_allocation.y = allocation->y + allocation->height; | |||
462 | ||||
463 | for (i = 0 ; i < priv->children->len; i++) | |||
464 | { | |||
465 | guint idx = priv->allocate_reverse ? priv->children->len - 1 - i : i; | |||
466 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, idx)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(idx)]); | |||
467 | child_allocation.height = sizes[idx].minimum_size; | |||
468 | child_allocation.width = allocation->width; | |||
469 | child_allocation.x = allocation->x; | |||
470 | if (priv->allocate_reverse) | |||
471 | child_allocation.y -= child_allocation.height; | |||
472 | ||||
473 | child_align = ctk_box_gadget_child_get_align (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ())))))), child); | |||
474 | ctk_box_gadget_allocate_child (child->object, | |||
475 | priv->orientation, | |||
476 | effective_align (child_align, priv->align_reverse), | |||
477 | &child_allocation, | |||
478 | -1, | |||
479 | &child_clip); | |||
480 | ||||
481 | if (i == 0) | |||
482 | *out_clip = child_clip; | |||
483 | else | |||
484 | cdk_rectangle_union (out_clip, &child_clip, out_clip); | |||
485 | ||||
486 | if (!priv->allocate_reverse) | |||
487 | child_allocation.y += sizes[idx].minimum_size; | |||
488 | } | |||
489 | } | |||
490 | } | |||
491 | ||||
492 | static gboolean | |||
493 | ctk_box_gadget_draw (CtkCssGadget *gadget, | |||
494 | cairo_t *cr, | |||
495 | int x G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
496 | int y G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
497 | int width G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
498 | int height G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
499 | { | |||
500 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
501 | CtkWidget *owner = ctk_css_gadget_get_owner (gadget); | |||
502 | guint i; | |||
503 | ||||
504 | for (i = 0; i < priv->children->len; i++) | |||
505 | { | |||
506 | guint draw_index = priv->draw_reverse ? priv->children->len - 1 - i : i; | |||
507 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, draw_index)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(draw_index)]); | |||
508 | ||||
509 | if (CTK_IS_WIDGET (child->object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child->object)); GType __t = ((ctk_widget_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
510 | ctk_container_propagate_draw (CTK_CONTAINER (owner)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((owner)), ((ctk_container_get_type ())))))), CTK_WIDGET (child->object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child->object)), ((ctk_widget_get_type ())))))), cr); | |||
511 | else | |||
512 | ctk_css_gadget_draw (CTK_CSS_GADGET (child->object)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child->object), ((ctk_css_gadget_get_type ())))))), cr); | |||
513 | } | |||
514 | ||||
515 | if (priv->draw_focus && ctk_widget_has_visible_focus (owner)) | |||
516 | return TRUE(!(0)); | |||
517 | ||||
518 | return FALSE(0); | |||
519 | } | |||
520 | ||||
521 | static void | |||
522 | ctk_box_gadget_finalize (GObject *object) | |||
523 | { | |||
524 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (object)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (object), ((ctk_box_gadget_get_type ()))))))); | |||
525 | ||||
526 | g_array_free (priv->children, TRUE(!(0))); | |||
527 | ||||
528 | G_OBJECT_CLASS (ctk_box_gadget_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_box_gadget_parent_class)), (((GType) ((20) << ( 2))))))))->finalize (object); | |||
529 | } | |||
530 | ||||
531 | static void | |||
532 | ctk_box_gadget_class_init (CtkBoxGadgetClass *klass) | |||
533 | { | |||
534 | CtkCssGadgetClass *gadget_class = CTK_CSS_GADGET_CLASS (klass)((((CtkCssGadgetClass*) (void *) g_type_check_class_cast ((GTypeClass *) (klass), ((ctk_css_gadget_get_type ())))))); | |||
535 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); | |||
536 | ||||
537 | object_class->finalize = ctk_box_gadget_finalize; | |||
538 | ||||
539 | gadget_class->get_preferred_size = ctk_box_gadget_get_preferred_size; | |||
540 | gadget_class->allocate = ctk_box_gadget_allocate; | |||
541 | gadget_class->draw = ctk_box_gadget_draw; | |||
542 | } | |||
543 | ||||
544 | static void | |||
545 | ctk_box_gadget_clear_child (gpointer data) | |||
546 | { | |||
547 | CtkBoxGadgetChild *child = data; | |||
548 | ||||
549 | g_object_unref (child->object); | |||
550 | } | |||
551 | ||||
552 | static void | |||
553 | ctk_box_gadget_init (CtkBoxGadget *gadget) | |||
554 | { | |||
555 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
556 | ||||
557 | priv->children = g_array_new (FALSE(0), FALSE(0), sizeof (CtkBoxGadgetChild)); | |||
558 | g_array_set_clear_func (priv->children, ctk_box_gadget_clear_child); | |||
559 | } | |||
560 | ||||
561 | CtkCssGadget * | |||
562 | ctk_box_gadget_new_for_node (CtkCssNode *node, | |||
563 | CtkWidget *owner) | |||
564 | { | |||
565 | return g_object_new (CTK_TYPE_BOX_GADGET(ctk_box_gadget_get_type ()), | |||
566 | "node", node, | |||
567 | "owner", owner, | |||
568 | NULL((void*)0)); | |||
569 | } | |||
570 | ||||
571 | CtkCssGadget * | |||
572 | ctk_box_gadget_new (const char *name, | |||
573 | CtkWidget *owner, | |||
574 | CtkCssGadget *parent, | |||
575 | CtkCssGadget *next_sibling) | |||
576 | { | |||
577 | CtkCssNode *node; | |||
578 | CtkCssGadget *result; | |||
579 | ||||
580 | node = ctk_css_node_new (); | |||
581 | ctk_css_node_set_name (node, g_intern_string (name)); | |||
582 | if (parent) | |||
583 | ctk_css_node_insert_before (ctk_css_gadget_get_node (parent), | |||
584 | node, | |||
585 | next_sibling ? ctk_css_gadget_get_node (next_sibling) : NULL((void*)0)); | |||
586 | ||||
587 | result = ctk_box_gadget_new_for_node (node, owner); | |||
588 | ||||
589 | g_object_unref (node); | |||
590 | ||||
591 | return result; | |||
592 | } | |||
593 | ||||
594 | void | |||
595 | ctk_box_gadget_set_orientation (CtkBoxGadget *gadget, | |||
596 | CtkOrientation orientation) | |||
597 | { | |||
598 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
599 | ||||
600 | priv->orientation = orientation; | |||
601 | } | |||
602 | ||||
603 | void | |||
604 | ctk_box_gadget_set_draw_focus (CtkBoxGadget *gadget, | |||
605 | gboolean draw_focus) | |||
606 | { | |||
607 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
608 | ||||
609 | priv->draw_focus = draw_focus; | |||
610 | } | |||
611 | ||||
612 | void | |||
613 | ctk_box_gadget_set_draw_reverse (CtkBoxGadget *gadget, | |||
614 | gboolean draw_reverse) | |||
615 | { | |||
616 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
617 | ||||
618 | priv->draw_reverse = draw_reverse; | |||
619 | } | |||
620 | ||||
621 | void | |||
622 | ctk_box_gadget_set_allocate_reverse (CtkBoxGadget *gadget, | |||
623 | gboolean allocate_reverse) | |||
624 | { | |||
625 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
626 | ||||
627 | priv->allocate_reverse = allocate_reverse; | |||
628 | } | |||
629 | ||||
630 | void | |||
631 | ctk_box_gadget_set_align_reverse (CtkBoxGadget *gadget, | |||
632 | gboolean align_reverse) | |||
633 | { | |||
634 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
635 | ||||
636 | priv->align_reverse = align_reverse; | |||
637 | } | |||
638 | ||||
639 | static CtkCssNode * | |||
640 | get_css_node (GObject *child) | |||
641 | { | |||
642 | if (CTK_IS_WIDGET (child)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (child)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
643 | return ctk_widget_get_css_node (CTK_WIDGET (child)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((child)), ((ctk_widget_get_type ()))))))); | |||
644 | else | |||
645 | return ctk_css_gadget_get_node (CTK_CSS_GADGET (child)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (child), ((ctk_css_gadget_get_type ()))))))); | |||
646 | } | |||
647 | ||||
648 | static void | |||
649 | ctk_box_gadget_insert_object (CtkBoxGadget *gadget, | |||
650 | int pos, | |||
651 | GObject *object, | |||
652 | gboolean expand, | |||
653 | CtkAlign align) | |||
654 | { | |||
655 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
656 | CtkBoxGadgetChild child; | |||
657 | ||||
658 | child.object = g_object_ref (object)((__typeof__ (object)) (g_object_ref) (object)); | |||
659 | child.expand = expand; | |||
660 | child.align = align; | |||
661 | ||||
662 | if (pos < 0 || pos >= priv->children->len) | |||
663 | { | |||
664 | g_array_append_val (priv->children, child)g_array_append_vals (priv->children, &(child), 1); | |||
665 | ctk_css_node_insert_before (ctk_css_gadget_get_node (CTK_CSS_GADGET (gadget)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ()))))))), | |||
666 | get_css_node (object), | |||
667 | NULL((void*)0)); | |||
668 | } | |||
669 | else | |||
670 | { | |||
671 | g_array_insert_val (priv->children, pos, child)g_array_insert_vals (priv->children, pos, &(child), 1); | |||
672 | ctk_css_node_insert_before (ctk_css_gadget_get_node (CTK_CSS_GADGET (gadget)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ()))))))), | |||
673 | get_css_node (object), | |||
674 | get_css_node (g_array_index (priv->children, CtkBoxGadgetChild, pos + 1)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(pos + 1)]).object)); | |||
675 | } | |||
676 | } | |||
677 | ||||
678 | void | |||
679 | ctk_box_gadget_insert_widget (CtkBoxGadget *gadget, | |||
680 | int pos, | |||
681 | CtkWidget *widget) | |||
682 | { | |||
683 | ctk_box_gadget_insert_object (gadget, pos, G_OBJECT (widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2)))))))), FALSE(0), CTK_ALIGN_FILL); | |||
684 | } | |||
685 | ||||
686 | static CtkBoxGadgetChild * | |||
687 | ctk_box_gadget_find_object (CtkBoxGadget *gadget, | |||
688 | GObject *object, | |||
689 | int *position) | |||
690 | { | |||
691 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
692 | guint i; | |||
693 | ||||
694 | for (i = 0; i < priv->children->len; i++) | |||
695 | { | |||
696 | CtkBoxGadgetChild *child = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
697 | ||||
698 | if (child->object == object) | |||
699 | { | |||
700 | if (position) | |||
701 | *position = i; | |||
702 | return child; | |||
703 | } | |||
704 | } | |||
705 | ||||
706 | return NULL((void*)0); | |||
707 | } | |||
708 | ||||
709 | static void | |||
710 | ctk_box_gadget_remove_object (CtkBoxGadget *gadget, | |||
711 | GObject *object) | |||
712 | { | |||
713 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (gadget); | |||
714 | CtkBoxGadgetChild *child; | |||
715 | int position; | |||
716 | ||||
717 | child = ctk_box_gadget_find_object (gadget, object, &position); | |||
718 | if (child) | |||
719 | { | |||
720 | ctk_css_node_set_parent (get_css_node (child->object), NULL((void*)0)); | |||
721 | g_array_remove_index (priv->children, position); | |||
722 | } | |||
723 | } | |||
724 | ||||
725 | void | |||
726 | ctk_box_gadget_remove_widget (CtkBoxGadget *gadget, | |||
727 | CtkWidget *widget) | |||
728 | { | |||
729 | ctk_box_gadget_remove_object (gadget, G_OBJECT (widget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((widget)), (((GType) ((20) << (2))))))))); | |||
730 | } | |||
731 | ||||
732 | void | |||
733 | ctk_box_gadget_insert_gadget_before (CtkBoxGadget *gadget, | |||
734 | CtkCssGadget *sibling, | |||
735 | CtkCssGadget *cssgadget, | |||
736 | gboolean expand, | |||
737 | CtkAlign align) | |||
738 | { | |||
739 | /* Insert at the end if no sibling specified */ | |||
740 | int pos = -1; | |||
741 | ||||
742 | if (sibling) | |||
743 | ctk_box_gadget_find_object (gadget, G_OBJECT (sibling)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sibling)), (((GType) ((20) << (2)))))))), &pos); | |||
744 | ||||
745 | ctk_box_gadget_insert_gadget (gadget, pos, cssgadget, expand, align); | |||
746 | } | |||
747 | ||||
748 | void | |||
749 | ctk_box_gadget_insert_gadget_after (CtkBoxGadget *gadget, | |||
750 | CtkCssGadget *sibling, | |||
751 | CtkCssGadget *cssgadget, | |||
752 | gboolean expand, | |||
753 | CtkAlign align) | |||
754 | { | |||
755 | /* Insert at the beginning if no sibling specified */ | |||
756 | int pos = 0; | |||
757 | ||||
758 | if (sibling && ctk_box_gadget_find_object (gadget, G_OBJECT (sibling)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((sibling)), (((GType) ((20) << (2)))))))), &pos)) | |||
759 | pos++; | |||
760 | ||||
761 | ctk_box_gadget_insert_gadget (gadget, pos, cssgadget, expand, align); | |||
762 | } | |||
763 | ||||
764 | void | |||
765 | ctk_box_gadget_insert_gadget (CtkBoxGadget *gadget, | |||
766 | int pos, | |||
767 | CtkCssGadget *cssgadget, | |||
768 | gboolean expand, | |||
769 | CtkAlign align) | |||
770 | { | |||
771 | ctk_box_gadget_insert_object (gadget, pos, G_OBJECT (cssgadget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((cssgadget)), (((GType) ((20) << (2)))))))), expand, align); | |||
772 | } | |||
773 | ||||
774 | void | |||
775 | ctk_box_gadget_remove_gadget (CtkBoxGadget *gadget, | |||
776 | CtkCssGadget *cssgadget) | |||
777 | { | |||
778 | ctk_box_gadget_remove_object (gadget, G_OBJECT (cssgadget)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((cssgadget)), (((GType) ((20) << (2))))))))); | |||
779 | } | |||
780 | ||||
781 | void | |||
782 | ctk_box_gadget_reverse_children (CtkBoxGadget *gadget) | |||
783 | { | |||
784 | CtkBoxGadgetPrivate *priv = ctk_box_gadget_get_instance_private (CTK_BOX_GADGET (gadget)((((CtkBoxGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_box_gadget_get_type ()))))))); | |||
785 | int i, j; | |||
786 | ||||
787 | ctk_css_node_reverse_children (ctk_css_gadget_get_node (CTK_CSS_GADGET (gadget)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ())))))))); | |||
788 | ||||
789 | for (i = 0, j = priv->children->len - 1; i < j; i++, j--) | |||
790 | { | |||
791 | CtkBoxGadgetChild *child1 = &g_array_index (priv->children, CtkBoxGadgetChild, i)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(i)]); | |||
792 | CtkBoxGadgetChild *child2 = &g_array_index (priv->children, CtkBoxGadgetChild, j)(((CtkBoxGadgetChild*) (void *) (priv->children)->data) [(j)]); | |||
793 | CtkBoxGadgetChild tmp; | |||
794 | ||||
795 | tmp = *child1; | |||
796 | *child1 = *child2; | |||
797 | *child2 = tmp; | |||
798 | } | |||
799 | } | |||
800 | ||||
801 | void | |||
802 | ctk_box_gadget_set_gadget_expand (CtkBoxGadget *gadget, | |||
803 | GObject *object, | |||
804 | gboolean expand) | |||
805 | { | |||
806 | CtkBoxGadgetChild *child; | |||
807 | ||||
808 | child = ctk_box_gadget_find_object (gadget, object, NULL((void*)0)); | |||
809 | ||||
810 | if (!child) | |||
811 | return; | |||
812 | ||||
813 | if (child->expand == expand) | |||
814 | return; | |||
815 | ||||
816 | child->expand = expand; | |||
817 | ctk_css_gadget_queue_resize (CTK_CSS_GADGET (gadget)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ()))))))); | |||
818 | } | |||
819 | ||||
820 | void | |||
821 | ctk_box_gadget_set_gadget_align (CtkBoxGadget *gadget, | |||
822 | GObject *object, | |||
823 | CtkAlign align) | |||
824 | { | |||
825 | CtkBoxGadgetChild *child; | |||
826 | ||||
827 | child = ctk_box_gadget_find_object (gadget, object, NULL((void*)0)); | |||
828 | ||||
829 | if (!child) | |||
830 | return; | |||
831 | ||||
832 | if (child->align == align) | |||
833 | return; | |||
834 | ||||
835 | child->align = align; | |||
836 | ctk_css_gadget_queue_resize (CTK_CSS_GADGET (gadget)((((CtkCssGadget*) (void *) g_type_check_instance_cast ((GTypeInstance *) (gadget), ((ctk_css_gadget_get_type ()))))))); | |||
837 | } |