1 #include "edje_private.h"
2 #include "edje_container.h"
7 _edje_container_relayout(Smart_Data *sd)
10 Evas_Coord x, y, w, h, sw;
13 if (sd->freeze > 0) return;
14 if (!sd->need_layout) return;
16 if (sd->w < sd->min_w) sw = sd->min_w;
17 else if (sd->w > sd->max_w) sw = sd->max_w;
25 EINA_LIST_FOREACH(sd->children, l, ei)
27 if (sd->homogenous) h = sd->min_row_h;
39 _edje_container_recalc(Smart_Data *sd)
43 int any_max_h = 0, any_max_w = 0;
46 if (sd->freeze > 0) return;
47 if (!sd->changed) return;
58 for (i = 0; i < sd->cols; i++)
60 sd->min_w += sd->colinfo[i].minw;
61 if (sd->colinfo[i].maxw >= 0)
64 sd->max_w += sd->colinfo[i].maxw;
66 sd->max_w = sd->colinfo[i].maxw;
71 if (any_max_w) sd->max_w = -1;
73 if (sd->w < sd->min_w)
74 sd->contents_w = sd->min_w;
75 else if ((sd->max_w >= 0) && (sd->w < sd->max_w))
78 EINA_LIST_FOREACH(sd->children, l, ei)
80 if (ei->minh > sd->min_row_h)
81 sd->min_row_h = ei->minh;
82 if (sd->max_row_h >= 0)
86 if (sd->max_row_h > ei->maxh)
87 sd->max_row_h = ei->maxh;
92 sd->min_h += ei->minh;
96 sd->max_h += ei->maxh;
110 sd->min_h = eina_list_count(sd->children) * sd->min_row_h;
114 sd->change_child = 0;
115 sd->change_child_list = 0;
119 _edje_container_relayout(sd);
123 _edje_item_recalc(Edje_Item *ei)
127 if (ei->freeze > 0) return;
128 if (!ei->recalc) return;
133 for (i = 0; i < ((Smart_Data *)(ei->sd))->cols; i++)
135 if (ei->cells[i].minh > ei->minh) ei->minh = ei->cells[i].minh;
136 if (ei->cells[i].maxh >= 0)
140 if (ei->cells[i].maxh < ei->maxh)
141 ei->maxh = ei->cells[i].maxh;
144 ei->maxh = ei->cells[i].maxh;
146 if (((Smart_Data *)(ei->sd))->colinfo[i].minw < ei->cells[i].minw)
147 ((Smart_Data *)(ei->sd))->colinfo[i].minw = ei->cells[i].minw;
148 if (((Smart_Data *)(ei->sd))->colinfo[i].maxw >= 0)
150 if (ei->cells[i].maxw >= 0)
152 if (((Smart_Data *)(ei->sd))->colinfo[i].maxw > ei->cells[i].maxw)
153 ((Smart_Data *)(ei->sd))->colinfo[i].maxw = ei->cells[i].maxw;
157 ((Smart_Data *)(ei->sd))->colinfo[i].maxw = ei->cells[i].maxw;
162 _edje_container_recalc(ei->sd);
166 /*****************************/
171 /*============================================================================*
173 *============================================================================*/
175 /*============================================================================*
177 *============================================================================*/
180 * @addtogroup Edje_container_Group Container
182 * @brief These functions provides an abstraction layer between the application
183 * code and the interface, while allowing extremely flexible dynamic layouts
186 * For more information, you can look at the @ref tutorial_list_page.
192 * @brief Create an edje item.
194 * @param cl The edje item of type Edje_Item_Class.
195 * @param data The edje item data.
197 * @return The new edje item created.
199 * This function creates an new edje item. The edje item data can be
200 * retrieved with edje_item_data_get().
202 * @see edje_item_del()
203 * @see edje_item_data_set()
204 * @see edje_item_data_get()
209 edje_item_add(Edje_Item_Class *cl, void *data)
213 ei = calloc(sizeof(Edje_Item), 1);
216 ei->class_data = data;
222 * @brief Delete an edje item.
224 * @param ei The edje item to be deleted.
226 * This function deletes the edje item from memory.
228 * @see edje_item_add()
229 * @see edje_item_data_set()
230 * @see edje_item_data_get()
235 edje_item_del(Edje_Item *ei)
240 if (ei->object) evas_object_del(ei->object);
241 if (ei->overlay_object) evas_object_del(ei->overlay_object);
245 sd->change_child_list = 1;
246 _edje_container_recalc(sd);
250 * @brief Return the smart object of the edje item.
252 * @param ei The edje item which the smart object of type Evas_Object is get
255 * This function returns the smart object in the edje item.
260 edje_item_container_get(Edje_Item *ei)
262 if (!ei->sd) return NULL;
263 return ((Smart_Data *)(ei->sd))->smart_obj;
266 /* an arbitrary data pointer to use to track other data */
268 * @brief Set the edje item data.
270 * @param ei The edje item of type Edje_Item_Class.
271 * @param data The edje item data.
273 * This function set the data of the edje item. The edje item data can be
274 * retrieved with edje_item_data_get().
276 * @see edje_item_add()
277 * @see edje_item_del()
278 * @see edje_item_data_get()
283 edje_item_data_set(Edje_Item *ei, void *data)
289 * @brief Get the data of the edje item.
291 * @param ei The edje item of type Edje_Item_Class.
293 * This function get the data of the edje item set by edje_item_data_set().
295 * @see edje_item_data_set()
296 * @see edje_item_add()
297 * @see edje_item_del()
302 edje_item_data_get(Edje_Item *ei)
307 /* this object covers the entire item */
310 edje_item_overlay_object_set(Edje_Item *ei, Evas_Object *obj)
312 if (ei->overlay_object)
314 /* FIXME: if it changed - remove...*/
316 ei->overlay_object = obj;
318 evas_object_smart_member_add(((Smart_Data *)(ei->sd))->smart_obj, obj);
324 edje_item_overlay_object_get(Edje_Item *ei)
326 return ei->overlay_object;
329 /* this object goes under entire item */
331 edje_item_object_set(Edje_Item *ei, Evas_Object *obj)
335 /* FIXME: if it changed - remove...*/
339 evas_object_smart_member_add(((Smart_Data *)(ei->sd))->smart_obj, obj);
343 edje_item_object_get(Edje_Item *ei)
348 /* optionally you can manage each column's object yourself OR let Edje do it */
350 edje_item_object_column_set(Edje_Item *ei, int col, Evas_Object *obj)
352 if (ei->cells_num <= (col + 1))
354 /* FIXME: unsafe realloc */
355 ei->cells = realloc(ei->cells, sizeof(Edje_Item_Cell) * col);
356 ei->cells_num = col + 1;
358 ei->cells[col].obj = obj;
362 edje_item_object_column_get(Edje_Item *ei, int col)
364 if (ei->cells_num <= (col + 1)) return NULL;
365 return ei->cells[col].obj;
368 /* query the item for the items preferred co-ords */
370 edje_item_geometry_get(Edje_Item *ei, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
380 if (x) *x = ((Smart_Data *)(ei->sd))->x;
381 if (y) *y = ((Smart_Data *)(ei->sd))->y + ei->y;
382 if (w) *w = ((Smart_Data *)(ei->sd))->w;
386 /* freeze and thaw items if u are about to do a bunch of changes */
388 edje_item_freeze(Edje_Item *ei)
395 edje_item_thaw(Edje_Item *ei)
398 if (ei->freeze > 0) return ei->freeze;
399 if (!ei->sd) return ei->freeze;
400 if (ei->recalc) _edje_item_recalc(ei);
406 edje_item_column_size_set(Edje_Item *ei, int col, Evas_Coord minw, Evas_Coord maxw, Evas_Coord minh, Evas_Coord maxh)
408 if (ei->cells_num <= (col + 1))
410 /* FIXME: unsafe realloc */
411 ei->cells = realloc(ei->cells, sizeof(Edje_Item_Cell) * col);
412 ei->cells_num = col + 1;
414 if ((ei->cells[col].minw == minw) &&
415 (ei->cells[col].minh == minh) &&
416 (ei->cells[col].maxw == maxw) &&
417 (ei->cells[col].maxh == maxh)) return;
418 ei->cells[col].minh = minh;
419 ei->cells[col].maxh = maxh;
420 ei->cells[col].minw = minw;
421 ei->cells[col].maxw = maxw;
425 ((Smart_Data *)(ei->sd))->changed = 1;
426 ((Smart_Data *)(ei->sd))->change_child = 1;
428 _edje_item_recalc(ei);
432 edje_item_column_size_get(Edje_Item *ei, int col, Evas_Coord *minw, Evas_Coord *maxw, Evas_Coord *minh, Evas_Coord *maxh)
434 if (ei->cells_num <= (col + 1))
438 if (maxw) *maxw = -1;
439 if (maxh) *maxh = -1;
441 if (minw) *minw = ei->cells[col].minw;
442 if (minh) *minh = ei->cells[col].minh;
443 if (maxw) *maxw = ei->cells[col].maxw;
444 if (maxh) *maxh = ei->cells[col].maxh;
447 /* selection stuff */
449 edje_item_select(Edje_Item *ei)
452 /* FIXME: trigger item to change visually */
456 edje_item_unselect(Edje_Item *ei)
459 /* FIXME: trigger item to change visually */
462 /* focus stuff - only 1 can be focuesd */
464 edje_item_focus(Edje_Item *ei)
470 edje_item_unfocus(Edje_Item *ei)
475 /* disable/enable stuff - stops focus and selection working on these items */
477 edje_item_enable(Edje_Item *ei)
483 edje_item_disable(Edje_Item *ei)
490 edje_item_selected_get(Edje_Item *ei)
496 edje_item_focused_get(Edje_Item *ei)
502 edje_item_disabled_get(Edje_Item *ei)
507 /***** container calls *****/
510 edje_container_freeze(Evas_Object *obj)
514 sd = evas_object_smart_data_get(obj);
521 edje_container_thaw(Evas_Object *obj)
525 sd = evas_object_smart_data_get(obj);
528 if (sd->freeze <= 0) _edje_container_recalc(sd);
533 edje_container_item_append(Evas_Object *obj, Edje_Item *ei)
537 sd = evas_object_smart_data_get(obj);
539 sd->children = eina_list_append(sd->children, ei);
541 sd->change_child_list = 1;
542 sd->rows = eina_list_count(sd->children);
543 _edje_container_recalc(sd);
547 edje_container_item_prepend(Evas_Object *obj, Edje_Item *ei)
551 sd = evas_object_smart_data_get(obj);
553 sd->children = eina_list_prepend(sd->children, ei);
555 sd->change_child_list = 1;
556 sd->rows = eina_list_count(sd->children);
557 _edje_container_recalc(sd);
561 edje_container_item_append_relative(Evas_Object *obj, Edje_Item *ei, Edje_Item *rel)
565 sd = evas_object_smart_data_get(obj);
567 sd->children = eina_list_append_relative(sd->children, ei, rel);
569 sd->change_child_list = 1;
570 sd->rows = eina_list_count(sd->children);
571 _edje_container_recalc(sd);
575 edje_container_item_prepend_relative(Evas_Object *obj, Edje_Item *ei, Edje_Item *rel)
579 sd = evas_object_smart_data_get(obj);
581 sd->children = eina_list_prepend_relative(sd->children, ei, rel);
583 sd->change_child_list = 1;
584 sd->rows = eina_list_count(sd->children);
585 _edje_container_recalc(sd);
589 edje_container_item_insert(Evas_Object *obj, Edje_Item *ei, int n)
594 sd = evas_object_smart_data_get(obj);
596 rel = eina_list_nth(sd->children, n);
598 sd->children = eina_list_append(sd->children, ei);
600 sd->children = eina_list_append_relative(sd->children, ei, rel);
602 sd->change_child_list = 1;
603 sd->rows = eina_list_count(sd->children);
604 _edje_container_recalc(sd);
608 edje_container_item_remove(Evas_Object *obj, Edje_Item *ei)
612 sd = evas_object_smart_data_get(obj);
614 sd->children = eina_list_remove(sd->children, ei);
616 sd->change_child_list = 1;
617 sd->rows = eina_list_count(sd->children);
618 _edje_container_recalc(sd);
622 edje_container_columns_set(Evas_Object *obj, int cols)
626 sd = evas_object_smart_data_get(obj);
628 if (sd->cols == cols) return;
629 sd->colinfo = realloc(sd->colinfo, cols * sizeof(Smart_Data_Colinfo));
634 for (i = sd->cols; i < cols; i++)
636 sd->colinfo[i].minw = 0;
637 sd->colinfo[i].maxw = -1;
643 _edje_container_recalc(sd);
647 edje_container_columns_get(Evas_Object *obj)
651 sd = evas_object_smart_data_get(obj);
657 edje_container_min_size_get(Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh)
661 sd = evas_object_smart_data_get(obj);
669 _edje_container_recalc(sd);
672 if (minw) *minw = sd->min_w;
673 if (minh) *minh = sd->min_h;
677 edje_container_max_size_get(Evas_Object *obj, Evas_Coord *maxw, Evas_Coord *maxh)
681 sd = evas_object_smart_data_get(obj);
689 _edje_container_recalc(sd);
692 if (maxw) *maxw = sd->max_w;
693 if (maxh) *maxh = sd->max_h;
697 edje_containter_align_set(Evas_Object *obj, double halign, double valign)
701 sd = evas_object_smart_data_get(obj);
703 if ((sd->align_x == halign) && (sd->align_y == valign)) return;
704 sd->align_x = halign;
705 sd->align_y = valign;
707 _edje_container_relayout(sd);
711 edje_container_align_get(Evas_Object *obj, double *halign, double *valign)
715 sd = evas_object_smart_data_get(obj);
717 if (halign) *halign = sd->align_x;
718 if (valign) *valign = sd->align_y;
722 edje_container_count_get(Evas_Object *obj)
726 sd = evas_object_smart_data_get(obj);
728 return eina_list_count(sd->children);
732 edje_container_item_first_get(Evas_Object *obj)
736 sd = evas_object_smart_data_get(obj);
737 if (!sd) return NULL;
738 if (!sd->children) return NULL;
739 return eina_list_data_get(sd->children);
743 edje_container_item_last_get(Evas_Object *obj)
747 sd = evas_object_smart_data_get(obj);
748 if (!sd) return NULL;
749 if (!sd->children) return NULL;
750 return0 eina_list_data_get(eina_list_last(sd->children));
754 edje_container_item_nth_get(Evas_Object *obj, int n)
758 sd = evas_object_smart_data_get(obj);
759 if (!sd) return NULL;
760 return eina_list_nth(sd->children, n);
764 edje_container_homogenous_size_set(Evas_Object *obj, int homog)
768 sd = evas_object_smart_data_get(obj);
770 if (((homog) && (sd->homogenous)) ||
771 ((!homog) && (!sd->homogenous))) return;
772 sd->homogenous = homog;
774 sd->change_child = 1;
775 _edje_container_recalc(sd);
779 edje_container_homogenous_size_get(Evas_Object *obj)
783 sd = evas_object_smart_data_get(obj);
785 return sd->homogenous;
789 edje_container_scroll_set(Evas_Object *obj, double pos, double shift)
793 sd = evas_object_smart_data_get(obj);
795 if ((sd->scroll_y == pos) && (sd->scroll_x == shift)) return;
797 sd->scroll_x = shift;
799 _edje_container_relayout(sd);
803 edje_container_scroll_get(Evas_Object *obj, double *pos, double *shift)
807 sd = evas_object_smart_data_get(obj);
809 if (pos) *pos = sd->scroll_y;
810 if (shift) *shift = sd->scroll_x;
813 static void _smart_init(void);
814 static void _smart_add(Evas_Object * obj);
815 static void _smart_del(Evas_Object * obj);
816 static void _smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y);
817 static void _smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h);
818 static void _smart_show(Evas_Object * obj);
819 static void _smart_hide(Evas_Object * obj);
820 static void _smart_color_set(Evas_Object * obj, int r, int g, int b, int a);
821 static void _smart_clip_set(Evas_Object * obj, Evas_Object * clip);
822 static void _smart_clip_unset(Evas_Object * obj);
824 static Evas_Smart *smart = NULL;
827 edje_container_object_add(Evas *evas)
830 return evas_object_smart_add(evas, smart);
833 /*******************************************/
834 /* Internal smart object required routines */
835 /*******************************************/
841 static const Evas_Smart_Class sc =
857 smart = evas_smart_class_new(&sc);
862 _smart_add(Evas_Object *obj)
866 sd = calloc(1, sizeof(Smart_Data));
868 // evas_object_smart_member_add(sd->obj, obj);
869 evas_object_smart_data_set(obj, sd);
874 _smart_del(Evas_Object *obj)
878 sd = evas_object_smart_data_get(obj);
880 if (sd->colinfo) free(sd->colinfo);
881 // evas_object_del(sd->obj);
886 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
890 sd = evas_object_smart_data_get(obj);
892 // evas_object_move(sd->obj, x, y);
896 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
900 sd = evas_object_smart_data_get(obj);
902 // evas_object_resize(sd->obj, w, h);
906 _smart_show(Evas_Object *obj)
910 sd = evas_object_smart_data_get(obj);
912 // evas_object_show(sd->obj);
916 _smart_hide(Evas_Object *obj)
920 sd = evas_object_smart_data_get(obj);
922 // evas_object_hide(sd->obj);
926 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
930 sd = evas_object_smart_data_get(obj);
932 // evas_object_color_set(sd->obj, r, g, b, a);
936 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
940 sd = evas_object_smart_data_get(obj);
942 // evas_object_clip_set(sd->obj, clip);
946 _smart_clip_unset(Evas_Object *obj)
950 sd = evas_object_smart_data_get(obj);
952 // evas_object_clip_unset(sd->obj);