aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/efl_ui_table.c
blob: fd7ee11e4c17ad47bae74b4fdaf4a60f1a04418d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
#include "efl_ui_table_private.h"

#define MY_CLASS EFL_UI_TABLE_CLASS
#define MY_CLASS_NAME "Efl.Ui.Table"

#define EFL_UI_TABLE_DATA_GET(o, pd) \
   Efl_Ui_Table_Data *pd = efl_data_scope_get(o, EFL_UI_TABLE_CLASS)

inline static Table_Item *
_efl_ui_table_item_date_get(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj)
{
   Table_Item *gi;
   if (!efl_invalidated_get(subobj) &&
       (obj != efl_canvas_object_render_parent_get(subobj)))
     {
        ERR("%p is not a child of %p", subobj, obj);
        return NULL;
     }
   gi = efl_key_data_get(subobj, TABLE_ITEM_KEY);
   if (!gi)
     {
        WRN("item %p has no table internal data", subobj);
        EINA_INLIST_FOREACH(EINA_INLIST_GET(pd->items), gi)
          {
             if (gi->object == subobj)
               break;
          }
        if (!gi)
          {
             ERR("item %p was not found in this table", subobj);
             return NULL;
          }
     }
   return gi;
}

static void
_on_child_size_changed(void *data, const Efl_Event *event EINA_UNUSED)
{
   Eo *table = data;
   efl_pack_layout_request(table);
}

static void
_on_child_hints_changed(void *data, const Efl_Event *event EINA_UNUSED)
{
   Eo *table = data;
   efl_pack_layout_request(table);
}

static void
_on_child_del(void *data, const Efl_Event *event)
{
   Eo *table = data;
   Table_Item *gi;
   EFL_UI_TABLE_DATA_GET(table, pd);

   gi = _efl_ui_table_item_date_get(table, pd, event->object);
   if (!gi) return;

   pd->items = (Table_Item *)
         eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
   free(gi);

   pd->count--;
   efl_key_data_set(event->object, TABLE_ITEM_KEY, NULL);

   efl_pack_layout_request(table);
}

EFL_CALLBACKS_ARRAY_DEFINE(efl_ui_table_callbacks,
  { EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _on_child_size_changed },
  { EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _on_child_hints_changed },
  { EFL_EVENT_DEL, _on_child_del }
);

static void
_efl_ui_table_last_position_get(Eo * obj, Efl_Ui_Table_Data *pd, int *last_col, int *last_row)
{
   Table_Item *gi;
   int col = -1, row  = -1;
   int req_cols, req_rows;

   if (!pd->linear_recalc)
     {
        *last_col = pd->last_col;
        *last_row = pd->last_row;
        return;
     }

   efl_pack_table_size_get(obj, &req_cols, &req_rows);

   if (efl_ui_layout_orientation_is_horizontal(pd->fill_dir, EINA_TRUE))
     {
        EINA_INLIST_REVERSE_FOREACH(EINA_INLIST_GET(pd->items), gi)
          {
             if ((gi->row < row) || (req_cols < gi->col) || (req_rows < gi->row))
               continue;

             if (gi->row > row)
               {
                  row = gi->row;
                  col = gi->col;
               }
             else if (gi->col > col)
               {
                  col = gi->col;
               }
          }
     }
   else
     {
        EINA_INLIST_REVERSE_FOREACH(EINA_INLIST_GET(pd->items), gi)
          {
             if ((gi->col < col) || (req_cols < gi->col) || (req_rows < gi->row))
               continue;

             if (gi->col > col)
               {
                  col = gi->col;
                  row = gi->row;
               }
             else if (gi->row > row)
               {
                  row = gi->row;
               }
          }
     }
   *last_col = col;
   *last_row = row;
   pd->linear_recalc = EINA_FALSE;
}

static void
_efl_ui_table_size_hints_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
   efl_pack_layout_request(ev->object);
}

