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;
297 _e_table_smart_extents_calcuate(sd);
303 if (w < minw) w = minw;
304 if (h < minh) h = minh;
305 EINA_LIST_FOREACH(sd->items, l, obj)
309 ti = evas_object_data_get(obj, "e_table_data");
310 if (ti->expand_w) expandw++;
311 if (ti->expand_h) expandh++;
325 EINA_LIST_FOREACH(sd->items, l, obj)
328 Evas_Coord ww, hh, ow, oh;
330 ti = evas_object_data_get(obj, "e_table_data");
332 xx = x + ((ti->col) * (w / (Evas_Coord)sd->size.cols));
333 yy = y + ((ti->row) * (h / (Evas_Coord)sd->size.rows));
334 ww = ((w / (Evas_Coord)sd->size.cols) * (ti->colspan));
335 hh = ((h / (Evas_Coord)sd->size.rows) * (ti->rowspan));
337 if (ti->expand_w) ow = ww;
338 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
340 if (ti->expand_h) oh = hh;
341 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
342 evas_object_move(obj,
343 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
344 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
345 evas_object_resize(obj, ow, oh);
350 int i, ex, tot, need, num, dif, left, nx;
351 EINA_LIST_FOREACH(sd->items, l, obj)
355 ti = evas_object_data_get(obj, "e_table_data");
356 if (sd->size.cols < (ti->col + ti->colspan))
357 sd->size.cols = ti->col + ti->colspan;
358 if (sd->size.rows < (ti->row + ti->rowspan))
359 sd->size.rows = ti->row + ti->rowspan;
361 if ((sd->size.cols > 0) && (sd->size.rows > 0))
363 int *cols, *rows, *colsx, *rowsx;
365 cols = calloc(sd->size.cols, sizeof(int));
366 rows = calloc(sd->size.rows, sizeof(int));
367 colsx = calloc(sd->size.cols, sizeof(int));
368 rowsx = calloc(sd->size.rows, sizeof(int));
370 EINA_LIST_FOREACH(sd->items, l, obj)
374 ti = evas_object_data_get(obj, "e_table_data");
375 for (i = ti->col; i < (ti->col + ti->colspan); i++)
376 colsx[i] |= ti->expand_w;
377 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
378 rowsx[i] |= ti->expand_h;
381 EINA_LIST_FOREACH(sd->items, l, obj)
385 ti = evas_object_data_get(obj, "e_table_data");
387 /* handle horizontal */
391 for (i = ti->col; i < (ti->col + num); i++)
404 for (i = ti->col; i < (ti->col + num); i++)
408 cols[i] += dif / num;
422 for (i = ti->col; i < (ti->col + num); i++)
442 /* handle vertical */
446 for (i = ti->row; i < (ti->row + num); i++)
459 for (i = ti->row; i < (ti->row + num); i++)
463 rows[i] += dif / num;
477 for (i = ti->row; i < (ti->row + num); i++)
499 for (i = 0; i < sd->size.cols; i++) { if (colsx[i]) ex++; }
501 for (i = 0; i < sd->size.cols; i++) tot += cols[i];
503 if ((ex > 0) && (dif > 0))
509 for (i = 0; i < sd->size.cols; i++)
530 for (i = 0; i < sd->size.rows; i++) { if (rowsx[i]) ex++; }
532 for (i = 0; i < sd->size.rows; i++) tot += rows[i];
534 if ((ex > 0) && (dif > 0))
540 for (i = 0; i < sd->size.rows; i++)
560 EINA_LIST_FOREACH(sd->items, l, obj)
563 Evas_Coord ww, hh, ow, oh, i;
565 ti = evas_object_data_get(obj, "e_table_data");
568 for (i = 0; i < ti->col; i++) xx += cols[i];
570 for (i = ti->col; i < (ti->col + ti->colspan); i++) ww += cols[i];
572 for (i = 0; i < ti->row; i++) yy += rows[i];
574 for (i = ti->row; i < (ti->row + ti->rowspan); i++) hh += rows[i];
577 if (ti->fill_w) ow = ww;
578 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
580 if (ti->fill_h) oh = hh;
581 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
582 evas_object_move(obj,
583 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
584 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
585 evas_object_resize(obj, ow, oh);
597 _e_table_smart_extents_calcuate(E_Smart_Data *sd)
603 sd->max.w = -1; /* max < 0 == unlimited */
612 EINA_LIST_FOREACH(sd->items, l, obj)
617 ti = evas_object_data_get(obj, "e_table_data");
618 if (sd->size.cols < (ti->col + ti->colspan))
619 sd->size.cols = ti->col + ti->colspan;
620 if (sd->size.rows < (ti->row + ti->rowspan))
621 sd->size.rows = ti->row + ti->rowspan;
622 mw = (ti->min.w + (ti->colspan - 1)) / ti->colspan;
623 mh = (ti->min.h + (ti->rowspan - 1)) / ti->rowspan;
624 if (minw < mw) minw = mw;
625 if (minh < mh) minh = mh;
627 minw *= sd->size.cols;
628 minh *= sd->size.rows;
632 int i, ex, tot, need, num, dif, left, nx;
633 EINA_LIST_FOREACH(sd->items, l, obj)
637 ti = evas_object_data_get(obj, "e_table_data");
638 if (sd->size.cols < (ti->col + ti->colspan))
639 sd->size.cols = ti->col + ti->colspan;
640 if (sd->size.rows < (ti->row + ti->rowspan))
641 sd->size.rows = ti->row + ti->rowspan;
643 if ((sd->size.cols > 0) && (sd->size.rows > 0))
645 int *cols, *rows, *colsx, *rowsx;
647 cols = calloc(sd->size.cols, sizeof(int));
648 rows = calloc(sd->size.rows, sizeof(int));
649 colsx = calloc(sd->size.cols, sizeof(int));
650 rowsx = calloc(sd->size.rows, sizeof(int));
652 EINA_LIST_FOREACH(sd->items, l, obj)
656 ti = evas_object_data_get(obj, "e_table_data");
657 for (i = ti->col; i < (ti->col + ti->colspan); i++)
658 colsx[i] |= ti->expand_w;
659 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
660 rowsx[i] |= ti->expand_h;
663 EINA_LIST_FOREACH(sd->items, l, obj)
667 ti = evas_object_data_get(obj, "e_table_data");
669 /* handle horizontal */
673 for (i = ti->col; i < (ti->col + num); i++)
686 for (i = ti->col; i < (ti->col + num); i++)
690 cols[i] += dif / num;
704 for (i = ti->col; i < (ti->col + num); i++)
724 /* handle vertical */
728 for (i = ti->row; i < (ti->row + num); i++)
741 for (i = ti->row; i < (ti->row + num); i++)
745 rows[i] += dif / num;
759 for (i = ti->row; i < (ti->row + num); i++)
779 for (i = 0; i < sd->size.cols; i++) minw += cols[i];
780 for (i = 0; i < sd->size.rows; i++) minh += rows[i];
792 _e_table_smart_init(void)
794 if (_e_smart) return;
796 static const Evas_Smart_Class sc =
799 EVAS_SMART_CLASS_VERSION,
803 _e_table_smart_resize,
806 _e_table_smart_color_set,
807 _e_table_smart_clip_set,
808 _e_table_smart_clip_unset,
817 _e_smart = evas_smart_class_new(&sc);
822 _e_table_smart_add(Evas_Object *obj)
826 sd = calloc(1, sizeof(E_Smart_Data));
833 sd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
834 evas_object_smart_member_add(sd->clip, obj);
835 evas_object_move(sd->clip, -100002, -100002);
836 evas_object_resize(sd->clip, 200004, 200004);
837 evas_object_color_set(sd->clip, 255, 255, 255, 255);
838 evas_object_smart_data_set(obj, sd);
842 _e_table_smart_del(Evas_Object *obj)
846 sd = evas_object_smart_data_get(obj);
853 child = eina_list_data_get(sd->items);
854 e_table_unpack(child);
857 evas_object_del(sd->clip);
862 _e_table_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
866 sd = evas_object_smart_data_get(obj);
868 if ((x == sd->x) && (y == sd->y)) return;
869 if ((x == sd->x) && (y == sd->y)) return;
877 EINA_LIST_FOREACH(sd->items, l, item)
881 evas_object_geometry_get(item, &ox, &oy, NULL, NULL);
882 evas_object_move(item, ox + dx, oy + dy);
890 _e_table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
894 sd = evas_object_smart_data_get(obj);
896 if ((w == sd->w) && (h == sd->h)) return;
900 _e_table_smart_reconfigure(sd);
904 _e_table_smart_show(Evas_Object *obj)
908 sd = evas_object_smart_data_get(obj);
910 if (sd->items) evas_object_show(sd->clip);
914 _e_table_smart_hide(Evas_Object *obj)
918 sd = evas_object_smart_data_get(obj);
920 evas_object_hide(sd->clip);
924 _e_table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
928 sd = evas_object_smart_data_get(obj);
930 evas_object_color_set(sd->clip, r, g, b, a);
934 _e_table_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
938 sd = evas_object_smart_data_get(obj);
940 evas_object_clip_set(sd->clip, clip);
944 _e_table_smart_clip_unset(Evas_Object *obj)
948 sd = evas_object_smart_data_get(obj);
950 evas_object_clip_unset(sd->clip);