Debian Codegraph @

clutter/deprecated/clutter-table-layout.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Copyright (C) 2009 Intel Corporation.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * Author:
22 * Jose Dapena Paz <[email protected]>
23 *
24 * Based on the MX MxTable actor by:
25 * Thomas Wood <[email protected]>
26 * and ClutterBoxLayout by:
27 * Emmanuele Bassi <[email protected]>
28 */
29
30 /**
31 * SECTION:clutter-table-layout
32 * @title: ClutterTableLayout
33 * @short_description: A layout manager arranging children in rows
34 * and columns
35 *
36 * The #ClutterTableLayout is a #ClutterLayoutManager implementing the
37 * following layout policy:
38 *
39 * - children are arranged in a table
40 * - each child specifies the specific row and column
41 * cell to appear;
42 * - a child can also set a span, and this way, take
43 * more than one cell both horizontally and vertically;
44 * - each child will be allocated to its natural
45 * size or, if set to expand, the available size;
46 * - if a child is set to fill on either (or both)
47 * axis, its allocation will match all the available size; the
48 * fill layout property only makes sense if the expand property is
49 * also set;
50 * - if a child is set to expand but not to fill then
51 * it is possible to control the alignment using the horizontal and
52 * vertical alignment layout properties.
53 *
54 * It is possible to control the spacing between children of a
55 * #ClutterTableLayout by using clutter_table_layout_set_row_spacing()
56 * and clutter_table_layout_set_column_spacing().
57 *
58 * In order to set the layout properties when packing an actor inside a
59 * #ClutterTableLayout you should use the clutter_table_layout_pack()
60 * function.
61 *
62 * A #ClutterTableLayout can use animations to transition between different
63 * values of the layout management properties; the easing mode and duration
64 * used for the animations are controlled by the
65 * #ClutterTableLayout:easing-mode and #ClutterTableLayout:easing-duration
66 * properties and their accessor functions.
67 *
68 * #ClutterTableLayout is available since Clutter 1.4
69 *
70 * Since Clutter 1.18 it's recommended to use #ClutterGridLayout instead
71 * of #ClutterTableLayout; the former supports right-to-left text direction,
72 * as well as using the alignment and expansion flags on #ClutterActor.
73 */
74
75 #ifdef HAVE_CONFIG_H
76 #include "config.h"
77 #endif
78
79 #include <math.h>
80
81 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
82 #include "deprecated/clutter-container.h"
83 #include "deprecated/clutter-alpha.h"
84
85 #include "clutter-table-layout.h"
86
87 #include "clutter-debug.h"
88 #include "clutter-enum-types.h"
89 #include "clutter-layout-meta.h"
90 #include "clutter-private.h"
91 #include "clutter-types.h"
92
93 #define CLUTTER_TYPE_TABLE_CHILD (clutter_table_child_get_type ())
94 #define CLUTTER_TABLE_CHILD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TABLE_CHILD, ClutterTableChild))
95 #define CLUTTER_IS_TABLE_CHILD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TABLE_CHILD))
96
97 typedef struct _ClutterTableChild ClutterTableChild;
98 typedef struct _ClutterLayoutMetaClass ClutterTableChildClass;
99
100 typedef struct _DimensionData {
101 gfloat min_size;
102 gfloat pref_size;
103 gfloat final_size;
104
105 guint expand : 1;
106 guint visible : 1;
107 } DimensionData;
108
109 struct _ClutterTableLayoutPrivate
110 {
111 ClutterContainer *container;
112
113 guint col_spacing;
114 guint row_spacing;
115
116 gint n_rows;
117 gint n_cols;
118 gint active_row;
119 gint active_col;
120 gint visible_rows;
121 gint visible_cols;
122
123 GArray *columns;
124 GArray *rows;
125
126 gulong easing_mode;
127 guint easing_duration;
128
129 guint is_animating : 1;
130 guint use_animations : 1;
131 };
132
133 struct _ClutterTableChild
134 {
135 ClutterLayoutMeta parent_instance;
136
137 gint col;
138 gint row;
139
140 gint col_span;
141 gint row_span;
142
143 ClutterTableAlignment x_align;
144 ClutterTableAlignment y_align;
145
146 guint x_expand : 1;
147 guint y_expand : 1;
148 guint x_fill : 1;
149 guint y_fill : 1;
150 };
151
152 enum
153 {
154 PROP_CHILD_0,
155
156 PROP_CHILD_ROW,
157 PROP_CHILD_COLUMN,
158 PROP_CHILD_ROW_SPAN,
159 PROP_CHILD_COLUMN_SPAN,
160 PROP_CHILD_X_ALIGN,
161 PROP_CHILD_Y_ALIGN,
162 PROP_CHILD_X_FILL,
163 PROP_CHILD_Y_FILL,
164 PROP_CHILD_X_EXPAND,
165 PROP_CHILD_Y_EXPAND
166 };
167
168 enum
169 {
170 PROP_0,
171
172 PROP_ROW_SPACING,
173 PROP_COLUMN_SPACING,
174 PROP_USE_ANIMATIONS,
175 PROP_EASING_MODE,
176 PROP_EASING_DURATION
177 };
178
179 GType clutter_table_child_get_type (void);
180
181 G_DEFINE_TYPE (ClutterTableChild, clutter_table_child, CLUTTER_TYPE_LAYOUT_META)
182
183 G_DEFINE_TYPE_WITH_PRIVATE (ClutterTableLayout, clutter_table_layout, CLUTTER_TYPE_LAYOUT_MANAGER)
184
185 /*
186 * ClutterBoxChild
187 */
188
189 static void
190 table_child_set_position (ClutterTableChild *self,
191 gint col,
192 gint row)
193 {
194 gboolean row_changed = FALSE, col_changed = FALSE;
195
196 if (self->col != col)
197 {
198 self->col = col;
199
200 col_changed = TRUE;
201 }
202
203 if (self->row != row)
204 {
205 self->row = row;
206
207 row_changed = TRUE;
208 }
209
210 if (row_changed || col_changed)
211 {
212 ClutterLayoutManager *layout;
213
214 layout = clutter_layout_meta_get_manager (CLUTTER_LAYOUT_META (self));
215 clutter_layout_manager_layout_changed (layout);
216
217 g_object_freeze_notify (G_OBJECT (self));
218
219 if (row_changed)
220 g_object_notify (G_OBJECT (self), "row");
221
222 if (col_changed)
223 g_object_notify (G_OBJECT (self), "column");
224
225 g_object_thaw_notify (G_OBJECT (self));
226 }
227 }
228
229 static void
230 table_child_set_span (ClutterTableChild *self,
231 gint col_span,
232 gint row_span)
233 {
234 gboolean row_changed = FALSE, col_changed = FALSE;
235
236 if (self->col_span != col_span)
237 {
238 self->col_span = col_span;
239
240 col_changed = TRUE;
241 }
242
243 if (self->row_span != row_span)
244 {
245 self->row_span = row_span;
246
247 row_changed = TRUE;
248 }
249
250 if (row_changed || col_changed)
251 {
252 ClutterLayoutManager *layout;
253
254 layout = clutter_layout_meta_get_manager (CLUTTER_LAYOUT_META (self));
255 clutter_layout_manager_layout_changed (layout);
256
257 if (row_changed)
258 g_object_notify (G_OBJECT (self), "row-span");
259
260 if (col_changed)
261 g_object_notify (G_OBJECT (self), "column-span");
262 }
263 }
264
265 static void
266 table_child_set_align (ClutterTableChild *self,
267 ClutterTableAlignment x_align,
268 ClutterTableAlignment y_align)
269 {
270 gboolean x_changed = FALSE, y_changed = FALSE;
271
272 if (self->x_align != x_align)
273 {
274 self->x_align = x_align;
275
276 x_changed = TRUE;
277 }
278
279 if (self->y_align != y_align)
280 {
281 self->y_align = y_align;
282
283 y_changed = TRUE;
284 }
285
286 if (x_changed || y_changed)
287 {
288 ClutterLayoutManager *layout;
289
290 layout = clutter_layout_meta_get_manager (CLUTTER_LAYOUT_META (self));
291 clutter_layout_manager_layout_changed (layout);
292
293 g_object_freeze_notify (G_OBJECT (self));
294
295 if (x_changed)
296 g_object_notify (G_OBJECT (self), "x-align");
297
298 if (y_changed)
299 g_object_notify (G_OBJECT (self), "y-align");
300
301 g_object_thaw_notify (G_OBJECT (self));
302 }
303 }
304
305 static void
306 table_child_set_fill (ClutterTableChild *self,
307 gboolean x_fill,
308 gboolean y_fill)
309 {
310 gboolean x_changed = FALSE, y_changed = FALSE;
311
312 x_fill = !!x_fill;
313 y_fill = !!y_fill;
314
315 if (self->x_fill != x_fill)
316 {
317 self->x_fill = x_fill;
318
319 x_changed = TRUE;
320 }
321
322 if (self->y_fill != y_fill)
323 {
324 self->y_fill = y_fill;
325
326 y_changed = TRUE;
327 }
328
329 if (x_changed || y_changed)
330 {
331 ClutterLayoutManager *layout;
332
333 layout = clutter_layout_meta_get_manager (CLUTTER_LAYOUT_META (self));
334 clutter_layout_manager_layout_changed (layout);
335
336 g_object_freeze_notify (G_OBJECT (self));
337
338 if (x_changed)
339 g_object_notify (G_OBJECT (self), "x-fill");
340
341 if (y_changed)
342 g_object_notify (G_OBJECT (self), "y-fill");
343
344 g_object_thaw_notify (G_OBJECT (self));
345 }
346 }
347
348 static void
349 table_child_set_expand (ClutterTableChild *self,
350 gboolean x_expand,
351 gboolean y_expand)
352 {
353 gboolean x_changed = FALSE, y_changed = FALSE;
354
355 x_expand = !!x_expand;
356 y_expand = !!y_expand;
357
358 if (self->x_expand != x_expand)
359 {
360 self->x_expand = x_expand;
361
362 x_changed = TRUE;
363 }
364
365 if (self->y_expand != y_expand)
366 {
367 self->y_expand = y_expand;
368
369 y_changed = TRUE;
370 }
371
372 if (x_changed || y_changed)
373 {
374 ClutterLayoutManager *layout;
375
376 layout = clutter_layout_meta_get_manager (CLUTTER_LAYOUT_META (self));
377 clutter_layout_manager_layout_changed (layout);
378
379 g_object_freeze_notify (G_OBJECT (self));
380
381 if (x_changed)
382 g_object_notify (G_OBJECT (self), "x-expand");
383
384 if (y_changed)
385 g_object_notify (G_OBJECT (self), "y-expand");
386
387 g_object_thaw_notify (G_OBJECT (self));
388 }
389 }
390
391 static void
392 clutter_table_child_set_property (GObject *gobject,
393 guint prop_id,
394 const GValue *value,
395 GParamSpec *pspec)
396 {
397 ClutterTableChild *self = CLUTTER_TABLE_CHILD (gobject);
398
399 switch (prop_id)
400 {
401 case PROP_CHILD_COLUMN:
402 table_child_set_position (self,
403 g_value_get_int (value),
404 self->row);
405 break;
406
407 case PROP_CHILD_ROW:
408 table_child_set_position (self,
409 self->col,
410 g_value_get_int (value));
411 break;
412
413 case PROP_CHILD_COLUMN_SPAN:
414 table_child_set_span (self,
415 g_value_get_int (value),
416 self->row_span);
417 break;
418
419 case PROP_CHILD_ROW_SPAN:
420 table_child_set_span (self,
421 self->col_span,
422 g_value_get_int (value));
423 break;
424
425 case PROP_CHILD_X_ALIGN:
426 table_child_set_align (self,
427 g_value_get_enum (value),
428 self->y_align);
429 break;
430
431 case PROP_CHILD_Y_ALIGN:
432 table_child_set_align (self,
433 self->x_align,
434 g_value_get_enum (value));
435 break;
436
437 case PROP_CHILD_X_FILL:
438 table_child_set_fill (self,
439 g_value_get_boolean (value),
440 self->y_fill);
441 break;
442
443 case PROP_CHILD_Y_FILL:
444 table_child_set_fill (self,
445 self->x_fill,
446 g_value_get_boolean (value));
447 break;
448
449 case PROP_CHILD_X_EXPAND:
450 table_child_set_expand (self,
451 g_value_get_boolean (value),
452 self->y_expand);
453 break;
454
455 case PROP_CHILD_Y_EXPAND:
456 table_child_set_expand (self,
457 self->x_expand,
458 g_value_get_boolean (value));
459 break;
460
461 default:
462 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
463 break;
464 }
465 }
466
467 static void
468 clutter_table_child_get_property (GObject *gobject,
469 guint prop_id,
470 GValue *value,
471 GParamSpec *pspec)
472 {
473 ClutterTableChild *self = CLUTTER_TABLE_CHILD (gobject);
474
475 switch (prop_id)
476 {
477 case PROP_CHILD_ROW:
478 g_value_set_int (value, self->row);
479 break;
480
481 case PROP_CHILD_COLUMN:
482 g_value_set_int (value, self->col);
483 break;
484
485 case PROP_CHILD_ROW_SPAN:
486 g_value_set_int (value, self->row_span);
487 break;
488
489 case PROP_CHILD_COLUMN_SPAN:
490 g_value_set_int (value, self->col_span);
491 break;
492
493 case PROP_CHILD_X_ALIGN:
494 g_value_set_enum (value, self->x_align);
495 break;
496
497 case PROP_CHILD_Y_ALIGN:
498 g_value_set_enum (value, self->y_align);
499 break;
500
501 case PROP_CHILD_X_FILL:
502 g_value_set_boolean (value, self->x_fill);
503 break;
504
505 case PROP_CHILD_Y_FILL:
506 g_value_set_boolean (value, self->y_fill);
507 break;
508
509 case PROP_CHILD_X_EXPAND:
510 g_value_set_boolean (value, self->x_expand);
511 break;
512
513 case PROP_CHILD_Y_EXPAND:
514 g_value_set_boolean (value, self->y_expand);
515 break;
516
517 default:
518 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
519 break;
520 }
521 }
522
523 static void
524 clutter_table_child_class_init (ClutterTableChildClass *klass)
525 {
526 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
527 GParamSpec *pspec;
528
529 gobject_class->set_property = clutter_table_child_set_property;
530 gobject_class->get_property = clutter_table_child_get_property;
531
532 pspec = g_param_spec_int ("column",
533 P_("Column Number"),
534 P_("The column the widget resides in"),
535 0, G_MAXINT,
536 0,
537 CLUTTER_PARAM_READWRITE);
538 g_object_class_install_property (gobject_class, PROP_CHILD_COLUMN, pspec);
539
540 pspec = g_param_spec_int ("row",
541 P_("Row Number"),
542 P_("The row the widget resides in"),
543 0, G_MAXINT,
544 0,
545 CLUTTER_PARAM_READWRITE);
546 g_object_class_install_property (gobject_class, PROP_CHILD_ROW, pspec);
547
548 pspec = g_param_spec_int ("column-span",
549 P_("Column Span"),
550 P_("The number of columns the widget should span"),
551 1, G_MAXINT,
552 1,
553 CLUTTER_PARAM_READWRITE);
554 g_object_class_install_property (gobject_class, PROP_CHILD_COLUMN_SPAN, pspec);
555
556 pspec = g_param_spec_int ("row-span",
557 P_("Row Span"),
558 P_("The number of rows the widget should span"),
559 1, G_MAXINT,
560 1,
561 CLUTTER_PARAM_READWRITE);
562 g_object_class_install_property (gobject_class, PROP_CHILD_ROW_SPAN, pspec);
563
564 pspec = g_param_spec_boolean ("x-expand",
565 P_("Horizontal Expand"),
566 P_("Allocate extra space for the child in horizontal axis"),
567 TRUE,
568 CLUTTER_PARAM_READWRITE);
569 g_object_class_install_property (gobject_class, PROP_CHILD_X_EXPAND, pspec);
570
571 pspec = g_param_spec_boolean ("y-expand",
572 P_("Vertical Expand"),
573 P_("Allocate extra space for the child in vertical axis"),
574 TRUE,
575 CLUTTER_PARAM_READWRITE);
576 g_object_class_install_property (gobject_class, PROP_CHILD_Y_EXPAND, pspec);
577
578 pspec = g_param_spec_boolean ("x-fill",
579 P_("Horizontal Fill"),
580 P_("Whether the child should receive priority when the container is allocating spare space on the horizontal axis"),
581 TRUE,
582 CLUTTER_PARAM_READWRITE);
583 g_object_class_install_property (gobject_class, PROP_CHILD_X_FILL, pspec);
584
585 pspec = g_param_spec_boolean ("y-fill",
586 P_("Vertical Fill"),
587 P_("Whether the child should receive priority when the container is allocating spare space on the vertical axis"),
588 TRUE,
589 CLUTTER_PARAM_READWRITE);
590 g_object_class_install_property (gobject_class, PROP_CHILD_Y_FILL, pspec);
591
592 /**
593 * ClutterTableLayout:x-align:
594 *
595 * The horizontal alignment of the actor within the cell
596 *
597 * Since: 1.4
598 */
599 pspec = g_param_spec_enum ("x-align",
600 P_("Horizontal Alignment"),
601 P_("Horizontal alignment of the actor within the cell"),
602 CLUTTER_TYPE_TABLE_ALIGNMENT,
603 CLUTTER_TABLE_ALIGNMENT_CENTER,
604 CLUTTER_PARAM_READWRITE);
605 g_object_class_install_property (gobject_class, PROP_CHILD_X_ALIGN, pspec);
606
607 /**
608 * ClutterTableLayout:y-align:
609 *
610 * The vertical alignment of the actor within the cell
611 *
612 * Since: 1.4
613 */
614 pspec = g_param_spec_enum ("y-align",
615 P_("Vertical Alignment"),
616 P_("Vertical alignment of the actor within the cell"),
617 CLUTTER_TYPE_TABLE_ALIGNMENT,
618 CLUTTER_TABLE_ALIGNMENT_CENTER,
619 CLUTTER_PARAM_READWRITE);
620 g_object_class_install_property (gobject_class, PROP_CHILD_Y_ALIGN, pspec);
621 }
622
623 static void
624 clutter_table_child_init (ClutterTableChild *self)
625 {
626 self->col_span = 1;
627 self->row_span = 1;
628
629 self->x_align = CLUTTER_TABLE_ALIGNMENT_CENTER;
630 self->y_align = CLUTTER_TABLE_ALIGNMENT_CENTER;
631
632 self->x_expand = TRUE;
633 self->y_expand = TRUE;
634
635 self->x_fill = TRUE;
636 self->y_fill = TRUE;
637 }
638
639 static GType
640 clutter_table_layout_get_child_meta_type (ClutterLayoutManager *manager)
641 {
642 return CLUTTER_TYPE_TABLE_CHILD;
643 }
644
645 static void
646 clutter_table_layout_set_container (ClutterLayoutManager *layout,
647 ClutterContainer *container)
648 {
649 ClutterTableLayoutPrivate *priv = CLUTTER_TABLE_LAYOUT (layout)->priv;
650
651 priv->container = container;
652 }
653
654
655 static void
656 update_row_col (ClutterTableLayout *layout,
657 ClutterContainer *container)
658 {
659 ClutterTableLayoutPrivate *priv = layout->priv;
660 ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (layout);
661 ClutterActor *actor, *child;
662 gint n_cols, n_rows;
663
664 n_cols = n_rows = 0;
665
666 if (container == NULL)
667 goto out;
668
669 actor = CLUTTER_ACTOR (container);
670 for (child = clutter_actor_get_first_child (actor);
671 child != NULL;
672 child = clutter_actor_get_next_sibling (child))
673 {
674 ClutterTableChild *meta;
675
676 meta =
677 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
678 container,
679 child));
680
681 n_cols = MAX (n_cols, meta->col + meta->col_span);
682 n_rows = MAX (n_rows, meta->row + meta->row_span);
683 }
684
685 out:
686 priv->n_cols = n_cols;
687 priv->n_rows = n_rows;
688
689 }
690
691 static void
692 calculate_col_widths (ClutterTableLayout *self,
693 ClutterContainer *container,
694 gint for_width)
695 {
696 ClutterTableLayoutPrivate *priv = self->priv;
697 ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (self);
698 ClutterActor *actor, *child;
699 gint i;
700 DimensionData *columns;
701 ClutterOrientation orientation = CLUTTER_ORIENTATION_HORIZONTAL;
702
703 update_row_col (self, container);
704 g_array_set_size (priv->columns, 0);
705 g_array_set_size (priv->columns, priv->n_cols);
706 columns = (DimensionData *) (void *) priv->columns->data;
707
708 /* reset the visibility of all columns */
709 priv->visible_cols = 0;
710 for (i = 0; i < priv->n_cols; i++)
711 {
712 columns[i].expand = FALSE;
713 columns[i].visible = FALSE;
714 }
715
716 actor = CLUTTER_ACTOR (container);
717
718 /* STAGE ONE: calculate column widths for non-spanned children */
719 for (child = clutter_actor_get_first_child (actor);
720 child != NULL;
721 child = clutter_actor_get_next_sibling (child))
722 {
723 ClutterTableChild *meta;
724 DimensionData *col;
725 gfloat c_min, c_pref;
726
727 if (!clutter_actor_is_visible (child))
728 continue;
729
730 meta =
731 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
732 container,
733 child));
734
735 if (meta->col_span > 1)
736 continue;
737
738 col = &columns[meta->col];
739
740 if (!col->visible)
741 {
742 col->visible = TRUE;
743 priv->visible_cols += 1;
744 }
745
746 clutter_actor_get_preferred_width (child, -1, &c_min, &c_pref);
747
748 col->min_size = MAX (col->min_size, c_min);
749 col->pref_size = MAX (col->pref_size, c_pref);
750
751 if (!col->expand)
752 {
753 col->expand = clutter_actor_needs_expand (child, orientation) ||
754 meta->x_expand;
755 }
756 }
757
758 /* STAGE TWO: take spanning children into account */
759 for (child = clutter_actor_get_first_child (actor);
760 child != NULL;
761 child = clutter_actor_get_next_sibling (child))
762 {
763 ClutterTableChild *meta;
764 gfloat c_min, c_pref;
765 gfloat min_width, pref_width;
766 gint start_col, end_col;
767 gint n_expand;
768
769 if (!clutter_actor_is_visible (child))
770 continue;
771
772 meta =
773 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
774 container,
775 child));
776
777 if (meta->col_span < 2)
778 continue;
779
780 start_col = meta->col;
781 end_col = meta->col + meta->col_span - 1;
782
783 clutter_actor_get_preferred_width (child, -1, &c_min, &c_pref);
784
785 /* check there is enough room for this actor */
786 min_width = 0;
787 pref_width = 0;
788 n_expand = 0;
789 for (i = start_col; i <= end_col; i++)
790 {
791 min_width += columns[i].min_size;
792 pref_width += columns[i].pref_size;
793
794 if (columns[i].expand)
795 n_expand++;
796
797 if (!columns[i].visible)
798 {
799 columns[i].visible = TRUE;
800 priv->visible_cols += 1;
801 }
802
803 if (!columns[i].expand)
804 {
805 columns[i].expand = clutter_actor_needs_expand (child,
806 orientation) ||
807 meta->x_expand;
808 }
809 }
810 min_width += priv->col_spacing * (meta->col_span - 1);
811 pref_width += priv->col_spacing * (meta->col_span - 1);
812
813 /* see calculate_row_heights() for comments */
814 /* (1) */
815 if (c_min > min_width)
816 {
817
818 /* (2) */
819 /* we can start from preferred width and decrease */
820 if (pref_width > c_min)
821 {
822 for (i = start_col; i <= end_col; i++)
823 columns[i].final_size = columns[i].pref_size;
824
825 while (pref_width > c_min)
826 {
827 for (i = start_col; i <= end_col; i++)
828 {
829 if (columns[i].final_size > columns[i].min_size)
830 {
831 columns[i].final_size--;
832 pref_width--;
833 }
834 }
835 }
836
837 for (i = start_col; i <= end_col; i++)
838 columns[i].min_size = columns[i].final_size;
839 }
840 else
841 {
842 /* (3) */
843 /* we can expand from preferred size */
844 gfloat expand_by;
845
846 expand_by = c_pref - pref_width;
847
848 for (i = start_col; i <= end_col; i++)
849 {
850 if (n_expand)
851 {
852 if (columns[i].expand)
853 columns[i].min_size = columns[i].pref_size
854 + expand_by / n_expand;
855 }
856 else
857 columns[i].min_size = columns[i].pref_size
858 + expand_by / meta->col_span;
859 }
860 }
861 }
862 }
863
864 /* calculate final widths */
865 if (for_width >= 0)
866 {
867 gfloat min_width, pref_width;
868 gint n_expand;
869
870 min_width = 0;
871 pref_width = 0;
872 n_expand = 0;
873
874 for (i = 0; i < self->priv->n_cols; i++)
875 {
876 pref_width += columns[i].pref_size;
877 min_width += columns[i].min_size;
878 if (columns[i].expand)
879 n_expand++;
880 }
881
882 pref_width += priv->col_spacing * MAX (priv->visible_cols - 1, 0);
883 min_width += priv->col_spacing * MAX (priv->visible_cols - 1, 0);
884
885 if (for_width <= min_width)
886 {
887 /* erk, we can't shrink this! */
888 for (i = 0; i < priv->n_cols; i++)
889 columns[i].final_size = columns[i].min_size;
890
891 return;
892 }
893
894 if (for_width == pref_width)
895 {
896 /* perfect! */
897 for (i = 0; i < self->priv->n_cols; i++)
898 columns[i].final_size = columns[i].pref_size;
899
900 return;
901 }
902
903 /* for_width is between min_width and pref_width */
904 if (for_width < pref_width && for_width > min_width)
905 {
906 gfloat width;
907
908 /* shrink columns until they reach min_width */
909
910 /* start with all columns at preferred size */
911 for (i = 0; i < self->priv->n_cols; i++)
912 columns[i].final_size = columns[i].pref_size;
913
914 width = pref_width;
915
916 while (width > for_width)
917 {
918 for (i = 0; i < self->priv->n_cols; i++)
919 {
920 if (columns[i].final_size > columns[i].min_size)
921 {
922 columns[i].final_size--;
923 width--;
924 }
925 }
926 }
927
928 return;
929 }
930
931 /* expand columns */
932 if (for_width > pref_width)
933 {
934 gfloat extra_width = for_width - pref_width;
935 gint remaining;
936
937 if (n_expand)
938 remaining = (gint) extra_width % n_expand;
939 else
940 remaining = (gint) extra_width % priv->n_cols;
941
942 for (i = 0; i < self->priv->n_cols; i++)
943 {
944 if (columns[i].expand)
945 {
946 columns[i].final_size = columns[i].pref_size
947 + (extra_width / n_expand);
948 }
949 else
950 columns[i].final_size = columns[i].pref_size;
951 }
952
953 /* distribute the remainder among children */
954 i = 0;
955 while (remaining)
956 {
957 columns[i].final_size++;
958 i++;
959 remaining--;
960 }
961 }
962 }
963
964 }
965
966 static void
967 calculate_row_heights (ClutterTableLayout *self,
968 ClutterContainer *container,
969 gint for_height)
970 {
971 ClutterTableLayoutPrivate *priv = self->priv;
972 ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (self);
973 ClutterActor *actor, *child;
974 gint i;
975 DimensionData *rows, *columns;
976 ClutterOrientation orientation = CLUTTER_ORIENTATION_VERTICAL;
977
978 update_row_col (self, container);
979 g_array_set_size (priv->rows, 0);
980 g_array_set_size (priv->rows, self->priv->n_rows);
981
982 rows = (DimensionData *) (void *) priv->rows->data;
983 columns = (DimensionData *) (void *) priv->columns->data;
984
985 /* reset the visibility of all rows */
986 priv->visible_rows = 0;
987 for (i = 0; i < priv->n_rows; i++)
988 {
989 rows[i].expand = FALSE;
990 rows[i].visible = FALSE;
991 }
992
993 actor = CLUTTER_ACTOR (container);
994
995 /* STAGE ONE: calculate row heights for non-spanned children */
996 for (child = clutter_actor_get_first_child (actor);
997 child != NULL;
998 child = clutter_actor_get_next_sibling (child))
999 {
1000 ClutterTableChild *meta;
1001 DimensionData *row;
1002 gfloat c_min, c_pref;
1003
1004 if (!clutter_actor_is_visible (child))
1005 continue;
1006
1007 meta =
1008 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
1009 container,
1010 child));
1011
1012 if (meta->row_span > 1)
1013 continue;
1014
1015 row = &rows[meta->row];
1016
1017 if (!row->visible)
1018 {
1019 row->visible = TRUE;
1020 priv->visible_rows += 1;
1021 }
1022
1023 clutter_actor_get_preferred_height (child, columns[meta->col].final_size,
1024 &c_min, &c_pref);
1025
1026 row->min_size = MAX (row->min_size, c_min);
1027 row->pref_size = MAX (row->pref_size, c_pref);
1028
1029 if (!row->expand)
1030 {
1031 row->expand = clutter_actor_needs_expand (child, orientation) ||
1032 meta->y_expand;
1033 }
1034 }
1035
1036 /* STAGE TWO: take spanning children into account */
1037 for (child = clutter_actor_get_first_child (actor);
1038 child != NULL;
1039 child = clutter_actor_get_next_sibling (child))
1040 {
1041 ClutterTableChild *meta;
1042 gfloat c_min, c_pref;
1043 gfloat min_height, pref_height;
1044 gint start_row, end_row;
1045 gint n_expand;
1046
1047 if (!clutter_actor_is_visible (child))
1048 continue;
1049
1050 meta =
1051 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (manager,
1052 container,
1053 child));
1054
1055 if (meta->row_span < 2)
1056 continue;
1057
1058 start_row = meta->row;
1059 end_row = meta->row + meta->row_span - 1;
1060
1061 clutter_actor_get_preferred_height (child, columns[meta->col].final_size,
1062 &c_min, &c_pref);
1063
1064
1065 /* check there is enough room for this actor */
1066 min_height = 0;
1067 pref_height = 0;
1068 n_expand = 0;
1069 for (i = start_row; i <= end_row; i++)
1070 {
1071 min_height += rows[i].min_size;
1072 pref_height += rows[i].pref_size;
1073
1074 if (rows[i].expand)
1075 n_expand++;
1076
1077 if (!rows[i].visible)
1078 {
1079 rows[i].visible = TRUE;
1080 priv->visible_rows += 1;
1081 }
1082
1083 if (!rows[i].expand)
1084 {
1085 rows[i].expand = clutter_actor_needs_expand (child, orientation) ||
1086 meta->y_expand;
1087 }
1088 }
1089
1090 min_height += priv->row_spacing * (meta->row_span - 1);
1091 pref_height += priv->row_spacing * (meta->row_span - 1);
1092
1093 /* 1) If the minimum height of the rows spanned is less than the
1094 * minimum height of the child that is spanning them, then we
1095 * must increase the minimum height of the rows spanned.
1096 *
1097 * 2) If the preferred height of the spanned rows is more than
1098 * the minimum height of the spanning child, then we can start
1099 * at this size and decrease each row evenly.
1100 *
1101 * 3) If the preferred height of the rows is more than the minimum
1102 * height of the spanned child, then we can start at the preferred
1103 * height and expand.
1104 */
1105
1106 /* (1) */
1107 if (c_min > min_height)
1108 {
1109
1110 /* (2) */
1111 /* we can start from preferred height and decrease */
1112 if (pref_height > c_min)
1113 {
1114 for (i = start_row; i <= end_row; i++)
1115 rows[i].final_size = rows[i].pref_size;
1116
1117 while (pref_height > c_min)
1118 {
1119 for (i = start_row; i <= end_row; i++)
1120 {
1121 if (rows[i].final_size > rows[i].min_size)
1122 {
1123 rows[i].final_size--;
1124 pref_height--;
1125 }
1126 }
1127 }
1128
1129 for (i = start_row; i <= end_row; i++)
1130 rows[i].min_size = rows[i].final_size;
1131 }
1132 else
1133 {
1134 /* (3) */
1135 /* we can expand from preferred size */
1136 gfloat expand_by = c_pref - pref_height;
1137
1138 for (i = start_row; i <= end_row; i++)
1139 {
1140 if (n_expand)
1141 {
1142 if (rows[i].expand)
1143 rows[i].min_size = rows[i].pref_size
1144 + expand_by / n_expand;
1145 }
1146 else
1147 rows[i].min_size = rows[i].pref_size
1148 + expand_by / meta->row_span;
1149 }
1150 }
1151 }
1152 }
1153
1154 /* calculate final heights */
1155 if (for_height >= 0)
1156 {
1157 gfloat min_height, pref_height;
1158 gint n_expand;
1159
1160 min_height = 0;
1161 pref_height = 0;
1162 n_expand = 0;
1163
1164 for (i = 0; i < self->priv->n_rows; i++)
1165 {
1166 pref_height += rows[i].pref_size;
1167 min_height += rows[i].min_size;
1168 if (rows[i].expand)
1169 n_expand++;
1170 }
1171
1172 pref_height += priv->row_spacing * MAX (priv->visible_rows - 1, 0);
1173 min_height += priv->row_spacing * MAX (priv->visible_rows - 1, 0);
1174
1175 if (for_height <= min_height)
1176 {
1177 /* erk, we can't shrink this! */
1178 for (i = 0; i < self->priv->n_rows; i++)
1179 rows[i].final_size = rows[i].min_size;
1180
1181 return;
1182 }
1183
1184 if (for_height == pref_height)
1185 {
1186 /* perfect! */
1187 for (i = 0; i < self->priv->n_rows; i++)
1188 rows[i].final_size = rows[i].pref_size;
1189
1190 return;
1191 }
1192
1193 /* for_height is between min_height and pref_height */
1194 if (for_height < pref_height && for_height > min_height)
1195 {
1196 gfloat height;
1197
1198 /* shrink rows until they reach min_height */
1199
1200 /* start with all rows at preferred size */
1201 for (i = 0; i < self->priv->n_rows; i++)
1202 rows[i].final_size = rows[i].pref_size;
1203
1204 height = pref_height;
1205
1206 while (height > for_height)
1207 {
1208 for (i = 0; i < priv->n_rows; i++)
1209 {
1210 if (rows[i].final_size > rows[i].min_size)
1211 {
1212 rows[i].final_size--;
1213 height--;
1214 }
1215 }
1216 }
1217
1218 return;
1219 }
1220
1221 /* expand rows */
1222 if (for_height > pref_height)
1223 {
1224 gfloat extra_height = for_height - pref_height;
1225 gint remaining;
1226
1227 if (n_expand)
1228 remaining = (gint) extra_height % n_expand;
1229 else
1230 remaining = (gint) extra_height % self->priv->n_rows;
1231
1232 for (i = 0; i < self->priv->n_rows; i++)
1233 {
1234 if (rows[i].expand)
1235 {
1236 rows[i].final_size = rows[i].pref_size
1237 + (extra_height / n_expand);
1238 }
1239 else
1240 rows[i].final_size = rows[i].pref_size;
1241 }
1242
1243 /* distribute the remainder among children */
1244 i = 0;
1245 while (remaining)
1246 {
1247 rows[i].final_size++;
1248 i++;
1249 remaining--;
1250 }
1251 }
1252 }
1253
1254 }
1255
1256 static void
1257 calculate_table_dimensions (ClutterTableLayout *self,
1258 ClutterContainer *container,
1259 gfloat for_width,
1260 gfloat for_height)
1261 {
1262 calculate_col_widths (self, container, for_width);
1263 calculate_row_heights (self, container, for_height);
1264 }
1265
1266 static void
1267 clutter_table_layout_get_preferred_width (ClutterLayoutManager *layout,
1268 ClutterContainer *container,
1269 gfloat for_height,
1270 gfloat *min_width_p,
1271 gfloat *natural_width_p)
1272 {
1273 ClutterTableLayout *self = CLUTTER_TABLE_LAYOUT (layout);
1274 ClutterTableLayoutPrivate *priv = self->priv;
1275 gfloat total_min_width, total_pref_width;
1276 DimensionData *columns;
1277 gint i;
1278
1279 update_row_col (self, container);
1280 if (priv->n_cols < 1)
1281 {
1282 *min_width_p = 0;
1283 *natural_width_p = 0;
1284 return;
1285 }
1286
1287 calculate_table_dimensions (self, container, -1, for_height);
1288 columns = (DimensionData *) (void *) priv->columns->data;
1289
1290 total_min_width = MAX ((priv->visible_cols - 1) * (float) priv->col_spacing, 0);
1291 total_pref_width = total_min_width;
1292
1293 for (i = 0; i < priv->n_cols; i++)
1294 {
1295 total_min_width += columns[i].min_size;
1296 total_pref_width += columns[i].pref_size;
1297 }
1298
1299 if (min_width_p)
1300 *min_width_p = total_min_width;
1301
1302 if (natural_width_p)
1303 *natural_width_p = total_pref_width;
1304 }
1305
1306 static void
1307 clutter_table_layout_get_preferred_height (ClutterLayoutManager *layout,
1308 ClutterContainer *container,
1309 gfloat for_width,
1310 gfloat *min_height_p,
1311 gfloat *natural_height_p)
1312 {
1313 ClutterTableLayout *self = CLUTTER_TABLE_LAYOUT (layout);
1314 ClutterTableLayoutPrivate *priv = self->priv;
1315 gfloat total_min_height, total_pref_height;
1316 DimensionData *rows;
1317 gint i;
1318
1319 update_row_col (self, container);
1320 if (priv->n_rows < 1)
1321 {
1322 *min_height_p = 0;
1323 *natural_height_p = 0;
1324 return;
1325 }
1326
1327 calculate_table_dimensions (self, container, for_width, -1);
1328 rows = (DimensionData *) (void *) priv->rows->data;
1329
1330 total_min_height = MAX ((priv->visible_rows - 1) * (float) priv->row_spacing, 0);
1331 total_pref_height = total_min_height;
1332
1333 for (i = 0; i < self->priv->n_rows; i++)
1334 {
1335 total_min_height += rows[i].min_size;
1336 total_pref_height += rows[i].pref_size;
1337 }
1338
1339 if (min_height_p)
1340 *min_height_p = total_min_height;
1341
1342 if (natural_height_p)
1343 *natural_height_p = total_pref_height;
1344 }
1345
1346 static gdouble
1347 get_table_alignment_factor (ClutterTableAlignment alignment)
1348 {
1349 switch (alignment)
1350 {
1351 case CLUTTER_TABLE_ALIGNMENT_START:
1352 return 0.0;
1353
1354 case CLUTTER_TABLE_ALIGNMENT_CENTER:
1355 return 0.5;
1356
1357 case CLUTTER_TABLE_ALIGNMENT_END:
1358 return 1.0;
1359 }
1360
1361 return 0.0;
1362 }
1363
1364 static void
1365 clutter_table_layout_allocate (ClutterLayoutManager *layout,
1366 ClutterContainer *container,
1367 const ClutterActorBox *box,
1368 ClutterAllocationFlags flags)
1369 {
1370 ClutterTableLayout *self = CLUTTER_TABLE_LAYOUT (layout);
1371 ClutterTableLayoutPrivate *priv = self->priv;
1372 ClutterActor *actor, *child;
1373 gint row_spacing, col_spacing;
1374 gint i;
1375 DimensionData *rows, *columns;
1376
1377 update_row_col (self, container);
1378 if (priv->n_cols < 1 || priv->n_rows < 1)
1379 return;
1380
1381 actor = CLUTTER_ACTOR (container);
1382
1383 if (clutter_actor_get_n_children (actor) == 0)
1384 return;
1385
1386 col_spacing = (priv->col_spacing);
1387 row_spacing = (priv->row_spacing);
1388
1389 calculate_table_dimensions (self, container,
1390 box->x2 - box->x1,
1391 box->y2 - box->y1);
1392
1393 rows = (DimensionData *) (void *) priv->rows->data;
1394 columns = (DimensionData *) (void *) priv->columns->data;
1395
1396 for (child = clutter_actor_get_first_child (actor);
1397 child != NULL;
1398 child = clutter_actor_get_next_sibling (child))
1399 {
1400 gint row, col, row_span, col_span;
1401 gint col_width, row_height;
1402 ClutterTableChild *meta;
1403 ClutterActorBox childbox;
1404 gint child_x, child_y;
1405 gdouble x_align, y_align;
1406 gboolean x_fill, y_fill;
1407
1408 if (!clutter_actor_is_visible (child))
1409 continue;
1410
1411 meta =
1412 CLUTTER_TABLE_CHILD (clutter_layout_manager_get_child_meta (layout,
1413 container,
1414 child));
1415
1416 /* get child properties */
1417 col = meta->col;
1418 row = meta->row;
1419 row_span = meta->row_span;
1420 col_span = meta->col_span;
1421 x_align = get_table_alignment_factor (meta->x_align);
1422 y_align = get_table_alignment_factor (meta->y_align);
1423 x_fill = meta->x_fill;
1424 y_fill = meta->y_fill;
1425
1426 /* initialise the width and height */
1427 col_width = columns[col].final_size;
1428 row_height = rows[row].final_size;
1429
1430 /* Add the widths of the spanned columns:
1431 *
1432 * First check that we have a non-zero span. Then we loop over each of
1433 * the columns that we're spanning but we stop short if we go past the
1434 * number of columns in the table. This is necessary to avoid accessing
1435 * uninitialised memory. We add the spacing in here too since we only
1436 * want to add as much spacing as times we successfully span.
1437 */
1438 if (col + col_span > priv->n_cols)
1439 g_warning (G_STRLOC ": column-span exceeds number of columns");
1440 if (row + row_span > priv->n_rows)
1441 g_warning (G_STRLOC ": row-span exceeds number of rows");
1442
1443 if (col_span > 1)
1444 {
1445 for (i = col + 1; i < col + col_span && i < priv->n_cols; i++)
1446 {
1447 col_width += columns[i].final_size;
1448 col_width += col_spacing;
1449 }
1450 }
1451
1452 /* add the height of the spanned rows */
1453 if (row_span > 1)
1454 {
1455 for (i = row + 1; i < row + row_span && i < priv->n_rows; i++)
1456 {
1457 row_height += rows[i].final_size;
1458 row_height += row_spacing;
1459 }
1460 }
1461
1462 /* calculate child x */
1463 child_x = clutter_actor_box_get_x (box);
1464 for (i = 0; i < col; i++)
1465 {
1466 if (columns[i].visible)
1467 {
1468 child_x += columns[i].final_size;
1469 child_x += col_spacing;
1470 }
1471 }
1472
1473 /* calculate child y */
1474 child_y = clutter_actor_box_get_y (box);
1475 for (i = 0; i < row; i++)
1476 {
1477 if (rows[i].visible)
1478 {
1479 child_y += rows[i].final_size;
1480 child_y += row_spacing;
1481 }
1482 }
1483
1484 /* set up childbox */
1485 childbox.x1 = (float) child_x;
1486 childbox.x2 = (float) MAX (0, child_x + col_width);
1487
1488 childbox.y1 = (float) child_y;
1489 childbox.y2 = (float) MAX (0, child_y + row_height);
1490
1491 if (priv->use_animations)
1492 {
1493 clutter_actor_save_easing_state (child);
1494 clutter_actor_set_easing_mode (child, priv->easing_mode);
1495 clutter_actor_set_easing_duration (child, priv->easing_duration);
1496 }
1497
1498 if (clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_HORIZONTAL) ||
1499 clutter_actor_needs_expand (child, CLUTTER_ORIENTATION_VERTICAL))
1500 clutter_actor_allocate (child, &childbox, flags);
1501 else
1502 clutter_actor_allocate_align_fill (child, &childbox,
1503 x_align, y_align,
1504 x_fill, y_fill,
1505 flags);
1506
1507 if (priv->use_animations)
1508 clutter_actor_restore_easing_state (child);
1509 }
1510 }
1511
1512 static void
1513 clutter_table_layout_set_property (GObject *gobject,
1514 guint prop_id,
1515 const GValue *value,
1516 GParamSpec *pspec)
1517 {
1518 ClutterTableLayout *self = CLUTTER_TABLE_LAYOUT (gobject);
1519
1520 switch (prop_id)
1521 {
1522 case PROP_COLUMN_SPACING:
1523 clutter_table_layout_set_column_spacing (self, g_value_get_uint (value));
1524 break;
1525
1526 case PROP_ROW_SPACING:
1527 clutter_table_layout_set_row_spacing (self, g_value_get_uint (value));
1528 break;
1529
1530 case PROP_USE_ANIMATIONS:
1531 clutter_table_layout_set_use_animations (self, g_value_get_boolean (value));
1532 break;
1533
1534 case PROP_EASING_MODE:
1535 clutter_table_layout_set_easing_mode (self, g_value_get_ulong (value));
1536 break;
1537
1538 case PROP_EASING_DURATION:
1539 clutter_table_layout_set_easing_duration (self, g_value_get_uint (value));
1540 break;
1541
1542 default:
1543 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
1544 break;
1545 }
1546 }
1547
1548 static void
1549 clutter_table_layout_get_property (GObject *gobject,
1550 guint prop_id,
1551 GValue *value,
1552 GParamSpec *pspec)
1553 {
1554 ClutterTableLayoutPrivate *priv = CLUTTER_TABLE_LAYOUT (gobject)->priv;
1555
1556 switch (prop_id)
1557 {
1558 case PROP_ROW_SPACING:
1559 g_value_set_uint (value, priv->row_spacing);
1560 break;
1561
1562 case PROP_COLUMN_SPACING:
1563 g_value_set_uint (value, priv->col_spacing);
1564 break;
1565
1566 case PROP_USE_ANIMATIONS:
1567 g_value_set_boolean (value, priv->use_animations);
1568 break;
1569
1570 case PROP_EASING_MODE:
1571 g_value_set_ulong (value, priv->easing_mode);
1572 break;
1573
1574 case PROP_EASING_DURATION:
1575 g_value_set_uint (value, priv->easing_duration);
1576 break;
1577
1578 default:
1579 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
1580 break;
1581 }
1582 }
1583
1584 static void
1585 clutter_table_layout_finalize (GObject *gobject)
1586 {
1587 ClutterTableLayoutPrivate *priv = CLUTTER_TABLE_LAYOUT (gobject)->priv;
1588
1589 g_array_free (priv->columns, TRUE);
1590 g_array_free (priv->rows, TRUE);
1591
1592 G_OBJECT_CLASS (clutter_table_layout_parent_class)->finalize (gobject);
1593 }
1594
1595 static void
1596 clutter_table_layout_class_init (ClutterTableLayoutClass *klass)
1597 {
1598 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1599 ClutterLayoutManagerClass *layout_class;
1600 GParamSpec *pspec;
1601
1602 layout_class = CLUTTER_LAYOUT_MANAGER_CLASS (klass);
1603
1604 gobject_class->set_property = clutter_table_layout_set_property;
1605 gobject_class->get_property = clutter_table_layout_get_property;
1606 gobject_class->finalize = clutter_table_layout_finalize;
1607
1608 layout_class->get_preferred_width =
1609 clutter_table_layout_get_preferred_width;
1610 layout_class->get_preferred_height =
1611 clutter_table_layout_get_preferred_height;
1612 layout_class->allocate = clutter_table_layout_allocate;
1613 layout_class->set_container = clutter_table_layout_set_container;
1614 layout_class->get_child_meta_type =
1615 clutter_table_layout_get_child_meta_type;
1616
1617 /**
1618 * ClutterTableLayout:column-spacing:
1619 *
1620 * The spacing between columns of the #ClutterTableLayout, in pixels
1621 *
1622 * Since: 1.4
1623 *
1624 * Deprecated: 1.18: Use #ClutterGridLayout:column-spacing instead
1625 */
1626 pspec = g_param_spec_uint ("column-spacing",
1627 P_("Column Spacing"),
1628 P_("Spacing between columns"),
1629 0, G_MAXUINT, 0,
1630 CLUTTER_PARAM_READWRITE);
1631 g_object_class_install_property (gobject_class, PROP_COLUMN_SPACING, pspec);
1632
1633 /**
1634 * ClutterTableLayout:row-spacing:
1635 *
1636 * The spacing between rows of the #ClutterTableLayout, in pixels
1637 *
1638 * Since: 1.4
1639 *
1640 * Deprecated: 1.18: Use #ClutterGridLayout:row-spacing instead
1641 */
1642 pspec = g_param_spec_uint ("row-spacing",
1643 P_("Row Spacing"),
1644 P_("Spacing between rows"),
1645 0, G_MAXUINT, 0,
1646 CLUTTER_PARAM_READWRITE);
1647 g_object_class_install_property (gobject_class, PROP_ROW_SPACING, pspec);
1648
1649 /**
1650 * ClutterTableLayout:use-animations:
1651 *
1652 * Whether the #ClutterTableLayout should animate changes in the
1653 * layout properties.
1654 *
1655 * By default, #ClutterTableLayout will honour the easing state of
1656 * the children when allocating them. Setting this property to
1657 * %TRUE will override the easing state with the layout manager's
1658 * #ClutterTableLayout:easing-mode and #ClutterTableLayout:easing-duration
1659 * properties.
1660 *
1661 * Since: 1.4
1662 *
1663 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
1664 * of the children when allocating them
1665 */
1666 pspec = g_param_spec_boolean ("use-animations",
1667 P_("Use Animations"),
1668 P_("Whether layout changes should be animated"),
1669 FALSE,
1670 CLUTTER_PARAM_READWRITE);
1671 g_object_class_install_property (gobject_class, PROP_USE_ANIMATIONS, pspec);
1672
1673 /**
1674 * ClutterTableLayout:easing-mode:
1675 *
1676 * The easing mode for the animations, in case
1677 * #ClutterTableLayout:use-animations is set to %TRUE.
1678 *
1679 * The easing mode has the same semantics of #ClutterAnimation:mode: it can
1680 * either be a value from the #ClutterAnimationMode enumeration, like
1681 * %CLUTTER_EASE_OUT_CUBIC, or a logical id as returned by
1682 * clutter_alpha_register_func().
1683 *
1684 * The default value is %CLUTTER_EASE_OUT_CUBIC.
1685 *
1686 * Since: 1.4
1687 *
1688 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
1689 * of the children when allocating them
1690 */
1691 pspec = g_param_spec_ulong ("easing-mode",
1692 P_("Easing Mode"),
1693 P_("The easing mode of the animations"),
1694 0, G_MAXULONG,
1695 CLUTTER_EASE_OUT_CUBIC,
1696 CLUTTER_PARAM_READWRITE);
1697 g_object_class_install_property (gobject_class, PROP_EASING_MODE, pspec);
1698
1699 /**
1700 * ClutterTableLayout:easing-duration:
1701 *
1702 * The duration of the animations, in case #ClutterTableLayout:use-animations
1703 * is set to %TRUE.
1704 *
1705 * The duration is expressed in milliseconds.
1706 *
1707 * Since: 1.4
1708 *
1709 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
1710 * of the children when allocating them
1711 */
1712 pspec = g_param_spec_uint ("easing-duration",
1713 P_("Easing Duration"),
1714 P_("The duration of the animations"),
1715 0, G_MAXUINT,
1716 500,
1717 CLUTTER_PARAM_READWRITE);
1718 g_object_class_install_property (gobject_class, PROP_EASING_DURATION, pspec);
1719 }
1720
1721 static void
1722 clutter_table_layout_init (ClutterTableLayout *layout)
1723 {
1724 ClutterTableLayoutPrivate *priv;
1725
1726 layout->priv = priv = clutter_table_layout_get_instance_private (layout);
1727
1728 priv->row_spacing = 0;
1729 priv->col_spacing = 0;
1730
1731 priv->use_animations = FALSE;
1732 priv->easing_mode = CLUTTER_EASE_OUT_CUBIC;
1733 priv->easing_duration = 500;
1734
1735 priv->columns = g_array_new (FALSE, TRUE, sizeof (DimensionData));
1736 priv->rows = g_array_new (FALSE, TRUE, sizeof (DimensionData));
1737 }
1738
1739 /**
1740 * clutter_table_layout_new:
1741 *
1742 * Creates a new #ClutterTableLayout layout manager
1743 *
1744 * Return value: the newly created #ClutterTableLayout
1745 *
1746 * Since: 1.4
1747 *
1748 * Deprecated: 1.18: Use #ClutterGridLayout instead
1749 */
1750 ClutterLayoutManager *
1751 clutter_table_layout_new (void)
1752 {
1753 return g_object_new (CLUTTER_TYPE_TABLE_LAYOUT, NULL);
1754 }
1755
1756 /**
1757 * clutter_table_layout_set_column_spacing:
1758 * @layout: a #ClutterTableLayout
1759 * @spacing: the spacing between columns of the layout, in pixels
1760 *
1761 * Sets the spacing between columns of @layout
1762 *
1763 * Since: 1.4
1764 *
1765 * Deprecated: 1.18: Use #ClutterGridLayout:column-spacing instead
1766 */
1767 void
1768 clutter_table_layout_set_column_spacing (ClutterTableLayout *layout,
1769 guint spacing)
1770 {
1771 ClutterTableLayoutPrivate *priv;
1772
1773 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
1774
1775 priv = layout->priv;
1776
1777 if (priv->col_spacing != spacing)
1778 {
1779 ClutterLayoutManager *manager;
1780
1781 priv->col_spacing = spacing;
1782
1783 manager = CLUTTER_LAYOUT_MANAGER (layout);
1784 clutter_layout_manager_layout_changed (manager);
1785
1786 g_object_notify (G_OBJECT (layout), "column-spacing");
1787 }
1788 }
1789
1790 /**
1791 * clutter_table_layout_get_column_spacing:
1792 * @layout: a #ClutterTableLayout
1793 *
1794 * Retrieves the spacing set using clutter_table_layout_set_column_spacing()
1795 *
1796 * Return value: the spacing between columns of the #ClutterTableLayout
1797 *
1798 * Since: 1.4
1799 *
1800 * Deprecated: 1.18: Use #ClutterGridLayout:column-spacing
1801 */
1802 guint
1803 clutter_table_layout_get_column_spacing (ClutterTableLayout *layout)
1804 {
1805 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), 0);
1806
1807 return layout->priv->col_spacing;
1808 }
1809
1810 /**
1811 * clutter_table_layout_set_row_spacing:
1812 * @layout: a #ClutterTableLayout
1813 * @spacing: the spacing between rows of the layout, in pixels
1814 *
1815 * Sets the spacing between rows of @layout
1816 *
1817 * Since: 1.4
1818 *
1819 * Deprecated: 1.18: Use #ClutterGridLayout:row-spacing instead
1820 */
1821 void
1822 clutter_table_layout_set_row_spacing (ClutterTableLayout *layout,
1823 guint spacing)
1824 {
1825 ClutterTableLayoutPrivate *priv;
1826
1827 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
1828
1829 priv = layout->priv;
1830
1831 if (priv->row_spacing != spacing)
1832 {
1833 ClutterLayoutManager *manager;
1834
1835 priv->row_spacing = spacing;
1836
1837 manager = CLUTTER_LAYOUT_MANAGER (layout);
1838 clutter_layout_manager_layout_changed (manager);
1839
1840 g_object_notify (G_OBJECT (layout), "row-spacing");
1841 }
1842 }
1843
1844 /**
1845 * clutter_table_layout_get_row_spacing:
1846 * @layout: a #ClutterTableLayout
1847 *
1848 * Retrieves the spacing set using clutter_table_layout_set_row_spacing()
1849 *
1850 * Return value: the spacing between rows of the #ClutterTableLayout
1851 *
1852 * Since: 1.4
1853 *
1854 * Deprecated: 1.18: Use #ClutterGridLayout:row-spacing instead
1855 */
1856 guint
1857 clutter_table_layout_get_row_spacing (ClutterTableLayout *layout)
1858 {
1859 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), 0);
1860
1861 return layout->priv->row_spacing;
1862 }
1863
1864 /**
1865 * clutter_table_layout_pack:
1866 * @layout: a #ClutterTableLayout
1867 * @actor: a #ClutterActor
1868 * @column: the column the @actor should be put, or -1 to append
1869 * @row: the row the @actor should be put, or -1 to append
1870 *
1871 * Packs @actor inside the #ClutterContainer associated to @layout
1872 * at the given row and column.
1873 *
1874 * Since: 1.4
1875 *
1876 * Deprecated: 1.18: Use clutter_grid_layout_attach() instead
1877 */
1878 void
1879 clutter_table_layout_pack (ClutterTableLayout *layout,
1880 ClutterActor *actor,
1881 gint column,
1882 gint row)
1883 {
1884 ClutterTableLayoutPrivate *priv;
1885 ClutterLayoutManager *manager;
1886 ClutterLayoutMeta *meta;
1887
1888 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
1889 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
1890
1891 priv = layout->priv;
1892
1893 if (priv->container == NULL)
1894 {
1895 g_warning ("The layout of type '%s' must be associated to "
1896 "a ClutterContainer before adding children",
1897 G_OBJECT_TYPE_NAME (layout));
1898 return;
1899 }
1900
1901 update_row_col (CLUTTER_TABLE_LAYOUT (layout), priv->container);
1902
1903 clutter_container_add_actor (priv->container, actor);
1904
1905 manager = CLUTTER_LAYOUT_MANAGER (layout);
1906 meta = clutter_layout_manager_get_child_meta (manager,
1907 priv->container,
1908 actor);
1909 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
1910
1911 if (row < 0)
1912 row = priv->n_rows;
1913
1914 if (column < 0)
1915 column = priv->n_cols;
1916
1917 table_child_set_position (CLUTTER_TABLE_CHILD (meta), column, row);
1918 }
1919
1920 /**
1921 * clutter_table_layout_set_span:
1922 * @layout: a #ClutterTableLayout
1923 * @actor: a #ClutterActor child of @layout
1924 * @column_span: Column span for @actor
1925 * @row_span: Row span for @actor
1926 *
1927 * Sets the row and column span for @actor
1928 * inside @layout
1929 *
1930 * Since: 1.4
1931 *
1932 * Deprecated: 1.18: Use the `width` and `height` layout properties
1933 * of #ClutterGridLayout instead
1934 */
1935 void
1936 clutter_table_layout_set_span (ClutterTableLayout *layout,
1937 ClutterActor *actor,
1938 gint column_span,
1939 gint row_span)
1940 {
1941 ClutterTableLayoutPrivate *priv;
1942 ClutterLayoutManager *manager;
1943 ClutterLayoutMeta *meta;
1944
1945 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
1946 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
1947
1948 priv = layout->priv;
1949
1950 if (priv->container == NULL)
1951 {
1952 g_warning ("The layout of type '%s' must be associated to "
1953 "a ClutterContainer before querying layout "
1954 "properties",
1955 G_OBJECT_TYPE_NAME (layout));
1956 return;
1957 }
1958
1959 manager = CLUTTER_LAYOUT_MANAGER (layout);
1960 meta = clutter_layout_manager_get_child_meta (manager,
1961 priv->container,
1962 actor);
1963 if (meta == NULL)
1964 {
1965 g_warning ("No layout meta found for the child of type '%s' "
1966 "inside the layout manager of type '%s'",
1967 G_OBJECT_TYPE_NAME (actor),
1968 G_OBJECT_TYPE_NAME (manager));
1969 return;
1970 }
1971
1972 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
1973
1974 table_child_set_span (CLUTTER_TABLE_CHILD (meta), column_span, row_span);
1975 }
1976
1977 /**
1978 * clutter_table_layout_get_span:
1979 * @layout: a #ClutterTableLayout
1980 * @actor: a #ClutterActor child of @layout
1981 * @column_span: (out): return location for the col span
1982 * @row_span: (out): return location for the row span
1983 *
1984 * Retrieves the row and column span for @actor as set using
1985 * clutter_table_layout_pack() or clutter_table_layout_set_span()
1986 *
1987 * Since: 1.4
1988 *
1989 * Deprecated: 1.18: Use the `width` and `height` layout properties
1990 * of #ClutterGridLayout instead
1991 */
1992 void
1993 clutter_table_layout_get_span (ClutterTableLayout *layout,
1994 ClutterActor *actor,
1995 gint *column_span,
1996 gint *row_span)
1997 {
1998 ClutterTableLayoutPrivate *priv;
1999 ClutterLayoutManager *manager;
2000 ClutterLayoutMeta *meta;
2001
2002 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2003 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2004
2005 priv = layout->priv;
2006
2007 if (priv->container == NULL)
2008 {
2009 g_warning ("The layout of type '%s' must be associated to "
2010 "a ClutterContainer before querying layout "
2011 "properties",
2012 G_OBJECT_TYPE_NAME (layout));
2013 return;
2014 }
2015
2016 manager = CLUTTER_LAYOUT_MANAGER (layout);
2017 meta = clutter_layout_manager_get_child_meta (manager,
2018 priv->container,
2019 actor);
2020 if (meta == NULL)
2021 {
2022 g_warning ("No layout meta found for the child of type '%s' "
2023 "inside the layout manager of type '%s'",
2024 G_OBJECT_TYPE_NAME (actor),
2025 G_OBJECT_TYPE_NAME (manager));
2026 return;
2027 }
2028
2029 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2030
2031 if (column_span)
2032 *column_span = CLUTTER_TABLE_CHILD (meta)->col_span;
2033
2034 if (row_span)
2035 *row_span = CLUTTER_TABLE_CHILD (meta)->row_span;
2036 }
2037
2038 /**
2039 * clutter_table_layout_set_alignment:
2040 * @layout: a #ClutterTableLayout
2041 * @actor: a #ClutterActor child of @layout
2042 * @x_align: Horizontal alignment policy for @actor
2043 * @y_align: Vertical alignment policy for @actor
2044 *
2045 * Sets the horizontal and vertical alignment policies for @actor
2046 * inside @layout
2047 *
2048 * Since: 1.4
2049 *
2050 * Deprecated: 1.12: Use clutter_actor_set_x_align() and
2051 * clutter_actor_set_y_align() instead.
2052 */
2053 void
2054 clutter_table_layout_set_alignment (ClutterTableLayout *layout,
2055 ClutterActor *actor,
2056 ClutterTableAlignment x_align,
2057 ClutterTableAlignment y_align)
2058 {
2059 ClutterTableLayoutPrivate *priv;
2060 ClutterLayoutManager *manager;
2061 ClutterLayoutMeta *meta;
2062
2063 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2064 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2065
2066 priv = layout->priv;
2067
2068 if (priv->container == NULL)
2069 {
2070 g_warning ("The layout of type '%s' must be associated to "
2071 "a ClutterContainer before querying layout "
2072 "properties",
2073 G_OBJECT_TYPE_NAME (layout));
2074 return;
2075 }
2076
2077 manager = CLUTTER_LAYOUT_MANAGER (layout);
2078 meta = clutter_layout_manager_get_child_meta (manager,
2079 priv->container,
2080 actor);
2081 if (meta == NULL)
2082 {
2083 g_warning ("No layout meta found for the child of type '%s' "
2084 "inside the layout manager of type '%s'",
2085 G_OBJECT_TYPE_NAME (actor),
2086 G_OBJECT_TYPE_NAME (manager));
2087 return;
2088 }
2089
2090 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2091
2092 table_child_set_align (CLUTTER_TABLE_CHILD (meta), x_align, y_align);
2093 }
2094
2095 /**
2096 * clutter_table_layout_get_alignment:
2097 * @layout: a #ClutterTableLayout
2098 * @actor: a #ClutterActor child of @layout
2099 * @x_align: (out): return location for the horizontal alignment policy
2100 * @y_align: (out): return location for the vertical alignment policy
2101 *
2102 * Retrieves the horizontal and vertical alignment policies for @actor
2103 * as set using clutter_table_layout_pack() or
2104 * clutter_table_layout_set_alignment().
2105 *
2106 * Since: 1.4
2107 *
2108 * Deprecated: 1.12: Use clutter_actor_get_x_align() and
2109 * clutter_actor_get_y_align() instead.
2110 */
2111 void
2112 clutter_table_layout_get_alignment (ClutterTableLayout *layout,
2113 ClutterActor *actor,
2114 ClutterTableAlignment *x_align,
2115 ClutterTableAlignment *y_align)
2116 {
2117 ClutterTableLayoutPrivate *priv;
2118 ClutterLayoutManager *manager;
2119 ClutterLayoutMeta *meta;
2120
2121 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2122 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2123
2124 priv = layout->priv;
2125
2126 if (priv->container == NULL)
2127 {
2128 g_warning ("The layout of type '%s' must be associated to "
2129 "a ClutterContainer before querying layout "
2130 "properties",
2131 G_OBJECT_TYPE_NAME (layout));
2132 return;
2133 }
2134
2135 manager = CLUTTER_LAYOUT_MANAGER (layout);
2136 meta = clutter_layout_manager_get_child_meta (manager,
2137 priv->container,
2138 actor);
2139 if (meta == NULL)
2140 {
2141 g_warning ("No layout meta found for the child of type '%s' "
2142 "inside the layout manager of type '%s'",
2143 G_OBJECT_TYPE_NAME (actor),
2144 G_OBJECT_TYPE_NAME (manager));
2145 return;
2146 }
2147
2148 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2149
2150 if (x_align)
2151 *x_align = CLUTTER_TABLE_CHILD (meta)->x_align;
2152
2153 if (y_align)
2154 *y_align = CLUTTER_TABLE_CHILD (meta)->y_align;
2155 }
2156
2157 /**
2158 * clutter_table_layout_set_fill:
2159 * @layout: a #ClutterTableLayout
2160 * @actor: a #ClutterActor child of @layout
2161 * @x_fill: whether @actor should fill horizontally the allocated space
2162 * @y_fill: whether @actor should fill vertically the allocated space
2163 *
2164 * Sets the horizontal and vertical fill policies for @actor
2165 * inside @layout
2166 *
2167 * Since: 1.4
2168 *
2169 * Deprecated: 1.12: Use clutter_actor_set_x_align() and
2170 * clutter_actor_set_y_align() instead.
2171 */
2172 void
2173 clutter_table_layout_set_fill (ClutterTableLayout *layout,
2174 ClutterActor *actor,
2175 gboolean x_fill,
2176 gboolean y_fill)
2177 {
2178 ClutterTableLayoutPrivate *priv;
2179 ClutterLayoutManager *manager;
2180 ClutterLayoutMeta *meta;
2181
2182 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2183 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2184
2185 priv = layout->priv;
2186
2187 if (priv->container == NULL)
2188 {
2189 g_warning ("The layout of type '%s' must be associated to "
2190 "a ClutterContainer before querying layout "
2191 "properties",
2192 G_OBJECT_TYPE_NAME (layout));
2193 return;
2194 }
2195
2196 manager = CLUTTER_LAYOUT_MANAGER (layout);
2197 meta = clutter_layout_manager_get_child_meta (manager,
2198 priv->container,
2199 actor);
2200 if (meta == NULL)
2201 {
2202 g_warning ("No layout meta found for the child of type '%s' "
2203 "inside the layout manager of type '%s'",
2204 G_OBJECT_TYPE_NAME (actor),
2205 G_OBJECT_TYPE_NAME (manager));
2206 return;
2207 }
2208
2209 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2210
2211 table_child_set_fill (CLUTTER_TABLE_CHILD (meta), x_fill, y_fill);
2212 }
2213
2214 /**
2215 * clutter_table_layout_get_fill:
2216 * @layout: a #ClutterTableLayout
2217 * @actor: a #ClutterActor child of @layout
2218 * @x_fill: (out): return location for the horizontal fill policy
2219 * @y_fill: (out): return location for the vertical fill policy
2220 *
2221 * Retrieves the horizontal and vertical fill policies for @actor
2222 * as set using clutter_table_layout_pack() or clutter_table_layout_set_fill()
2223 *
2224 * Since: 1.4
2225 *
2226 * Deprecated: 1.12: Use clutter_actor_get_x_align() and
2227 * clutter_actor_get_y_align() instead.
2228 */
2229 void
2230 clutter_table_layout_get_fill (ClutterTableLayout *layout,
2231 ClutterActor *actor,
2232 gboolean *x_fill,
2233 gboolean *y_fill)
2234 {
2235 ClutterTableLayoutPrivate *priv;
2236 ClutterLayoutManager *manager;
2237 ClutterLayoutMeta *meta;
2238
2239 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2240 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2241
2242 priv = layout->priv;
2243
2244 if (priv->container == NULL)
2245 {
2246 g_warning ("The layout of type '%s' must be associated to "
2247 "a ClutterContainer before querying layout "
2248 "properties",
2249 G_OBJECT_TYPE_NAME (layout));
2250 return;
2251 }
2252
2253 manager = CLUTTER_LAYOUT_MANAGER (layout);
2254 meta = clutter_layout_manager_get_child_meta (manager,
2255 priv->container,
2256 actor);
2257 if (meta == NULL)
2258 {
2259 g_warning ("No layout meta found for the child of type '%s' "
2260 "inside the layout manager of type '%s'",
2261 G_OBJECT_TYPE_NAME (actor),
2262 G_OBJECT_TYPE_NAME (manager));
2263 return;
2264 }
2265
2266 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2267
2268 if (x_fill)
2269 *x_fill = CLUTTER_TABLE_CHILD (meta)->x_fill;
2270
2271 if (y_fill)
2272 *y_fill = CLUTTER_TABLE_CHILD (meta)->y_fill;
2273 }
2274
2275
2276 /**
2277 * clutter_table_layout_set_expand:
2278 * @layout: a #ClutterTableLayout
2279 * @actor: a #ClutterActor child of @layout
2280 * @x_expand: whether @actor should allocate extra space horizontally
2281 * @y_expand: whether @actor should allocate extra space vertically
2282 *
2283 * Sets the horizontal and vertical expand policies for @actor
2284 * inside @layout
2285 *
2286 * Since: 1.4
2287 *
2288 * Deprecated: 1.12: Use clutter_actor_set_x_expand() or
2289 * clutter_actor_set_y_expand() instead.
2290 */
2291 void
2292 clutter_table_layout_set_expand (ClutterTableLayout *layout,
2293 ClutterActor *actor,
2294 gboolean x_expand,
2295 gboolean y_expand)
2296 {
2297 ClutterTableLayoutPrivate *priv;
2298 ClutterLayoutManager *manager;
2299 ClutterLayoutMeta *meta;
2300
2301 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2302 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2303
2304 priv = layout->priv;
2305
2306 if (priv->container == NULL)
2307 {
2308 g_warning ("The layout of type '%s' must be associated to "
2309 "a ClutterContainer before querying layout "
2310 "properties",
2311 G_OBJECT_TYPE_NAME (layout));
2312 return;
2313 }
2314
2315 manager = CLUTTER_LAYOUT_MANAGER (layout);
2316 meta = clutter_layout_manager_get_child_meta (manager,
2317 priv->container,
2318 actor);
2319 if (meta == NULL)
2320 {
2321 g_warning ("No layout meta found for the child of type '%s' "
2322 "inside the layout manager of type '%s'",
2323 G_OBJECT_TYPE_NAME (actor),
2324 G_OBJECT_TYPE_NAME (manager));
2325 return;
2326 }
2327
2328 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2329
2330 table_child_set_expand (CLUTTER_TABLE_CHILD (meta), x_expand, y_expand);
2331 }
2332
2333 /**
2334 * clutter_table_layout_get_expand:
2335 * @layout: a #ClutterTableLayout
2336 * @actor: a #ClutterActor child of @layout
2337 * @x_expand: (out): return location for the horizontal expand policy
2338 * @y_expand: (out): return location for the vertical expand policy
2339 *
2340 * Retrieves the horizontal and vertical expand policies for @actor
2341 * as set using clutter_table_layout_pack() or clutter_table_layout_set_expand()
2342 *
2343 * Since: 1.4
2344 *
2345 * Deprecated: 1.12: Use clutter_actor_get_x_expand() and
2346 * clutter_actor_get_y_expand() instead.
2347 */
2348 void
2349 clutter_table_layout_get_expand (ClutterTableLayout *layout,
2350 ClutterActor *actor,
2351 gboolean *x_expand,
2352 gboolean *y_expand)
2353 {
2354 ClutterTableLayoutPrivate *priv;
2355 ClutterLayoutManager *manager;
2356 ClutterLayoutMeta *meta;
2357
2358 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2359 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
2360
2361 priv = layout->priv;
2362
2363 if (priv->container == NULL)
2364 {
2365 g_warning ("The layout of type '%s' must be associated to "
2366 "a ClutterContainer before querying layout "
2367 "properties",
2368 G_OBJECT_TYPE_NAME (layout));
2369 return;
2370 }
2371
2372 manager = CLUTTER_LAYOUT_MANAGER (layout);
2373 meta = clutter_layout_manager_get_child_meta (manager,
2374 priv->container,
2375 actor);
2376 if (meta == NULL)
2377 {
2378 g_warning ("No layout meta found for the child of type '%s' "
2379 "inside the layout manager of type '%s'",
2380 G_OBJECT_TYPE_NAME (actor),
2381 G_OBJECT_TYPE_NAME (manager));
2382 return;
2383 }
2384
2385 g_assert (CLUTTER_IS_TABLE_CHILD (meta));
2386
2387 if (x_expand)
2388 *x_expand = CLUTTER_TABLE_CHILD (meta)->x_expand;
2389
2390 if (y_expand)
2391 *y_expand = CLUTTER_TABLE_CHILD (meta)->y_expand;
2392 }
2393
2394 /**
2395 * clutter_table_layout_set_use_animations:
2396 * @layout: a #ClutterTableLayout
2397 * @animate: %TRUE if the @layout should use animations
2398 *
2399 * Sets whether @layout should animate changes in the layout properties
2400 *
2401 * The duration of the animations is controlled by
2402 * clutter_table_layout_set_easing_duration(); the easing mode to be used
2403 * by the animations is controlled by clutter_table_layout_set_easing_mode()
2404 *
2405 * Since: 1.4
2406 *
2407 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2408 * of the children when allocating them. See clutter_actor_set_easing_mode()
2409 * and clutter_actor_set_easing_duration().
2410 */
2411 void
2412 clutter_table_layout_set_use_animations (ClutterTableLayout *layout,
2413 gboolean animate)
2414 {
2415 ClutterTableLayoutPrivate *priv;
2416
2417 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2418
2419 priv = layout->priv;
2420
2421 animate = !!animate;
2422 if (priv->use_animations != animate)
2423 {
2424 priv->use_animations = animate;
2425
2426 g_object_notify (G_OBJECT (layout), "use-animations");
2427 }
2428 }
2429
2430 /**
2431 * clutter_table_layout_get_use_animations:
2432 * @layout: a #ClutterTableLayout
2433 *
2434 * Retrieves whether @layout should animate changes in the layout properties
2435 *
2436 * Since clutter_table_layout_set_use_animations()
2437 *
2438 * Return value: %TRUE if the animations should be used, %FALSE otherwise
2439 *
2440 * Since: 1.4
2441 *
2442 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2443 * of the children when allocating them. See clutter_actor_set_easing_mode()
2444 * and clutter_actor_set_easing_duration().
2445 */
2446 gboolean
2447 clutter_table_layout_get_use_animations (ClutterTableLayout *layout)
2448 {
2449 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), FALSE);
2450
2451 return layout->priv->use_animations;
2452 }
2453
2454 /**
2455 * clutter_table_layout_set_easing_mode:
2456 * @layout: a #ClutterTableLayout
2457 * @mode: an easing mode, either from #ClutterAnimationMode or a logical id
2458 * from clutter_alpha_register_func()
2459 *
2460 * Sets the easing mode to be used by @layout when animating changes in layout
2461 * properties
2462 *
2463 * Use clutter_table_layout_set_use_animations() to enable and disable the
2464 * animations
2465 *
2466 * Since: 1.4
2467 *
2468 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2469 * of the children when allocating them. See clutter_actor_set_easing_mode()
2470 * and clutter_actor_set_easing_duration().
2471 */
2472 void
2473 clutter_table_layout_set_easing_mode (ClutterTableLayout *layout,
2474 gulong mode)
2475 {
2476 ClutterTableLayoutPrivate *priv;
2477
2478 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2479
2480 priv = layout->priv;
2481
2482 if (priv->easing_mode != mode)
2483 {
2484 priv->easing_mode = mode;
2485
2486 g_object_notify (G_OBJECT (layout), "easing-mode");
2487 }
2488 }
2489
2490 /**
2491 * clutter_table_layout_get_easing_mode:
2492 * @layout: a #ClutterTableLayout
2493 *
2494 * Retrieves the easing mode set using clutter_table_layout_set_easing_mode()
2495 *
2496 * Return value: an easing mode
2497 *
2498 * Since: 1.4
2499 *
2500 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2501 * of the children when allocating them. See clutter_actor_set_easing_mode()
2502 * and clutter_actor_set_easing_duration().
2503 */
2504 gulong
2505 clutter_table_layout_get_easing_mode (ClutterTableLayout *layout)
2506 {
2507 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout),
2508 CLUTTER_EASE_OUT_CUBIC);
2509
2510 return layout->priv->easing_mode;
2511 }
2512
2513 /**
2514 * clutter_table_layout_set_easing_duration:
2515 * @layout: a #ClutterTableLayout
2516 * @msecs: the duration of the animations, in milliseconds
2517 *
2518 * Sets the duration of the animations used by @layout when animating changes
2519 * in the layout properties
2520 *
2521 * Use clutter_table_layout_set_use_animations() to enable and disable the
2522 * animations
2523 *
2524 * Since: 1.4
2525 *
2526 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2527 * of the children when allocating them. See clutter_actor_set_easing_mode()
2528 * and clutter_actor_set_easing_duration().
2529 */
2530 void
2531 clutter_table_layout_set_easing_duration (ClutterTableLayout *layout,
2532 guint msecs)
2533 {
2534 ClutterTableLayoutPrivate *priv;
2535
2536 g_return_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout));
2537
2538 priv = layout->priv;
2539
2540 if (priv->easing_duration != msecs)
2541 {
2542 priv->easing_duration = msecs;
2543
2544 g_object_notify (G_OBJECT (layout), "easing-duration");
2545 }
2546 }
2547
2548 /**
2549 * clutter_table_layout_get_easing_duration:
2550 * @layout: a #ClutterTableLayout
2551 *
2552 * Retrieves the duration set using clutter_table_layout_set_easing_duration()
2553 *
2554 * Return value: the duration of the animations, in milliseconds
2555 *
2556 * Since: 1.4
2557 *
2558 * Deprecated: 1.12: #ClutterTableLayout will honour the easing state
2559 * of the children when allocating them. See clutter_actor_set_easing_mode()
2560 * and clutter_actor_set_easing_duration().
2561 */
2562 guint
2563 clutter_table_layout_get_easing_duration (ClutterTableLayout *layout)
2564 {
2565 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), 500);
2566
2567 return layout->priv->easing_duration;
2568 }
2569
2570
2571 /**
2572 * clutter_table_layout_get_row_count:
2573 * @layout: A #ClutterTableLayout
2574 *
2575 * Retrieve the current number rows in the @layout
2576 *
2577 * Returns: the number of rows
2578 *
2579 * Since: 1.4
2580 *
2581 * Deprecated: 1.18: No direct replacement is available
2582 */
2583 gint
2584 clutter_table_layout_get_row_count (ClutterTableLayout *layout)
2585 {
2586 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), -1);
2587
2588 update_row_col (layout, layout->priv->container);
2589 return CLUTTER_TABLE_LAYOUT (layout)->priv->n_rows;
2590 }
2591
2592 /**
2593 * clutter_table_layout_get_column_count:
2594 * @layout: A #ClutterTableLayout
2595 *
2596 * Retrieve the current number of columns in @layout
2597 *
2598 * Returns: the number of columns
2599 *
2600 * Since: 1.4
2601 *
2602 * Deprecated: 1.18: No direct replacement is available
2603 */
2604 gint
2605 clutter_table_layout_get_column_count (ClutterTableLayout *layout)
2606 {
2607 g_return_val_if_fail (CLUTTER_IS_TABLE_LAYOUT (layout), -1);
2608
2609 update_row_col (layout, layout->priv->container);
2610 return CLUTTER_TABLE_LAYOUT (layout)->priv->n_cols;
2611 }