EOLIAN static void
_efl_ui_table_homogeneous_set(Eo *obj, Efl_Ui_Table_Data *pd, Eina_Bool homogeneoush, Eina_Bool homogeneousv)
{
   homogeneoush = !!homogeneoush;
   homogeneousv = !!homogeneousv;

   if ((pd->homogeneoush == homogeneoush) && (pd->homogeneousv == homogeneousv))
     return;

   pd->homogeneoush = homogeneoush;
   pd->homogeneousv = homogeneousv;
   efl_pack_layout_request(obj);
}

EOLIAN static void
_efl_ui_table_homogeneous_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, Eina_Bool *homogeneoush, Eina_Bool *homogeneousv)
{
   if (homogeneoush) *homogeneoush = pd->homogeneoush;
   if (homogeneousv) *homogeneousv = pd->homogeneousv;
}

EOLIAN static void
_efl_ui_table_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Table_Data *pd)
{
   _efl_ui_table_custom_layout(obj, pd);
}

EOLIAN void
_efl_ui_table_efl_canvas_group_group_calculate(Eo *obj, Efl_Ui_Table_Data *_pd EINA_UNUSED)
{
   efl_pack_layout_update(obj);
}

EOLIAN static void
_efl_ui_table_efl_gfx_entity_size_set(Eo *obj, Efl_Ui_Table_Data *_pd EINA_UNUSED, Eina_Size2D sz)
{
   efl_gfx_entity_size_set(efl_super(obj, MY_CLASS), sz);
   efl_canvas_group_change(obj);
}

EOLIAN static void
_efl_ui_table_efl_gfx_entity_position_set(Eo *obj, Efl_Ui_Table_Data *_pd EINA_UNUSED, Eina_Position2D pos)
{
   efl_gfx_entity_position_set(efl_super(obj, MY_CLASS), pos);
   efl_canvas_group_change(obj);
}

EOLIAN static void
_efl_ui_table_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Table_Data *pd)
{
   pd->clipper = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj);
   evas_object_static_clip_set(pd->clipper, EINA_TRUE);
   efl_gfx_entity_geometry_set(pd->clipper, EINA_RECT(-49999, -49999, 99999, 99999));
   efl_canvas_group_member_add(obj, pd->clipper);
   efl_ui_widget_sub_object_add(obj, pd->clipper);

   efl_canvas_group_add(efl_super(obj, MY_CLASS));
   elm_widget_sub_object_parent_add(obj);

   efl_ui_widget_focus_allow_set(obj, EINA_FALSE);
   elm_widget_highlight_ignore_set(obj, EINA_FALSE);

   efl_event_callback_add(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED,
                          _efl_ui_table_size_hints_changed_cb, NULL);
}

EOLIAN static void
_efl_ui_table_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Table_Data *_pd EINA_UNUSED)
{
   efl_event_callback_del(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED,
                          _efl_ui_table_size_hints_changed_cb, NULL);

   efl_canvas_group_del(efl_super(obj, MY_CLASS));
}

EOLIAN static Eo *
_efl_ui_table_efl_object_constructor(Eo *obj, Efl_Ui_Table_Data *pd)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   efl_canvas_object_type_set(obj, MY_CLASS_NAME);
   efl_access_object_access_type_set(obj, EFL_ACCESS_TYPE_SKIPPED);
   efl_access_object_role_set(obj, EFL_ACCESS_ROLE_FILLER);

   pd->fill_dir = EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL;
   pd->last_col = -1;
   pd->last_row = -1;
   pd->req_cols = 0;
   pd->req_rows = 0;
   pd->cols = 0;
   pd->rows = 0;
   pd->align.h = 0.5;
   pd->align.v = 0.5;

   return obj;
}

EOLIAN static void
_efl_ui_table_efl_object_invalidate(Eo *obj, Efl_Ui_Table_Data *pd)
{
   Table_Item *gi;

   efl_invalidate(efl_super(obj, MY_CLASS));

   EINA_INLIST_FREE(EINA_INLIST_GET(pd->items), gi)
     {
        efl_event_callback_array_del(gi->object, efl_ui_table_callbacks(), obj);
     }
}

