3 typedef struct _E_Smart_Data E_Smart_Data;
4 typedef struct _E_Table_Item E_Table_Item;
12 unsigned char changed : 1;
13 unsigned char homogenous : 1;
29 int col, row, colspan, rowspan;
30 unsigned char fill_w : 1;
31 unsigned char fill_h : 1;
32 unsigned char expand_w : 1;
33 unsigned char expand_h : 1;
43 /* local subsystem functions */
44 static E_Table_Item *_e_table_smart_adopt(E_Smart_Data *sd, Evas_Object *obj);
45 static void _e_table_smart_disown(Evas_Object *obj);
46 static void _e_table_smart_item_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _e_table_smart_reconfigure(E_Smart_Data *sd);
48 static void _e_table_smart_extents_calcuate(E_Smart_Data *sd);
50 static void _e_table_smart_init(void);
51 static void _e_table_smart_add(Evas_Object *obj);
52 static void _e_table_smart_del(Evas_Object *obj);
53 static void _e_table_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
54 static void _e_table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
55 static void _e_table_smart_show(Evas_Object *obj);
56 static void _e_table_smart_hide(Evas_Object *obj);
57 static void _e_table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
58 static void _e_table_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
59 static void _e_table_smart_clip_unset(Evas_Object *obj);
61 /* local subsystem globals */
62 static Evas_Smart *_e_smart = NULL;
64 /* externally accessible functions */
66 e_table_add(Evas *evas)
68 _e_table_smart_init();
69 return evas_object_smart_add(evas, _e_smart);
73 e_table_freeze(Evas_Object *obj)
77 sd = evas_object_smart_data_get(obj);
83 e_table_thaw(Evas_Object *obj)
87 sd = evas_object_smart_data_get(obj);
89 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
94 e_table_homogenous_set(Evas_Object *obj, int homogenous)
98 sd = evas_object_smart_data_get(obj);
99 if (sd->homogenous == homogenous) return;
100 sd->homogenous = homogenous;
102 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
106 e_table_pack(Evas_Object *obj, Evas_Object *child, int col, int row, int colspan, int rowspan)
111 sd = evas_object_smart_data_get(obj);
112 _e_table_smart_adopt(sd, child);
113 sd->items = eina_list_append(sd->items, child);
114 ti = evas_object_data_get(child, "e_table_data");
119 ti->colspan = colspan;
120 ti->rowspan = rowspan;
121 if (sd->size.cols < (col + colspan)) sd->size.cols = col + colspan;
122 if (sd->size.rows < (row + rowspan)) sd->size.rows = row + rowspan;
125 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
129 e_table_pack_options_set(Evas_Object *obj, int fill_w, int fill_h, int expand_w, int expand_h, double align_x, double align_y, Evas_Coord min_w, Evas_Coord min_h, Evas_Coord max_w, Evas_Coord max_h)
133 ti = evas_object_data_get(obj, "e_table_data");
137 ti->expand_w = expand_w;
138 ti->expand_h = expand_h;
139 ti->align.x = align_x;
140 ti->align.y = align_y;
146 if (ti->sd->frozen <= 0) _e_table_smart_reconfigure(ti->sd);
150 e_table_unpack(Evas_Object *obj)
155 ti = evas_object_data_get(obj, "e_table_data");
158 sd->items = eina_list_remove(sd->items, obj);
159 _e_table_smart_disown(obj);
161 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
165 e_table_col_row_size_get(Evas_Object *obj, int *cols, int *rows)
169 sd = evas_object_smart_data_get(obj);
170 if (sd->changed) _e_table_smart_extents_calcuate(sd);
171 if (cols) *cols = sd->size.cols;
172 if (rows) *rows = sd->size.rows;
176 e_table_size_min_get(Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh)
180 sd = evas_object_smart_data_get(obj);
181 if (sd->changed) _e_table_smart_extents_calcuate(sd);
182 if (minw) *minw = sd->min.w;
183 if (minh) *minh = sd->min.h;
187 e_table_size_max_get(Evas_Object *obj, Evas_Coord *maxw, Evas_Coord *maxh)
191 sd = evas_object_smart_data_get(obj);
192 if (sd->changed) _e_table_smart_extents_calcuate(sd);
193 if (maxw) *maxw = sd->max.w;
194 if (maxh) *maxh = sd->max.h;
198 e_table_align_get(Evas_Object *obj, double *ax, double *ay)
202 sd = evas_object_smart_data_get(obj);
203 if (ax) *ax = sd->align.x;
204 if (ay) *ay = sd->align.y;
208 e_table_align_set(Evas_Object *obj, double ax, double ay)
212 sd = evas_object_smart_data_get(obj);
213 if ((sd->align.x == ax) && (sd->align.y == ay)) return;
217 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
220 /* local subsystem functions */
221 static E_Table_Item *
222 _e_table_smart_adopt(E_Smart_Data *sd, Evas_Object *obj)
226 ti = calloc(1, sizeof(E_Table_Item));
227 if (!ti) return NULL;
245 evas_object_clip_set(obj, sd->clip);
246 // evas_object_stack_above(obj, sd->obj);
247 evas_object_smart_member_add(obj, ti->sd->obj);
248 evas_object_data_set(obj, "e_table_data", ti);
249 evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
250 _e_table_smart_item_del_hook, NULL);
251 // evas_object_stack_below(obj, sd->obj);
252 if ((!evas_object_visible_get(sd->clip)) &&
253 (evas_object_visible_get(sd->obj)))
254 evas_object_show(sd->clip);
259 _e_table_smart_disown(Evas_Object *obj)
263 ti = evas_object_data_get(obj, "e_table_data");
267 if (evas_object_visible_get(ti->sd->clip))
268 evas_object_hide(ti->sd->clip);
270 evas_object_event_callback_del(obj,
272 _e_table_smart_item_del_hook);
273 evas_object_smart_member_del(obj);
274 evas_object_data_del(obj, "e_table_data");
279 _e_table_smart_item_del_hook(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
285 _e_table_smart_reconfigure(E_Smart_Data *sd)
287 Evas_Coord x, y, w, h, xx, yy;
290 int minw, minh, expandw, expandh;
292 if (!sd->changed) return;
299 _e_table_smart_extents_calcuate(sd);
307 x = x + ((w - minw) * (1.0 - sd->align.x));
312 y = y + ((h - minh) * (1.0 - sd->align.y));
315 EINA_LIST_FOREACH(sd->items, l, obj)
319 ti = evas_object_data_get(obj, "e_table_data");
320 if (ti->expand_w) expandw++;
321 if (ti->expand_h) expandh++;
335 EINA_LIST_FOREACH(sd->items, l, obj)
338 Evas_Coord ww, hh, ow, oh;
340 ti = evas_object_data_get(obj, "e_table_data");
342 xx = x + ((ti->col) * (w / (Evas_Coord)sd->size.cols));
343 yy = y + ((ti->row) * (h / (Evas_Coord)sd->size.rows));
344 ww = ((w / (Evas_Coord)sd->size.cols) * (ti->colspan));
345 hh = ((h / (Evas_Coord)sd->size.rows) * (ti->rowspan));
347 if (ti->expand_w) ow = ww;
348 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
350 if (ti->expand_h) oh = hh;
351 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
352 evas_object_move(obj,
353 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
354 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
355 evas_object_resize(obj, ow, oh);
360 int i, ex, tot, need, num, dif, left, nx;
361 EINA_LIST_FOREACH(sd->items, l, obj)
365 ti = evas_object_data_get(obj, "e_table_data");
366 if (sd->size.cols < (ti->col + ti->colspan))
367 sd->size.cols = ti->col + ti->colspan;
368 if (sd->size.rows < (ti->row + ti->rowspan))
369 sd->size.rows = ti->row + ti->rowspan;
371 if ((sd->size.cols > 0) && (sd->size.rows > 0))
373 int *cols, *rows, *colsx, *rowsx;
375 cols = calloc(sd->size.cols, sizeof(int));
376 rows = calloc(sd->size.rows, sizeof(int));
377 colsx = calloc(sd->size.cols, sizeof(int));
378 rowsx = calloc(sd->size.rows, sizeof(int));
380 EINA_LIST_FOREACH(sd->items, l, obj)
384 ti = evas_object_data_get(obj, "e_table_data");
385 for (i = ti->col; i < (ti->col + ti->colspan); i++)
386 colsx[i] |= ti->expand_w;
387 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
388 rowsx[i] |= ti->expand_h;
391 EINA_LIST_FOREACH(sd->items, l, obj)
395 ti = evas_object_data_get(obj, "e_table_data");
397 /* handle horizontal */
401 for (i = ti->col; i < (ti->col + num); i++)
414 for (i = ti->col; i < (ti->col + num); i++)
418 cols[i] += dif / num;
432 for (i = ti->col; i < (ti->col + num); i++)
452 /* handle vertical */
456 for (i = ti->row; i < (ti->row + num); i++)
469 for (i = ti->row; i < (ti->row + num); i++)
473 rows[i] += dif / num;
487 for (i = ti->row; i < (ti->row + num); i++)
509 for (i = 0; i < sd->size.cols; i++) { if (colsx[i]) ex++; }
511 for (i = 0; i < sd->size.cols; i++) tot += cols[i];
513 if ((ex > 0) && (dif > 0))
519 for (i = 0; i < sd->size.cols; i++)
540 for (i = 0; i < sd->size.rows; i++) { if (rowsx[i]) ex++; }
542 for (i = 0; i < sd->size.rows; i++) tot += rows[i];
544 if ((ex > 0) && (dif > 0))
550 for (i = 0; i < sd->size.rows; i++)
570 EINA_LIST_FOREACH(sd->items, l, obj)
573 Evas_Coord ww, hh, ow, oh, i;
575 ti = evas_object_data_get(obj, "e_table_data");
578 for (i = 0; i < ti->col; i++) xx += cols[i];
580 for (i = ti->col; i < (ti->col + ti->colspan); i++) ww += cols[i];
582 for (i = 0; i < ti->row; i++) yy += rows[i];
584 for (i = ti->row; i < (ti->row + ti->rowspan); i++) hh += rows[i];
587 if (ti->fill_w) ow = ww;
588 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
590 if (ti->fill_h) oh = hh;
591 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
592 evas_object_move(obj,
593 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
594 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
595 evas_object_resize(obj, ow, oh);
607 _e_table_smart_extents_calcuate(E_Smart_Data *sd)
613 sd->max.w = -1; /* max < 0 == unlimited */
622 EINA_LIST_FOREACH(sd->items, l, obj)
627 ti = evas_object_data_get(obj, "e_table_data");
628 if (sd->size.cols < (ti->col + ti->colspan))
629 sd->size.cols = ti->col + ti->colspan;
630 if (sd->size.rows < (ti->row + ti->rowspan))
631 sd->size.rows = ti->row + ti->rowspan;
632 mw = (ti->min.w + (ti->colspan - 1)) / ti->colspan;
633 mh = (ti->min.h + (ti->rowspan - 1)) / ti->rowspan;
634 if (minw < mw) minw = mw;
635 if (minh < mh) minh = mh;
637 minw *= sd->size.cols;
638 minh *= sd->size.rows;
642 int i, ex, tot, need, num, dif, left, nx;
643 EINA_LIST_FOREACH(sd->items, l, obj)
647 ti = evas_object_data_get(obj, "e_table_data");
648 if (sd->size.cols < (ti->col + ti->colspan))
649 sd->size.cols = ti->col + ti->colspan;
650 if (sd->size.rows < (ti->row + ti->rowspan))
651 sd->size.rows = ti->row + ti->rowspan;
653 if ((sd->size.cols > 0) && (sd->size.rows > 0))
655 int *cols, *rows, *colsx, *rowsx;
657 cols = calloc(sd->size.cols, sizeof(int));
658 rows = calloc(sd->size.rows, sizeof(int));
659 colsx = calloc(sd->size.cols, sizeof(int));
660 rowsx = calloc(sd->size.rows, sizeof(int));
662 EINA_LIST_FOREACH(sd->items, l, obj)
666 ti = evas_object_data_get(obj, "e_table_data");
667 for (i = ti->col; i < (ti->col + ti->colspan); i++)
668 colsx[i] |= ti->expand_w;
669 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
670 rowsx[i] |= ti->expand_h;
673 EINA_LIST_FOREACH(sd->items, l, obj)
677 ti = evas_object_data_get(obj, "e_table_data");
679 /* handle horizontal */
683 for (i = ti->col; i < (ti->col + num); i++)
696 for (i = ti->col; i < (ti->col + num); i++)
700 cols[i] += dif / num;
714 for (i = ti->col; i < (ti->col + num); i++)
734 /* handle vertical */
738 for (i = ti->row; i < (ti->row + num); i++)
751 for (i = ti->row; i < (ti->row + num); i++)
755 rows[i] += dif / num;
769 for (i = ti->row; i < (ti->row + num); i++)
789 for (i = 0; i < sd->size.cols; i++) minw += cols[i];
790 for (i = 0; i < sd->size.rows; i++) minh += rows[i];
802 _e_table_smart_init(void)
804 if (_e_smart) return;
806 static const Evas_Smart_Class sc =
809 EVAS_SMART_CLASS_VERSION,
813 _e_table_smart_resize,
816 _e_table_smart_color_set,
817 _e_table_smart_clip_set,
818 _e_table_smart_clip_unset,
827 _e_smart = evas_smart_class_new(&sc);
832 _e_table_smart_add(Evas_Object *obj)
836 sd = calloc(1, sizeof(E_Smart_Data));
843 sd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
844 evas_object_smart_member_add(sd->clip, obj);
845 evas_object_move(sd->clip, -100002, -100002);
846 evas_object_resize(sd->clip, 200004, 200004);
847 evas_object_color_set(sd->clip, 255, 255, 255, 255);
848 evas_object_smart_data_set(obj, sd);
852 _e_table_smart_del(Evas_Object *obj)
856 sd = evas_object_smart_data_get(obj);
863 child = eina_list_data_get(sd->items);
864 e_table_unpack(child);
867 evas_object_del(sd->clip);
872 _e_table_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
876 sd = evas_object_smart_data_get(obj);
878 if ((x == sd->x) && (y == sd->y)) return;
879 if ((x == sd->x) && (y == sd->y)) return;
887 EINA_LIST_FOREACH(sd->items, l, item)
891 evas_object_geometry_get(item, &ox, &oy, NULL, NULL);
892 evas_object_move(item, ox + dx, oy + dy);
900 _e_table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
904 sd = evas_object_smart_data_get(obj);
906 if ((w == sd->w) && (h == sd->h)) return;
910 _e_table_smart_reconfigure(sd);
914 _e_table_smart_show(Evas_Object *obj)
918 sd = evas_object_smart_data_get(obj);
920 if (sd->items) evas_object_show(sd->clip);
924 _e_table_smart_hide(Evas_Object *obj)
928 sd = evas_object_smart_data_get(obj);
930 evas_object_hide(sd->clip);
934 _e_table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
938 sd = evas_object_smart_data_get(obj);
940 evas_object_color_set(sd->clip, r, g, b, a);
944 _e_table_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
948 sd = evas_object_smart_data_get(obj);
950 evas_object_clip_set(sd->clip, clip);
954 _e_table_smart_clip_unset(Evas_Object *obj)
958 sd = evas_object_smart_data_get(obj);
960 evas_object_clip_unset(sd->clip);