elementary/layout - adding description and moving function reference docs.
[framework/uifw/elementary.git] / src / lib / elm_layout.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Subinfo Subinfo;
6 typedef struct _Part_Cursor Part_Cursor;
7
8 struct _Widget_Data
9 {
10    Evas_Object *obj;
11    Evas_Object *lay;
12    Eina_List *subs;
13    Eina_List *parts_cursors;
14    Eina_Bool needs_size_calc:1;
15    const char *clas, *group, *style;
16 };
17
18 struct _Subinfo
19 {
20    const char *part;
21    Evas_Object *obj;
22    enum {
23      SWALLOW,
24      BOX_APPEND,
25      BOX_PREPEND,
26      BOX_INSERT_BEFORE,
27      BOX_INSERT_AT,
28      TABLE_PACK,
29      TEXT
30    } type;
31    union {
32       union {
33          const Evas_Object *reference;
34          unsigned int pos;
35       } box;
36       struct {
37          unsigned short col, row, colspan, rowspan;
38       } table;
39       struct {
40          const char *text;
41       } text;
42    } p;
43 };
44
45 struct _Part_Cursor
46 {
47    Evas_Object *obj;
48    const char *part;
49    const char *cursor;
50    const char *style;
51    Eina_Bool engine_only:1;
52 };
53
54 static const char *widtype = NULL;
55 static void _del_hook(Evas_Object *obj);
56 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
57 static void _theme_hook(Evas_Object *obj);
58 static void _sizing_eval(Widget_Data *wd);
59 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
60 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
61 static void _part_cursor_free(Part_Cursor *pc);
62
63 static const char SIG_THEME_CHANGED[] = "theme,changed";
64
65 static const Evas_Smart_Cb_Description _signals[] = {
66    {SIG_THEME_CHANGED, ""},
67    {NULL, NULL}
68 };
69
70 static void
71 _del_hook(Evas_Object *obj)
72 {
73    Widget_Data *wd = elm_widget_data_get(obj);
74    Subinfo *si;
75    Part_Cursor *pc;
76
77    if (!wd) return;
78    EINA_LIST_FREE(wd->subs, si)
79      {
80         eina_stringshare_del(si->part);
81         if (si->type == TEXT)
82           eina_stringshare_del(si->p.text.text);
83         free(si);
84      }
85    EINA_LIST_FREE(wd->parts_cursors, pc) _part_cursor_free(pc);
86    free(wd);
87 }
88
89 static void
90 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
91 {
92    Widget_Data *wd = elm_widget_data_get(obj);
93    if (!wd) return;
94    edje_object_mirrored_set(wd->lay, rtl);
95 }
96
97 static void
98 _theme_hook(Evas_Object *obj)
99 {
100    Widget_Data *wd = elm_widget_data_get(obj);
101    if (!wd) return;
102    _elm_widget_mirrored_reload(obj);
103    _mirrored_set(obj, elm_widget_mirrored_get(obj));
104    _elm_theme_object_set(obj, wd->lay, wd->clas, wd->group, wd->style);
105    edje_object_scale_set(wd->lay, elm_widget_scale_get(obj) *
106                          _elm_config->scale);
107    evas_object_smart_callback_call(obj, SIG_THEME_CHANGED, NULL);
108    _sizing_eval(wd);
109 }
110
111 static void
112 _changed_hook(Evas_Object *obj)
113 {
114    Widget_Data *wd = elm_widget_data_get(obj);
115    if (!wd) return;
116    if (wd->needs_size_calc)
117      {
118         _sizing_eval(wd);
119         wd->needs_size_calc = 0;
120      }
121 }
122
123 static void
124 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
125 {
126    Widget_Data *wd = elm_widget_data_get(obj);
127    edje_object_signal_emit(wd->lay, emission, source);
128 }
129
130 static void
131 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
132 {
133    Widget_Data *wd = elm_widget_data_get(obj);
134    edje_object_signal_callback_add(wd->lay, emission, source, func_cb, data);
135 }
136
137 static void
138 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
139 {
140    Widget_Data *wd = elm_widget_data_get(obj);
141    edje_object_signal_callback_del_full(wd->lay, emission, source, func_cb,
142                                         data);
143 }
144
145
146 static void *
147 _elm_layout_list_data_get(const Eina_List *list)
148 {
149    Subinfo *si = eina_list_data_get(list);
150    return si->obj;
151 }
152
153 static Eina_Bool
154 _elm_layout_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
155 {
156    Widget_Data *wd = elm_widget_data_get(obj);
157    const Eina_List *items;
158    void *(*list_data_get) (const Eina_List *list);
159
160    if ((!wd) || (!wd->subs))
161      return EINA_FALSE;
162
163    /* Focus chain (This block is diferent of elm_win cycle)*/
164    if ((items = elm_widget_focus_custom_chain_get(obj)))
165      list_data_get = eina_list_data_get;
166    else
167      {
168         items = wd->subs;
169         list_data_get = _elm_layout_list_data_get;
170
171         if (!items) return EINA_FALSE;
172      }
173
174    return elm_widget_focus_list_next_get(obj, items, list_data_get, dir,
175                                          next);
176 }
177
178 static void
179 _sizing_eval(Widget_Data *wd)
180 {
181    Evas_Coord minw = -1, minh = -1;
182    edje_object_size_min_calc(wd->lay, &minw, &minh);
183    evas_object_size_hint_min_set(wd->obj, minw, minh);
184    evas_object_size_hint_max_set(wd->obj, -1, -1);
185 }
186
187 static void
188 _request_sizing_eval(Widget_Data *wd)
189 {
190    if (wd->needs_size_calc) return;
191    wd->needs_size_calc = 1;
192    evas_object_smart_changed(wd->obj);
193 }
194
195 static void
196 _part_cursor_free(Part_Cursor *pc)
197 {
198    eina_stringshare_del(pc->part);
199    eina_stringshare_del(pc->style);
200    eina_stringshare_del(pc->cursor);
201    free(pc);
202 }
203
204 static void
205 _part_cursor_part_apply(const Part_Cursor *pc)
206 {
207    elm_object_cursor_set(pc->obj, pc->cursor);
208    elm_object_cursor_style_set(pc->obj, pc->style);
209    elm_object_cursor_engine_only_set(pc->obj, pc->engine_only);
210 }
211
212 static Part_Cursor *
213 _parts_cursors_find(Widget_Data *wd, const char *part)
214 {
215    const Eina_List *l;
216    Part_Cursor *pc;
217    EINA_LIST_FOREACH(wd->parts_cursors, l, pc)
218      {
219         if (!strcmp(pc->part, part))
220           return pc;
221      }
222    return NULL;
223 }
224
225 static void
226 _parts_cursors_apply(Widget_Data *wd)
227 {
228    const char *file, *group;
229    const Eina_List *l;
230    Part_Cursor *pc;
231
232    edje_object_file_get(wd->lay, &file, &group);
233
234    EINA_LIST_FOREACH(wd->parts_cursors, l, pc)
235      {
236         Evas_Object *obj = (Evas_Object *)edje_object_part_object_get
237            (wd->lay, pc->part);
238
239         if (!obj)
240           {
241              pc->obj = NULL;
242              WRN("no part '%s' in group '%s' of file '%s'. "
243                  "Cannot set cursor '%s'",
244                  pc->part, group, file, pc->cursor);
245              continue;
246           }
247         else if (evas_object_pass_events_get(obj))
248           {
249              pc->obj = NULL;
250              WRN("part '%s' in group '%s' of file '%s' has mouse_events: 0. "
251                  "Cannot set cursor '%s'",
252                  pc->part, group, file, pc->cursor);
253              continue;
254           }
255
256         pc->obj = obj;
257         _part_cursor_part_apply(pc);
258      }
259 }
260
261 static void
262 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
263 {
264    _request_sizing_eval(data);
265 }
266
267 static void
268 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
269 {
270    Widget_Data *wd = elm_widget_data_get(obj);
271    Evas_Object *sub = event_info;
272    Eina_List *l;
273    Subinfo *si;
274    if (!wd) return;
275    EINA_LIST_FOREACH(wd->subs, l, si)
276      {
277         if (si->obj == sub)
278           {
279              evas_object_event_callback_del_full(sub,
280                                                  EVAS_CALLBACK_CHANGED_SIZE_HINTS,
281                                                  _changed_size_hints,
282                                                  wd);
283              wd->subs = eina_list_remove_list(wd->subs, l);
284              eina_stringshare_del(si->part);
285              free(si);
286              break;
287           }
288      }
289 }
290
291 static void
292 _signal_size_eval(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
293 {
294    _request_sizing_eval(data);
295 }
296
297 static void
298 _parts_text_fix(Widget_Data *wd)
299 {
300    const Eina_List *l;
301    Subinfo *si;
302
303    EINA_LIST_FOREACH(wd->subs, l, si)
304      {
305         if (si->type == TEXT)
306           edje_object_part_text_set(wd->lay, si->part, si->p.text.text);
307      }
308 }
309
310 static void
311 _elm_layout_label_set(Evas_Object *obj, const char *part, const char *text)
312 {
313    Widget_Data *wd = elm_widget_data_get(obj);
314    Subinfo *si = NULL;
315    Eina_List *l;
316    ELM_CHECK_WIDTYPE(obj, widtype);
317    if (!part) part = "elm.text";
318
319    EINA_LIST_FOREACH(wd->subs, l, si)
320      {
321         if ((si->type == TEXT) && (!strcmp(part, si->part)))
322           {
323              if (!text)
324                {
325                   eina_stringshare_del(si->part);
326                   eina_stringshare_del(si->p.text.text);
327                   free(si);
328                   edje_object_part_text_set(wd->lay, part, NULL);
329                   wd->subs = eina_list_remove_list(wd->subs, l);
330                   return;
331                }
332              else
333                break;
334           }
335         si = NULL;
336      }
337
338    if (!si)
339      {
340         si = ELM_NEW(Subinfo);
341         if (!si) return;
342         si->type = TEXT;
343         si->part = eina_stringshare_add(part);
344         wd->subs = eina_list_append(wd->subs, si);
345      }
346
347    eina_stringshare_replace(&si->p.text.text, text);
348    edje_object_part_text_set(wd->lay, part, text);
349    _request_sizing_eval(wd);
350 }
351
352 static const char *
353 _elm_layout_label_get(const Evas_Object *obj, const char *part)
354 {
355    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
356    Widget_Data *wd = elm_widget_data_get(obj);
357    if (!part) part = "elm.text";
358    return edje_object_part_text_get(wd->lay, part);
359 }
360
361 EAPI Evas_Object *
362 elm_layout_add(Evas_Object *parent)
363 {
364    Evas_Object *obj;
365    Evas *e;
366    Widget_Data *wd;
367
368    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
369
370    ELM_SET_WIDTYPE(widtype, "layout");
371    elm_widget_type_set(obj, "layout");
372    elm_widget_sub_object_add(parent, obj);
373    elm_widget_data_set(obj, wd);
374    elm_widget_del_hook_set(obj, _del_hook);
375    elm_widget_theme_hook_set(obj, _theme_hook);
376    elm_widget_changed_hook_set(obj, _changed_hook);
377    elm_widget_can_focus_set(obj, EINA_FALSE);
378    elm_widget_focus_next_hook_set(obj, _elm_layout_focus_next_hook);
379    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
380    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
381    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
382    elm_widget_text_set_hook_set(obj, _elm_layout_label_set);
383    elm_widget_text_get_hook_set(obj, _elm_layout_label_get);
384
385    wd->obj = obj;
386    wd->lay = edje_object_add(e);
387    elm_widget_resize_object_set(obj, wd->lay);
388    edje_object_signal_callback_add(wd->lay, "size,eval", "elm",
389                                    _signal_size_eval, wd);
390
391    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
392    evas_object_smart_callbacks_descriptions_set(obj, _signals);
393
394    _mirrored_set(obj, elm_widget_mirrored_get(obj));
395    _request_sizing_eval(wd);
396    return obj;
397 }
398
399 EAPI Eina_Bool
400 elm_layout_file_set(Evas_Object *obj, const char *file, const char *group)
401 {
402    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
403    Widget_Data *wd = elm_widget_data_get(obj);
404    if (!wd) return EINA_FALSE;
405    Eina_Bool ret = edje_object_file_set(wd->lay, file, group);
406    if (ret)
407      {
408         _parts_text_fix(wd);
409         _request_sizing_eval(wd);
410         _parts_cursors_apply(wd);
411      }
412    else DBG("failed to set edje file '%s', group '%s': %s",
413             file, group,
414             edje_load_error_str(edje_object_load_error_get(wd->lay)));
415    return ret;
416 }
417
418 EAPI Eina_Bool
419 elm_layout_theme_set(Evas_Object *obj, const char *clas, const char *group, const char *style)
420 {
421    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
422    Widget_Data *wd = elm_widget_data_get(obj);
423    if (!wd) return EINA_FALSE;
424    Eina_Bool ret = _elm_theme_object_set(obj, wd->lay, clas, group, style);
425    wd->clas = clas;
426    wd->group = group;
427    wd->style = style;
428    if (ret)
429      {
430         _parts_text_fix(wd);
431         _request_sizing_eval(wd);
432         _parts_cursors_apply(wd);
433      }
434    return ret;
435 }
436
437 EAPI void
438 elm_layout_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
439 {
440    ELM_CHECK_WIDTYPE(obj, widtype);
441    Widget_Data *wd = elm_widget_data_get(obj);
442    Subinfo *si;
443    const Eina_List *l;
444    if (!wd) return;
445    EINA_LIST_FOREACH(wd->subs, l, si)
446      {
447         if ((si->type == SWALLOW) && (!strcmp(swallow, si->part)))
448           {
449              if (content == si->obj) return;
450              evas_object_del(si->obj);
451              break;
452           }
453      }
454    if (content)
455      {
456         elm_widget_sub_object_add(obj, content);
457         evas_object_event_callback_add(content,
458                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
459                                        _changed_size_hints, wd);
460         if (!edje_object_part_swallow(wd->lay, swallow, content))
461           WRN("could not swallow %p into part '%s'", content, swallow);
462         si = ELM_NEW(Subinfo);
463         si->type = SWALLOW;
464         si->part = eina_stringshare_add(swallow);
465         si->obj = content;
466         wd->subs = eina_list_append(wd->subs, si);
467      }
468    _request_sizing_eval(wd);
469 }
470
471 EAPI Evas_Object *
472 elm_layout_content_get(const Evas_Object *obj, const char *swallow)
473 {
474    Widget_Data *wd = elm_widget_data_get(obj);
475    const Eina_List *l;
476    Subinfo *si;
477    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
478
479    EINA_LIST_FOREACH(wd->subs, l, si)
480      {
481         if ((si->type == SWALLOW) && !strcmp(swallow, si->part))
482           return si->obj;
483      }
484    return NULL;
485 }
486
487 EAPI Evas_Object *
488 elm_layout_content_unset(Evas_Object *obj, const char *swallow)
489 {
490    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
491    Widget_Data *wd = elm_widget_data_get(obj);
492    Subinfo *si;
493    const Eina_List *l;
494    if (!wd) return NULL;
495    EINA_LIST_FOREACH(wd->subs, l, si)
496      {
497         if ((si->type == SWALLOW) && (!strcmp(swallow, si->part)))
498           {
499              Evas_Object *content;
500              if (!si->obj) return NULL;
501              content = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
502              elm_widget_sub_object_del(obj, content);
503              edje_object_part_unswallow(wd->lay, content);
504              return content;
505           }
506      }
507    return NULL;
508 }
509
510 EAPI void
511 elm_layout_text_set(Evas_Object *obj, const char *part, const char *text)
512 {
513    _elm_layout_label_set(obj, part, text);
514 }
515
516 EAPI const char *
517 elm_layout_text_get(const Evas_Object *obj, const char *part)
518 {
519    return _elm_layout_label_get(obj, part);
520 }
521
522 EAPI void
523 elm_layout_box_append(Evas_Object *obj, const char *part, Evas_Object *child)
524 {
525    ELM_CHECK_WIDTYPE(obj, widtype);
526    Widget_Data *wd = elm_widget_data_get(obj);
527    Subinfo *si;
528    if (!wd) return;
529
530    if (!edje_object_part_box_append(wd->lay, part, child))
531      WRN("child %p could not be appended to box part '%s'", child, part);
532    elm_widget_sub_object_add(obj, child);
533    evas_object_event_callback_add
534       (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, wd);
535
536    si = ELM_NEW(Subinfo);
537    si->type = BOX_APPEND;
538    si->part = eina_stringshare_add(part);
539    si->obj = child;
540    wd->subs = eina_list_append(wd->subs, si);
541    _request_sizing_eval(wd);
542 }
543
544 EAPI void
545 elm_layout_box_prepend(Evas_Object *obj, const char *part, Evas_Object *child)
546 {
547    ELM_CHECK_WIDTYPE(obj, widtype);
548    Widget_Data *wd = elm_widget_data_get(obj);
549    Subinfo *si;
550    if (!wd) return;
551
552    if (!edje_object_part_box_prepend(wd->lay, part, child))
553      WRN("child %p could not be prepended to box part '%s'", child, part);
554    elm_widget_sub_object_add(obj, child);
555    evas_object_event_callback_add
556       (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, wd);
557
558    si = ELM_NEW(Subinfo);
559    si->type = BOX_PREPEND;
560    si->part = eina_stringshare_add(part);
561    si->obj = child;
562    wd->subs = eina_list_prepend(wd->subs, si);
563    _request_sizing_eval(wd);
564 }
565
566 static void
567 _box_reference_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
568 {
569    Subinfo *si = data;
570    si->p.box.reference = NULL;
571 }
572
573 EAPI void
574 elm_layout_box_insert_before(Evas_Object *obj, const char *part, Evas_Object *child, const Evas_Object *reference)
575 {
576    ELM_CHECK_WIDTYPE(obj, widtype);
577    Widget_Data *wd = elm_widget_data_get(obj);
578    Subinfo *si;
579    if (!wd) return;
580
581    if (!edje_object_part_box_insert_before(wd->lay, part, child, reference))
582      WRN("child %p could not be inserted before %p inf box part '%s'",
583          child, reference, part);
584
585    si = ELM_NEW(Subinfo);
586    si->type = BOX_INSERT_BEFORE;
587    si->part = eina_stringshare_add(part);
588    si->obj = child;
589    si->p.box.reference = reference;
590
591    elm_widget_sub_object_add(obj, child);
592    evas_object_event_callback_add
593       (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, wd);
594    evas_object_event_callback_add
595       ((Evas_Object *)reference, EVAS_CALLBACK_DEL, _box_reference_del, si);
596
597    wd->subs = eina_list_append(wd->subs, si);
598    _request_sizing_eval(wd);
599 }
600
601 EAPI void
602 elm_layout_box_insert_at(Evas_Object *obj, const char *part, Evas_Object *child, unsigned int pos)
603 {
604    ELM_CHECK_WIDTYPE(obj, widtype);
605    Widget_Data *wd = elm_widget_data_get(obj);
606    Subinfo *si;
607    if (!wd) return;
608
609    if (!edje_object_part_box_insert_at(wd->lay, part, child, pos))
610      WRN("child %p could not be inserted at %u to box part '%s'",
611          child, pos, part);
612
613    elm_widget_sub_object_add(obj, child);
614    evas_object_event_callback_add
615       (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, wd);
616
617    si = ELM_NEW(Subinfo);
618    si->type = BOX_INSERT_AT;
619    si->part = eina_stringshare_add(part);
620    si->obj = child;
621    si->p.box.pos = pos;
622    wd->subs = eina_list_append(wd->subs, si);
623    _request_sizing_eval(wd);
624 }
625
626 static Evas_Object *
627 _sub_box_remove(Widget_Data *wd, Subinfo *si)
628 {
629    Evas_Object *child;
630
631    if (si->type == BOX_INSERT_BEFORE)
632      evas_object_event_callback_del_full
633         ((Evas_Object *)si->p.box.reference,
634          EVAS_CALLBACK_DEL, _box_reference_del, si);
635
636    child = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
637    edje_object_part_box_remove(wd->lay, si->part, child);
638    elm_widget_sub_object_del(wd->obj, child);
639    return child;
640 }
641
642 static Evas_Object *
643 _sub_table_remove(Widget_Data *wd, Subinfo *si)
644 {
645    Evas_Object *child;
646
647    child = si->obj; /* si will die in _sub_del due elm_widget_sub_object_del() */
648    edje_object_part_table_unpack(wd->lay, si->part, child);
649    elm_widget_sub_object_del(wd->obj, child);
650    return child;
651 }
652
653 static Eina_Bool
654 _sub_box_is(const Subinfo *si)
655 {
656    switch (si->type)
657      {
658       case BOX_APPEND:
659       case BOX_PREPEND:
660       case BOX_INSERT_BEFORE:
661       case BOX_INSERT_AT:
662          return EINA_TRUE;
663       default:
664          return EINA_FALSE;
665      }
666 }
667
668 EAPI Evas_Object *
669 elm_layout_box_remove(Evas_Object *obj, const char *part, Evas_Object *child)
670 {
671    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
672    Widget_Data *wd = elm_widget_data_get(obj);
673    const Eina_List *l;
674    Subinfo *si;
675
676    if (!wd) return NULL;
677
678    EINA_SAFETY_ON_NULL_RETURN_VAL(part, NULL);
679    EINA_SAFETY_ON_NULL_RETURN_VAL(child, NULL);
680    EINA_LIST_FOREACH(wd->subs, l, si)
681      {
682         if (!_sub_box_is(si)) continue;
683         if ((si->obj == child) && (!strcmp(si->part, part)))
684           return _sub_box_remove(wd, si);
685      }
686    return NULL;
687 }
688
689 EAPI void
690 elm_layout_box_remove_all(Evas_Object *obj, const char *part, Eina_Bool clear)
691 {
692    ELM_CHECK_WIDTYPE(obj, widtype);
693    Widget_Data *wd = elm_widget_data_get(obj);
694    Subinfo *si;
695    Eina_List *lst;
696
697    if (!wd) return;
698    EINA_SAFETY_ON_NULL_RETURN(part);
699
700    lst = eina_list_clone(wd->subs);
701    EINA_LIST_FREE(lst, si)
702      {
703         if (!_sub_box_is(si)) continue;
704         if (!strcmp(si->part, part))
705           {
706              Evas_Object *child = _sub_box_remove(wd, si);
707              if ((clear) && (child)) evas_object_del(child);
708           }
709      }
710    /* eventually something may not be added with layout, del them as well */
711    edje_object_part_box_remove_all(wd->lay, part, clear);
712 }
713
714 EAPI void
715 elm_layout_table_pack(Evas_Object *obj, const char *part, Evas_Object *child, unsigned short col, unsigned short row, unsigned short colspan, unsigned short rowspan)
716 {
717    ELM_CHECK_WIDTYPE(obj, widtype);
718    Widget_Data *wd = elm_widget_data_get(obj);
719    Subinfo *si;
720    if (!wd) return;
721
722    if (!edje_object_part_table_pack
723        (wd->lay, part, child, col, row, colspan, rowspan))
724      WRN("child %p could not be packed into box part '%s' col=%uh, row=%hu, "
725          "colspan=%hu, rowspan=%hu", child, part, col, row, colspan, rowspan);
726
727    elm_widget_sub_object_add(obj, child);
728    evas_object_event_callback_add
729       (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, wd);
730
731    si = ELM_NEW(Subinfo);
732    si->type = TABLE_PACK;
733    si->part = eina_stringshare_add(part);
734    si->obj = child;
735    si->p.table.col = col;
736    si->p.table.row = row;
737    si->p.table.colspan = colspan;
738    si->p.table.rowspan = rowspan;
739    wd->subs = eina_list_append(wd->subs, si);
740    _request_sizing_eval(wd);
741 }
742
743 EAPI Evas_Object *
744 elm_layout_table_unpack(Evas_Object *obj, const char *part, Evas_Object *child)
745 {
746    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
747    Widget_Data *wd = elm_widget_data_get(obj);
748    const Eina_List *l;
749    Subinfo *si;
750
751    if (!wd) return NULL;
752
753    EINA_SAFETY_ON_NULL_RETURN_VAL(part, NULL);
754    EINA_SAFETY_ON_NULL_RETURN_VAL(child, NULL);
755    EINA_LIST_FOREACH(wd->subs, l, si)
756      {
757         if (si->type != TABLE_PACK) continue;
758         if ((si->obj == child) && (!strcmp(si->part, part)))
759           return _sub_table_remove(wd, si);
760      }
761    return NULL;
762 }
763
764 EAPI void
765 elm_layout_table_clear(Evas_Object *obj, const char *part, Eina_Bool clear)
766 {
767    ELM_CHECK_WIDTYPE(obj, widtype);
768    Widget_Data *wd = elm_widget_data_get(obj);
769    Subinfo *si;
770    Eina_List *lst;
771
772    if (!wd) return;
773    EINA_SAFETY_ON_NULL_RETURN(part);
774
775    lst = eina_list_clone(wd->subs);
776    EINA_LIST_FREE(lst, si)
777      {
778         if (si->type != TABLE_PACK) continue;
779         if (!strcmp(si->part, part))
780           {
781              Evas_Object *child = _sub_table_remove(wd, si);
782              if ((clear) && (child)) evas_object_del(child);
783           }
784      }
785    /* eventually something may not be added with layout, del them as well */
786    edje_object_part_table_clear(wd->lay, part, clear);
787 }
788
789 EAPI Evas_Object *
790 elm_layout_edje_get(const Evas_Object *obj)
791 {
792    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
793    Widget_Data *wd = elm_widget_data_get(obj);
794    if (!wd) return NULL;
795    return wd->lay;
796 }
797
798 EAPI const char *
799 elm_layout_data_get(const Evas_Object *obj, const char *key)
800 {
801    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
802    Widget_Data *wd = elm_widget_data_get(obj);
803    return edje_object_data_get(wd->lay, key);
804 }
805
806 EAPI void
807 elm_layout_sizing_eval(Evas_Object *obj)
808 {
809    ELM_CHECK_WIDTYPE(obj, widtype);
810    Widget_Data *wd = elm_widget_data_get(obj);
811    EINA_SAFETY_ON_NULL_RETURN(wd);
812    _request_sizing_eval(wd);
813 }
814
815 /**
816  * Sets a specific cursor for an edje part.
817  *
818  * @param obj The layout object.
819  * @param part_name a part from loaded edje group.
820  * @param cursor cursor name to use, see Elementary_Cursor.h
821  *
822  * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
823  *         part not exists or it has "mouse_events: 0".
824  *
825  * @ingroup Layout
826  */
827 EAPI Eina_Bool
828 elm_layout_part_cursor_set(Evas_Object *obj, const char *part_name, const char *cursor)
829 {
830    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
831    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, EINA_FALSE);
832    Widget_Data *wd = elm_widget_data_get(obj);
833    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
834    Evas_Object *part_obj;
835    Part_Cursor *pc;
836
837    part_obj = (Evas_Object *)edje_object_part_object_get(wd->lay, part_name);
838    if (!part_obj)
839      {
840         const char *group, *file;
841         edje_object_file_get(wd->lay, &file, &group);
842         WRN("no part '%s' in group '%s' of file '%s'. Cannot set cursor '%s'",
843             part_name, group, file, cursor);
844         return EINA_FALSE;
845      }
846    if (evas_object_pass_events_get(part_obj))
847      {
848         const char *group, *file;
849         edje_object_file_get(wd->lay, &file, &group);
850         WRN("part '%s' in group '%s' of file '%s' has mouse_events: 0. "
851             "Cannot set cursor '%s'",
852             part_name, group, file, cursor);
853         return EINA_FALSE;
854      }
855
856    pc = _parts_cursors_find(wd, part_name);
857    if (pc) eina_stringshare_replace(&pc->cursor, cursor);
858    else
859      {
860         pc = calloc(1, sizeof(*pc));
861         pc->part = eina_stringshare_add(part_name);
862         pc->cursor = eina_stringshare_add(cursor);
863      }
864
865    pc->obj = part_obj;
866    elm_object_sub_cursor_set(part_obj, obj, pc->cursor);
867    return EINA_TRUE;
868 }
869
870 /**
871  * Get the cursor to be shown when mouse is over an edje part
872  *
873  * @param obj The layout object.
874  * @param part_name a part from loaded edje group.
875  * @return the cursor name.
876  *
877  * @ingroup Layout
878  */
879 EAPI const char *
880 elm_layout_part_cursor_get(const Evas_Object *obj, const char *part_name)
881 {
882    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
883    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, NULL);
884    Widget_Data *wd = elm_widget_data_get(obj);
885    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
886    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
887    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, NULL);
888    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, NULL);
889    return elm_object_cursor_get(pc->obj);
890 }
891
892 /**
893  * Unsets a cursor previously set with elm_layout_part_cursor_set().
894  *
895  * @param obj The layout object.
896  * @param part_name a part from loaded edje group, that had a cursor set
897  *        with elm_layout_part_cursor_set().
898  *
899  * @ingroup Layout
900  */
901 EAPI void
902 elm_layout_part_cursor_unset(Evas_Object *obj, const char *part_name)
903 {
904    ELM_CHECK_WIDTYPE(obj, widtype);
905    EINA_SAFETY_ON_NULL_RETURN(part_name);
906    Widget_Data *wd = elm_widget_data_get(obj);
907    EINA_SAFETY_ON_NULL_RETURN(wd);
908    Eina_List *l;
909    Part_Cursor *pc;
910
911    EINA_LIST_FOREACH(wd->parts_cursors, l, pc)
912      {
913         if (!strcmp(part_name, pc->part))
914           {
915              if (pc->obj) elm_object_cursor_unset(pc->obj);
916              _part_cursor_free(pc);
917              wd->parts_cursors = eina_list_remove_list(wd->parts_cursors, l);
918              return;
919           }
920      }
921 }
922
923 /**
924  * Sets a specific cursor style for an edje part.
925  *
926  * @param obj The layout object.
927  * @param part_name a part from loaded edje group.
928  * @param style the theme style to use (default, transparent, ...)
929  *
930  * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
931  *         part not exists or it did not had a cursor set.
932  *
933  * @ingroup Layout
934  */
935 EAPI Eina_Bool
936 elm_layout_part_cursor_style_set(Evas_Object *obj, const char *part_name, const char *style)
937 {
938    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
939    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, EINA_FALSE);
940    Widget_Data *wd = elm_widget_data_get(obj);
941    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
942    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
943    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, EINA_FALSE);
944    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, EINA_FALSE);
945
946    eina_stringshare_replace(&pc->style, style);
947    elm_object_cursor_style_set(pc->obj, pc->style);
948    return EINA_TRUE;
949 }
950
951 /**
952  * Gets a specific cursor style for an edje part.
953  *
954  * @param obj The layout object.
955  * @param part_name a part from loaded edje group.
956  *
957  * @return the theme style in use, defaults to "default". If the
958  *         object does not have a cursor set, then NULL is returned.
959  *
960  * @ingroup Layout
961  */
962 EAPI const char *
963 elm_layout_part_cursor_style_get(const Evas_Object *obj, const char *part_name)
964 {
965    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
966    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, NULL);
967    Widget_Data *wd = elm_widget_data_get(obj);
968    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, NULL);
969    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
970    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, NULL);
971    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, NULL);
972    return elm_object_cursor_style_get(pc->obj);
973 }
974
975 /**
976  * Sets if the cursor set should be searched on the theme or should use
977  * the provided by the engine, only.
978  *
979  * @note before you set if should look on theme you should define a
980  * cursor with elm_layout_part_cursor_set(). By default it will only
981  * look for cursors provided by the engine.
982  *
983  * @param obj The layout object.
984  * @param part_name a part from loaded edje group.
985  * @param engine_only if cursors should be just provided by the engine
986  *        or should also search on widget's theme as well
987  *
988  * @return EINA_TRUE on success or EINA_FALSE on failure, that may be
989  *         part not exists or it did not had a cursor set.
990  *
991  * @ingroup Layout
992  */
993 EAPI Eina_Bool
994 elm_layout_part_cursor_engine_only_set(Evas_Object *obj, const char *part_name, Eina_Bool engine_only)
995 {
996    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
997    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, EINA_FALSE);
998    Widget_Data *wd = elm_widget_data_get(obj);
999    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
1000    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
1001    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, EINA_FALSE);
1002    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, EINA_FALSE);
1003
1004    pc->engine_only = !!engine_only;
1005    elm_object_cursor_engine_only_set(pc->obj, pc->engine_only);
1006    return EINA_TRUE;
1007 }
1008
1009 /**
1010  * Gets a specific cursor engine_only for an edje part.
1011  *
1012  * @param obj The layout object.
1013  * @param part_name a part from loaded edje group.
1014  *
1015  * @return whenever the cursor is just provided by engine or also from theme.
1016  *
1017  * @ingroup Layout
1018  */
1019 EAPI Eina_Bool
1020 elm_layout_part_cursor_engine_only_get(const Evas_Object *obj, const char *part_name)
1021 {
1022    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1023    EINA_SAFETY_ON_NULL_RETURN_VAL(part_name, EINA_FALSE);
1024    Widget_Data *wd = elm_widget_data_get(obj);
1025    EINA_SAFETY_ON_NULL_RETURN_VAL(wd, EINA_FALSE);
1026    Part_Cursor *pc = _parts_cursors_find(wd, part_name);
1027    EINA_SAFETY_ON_NULL_RETURN_VAL(pc, EINA_FALSE);
1028    EINA_SAFETY_ON_NULL_RETURN_VAL(pc->obj, EINA_FALSE);
1029    return elm_object_cursor_engine_only_get(pc->obj);
1030 }