EOLIAN static void
_efl_ui_table_efl_gfx_arrangement_content_padding_set(Eo *obj, Efl_Ui_Table_Data *pd, double h, double v, Eina_Bool scalable)
{
   scalable = !!scalable;
   if (h < 0) h = 0;
   if (v < 0) v = 0;

   if (EINA_DBL_EQ(pd->pad.h, h) && EINA_DBL_EQ(pd->pad.v, v) &&
       (pd->pad.scalable == scalable))
     return;

   pd->pad.h = h;
   pd->pad.v = v;
   pd->pad.scalable = scalable;

   efl_pack_layout_request(obj);
}

EOLIAN static void
_efl_ui_table_efl_gfx_arrangement_content_padding_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, double *h, double *v, Eina_Bool *scalable)
{
   if (scalable) *scalable = pd->pad.scalable;
   if (h) *h = pd->pad.h;
   if (v) *v = pd->pad.v;
}

EOLIAN static void
_efl_ui_table_efl_gfx_arrangement_content_align_set(Eo *obj, Efl_Ui_Table_Data *pd, double h, double v)
{
   if (h < 0) h = -1;
   else if (h > 1) h = 1;
   if (v < 0) v = -1;
   else if (v > 1) v = 1;

   if (EINA_DBL_EQ(pd->align.h, h) && EINA_DBL_EQ(pd->align.v, v))
     return;

   pd->align.h = h;
   pd->align.v = v;

   efl_pack_layout_request(obj);
}

EOLIAN static void
_efl_ui_table_efl_gfx_arrangement_content_align_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, double *h, double *v)
{
   if (h) *h = pd->align.h;
   if (v) *v = pd->align.v;
}

static Eina_Bool
_pack_at(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj, int col, int row, int colspan, int rowspan)
{
   Table_Item *gi;

   if (efl_key_data_get(subobj, TABLE_ITEM_KEY))
     {
        if (efl_canvas_object_render_parent_get(subobj) == obj)
          ERR("subobj %p %s is already added to this", subobj, efl_class_name_get(subobj));
        else
          ERR("subobj %p %s currently belongs to different table", subobj, efl_class_name_get(subobj));

        return EINA_FALSE;
     }

   if (col < 0) col = 0;
   if (row < 0) row = 0;

   // note: we could have colspan = -1 mean "full width" if req_cols is set?
   if (colspan < 1) colspan = 1;
   if (rowspan < 1) rowspan = 1;

   if (((int64_t) col + (int64_t) colspan) > (int64_t) INT_MAX)
     colspan = INT_MAX - col;

   if (((int64_t) row + (int64_t) rowspan) > (int64_t) INT_MAX)
     rowspan = INT_MAX - row;

   if ((pd->req_cols && ((col + colspan) > pd->req_cols)) ||
       (pd->req_rows && ((row + rowspan) > pd->req_rows)))
     {
        ERR("table requested size exceeded! packing in extra cell at "
            "%d,%d %dx%d (table: %dx%d)",
            col, row, colspan, rowspan, pd->req_cols, pd->req_rows);
     }

   if (!efl_ui_widget_sub_object_add(obj, subobj))
     return EINA_FALSE;

   gi = calloc(1, sizeof(*gi));
   if (!gi) return EINA_FALSE;
   gi->col = col;
   gi->row = row;
   gi->col_span = colspan;
   gi->row_span = rowspan;
   gi->object = subobj;
   pd->count++;
   pd->items = (Table_Item *)
       eina_inlist_append(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));

   efl_key_data_set(subobj, TABLE_ITEM_KEY, gi);
   efl_key_data_set(subobj, "_elm_leaveme", obj);
   efl_canvas_object_clipper_set(subobj, pd->clipper);
   efl_event_callback_array_add(subobj, efl_ui_table_callbacks(), obj);

   efl_canvas_group_member_add(obj, subobj);
   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_ADDED, subobj);

   if ((gi->col > pd->last_col) || (gi->row > pd->last_row))
     pd->linear_recalc = EINA_TRUE;

   if (pd->cols < gi->col + gi->col_span)
     pd->cols = gi->col + gi->col_span;
   if (pd->rows < gi->row + gi->row_span)
     pd->rows = gi->row + gi->row_span;

   efl_pack_layout_request(obj);

   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_table_pack_table(Eo *obj, Efl_Ui_Table_Data *pd,
                                     Efl_Gfx_Entity *subobj,
                                     int col, int row, int colspan, int rowspan)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(subobj, EINA_FALSE);

   return _pack_at(obj, pd, subobj, col, row, colspan, rowspan);
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_table_table_position_get(const Eo *obj, Efl_Ui_Table_Data *pd, Evas_Object *subobj, int *col, int *row, int *colspan, int *rowspan)
{
   int c = -1, r = -1, cs = 0, rs = 0;
   Table_Item *gi;
   Eina_Bool ret = EINA_FALSE;

   gi = _efl_ui_table_item_date_get((Eo *)obj, pd, subobj);
   if (gi)
     {
        c = gi->col;
        r = gi->row;
        cs = gi->col_span;
        rs = gi->row_span;
        ret = EINA_TRUE;
     }

   if (col) *col = c;
   if (row) *row = r;
   if (colspan) *colspan = cs;
   if (rowspan) *rowspan = rs;
   return ret;
}

