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;
32 int col, row, colspan, rowspan;
33 unsigned char fill_w : 1;
34 unsigned char fill_h : 1;
35 unsigned char expand_w : 1;
36 unsigned char expand_h : 1;
48 /* local subsystem functions */
49 static E_Table_Item *_e_table_smart_adopt(E_Smart_Data *sd, Evas_Object *obj);
50 static void _e_table_smart_disown(Evas_Object *obj);
51 static void _e_table_smart_item_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
52 static void _e_table_smart_reconfigure(E_Smart_Data *sd);
53 static void _e_table_smart_extents_calcuate(E_Smart_Data *sd);
55 static void _e_table_smart_init(void);
56 static void _e_table_smart_add(Evas_Object *obj);
57 static void _e_table_smart_del(Evas_Object *obj);
58 static void _e_table_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
59 static void _e_table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
60 static void _e_table_smart_show(Evas_Object *obj);
61 static void _e_table_smart_hide(Evas_Object *obj);
62 static void _e_table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
63 static void _e_table_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
64 static void _e_table_smart_clip_unset(Evas_Object *obj);
66 /* local subsystem globals */
67 static Evas_Smart *_e_smart = NULL;
69 /* externally accessible functions */
71 e_table_add(Evas *evas)
73 _e_table_smart_init();
74 return evas_object_smart_add(evas, _e_smart);
78 e_table_freeze(Evas_Object *obj)
82 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
83 sd = evas_object_smart_data_get(obj);
89 e_table_thaw(Evas_Object *obj)
93 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
94 sd = evas_object_smart_data_get(obj);
96 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
101 e_table_homogenous_set(Evas_Object *obj, int homogenous)
105 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
106 sd = evas_object_smart_data_get(obj);
107 if (sd->homogenous == homogenous) return;
108 sd->homogenous = homogenous;
110 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
114 e_table_pack(Evas_Object *obj, Evas_Object *child, int col, int row, int colspan, int rowspan)
119 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
120 sd = evas_object_smart_data_get(obj);
121 _e_table_smart_adopt(sd, child);
122 sd->items = eina_list_append(sd->items, child);
123 ti = evas_object_data_get(child, "e_table_data");
128 ti->colspan = colspan;
129 ti->rowspan = rowspan;
130 if (sd->size.cols < (col + colspan)) sd->size.cols = col + colspan;
131 if (sd->size.rows < (row + rowspan)) sd->size.rows = row + rowspan;
134 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
138 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)
142 ti = evas_object_data_get(obj, "e_table_data");
146 ti->expand_w = expand_w;
147 ti->expand_h = expand_h;
148 ti->align.x = align_x;
149 ti->align.y = align_y;
155 if (ti->sd->frozen <= 0) _e_table_smart_reconfigure(ti->sd);
159 e_table_unpack(Evas_Object *obj)
164 ti = evas_object_data_get(obj, "e_table_data");
167 sd->items = eina_list_remove(sd->items, obj);
168 _e_table_smart_disown(obj);
170 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
174 e_table_col_row_size_get(Evas_Object *obj, int *cols, int *rows)
178 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
179 sd = evas_object_smart_data_get(obj);
180 if (sd->changed) _e_table_smart_extents_calcuate(sd);
181 if (cols) *cols = sd->size.cols;
182 if (rows) *rows = sd->size.rows;
186 e_table_size_min_get(Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh)
190 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
191 sd = evas_object_smart_data_get(obj);
192 if (sd->changed) _e_table_smart_extents_calcuate(sd);
193 if (minw) *minw = sd->min.w;
194 if (minh) *minh = sd->min.h;
198 e_table_size_max_get(Evas_Object *obj, Evas_Coord *maxw, Evas_Coord *maxh)
202 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
203 sd = evas_object_smart_data_get(obj);
204 if (sd->changed) _e_table_smart_extents_calcuate(sd);
205 if (maxw) *maxw = sd->max.w;
206 if (maxh) *maxh = sd->max.h;
210 e_table_align_get(Evas_Object *obj, double *ax, double *ay)
214 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
215 sd = evas_object_smart_data_get(obj);
216 if (ax) *ax = sd->align.x;
217 if (ay) *ay = sd->align.y;
221 e_table_align_set(Evas_Object *obj, double ax, double ay)
225 if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
226 sd = evas_object_smart_data_get(obj);
227 if ((sd->align.x == ax) && (sd->align.y == ay)) return;
231 if (sd->frozen <= 0) _e_table_smart_reconfigure(sd);
234 /* local subsystem functions */
235 static E_Table_Item *
236 _e_table_smart_adopt(E_Smart_Data *sd, Evas_Object *obj)
240 ti = calloc(1, sizeof(E_Table_Item));
241 if (!ti) return NULL;
259 evas_object_clip_set(obj, sd->clip);
260 // evas_object_stack_above(obj, sd->obj);
261 evas_object_smart_member_add(obj, ti->sd->obj);
262 evas_object_data_set(obj, "e_table_data", ti);
263 evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
264 _e_table_smart_item_del_hook, NULL);
265 // evas_object_stack_below(obj, sd->obj);
266 if ((!evas_object_visible_get(sd->clip)) &&
267 (evas_object_visible_get(sd->obj)))
268 evas_object_show(sd->clip);
273 _e_table_smart_disown(Evas_Object *obj)
277 ti = evas_object_data_get(obj, "e_table_data");
281 if (evas_object_visible_get(ti->sd->clip))
282 evas_object_hide(ti->sd->clip);
284 evas_object_event_callback_del(obj,
286 _e_table_smart_item_del_hook);
287 evas_object_smart_member_del(obj);
288 evas_object_data_del(obj, "e_table_data");
293 _e_table_smart_item_del_hook(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
299 _e_table_smart_reconfigure(E_Smart_Data *sd)
301 Evas_Coord x, y, w, h, xx, yy;
304 int minw, minh, expandw, expandh;
306 if (!sd->changed) return;
311 _e_table_smart_extents_calcuate(sd);
317 if (w < minw) w = minw;
318 if (h < minh) h = minh;
319 EINA_LIST_FOREACH(sd->items, l, obj)
323 ti = evas_object_data_get(obj, "e_table_data");
324 if (ti->expand_w) expandw++;
325 if (ti->expand_h) expandh++;
339 EINA_LIST_FOREACH(sd->items, l, obj)
342 Evas_Coord ww, hh, ow, oh;
344 ti = evas_object_data_get(obj, "e_table_data");
346 xx = x + ((ti->col) * (w / (Evas_Coord)sd->size.cols));
347 yy = y + ((ti->row) * (h / (Evas_Coord)sd->size.rows));
348 ww = ((w / (Evas_Coord)sd->size.cols) * (ti->colspan));
349 hh = ((h / (Evas_Coord)sd->size.rows) * (ti->rowspan));
351 if (ti->expand_w) ow = ww;
352 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
354 if (ti->expand_h) oh = hh;
355 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
356 evas_object_move(obj,
357 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
358 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
359 evas_object_resize(obj, ow, oh);
364 int i, ex, tot, need, num, dif, left, nx;
365 EINA_LIST_FOREACH(sd->items, l, obj)
369 ti = evas_object_data_get(obj, "e_table_data");
370 if (sd->size.cols < (ti->col + ti->colspan))
371 sd->size.cols = ti->col + ti->colspan;
372 if (sd->size.rows < (ti->row + ti->rowspan))
373 sd->size.rows = ti->row + ti->rowspan;
375 if ((sd->size.cols > 0) && (sd->size.rows > 0))
377 int *cols, *rows, *colsx, *rowsx;
379 cols = calloc(sd->size.cols, sizeof(int));
380 rows = calloc(sd->size.rows, sizeof(int));
381 colsx = calloc(sd->size.cols, sizeof(int));
382 rowsx = calloc(sd->size.rows, sizeof(int));
384 EINA_LIST_FOREACH(sd->items, l, obj)
388 ti = evas_object_data_get(obj, "e_table_data");
389 for (i = ti->col; i < (ti->col + ti->colspan); i++)
390 colsx[i] |= ti->expand_w;
391 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
392 rowsx[i] |= ti->expand_h;
395 EINA_LIST_FOREACH(sd->items, l, obj)
399 ti = evas_object_data_get(obj, "e_table_data");
401 /* handle horizontal */
405 for (i = ti->col; i < (ti->col + num); i++)
418 for (i = ti->col; i < (ti->col + num); i++)
422 cols[i] += dif / num;
436 for (i = ti->col; i < (ti->col + num); i++)
456 /* handle vertical */
460 for (i = ti->row; i < (ti->row + num); i++)
473 for (i = ti->row; i < (ti->row + num); i++)
477 rows[i] += dif / num;
491 for (i = ti->row; i < (ti->row + num); i++)
513 for (i = 0; i < sd->size.cols; i++) {
518 for (i = 0; i < sd->size.cols; i++)
521 if ((ex > 0) && (dif > 0))
527 for (i = 0; i < sd->size.cols; i++)
548 for (i = 0; i < sd->size.rows; i++) {
553 for (i = 0; i < sd->size.rows; i++)
556 if ((ex > 0) && (dif > 0))
562 for (i = 0; i < sd->size.rows; i++)
582 EINA_LIST_FOREACH(sd->items, l, obj)
585 Evas_Coord ww, hh, ow, oh, idx;
587 ti = evas_object_data_get(obj, "e_table_data");
590 for (idx = 0; idx < ti->col; idx++)
593 for (idx = ti->col; idx < (ti->col + ti->colspan); idx++)
596 for (idx = 0; idx < ti->row; idx++)
599 for (idx = ti->row; idx < (ti->row + ti->rowspan); idx++)
603 if (ti->fill_w) ow = ww;
604 if ((ti->max.w >= 0) && (ti->max.w < ow)) ow = ti->max.w;
606 if (ti->fill_h) oh = hh;
607 if ((ti->max.h >= 0) && (ti->max.h < oh)) oh = ti->max.h;
608 evas_object_move(obj,
609 xx + (Evas_Coord)(((double)(ww - ow)) * ti->align.x),
610 yy + (Evas_Coord)(((double)(hh - oh)) * ti->align.y));
611 evas_object_resize(obj, ow, oh);
623 _e_table_smart_extents_calcuate(E_Smart_Data *sd)
629 sd->max.w = -1; /* max < 0 == unlimited */
638 EINA_LIST_FOREACH(sd->items, l, obj)
643 ti = evas_object_data_get(obj, "e_table_data");
644 if (sd->size.cols < (ti->col + ti->colspan))
645 sd->size.cols = ti->col + ti->colspan;
646 if (sd->size.rows < (ti->row + ti->rowspan))
647 sd->size.rows = ti->row + ti->rowspan;
648 mw = (ti->min.w + (ti->colspan - 1)) / ti->colspan;
649 mh = (ti->min.h + (ti->rowspan - 1)) / ti->rowspan;
650 if (minw < mw) minw = mw;
651 if (minh < mh) minh = mh;
653 minw *= sd->size.cols;
654 minh *= sd->size.rows;
658 int i, ex, tot, need, num, dif, left, nx;
659 EINA_LIST_FOREACH(sd->items, l, obj)
663 ti = evas_object_data_get(obj, "e_table_data");
664 if (sd->size.cols < (ti->col + ti->colspan))
665 sd->size.cols = ti->col + ti->colspan;
666 if (sd->size.rows < (ti->row + ti->rowspan))
667 sd->size.rows = ti->row + ti->rowspan;
669 if ((sd->size.cols > 0) && (sd->size.rows > 0))
671 int *cols, *rows, *colsx, *rowsx;
673 cols = calloc(sd->size.cols, sizeof(int));
674 rows = calloc(sd->size.rows, sizeof(int));
675 colsx = calloc(sd->size.cols, sizeof(int));
676 rowsx = calloc(sd->size.rows, sizeof(int));
678 EINA_LIST_FOREACH(sd->items, l, obj)
682 ti = evas_object_data_get(obj, "e_table_data");
683 for (i = ti->col; i < (ti->col + ti->colspan); i++)
684 colsx[i] |= ti->expand_w;
685 for (i = ti->row; i < (ti->row + ti->rowspan); i++)
686 rowsx[i] |= ti->expand_h;
689 EINA_LIST_FOREACH(sd->items, l, obj)
693 ti = evas_object_data_get(obj, "e_table_data");
695 /* handle horizontal */
699 for (i = ti->col; i < (ti->col + num); i++)
712 for (i = ti->col; i < (ti->col + num); i++)
716 cols[i] += dif / num;
730 for (i = ti->col; i < (ti->col + num); i++)
750 /* handle vertical */
754 for (i = ti->row; i < (ti->row + num); i++)
767 for (i = ti->row; i < (ti->row + num); i++)
771 rows[i] += dif / num;
785 for (i = ti->row; i < (ti->row + num); i++)
805 for (i = 0; i < sd->size.cols; i++)
807 for (i = 0; i < sd->size.rows; i++)
820 _e_table_smart_init(void)
822 if (_e_smart) return;
824 static const Evas_Smart_Class sc =
827 EVAS_SMART_CLASS_VERSION,
831 _e_table_smart_resize,
834 _e_table_smart_color_set,
835 _e_table_smart_clip_set,
836 _e_table_smart_clip_unset,
845 _e_smart = evas_smart_class_new(&sc);
850 _e_table_smart_add(Evas_Object *obj)
854 sd = calloc(1, sizeof(E_Smart_Data));
861 sd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
862 evas_object_smart_member_add(sd->clip, obj);
863 evas_object_move(sd->clip, -100002, -100002);
864 evas_object_resize(sd->clip, 200004, 200004);
865 evas_object_color_set(sd->clip, 255, 255, 255, 255);
866 evas_object_smart_data_set(obj, sd);
870 _e_table_smart_del(Evas_Object *obj)
874 sd = evas_object_smart_data_get(obj);
881 child = eina_list_data_get(sd->items);
882 e_table_unpack(child);
885 evas_object_del(sd->clip);
890 _e_table_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
894 sd = evas_object_smart_data_get(obj);
896 if ((x == sd->x) && (y == sd->y)) return;
897 if ((x == sd->x) && (y == sd->y)) return;
905 EINA_LIST_FOREACH(sd->items, l, item)
909 evas_object_geometry_get(item, &ox, &oy, NULL, NULL);
910 evas_object_move(item, ox + dx, oy + dy);
918 _e_table_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
922 sd = evas_object_smart_data_get(obj);
924 if ((w == sd->w) && (h == sd->h)) return;
928 _e_table_smart_reconfigure(sd);
932 _e_table_smart_show(Evas_Object *obj)
936 sd = evas_object_smart_data_get(obj);
938 if (sd->items) evas_object_show(sd->clip);
942 _e_table_smart_hide(Evas_Object *obj)
946 sd = evas_object_smart_data_get(obj);
948 evas_object_hide(sd->clip);
952 _e_table_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
956 sd = evas_object_smart_data_get(obj);
958 evas_object_color_set(sd->clip, r, g, b, a);
962 _e_table_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
966 sd = evas_object_smart_data_get(obj);
968 evas_object_clip_set(sd->clip, clip);
972 _e_table_smart_clip_unset(Evas_Object *obj)
976 sd = evas_object_smart_data_get(obj);
978 evas_object_clip_unset(sd->clip);