EOLIAN static Efl_Gfx_Entity *
_efl_ui_table_efl_pack_table_table_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, int col, int row)
{
   Table_Item *gi;
   EINA_INLIST_FOREACH(EINA_INLIST_GET(pd->items), gi)
     {
        if (gi->col == col && gi->row == row)
          return gi->object;
     }

   return NULL;
}

static Eina_Bool
_item_remove(Efl_Ui_Table *obj, Efl_Ui_Table_Data *pd, Table_Item *gi)
{
   Efl_Gfx_Entity *subobj = gi->object;

   if (!subobj || !_elm_widget_sub_object_redirect_to_top(obj, subobj))
     return EINA_FALSE;

   efl_canvas_object_clipper_set(subobj, NULL);
   efl_key_data_set(subobj, "_elm_leaveme", NULL);
   efl_key_data_set(subobj, TABLE_ITEM_KEY, NULL);
   efl_event_callback_array_del(subobj, efl_ui_table_callbacks(), obj);

   efl_canvas_group_member_remove(obj, subobj);
   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_REMOVED, subobj);

   if ((gi->col == pd->last_col) && (gi->row == pd->last_row))
     pd->linear_recalc = EINA_TRUE;

   if (gi->col + gi->col_span >= pd->cols)
     pd->cols_recalc = EINA_TRUE;
   if (gi->row + gi->row_span >= pd->rows)
     pd->rows_recalc = EINA_TRUE;

   pd->items = (Table_Item *)
         eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
   free(gi);

   pd->count--;
   efl_pack_layout_request(obj);

   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_unpack(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj)
{
   Table_Item *gi = _efl_ui_table_item_date_get(obj, pd, subobj);
   if (!gi) return EINA_FALSE;

   return _item_remove(obj, pd, gi);
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_pack_clear(Eo *obj, Efl_Ui_Table_Data *pd)
{
   Table_Item *gi;

   EINA_INLIST_FREE(EINA_INLIST_GET(pd->items), gi)
     {
        efl_event_callback_array_del(gi->object, efl_ui_table_callbacks(), obj);
        efl_del(gi->object);

        pd->items = (Table_Item *)
            eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
        free(gi);
     }

   pd->linear_recalc = EINA_TRUE;
   pd->cols_recalc = EINA_TRUE;
   pd->rows_recalc = EINA_TRUE;

   pd->last_col = -1;
   pd->last_row = -1;
   pd->cols = 0;
   pd->rows = 0;
   pd->count = 0;
   efl_pack_layout_request(obj);

   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_unpack_all(Eo *obj, Efl_Ui_Table_Data *pd)
{
   Table_Item *gi;
   Eina_Bool ret = EINA_TRUE;

   EINA_INLIST_FREE(EINA_INLIST_GET(pd->items), gi)
     ret &= _item_remove(obj, pd, gi);

   pd->linear_recalc = EINA_TRUE;
   pd->cols_recalc = EINA_TRUE;
   pd->rows_recalc = EINA_TRUE;

   pd->last_col = -1;
   pd->last_row = -1;
   pd->cols = 0;
   pd->rows = 0;

   return ret;
}

EOLIAN static void
_efl_ui_table_efl_pack_layout_layout_request(Eo *obj, Efl_Ui_Table_Data *pd EINA_UNUSED)
{
   efl_canvas_group_need_recalculate_set(obj, EINA_TRUE);
}

static Eina_Bool
_efl_ui_table_item_iterator_next(Table_Item_Iterator *it, void **data)
{
   Table_Item *gi;

   if (!it->cur)
     return EINA_FALSE;

   if (data)
     {
        gi = EINA_INLIST_CONTAINER_GET(it->cur, Table_Item);
        *data = gi->object;
     }

   it->cur = it->cur->next;

   return EINA_TRUE;
}

static Eo *
_efl_ui_table_item_iterator_get_container(Table_Item_Iterator *it)
{
   return it->object;
}

static void
_efl_ui_table_item_iterator_free(Table_Item_Iterator *it)
{
   free(it);
}

static inline Eina_Iterator *
_efl_ui_table_item_iterator_create(Eo *obj, Eina_Inlist *list)
{
   Table_Item_Iterator *it;

   it = calloc(1, sizeof(*it));
   if (!it) return NULL;

   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->object = obj;
   it->cur = list;

   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(_efl_ui_table_item_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
     _efl_ui_table_item_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_efl_ui_table_item_iterator_free);

   return &it->iterator;
}

EOLIAN static Eina_Iterator *
_efl_ui_table_efl_container_content_iterate(Eo *obj, Efl_Ui_Table_Data *pd)
{
   Table_Item_Iterator *it;

   if (!pd->count)
     return NULL;

   it = calloc(1, sizeof(*it));
   if (!it) return NULL;

   EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);

   it->object = obj;
   it->cur = EINA_INLIST_GET(pd->items);

   it->iterator.version = EINA_ITERATOR_VERSION;
   it->iterator.next = FUNC_ITERATOR_NEXT(_efl_ui_table_item_iterator_next);
   it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(
     _efl_ui_table_item_iterator_get_container);
   it->iterator.free = FUNC_ITERATOR_FREE(_efl_ui_table_item_iterator_free);

   return &it->iterator;
}

EOLIAN static int
_efl_ui_table_efl_container_content_count(Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd)
{
   return pd->count;
}

EOLIAN static Eina_Iterator *
_efl_ui_table_efl_pack_table_table_contents_get(Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, int col, int row, Eina_Bool below)
{
   Table_Item *gi;
   Eina_List *atlist = NULL;

   EINA_INLIST_FOREACH(EINA_INLIST_GET(pd->items), gi)
     {
        if ((gi->col == col) && (gi->row == row))
          atlist = eina_list_append(atlist, gi->object);
        else if (below)
          {
             if ((gi->col <= col) && (gi->col + gi->col_span >= col) &&
                 (gi->row <= row) && (gi->row + gi->row_span >= row))
               atlist = eina_list_append(atlist, gi->object);
          }
     }

   return eina_list_iterator_new(atlist);
}

EOLIAN static void
_efl_ui_table_efl_ui_layout_orientable_orientation_set(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Ui_Layout_Orientation dir)
{
   if (pd->fill_dir == dir)
     return;

   if (dir == EFL_UI_LAYOUT_ORIENTATION_DEFAULT)
     dir = EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL;

   pd->fill_dir = dir;

   efl_pack_layout_request(obj);
}

EOLIAN static Efl_Ui_Layout_Orientation
_efl_ui_table_efl_ui_layout_orientable_orientation_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd)
{
   return pd->fill_dir;
}

EOLIAN static void
_efl_ui_table_efl_pack_table_table_size_set(Eo *obj, Efl_Ui_Table_Data *pd, int cols, int rows)
{
   if (cols < 0) cols = 0;
   if (rows < 0) rows = 0;

   if ((pd->req_cols == cols) && (pd->req_rows == rows))
     return;

   pd->req_cols = cols;
   pd->req_rows = rows;
   pd->linear_recalc = EINA_TRUE;

   efl_pack_layout_request(obj);
}

EOLIAN static void
_efl_ui_table_efl_pack_table_table_size_get(const Eo *obj, Efl_Ui_Table_Data *pd EINA_UNUSED, int *cols, int *rows)
{
   if (cols) *cols = efl_pack_table_columns_get(obj);
   if (rows) *rows = efl_pack_table_rows_get(obj);
}

EOLIAN static void
_efl_ui_table_efl_pack_table_table_columns_set(Eo *obj, Efl_Ui_Table_Data *pd, int columns)
{
   if (pd->req_cols == columns)
     return;

   pd->req_cols = columns;
   pd->linear_recalc = EINA_TRUE;

   efl_pack_layout_request(obj);
}

EOLIAN static int
_efl_ui_table_efl_pack_table_table_columns_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd)
{
   Table_Item *gi;
   if (pd->cols_recalc)
     {
        pd->cols = 0;
        EINA_INLIST_REVERSE_FOREACH(EINA_INLIST_GET(pd->items), gi)
          {
             if (pd->cols < gi->col + gi->col_span)
               pd->cols = gi->col+ gi->col_span;
          }
        pd->cols_recalc = EINA_FALSE;
     }
   return pd->req_cols ? : pd->cols;
}

EOLIAN static void
_efl_ui_table_efl_pack_table_table_rows_set(Eo *obj, Efl_Ui_Table_Data *pd, int rows)
{
   if (pd->req_rows == rows)
     return;

   pd->req_rows = rows;
   pd->linear_recalc = EINA_TRUE;

   efl_pack_layout_request(obj);
}

EOLIAN static int
_efl_ui_table_efl_pack_table_table_rows_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd)
{
   Table_Item *gi;
   if (pd->rows_recalc)
     {
        pd->rows = 0;
        EINA_INLIST_REVERSE_FOREACH(EINA_INLIST_GET(pd->items), gi)
          {
             if (pd->rows < gi->row + gi->row_span)
               pd->rows = gi->row + gi->row_span;
          }
        pd->rows_recalc = EINA_FALSE;
     }
   return pd->req_rows ? : pd->rows;
}

EOLIAN static Eina_Bool
_efl_ui_table_efl_pack_pack(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj)
{
   int last_col, last_row;

   EINA_SAFETY_ON_NULL_RETURN_VAL(subobj, EINA_FALSE);

   _efl_ui_table_last_position_get(obj, pd, &last_col, &last_row);

   if (efl_ui_layout_orientation_is_horizontal(pd->fill_dir, EINA_TRUE))
     {
        last_col++;
        if (pd->req_cols && (last_col >= pd->req_cols))
          {
             last_col = 0;
             last_row++;
          }
        if (last_row < 0) last_row = 0;
     }
   else
     {
        last_row++;
        if (pd->req_rows && (last_row >= pd->req_rows))
          {
             last_row = 0;
             last_col++;
          }
        if (last_col < 0) last_col = 0;
     }

   pd->last_col = last_col;
   pd->last_row = last_row;

   DBG("packing new obj at %d,%d", last_col, last_row);
   return _pack_at(obj, pd, subobj, last_col, last_row, 1, 1);
}

/* Internal EO APIs and hidden overrides */

#define EFL_UI_TABLE_EXTRA_OPS \
   EFL_CANVAS_GROUP_ADD_DEL_OPS(efl_ui_table)

#include "efl_ui_table.eo.c"