elementary/segment_control, panes, photocam, photo, win, toolbar, thumb, slideshow...
[framework/uifw/elementary.git] / src / lib / elm_toolbar.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Toolbar Toolbar
6  *
7  * A toolbar is a widget that displays a list of buttons inside
8  * a box.  It is scrollable, and only one item can be selected at a time.
9  *
10  * Signals that you can add callbacks for are:
11  *
12  * "clicked" - when the user clicks on a toolbar item and becomes selected
13  *
14  */
15
16 typedef struct _Widget_Data Widget_Data;
17
18 struct _Widget_Data
19 {
20    Evas_Object *scr, *bx;
21    Evas_Object *menu_parent;
22    Eina_Inlist *items;
23    Elm_Toolbar_Item *more_item, *selected_item;
24    Elm_Toolbar_Shrink_Mode shrink_mode;
25    Elm_Icon_Lookup_Order lookup_order;
26    int icon_size;
27    double align;
28    Eina_Bool homogeneous : 1;
29    Eina_Bool no_select : 1;
30    Ecore_Job *resize_job;
31 };
32
33 struct _Elm_Toolbar_Item
34 {
35    Elm_Widget_Item base;
36    EINA_INLIST;
37    const char *label;
38    const char *icon_str;
39    Evas_Object *icon;
40    Evas_Object *o_menu;
41    Evas_Smart_Cb func;
42    struct {
43       int priority;
44       Eina_Bool visible : 1;
45    } prio;
46    Eina_Bool selected : 1;
47    Eina_Bool disabled : 1;
48    Eina_Bool separator : 1;
49    Eina_Bool menu : 1;
50    Eina_List *states;
51    Eina_List *current_state;
52 };
53
54 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item)      \
55   ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
56
57 struct _Elm_Toolbar_Item_State
58 {
59    const char *label;
60    const char *icon_str;
61    Evas_Object *icon;
62    Evas_Smart_Cb func;
63    const void *data;
64 };
65
66 static const char *widtype = NULL;
67 static void _item_show(Elm_Toolbar_Item *it);
68 static void _item_select(Elm_Toolbar_Item *it);
69 static void _item_unselect(Elm_Toolbar_Item *it);
70 static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
71 static void _del_pre_hook(Evas_Object *obj);
72 static void _del_hook(Evas_Object *obj);
73 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
74 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
75 static void _theme_hook(Evas_Object *obj);
76 static void _sizing_eval(Evas_Object *obj);
77 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
78 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
79 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
80 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
81 static void _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal);
82 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
83
84 static const char SIG_CLICKED[] = "clicked";
85
86 static const Evas_Smart_Cb_Description _signals[] = {
87    {SIG_CLICKED, ""},
88    {NULL, NULL}
89 };
90
91
92 static Eina_Bool
93 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
94 {
95    char icon_str[512];
96
97    if ((!type) || (!*type)) goto end;
98    if ((!icon) || (!*icon)) return EINA_FALSE;
99    if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
100        && (elm_icon_standard_set(icon_obj, icon_str)))
101      return EINA_TRUE;
102 end:
103    if (elm_icon_standard_set(icon_obj, icon))
104      return EINA_TRUE;
105    WRN("couldn't find icon definition for '%s'", icon);
106    return EINA_FALSE;
107 }
108
109 static int
110 _elm_toolbar_icon_size_get(Widget_Data *wd)
111 {
112    const char *icon_size = edje_object_data_get(
113       elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
114    if (icon_size)
115      return atoi(icon_size);
116    return _elm_config->icon_size;
117 }
118
119 static void
120 _item_show(Elm_Toolbar_Item *it)
121 {
122    Widget_Data *wd = elm_widget_data_get(it->base.widget);
123    Evas_Coord x, y, w, h, bx, by;
124
125    if (!wd) return;
126    evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
127    evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
128    elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
129 }
130
131 static void
132 _item_unselect(Elm_Toolbar_Item *item)
133 {
134    Widget_Data *wd;
135    if ((!item) || (!item->selected)) return;
136    wd = elm_widget_data_get(item->base.widget);
137    if (!wd) return;
138    item->selected = EINA_FALSE;
139    wd->selected_item = NULL;
140    edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
141    elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
142 }
143
144 static void
145 _item_select(Elm_Toolbar_Item *it)
146 {
147    Elm_Toolbar_Item *it2;
148    Widget_Data *wd = elm_widget_data_get(it->base.widget);
149    Evas_Object *obj2;
150
151    if (!wd) return;
152    if ((it->selected) || (it->disabled) || (it->separator)) return;
153
154    if (!wd->no_select)
155      {
156         it2 = elm_toolbar_selected_item_get(it->base.widget);
157         _item_unselect(it2);
158
159         it->selected = EINA_TRUE;
160         wd->selected_item = it;
161         edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
162         elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
163         _item_show(it);
164      }
165    obj2 = it->base.widget;
166    if (it->menu)
167      {
168         evas_object_show(it->o_menu);
169         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
170                                        _menu_move_resize, it);
171         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOVE,
172                                        _menu_move_resize, it);
173
174         _menu_move_resize(it, NULL, NULL, NULL);
175      }
176    if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
177    evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
178 }
179
180 static void
181 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
182 {
183    Elm_Toolbar_Item *selected;
184    Elm_Toolbar_Item *it = data;
185    selected = elm_toolbar_selected_item_get(it->base.widget);
186    _item_unselect(selected);
187 }
188
189 static void
190 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
191 {
192    // avoid hide being emitted during object deletion
193    evas_object_event_callback_del_full
194       (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
195 }
196
197 static void
198 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
199 {
200    Elm_Toolbar_Item *it = data;
201    Evas_Coord x,y,w,h;
202    Widget_Data *wd = elm_widget_data_get(it->base.widget);
203
204    if ((!wd) || (!wd->menu_parent)) return;
205    evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
206    elm_menu_move(it->o_menu, x, y+h);
207 }
208
209 static void
210 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
211 {
212    Widget_Data *wd = elm_widget_data_get(it->base.widget);
213
214    if (!wd) return;
215    if (it->disabled == disabled) return;
216    it->disabled = disabled;
217    if (it->disabled)
218      {
219         edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
220         elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
221      }
222    else
223      {
224         edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
225         elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
226      }
227 }
228
229 static void
230 _item_del(Elm_Toolbar_Item *it)
231 {
232    Elm_Toolbar_Item_State *it_state;
233    _item_unselect(it);
234    elm_widget_item_pre_notify_del(it);
235    EINA_LIST_FREE(it->states, it_state)
236      {
237         if (it->icon == it_state->icon)
238           it->icon = NULL;
239         eina_stringshare_del(it_state->label);
240         eina_stringshare_del(it_state->icon_str);
241         if (it_state->icon) evas_object_del(it_state->icon);
242         free(it_state);
243      }
244    eina_stringshare_del(it->label);
245    eina_stringshare_del(it->icon_str);
246    if (it->icon) evas_object_del(it->icon);
247    //TODO: See if checking for wd->menu_parent is necessary before deleting menu
248    if (it->o_menu) evas_object_del(it->o_menu);
249    elm_widget_item_del(it);
250 }
251
252 static void
253 _del_pre_hook(Evas_Object *obj)
254 {
255    Widget_Data *wd = elm_widget_data_get(obj);
256    Elm_Toolbar_Item *it, *next;
257
258    if (!wd) return;
259    it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
260    while(it)
261      {
262         next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
263         _item_del(it);
264         it = next;
265      }
266    if (wd->more_item)
267      _item_del(wd->more_item);
268 }
269
270 static void
271 _del_hook(Evas_Object *obj)
272 {
273    Widget_Data *wd = elm_widget_data_get(obj);
274
275    if (!wd) return;
276    free(wd);
277 }
278
279
280 static void
281 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
282 {
283    edje_object_mirrored_set(it->base.view, mirrored);
284    elm_widget_mirrored_set(it->o_menu, mirrored);
285 }
286
287 static void
288 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
289 {
290    Evas_Object *view = it->base.view;
291    Evas_Coord mw, mh;
292    const char *style = elm_widget_style_get(obj);
293
294    _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
295    edje_object_scale_set(view, scale);
296    if (!it->separator)
297      {
298         _elm_theme_object_set(obj, view, "toolbar", "item", style);
299         if (it->selected)
300           {
301              edje_object_signal_emit(view, "elm,state,selected", "elm");
302              elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
303           }
304         if (it->disabled)
305           {
306              edje_object_signal_emit(view, "elm,state,disabled", "elm");
307              elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
308           }
309         if (it->icon)
310           {
311              int ms = 0;
312
313              ms = ((double)icon_size * scale);
314              evas_object_size_hint_min_set(it->icon, ms, ms);
315              evas_object_size_hint_max_set(it->icon, ms, ms);
316              edje_object_part_swallow(view, "elm.swallow.icon",
317                                       it->icon);
318           }
319         edje_object_part_text_set(view, "elm.text", it->label);
320      }
321    else
322      _elm_theme_object_set(obj, view, "toolbar", "separator", style);
323
324    mw = mh = -1;
325    if (!it->separator)
326      elm_coords_finger_size_adjust(1, &mw, 1, &mh);
327    edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
328    if (!it->separator)
329      elm_coords_finger_size_adjust(1, &mw, 1, &mh);
330    evas_object_size_hint_min_set(view, mw, mh);
331 }
332
333 static void
334 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
335 {
336    Widget_Data *wd = elm_widget_data_get(obj);
337    Elm_Toolbar_Item *it;
338
339    EINA_INLIST_FOREACH(wd->items, it)
340       _mirrored_set_item(obj, it, mirrored);
341    if (wd->more_item)
342      _mirrored_set_item(obj, wd->more_item, mirrored);
343 }
344
345 static void
346 _theme_hook(Evas_Object *obj)
347 {
348    Widget_Data *wd = elm_widget_data_get(obj);
349    Elm_Toolbar_Item *it;
350    double scale = 0;
351
352    if (!wd) return;
353    _elm_widget_mirrored_reload(obj);
354    elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
355    _mirrored_set(obj, elm_widget_mirrored_get(obj));
356    scale = (elm_widget_scale_get(obj) * _elm_config->scale);
357    edje_object_scale_set(wd->scr, scale);
358    wd->icon_size = _elm_toolbar_icon_size_get(wd);
359    EINA_INLIST_FOREACH(wd->items, it)
360       _theme_hook_item(obj, it, scale, wd->icon_size);
361    if (wd->more_item)
362      _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
363    _sizing_eval(obj);
364 }
365
366 static void
367 _sizing_eval(Evas_Object *obj)
368 {
369    Widget_Data *wd = elm_widget_data_get(obj);
370    Evas_Coord minw = -1, minh = -1, minw_bx;
371    Evas_Coord vw = 0, vh = 0;
372    Evas_Coord w, h;
373
374    if (!wd) return;
375    evas_object_smart_calculate(wd->bx);
376    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
377                              &minw, &minh);
378    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
379    if (w < minw) w = minw;
380    if (h < minh) h = minh;
381
382    evas_object_resize(wd->scr, w, h);
383
384    evas_object_size_hint_min_get(wd->bx, &minw, &minh);
385    minw_bx = minw;
386    if (w > minw) minw = w;
387    evas_object_resize(wd->bx, minw, minh);
388    elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
389    switch (wd->shrink_mode)
390      {
391       case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
392       case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
393       case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
394       case ELM_TOOLBAR_SHRINK_NONE: minw = minw_bx + (w - vw); break;
395      }
396    minh = minh + (h - vh);
397    evas_object_size_hint_min_set(obj, minw, minh);
398    evas_object_size_hint_max_set(obj, -1, -1);
399 }
400
401 static void
402 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
403 {
404    item->o_menu = elm_menu_add(item->base.view);
405    if (wd->menu_parent)
406      elm_menu_parent_set(item->o_menu, wd->menu_parent);
407    evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
408                                   _menu_hide, item);
409    evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
410                                   _menu_del, item);
411 }
412
413 static void
414 _item_menu_destroy(Elm_Toolbar_Item *item)
415 {
416    if (item->o_menu)
417      {
418         evas_object_del(item->o_menu);
419         item->o_menu = NULL;
420      }
421 }
422
423 static int
424 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
425 {
426    const Elm_Toolbar_Item *eti1 = i1;
427    const Elm_Toolbar_Item *eti2 = i2;
428
429    if (!eti2) return 1;
430    if (!eti1) return -1;
431
432    return eti2->prio.priority - eti1->prio.priority;
433 }
434
435 static void
436 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
437 {
438    Elm_Toolbar_Item *it;
439    Eina_List *sorted = NULL;
440    Evas_Coord ciw;
441
442    EINA_INLIST_FOREACH(wd->items, it)
443      {
444         sorted = eina_list_sorted_insert(sorted,
445                                          _toolbar_item_prio_compare_cb, it);
446      }
447
448    if (wd->more_item)
449      {
450         evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &ciw, NULL);
451         *iw += ciw;
452      }
453    EINA_LIST_FREE(sorted, it)
454      {
455         evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
456         *iw += ciw;
457         it->prio.visible = (*iw <= vw);
458      }
459 }
460
461 static void
462 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
463 {
464    Elm_Toolbar_Item *it = data;
465    if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
466 }
467
468 static void
469 _resize_job(void *data)
470 {
471    Widget_Data *wd = elm_widget_data_get(data);
472    Evas_Coord mw, mh, vw, vh, w, h;
473    Elm_Toolbar_Item *it;
474    Evas_Object *obj = (Evas_Object *) data;
475
476    if (!wd) return;
477    wd->resize_job = NULL;
478    elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
479    evas_object_size_hint_min_get(wd->bx, &mw, &mh);
480    evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
481    if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
482      {
483         Evas_Coord iw = 0, more_w;
484
485         evas_object_resize(wd->bx, vw, h);
486         _fix_items_visibility(wd, &iw, vw);
487         evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &more_w, NULL);
488         if (iw - more_w <= vw)
489           iw -= more_w;
490
491         /* All items are removed from the box object, since removing individual
492          * items won't trigger a resize. Items are be readded below. */
493         evas_object_box_remove_all(wd->bx, EINA_FALSE);
494         if (iw > vw)
495           {
496              Evas_Object *menu;
497
498              _item_menu_destroy(wd->more_item);
499              _item_menu_create(wd, wd->more_item);
500              menu = elm_toolbar_item_menu_get(wd->more_item);
501
502              EINA_INLIST_FOREACH(wd->items, it)
503                {
504                   if (!it->prio.visible)
505                     {
506                        if (it->separator)
507                          elm_menu_item_separator_add(menu, NULL);
508                        else
509                          {
510                             Elm_Menu_Item *item;
511                             item = elm_menu_item_add(menu, NULL, it->icon_str, it->label,
512                                                      _elm_toolbar_item_menu_cb, it);
513                             elm_menu_item_disabled_set(item, it->disabled);
514                             if (it->o_menu) elm_menu_clone(it->o_menu, menu, item);
515                          }
516                        evas_object_hide(it->base.view);
517                     }
518                   else
519                     {
520                        evas_object_box_append(wd->bx, it->base.view);
521                        evas_object_show(it->base.view);
522                     }
523                }
524
525              evas_object_box_append(wd->bx, wd->more_item->base.view);
526              evas_object_show(wd->more_item->base.view);
527           }
528         else
529           {
530              /* All items are visible, show them all (except for the "More"
531               * button, of course). */
532              EINA_INLIST_FOREACH(wd->items, it)
533                {
534                   evas_object_show(it->base.view);
535                   evas_object_box_append(wd->bx, it->base.view);
536                }
537              evas_object_hide(wd->more_item->base.view);
538           }
539      }
540    else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
541      {
542         Evas_Coord iw = 0;
543
544         evas_object_resize(wd->bx, vw, h);
545         _fix_items_visibility(wd, &iw, vw);
546         evas_object_box_remove_all(wd->bx, EINA_FALSE);
547         if (iw > vw)
548           {
549              EINA_INLIST_FOREACH(wd->items, it)
550                {
551                   if (!it->prio.visible)
552                     evas_object_hide(it->base.view);
553                   else
554                     {
555                        evas_object_box_append(wd->bx, it->base.view);
556                        evas_object_show(it->base.view);
557                     }
558                }
559           }
560         else
561           {
562              /* All items are visible, show them all */
563              EINA_INLIST_FOREACH(wd->items, it)
564                {
565                   evas_object_show(it->base.view);
566                   evas_object_box_append(wd->bx, it->base.view);
567                }
568           }
569      }
570    else
571      {
572         if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
573         EINA_INLIST_FOREACH(wd->items, it)
574           {
575              if (it->selected)
576                {
577                   _item_show(it);
578                   break;
579                }
580           }
581      }
582
583    _mirrored_set(obj, elm_widget_mirrored_get(obj));
584 }
585
586 static void
587 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
588 {
589    _sizing_eval(data);
590    _resize(data, NULL, NULL, NULL);
591 }
592
593 static void
594 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
595 {
596    Widget_Data *wd = elm_widget_data_get(data);
597    if (!wd->resize_job)
598      wd->resize_job = ecore_job_add(_resize_job, data);
599 }
600
601 static void
602 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
603 {
604    _item_select(data);
605 }
606
607 static void
608 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
609 {
610    Elm_Toolbar_Item *it = data;
611    edje_object_signal_emit(it->base.view, "elm,state,highlighted", "elm");
612    elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
613 }
614
615 static void
616 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
617 {
618    Elm_Toolbar_Item *it = data;
619    edje_object_signal_emit(it->base.view, "elm,state,unhighlighted", "elm");
620    elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
621 }
622
623 static void
624 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
625 {
626    Evas_Object *obj = (Evas_Object *) data;
627    Widget_Data *wd = elm_widget_data_get(obj);
628    if (!wd) return;
629    _els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
630 }
631
632 static Elm_Toolbar_Item *
633 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
634 {
635    Widget_Data *wd = elm_widget_data_get(obj);
636    Evas_Object *icon_obj;
637    Evas_Coord mw, mh;
638    Elm_Toolbar_Item *it;
639
640    icon_obj = elm_icon_add(obj);
641    elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
642    if (!icon_obj) return NULL;
643    it = elm_widget_item_new(obj, Elm_Toolbar_Item);
644    if (!it)
645      {
646         evas_object_del(icon_obj);
647         return NULL;
648      }
649    it->label = eina_stringshare_add(label);
650    it->prio.visible = 1;
651    it->prio.priority = 0;
652    it->func = func;
653    it->separator = EINA_FALSE;
654    it->base.data = data;
655    it->base.view = edje_object_add(evas_object_evas_get(obj));
656    if (_item_icon_set(icon_obj, "toolbar/", icon))
657      {
658         it->icon = icon_obj;
659         it->icon_str = eina_stringshare_add(icon);
660      }
661    else
662      {
663         it->icon = NULL;
664         it->icon_str = NULL;
665         evas_object_del(icon_obj);
666      }
667
668    _elm_theme_object_set(obj, it->base.view, "toolbar", "item",
669                          elm_widget_style_get(obj));
670    edje_object_signal_callback_add(it->base.view, "elm,action,click", "elm",
671                                    _select, it);
672    edje_object_signal_callback_add(it->base.view, "elm,mouse,in", "elm",
673                                    _mouse_in, it);
674    edje_object_signal_callback_add(it->base.view, "elm,mouse,out", "elm",
675                                    _mouse_out, it);
676    elm_widget_sub_object_add(obj, it->base.view);
677    if (it->icon)
678      {
679         int ms = 0;
680
681         ms = ((double)wd->icon_size * _elm_config->scale);
682         evas_object_size_hint_min_set(it->icon, ms, ms);
683         evas_object_size_hint_max_set(it->icon, ms, ms);
684         edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
685         evas_object_show(it->icon);
686         elm_widget_sub_object_add(obj, it->icon);
687      }
688    edje_object_part_text_set(it->base.view, "elm.text", it->label);
689    mw = mh = -1;
690    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
691    edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
692    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
693    evas_object_size_hint_weight_set(it->base.view, -1.0, EVAS_HINT_EXPAND);
694    evas_object_size_hint_align_set(it->base.view, 0.5, EVAS_HINT_FILL);
695    evas_object_size_hint_min_set(it->base.view, mw, mh);
696    evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
697                                   _resize_item, obj);
698    return it;
699 }
700
701 /**
702  * Add a toolbar object to @p parent.
703  *
704  * @param parent The parent object
705  *
706  * @return The created object, or NULL on failure
707  *
708  * @ingroup Toolbar
709  */
710 EAPI Evas_Object *
711 elm_toolbar_add(Evas_Object *parent)
712 {
713    Evas_Object *obj;
714    Evas *e;
715    Widget_Data *wd;
716
717    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
718
719    ELM_SET_WIDTYPE(widtype, "toolbar");
720    elm_widget_type_set(obj, "toolbar");
721    elm_widget_sub_object_add(parent, obj);
722    elm_widget_data_set(obj, wd);
723    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
724    elm_widget_del_hook_set(obj, _del_hook);
725    elm_widget_theme_hook_set(obj, _theme_hook);
726    elm_widget_can_focus_set(obj, EINA_FALSE);
727
728    wd->more_item = NULL;
729    wd->selected_item = NULL;
730    wd->scr = elm_smart_scroller_add(e);
731    elm_smart_scroller_widget_set(wd->scr, obj);
732    elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
733    elm_smart_scroller_bounce_allow_set(wd->scr,
734                                        _elm_config->thumbscroll_bounce_enable,
735                                        EINA_FALSE);
736    elm_widget_resize_object_set(obj, wd->scr);
737    elm_smart_scroller_policy_set(wd->scr,
738                                  ELM_SMART_SCROLLER_POLICY_AUTO,
739                                  ELM_SMART_SCROLLER_POLICY_OFF);
740
741
742    wd->icon_size = _elm_toolbar_icon_size_get(wd);
743
744
745    wd->homogeneous = EINA_TRUE;
746    wd->align = 0.5;
747
748    wd->bx = evas_object_box_add(e);
749    evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
750    evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
751    elm_widget_sub_object_add(obj, wd->bx);
752    elm_smart_scroller_child_set(wd->scr, wd->bx);
753    evas_object_show(wd->bx);
754
755    elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
756    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
757    evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
758    elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
759
760    evas_object_smart_callbacks_descriptions_set(obj, _signals);
761
762    _sizing_eval(obj);
763    return obj;
764 }
765
766 /**
767  * Set the icon size (in pixels) for the toolbar.
768  *
769  * @param obj The toolbar object
770  * @param icon_size The icon size in pixels
771  *
772  * @ingroup Toolbar
773  */
774 EAPI void
775 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
776 {
777    ELM_CHECK_WIDTYPE(obj, widtype);
778    Widget_Data *wd = elm_widget_data_get(obj);
779    if (!wd) return;
780    if (wd->icon_size == icon_size) return;
781    wd->icon_size = icon_size;
782    _theme_hook(obj);
783 }
784
785 /**
786  * Get the icon size (in pixels) for the toolbar.
787  *
788  * @param obj The toolbar object
789  * @return The icon size in pixels
790  *
791  * @ingroup Toolbar
792  */
793 EAPI int
794 elm_toolbar_icon_size_get(const Evas_Object *obj)
795 {
796    ELM_CHECK_WIDTYPE(obj, widtype) 0;
797    Widget_Data *wd = elm_widget_data_get(obj);
798    if (!wd) return 0;
799    return wd->icon_size;
800 }
801
802 /**
803  * Append item to the toolbar
804  *
805  * @param obj The toolbar object
806  * @param icon A string with icon name or the absolute path of an image file.
807  * @param label The label of the item
808  * @param func The function to call when the item is clicked
809  * @param data The data to associate with the item
810  * @return The toolbar item, or NULL upon failure
811  *
812  * @see elm_toolbar_item_icon_set
813  *
814  * @ingroup Toolbar
815  */
816 EAPI Elm_Toolbar_Item *
817 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
818 {
819    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
820    Widget_Data *wd = elm_widget_data_get(obj);
821    if (!wd) return NULL;
822
823    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
824    if (!it) return NULL;
825
826    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
827    evas_object_box_append(wd->bx, it->base.view);
828    evas_object_show(it->base.view);
829    _sizing_eval(obj);
830
831    return it;
832 }
833
834 static void
835 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
836 {
837    Elm_Toolbar_Item *it = event_info;
838    Elm_Toolbar_Item_State *it_state;
839
840    it_state = eina_list_data_get(it->current_state);
841    if (it_state->func)
842      it_state->func((void *)it_state->data, obj, event_info);
843 }
844
845 /**
846  * Sets the next @p item state as the current state.
847  *
848  * @param item The item.
849  *
850  * @ingroup Toolbar
851  */
852 EAPI Elm_Toolbar_Item_State *
853 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
854 {
855    Widget_Data *wd;
856    Evas_Object *obj;
857    Eina_List *next_state;
858    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
859
860    obj = item->base.widget;
861    wd = elm_widget_data_get(obj);
862    if (!wd) return NULL;
863    if (!item->states) return NULL;
864
865    next_state = eina_list_next(item->current_state);
866    if (!next_state)
867      next_state = eina_list_next(item->states);
868    return eina_list_data_get(next_state);
869 }
870
871 /**
872  * Sets the previous @p item state as the current state.
873  *
874  * @param item The item.
875  *
876  * @ingroup Toolbar
877  */
878 EAPI Elm_Toolbar_Item_State *
879 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
880 {
881    Widget_Data *wd;
882    Evas_Object *obj;
883    Eina_List *prev_state;
884    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
885
886    obj = item->base.widget;
887    wd = elm_widget_data_get(obj);
888    if (!wd) return NULL;
889    if (!item->states) return NULL;
890
891    prev_state = eina_list_prev(item->current_state);
892    if ((!prev_state) || (prev_state == item->states))
893      prev_state = eina_list_last(item->states);
894    return eina_list_data_get(prev_state);
895 }
896
897 /**
898  * Unset the state of @p it
899  * The default icon and label from this item will be displayed.
900  *
901  * @param it The item.
902  *
903  * @ingroup Toolbar
904  */
905 EAPI void
906 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
907 {
908    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
909    elm_toolbar_item_state_set(it, NULL);
910 }
911
912 /**
913  * Sets @p state as the current state of @p it.
914  * If @p state is NULL, it won't select any state and the default icon and
915  * label will be used.
916  *
917  * @param it The item.
918  * @param state The state to use.
919  *
920  * @return True if the state was correctly set.
921  *
922  * @ingroup Toolbar
923  */
924 EAPI Eina_Bool
925 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
926 {
927    Widget_Data *wd;
928    Eina_List *next_state;
929    Elm_Toolbar_Item_State *it_state;
930    Evas_Object *obj;
931    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
932
933    obj = it->base.widget;
934    wd = elm_widget_data_get(obj);
935    if (!wd) return EINA_FALSE;
936    if (!it->states) return EINA_FALSE;
937
938    if (state)
939      {
940         next_state = eina_list_data_find_list(it->states, state);
941         if (!next_state) return EINA_FALSE;
942      }
943    else
944      next_state = it->states;
945
946    if (next_state == it->current_state) return EINA_TRUE;
947
948    it_state = eina_list_data_get(next_state);
949    if (eina_list_data_find(it->current_state, state))
950      {
951         _item_label_set(it, it_state->label, "elm,state,label_set,forward");
952         _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
953                                        wd->icon_size, "elm,state,icon_set,forward");
954      }
955    else
956      {
957         _item_label_set(it, it_state->label, "elm,state,label_set,backward");
958         _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
959                                        wd->icon_size, "elm,state,icon_set,backward");
960      }
961    if (it->disabled)
962      elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
963    else
964      elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
965
966    it->current_state = next_state;
967    return EINA_TRUE;
968 }
969
970 /**
971  * Get the current state of @p item.
972  * If no state is selected, returns NULL.
973  *
974  * @param item The item.
975  *
976  * @return The state.
977  *
978  * @ingroup Toolbar
979  */
980 EAPI Elm_Toolbar_Item_State *
981 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
982 {
983    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
984    if ((!it->states) || (!it->current_state)) return NULL;
985    if (it->current_state == it->states) return NULL;
986
987    return eina_list_data_get(it->current_state);
988 }
989
990 static Elm_Toolbar_Item_State *
991 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
992 {
993    Elm_Toolbar_Item_State *it_state;
994    it_state = ELM_NEW(Elm_Toolbar_Item_State);
995    it_state->label = eina_stringshare_add(label);
996    it_state->icon_str = eina_stringshare_add(icon_str);
997    it_state->icon = icon;
998    it_state->func = func;
999    it_state->data = data;
1000    return it_state;
1001 }
1002
1003 /**
1004  * Add a new state to @p item
1005  *
1006  * @param item The item.
1007  * @param icon The icon string
1008  * @param label The label of the new state
1009  * @param func The function to call when the item is clicked when this state is
1010  * selected.
1011  * @param data The data to associate with the state
1012  * @return The toolbar item state, or NULL upon failure
1013  *
1014  * @ingroup Toolbar
1015  */
1016 EAPI Elm_Toolbar_Item_State *
1017 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1018 {
1019    Elm_Toolbar_Item_State *it_state;
1020    Evas_Object *icon_obj;
1021    Evas_Object *obj;
1022    Widget_Data *wd;
1023    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1024    obj = item->base.widget;
1025    wd = elm_widget_data_get(item->base.widget);
1026    if (!wd) return NULL;
1027
1028    if (!item->states)
1029      {
1030         it_state = _item_state_new(item->label, item->icon_str, item->icon,
1031                                    item->func, item->base.data);
1032         item->states = eina_list_append(item->states, it_state);
1033         item->current_state = item->states;
1034      }
1035
1036    icon_obj = elm_icon_add(obj);
1037    elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1038    if (!icon_obj) goto error_state_add;
1039
1040    if (!_item_icon_set(icon_obj, "toolbar/", icon))
1041      {
1042         evas_object_del(icon_obj);
1043         icon_obj = NULL;
1044         icon = NULL;
1045      }
1046
1047    it_state = _item_state_new(label, icon, icon_obj, func, data);
1048    item->states = eina_list_append(item->states, it_state);
1049    item->func = _elm_toolbar_item_state_cb;
1050    item->base.data = NULL;
1051
1052    return it_state;
1053
1054 error_state_add:
1055    if (item->states && !eina_list_next(item->states))
1056      {
1057         eina_stringshare_del(item->label);
1058         eina_stringshare_del(item->icon_str);
1059         free(eina_list_data_get(item->states));
1060         eina_list_free(item->states);
1061         item->states = NULL;
1062      }
1063    return NULL;
1064 }
1065
1066 EAPI Eina_Bool
1067 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1068 {
1069    Eina_List *del_state;
1070    Elm_Toolbar_Item_State *it_state;
1071    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1072
1073    if (!state) return EINA_FALSE;
1074    if (!item->states) return EINA_FALSE;
1075
1076    del_state = eina_list_data_find_list(item->states, state);
1077    if (del_state == item->states) return EINA_FALSE;
1078    if (del_state == item->current_state)
1079      elm_toolbar_item_state_unset(item);
1080
1081    eina_stringshare_del(state->label);
1082    eina_stringshare_del(state->icon_str);
1083    if (state->icon) evas_object_del(state->icon);
1084    free(state);
1085    item->states = eina_list_remove_list(item->states, del_state);
1086    if (item->states && !eina_list_next(item->states))
1087      {
1088         it_state = eina_list_data_get(item->states);
1089         item->base.data = it_state->data;
1090         item->func = it_state->func;
1091         eina_stringshare_del(it_state->label);
1092         eina_stringshare_del(it_state->icon_str);
1093         free(eina_list_data_get(item->states));
1094         eina_list_free(item->states);
1095         item->states = NULL;
1096      }
1097    return EINA_TRUE;
1098 }
1099
1100
1101 /**
1102  * Prepend item to the toolbar
1103  *
1104  * @param obj The toolbar object
1105  * @param icon A string with icon name or the absolute path of an image file.
1106  * @param label The label of the item
1107  * @param func The function to call when the item is clicked
1108  * @param data The data to associate with the item
1109  * @return The toolbar item, or NULL upon failure
1110  *
1111  * @see elm_toolbar_item_icon_set
1112  *
1113  * @ingroup Toolbar
1114  */
1115 EAPI Elm_Toolbar_Item *
1116 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1117 {
1118    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1119    Widget_Data *wd = elm_widget_data_get(obj);
1120    if (!wd) return NULL;
1121
1122    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1123    if (!it) return NULL;
1124
1125    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1126    evas_object_box_prepend(wd->bx, it->base.view);
1127    evas_object_show(it->base.view);
1128    _sizing_eval(obj);
1129
1130    return it;
1131 }
1132
1133 /**
1134  * Insert item before another in the toolbar
1135  *
1136  * @param obj The toolbar object
1137  * @param before The item to insert before
1138  * @param icon A string with icon name or the absolute path of an image file.
1139  * @param label The label of the item
1140  * @param func The function to call when the item is clicked
1141  * @param data The data to associate with the item
1142  * @return The toolbar item, or NULL upon failure
1143  *
1144  * @see elm_toolbar_item_icon_set
1145  *
1146  * @ingroup Toolbar
1147  */
1148 EAPI Elm_Toolbar_Item *
1149 elm_toolbar_item_insert_before(Evas_Object *obj, Elm_Toolbar_Item *before, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1150 {
1151    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1152    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1153    Widget_Data *wd = elm_widget_data_get(obj);
1154    if (!wd) return NULL;
1155
1156    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1157    if (!it) return NULL;
1158
1159    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1160                                             EINA_INLIST_GET(before));
1161    evas_object_box_insert_before(wd->bx, it->base.view, before->base.view);
1162    evas_object_show(it->base.view);
1163    _sizing_eval(obj);
1164
1165    return it;
1166 }
1167
1168 /**
1169  * Insert item after another in the toolbar
1170  *
1171  * @param obj The toolbar object
1172  * @param after The item to insert after
1173  * @param icon A string with icon name or the absolute path of an image file.
1174  * @param label The label of the item
1175  * @param func The function to call when the item is clicked
1176  * @param data The data to associate with the item
1177  * @return The toolbar item, or NULL upon failure
1178  *
1179  * @see elm_toolbar_item_icon_set
1180  *
1181  * @ingroup Toolbar
1182  */
1183 EAPI Elm_Toolbar_Item *
1184 elm_toolbar_item_insert_after(Evas_Object *obj, Elm_Toolbar_Item *after, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1185 {
1186    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1187    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1188    Widget_Data *wd = elm_widget_data_get(obj);
1189    if (!wd) return NULL;
1190
1191    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1192    if (!it) return NULL;
1193
1194    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1195                                            EINA_INLIST_GET(after));
1196    evas_object_box_insert_after(wd->bx, it->base.view, after->base.view);
1197    evas_object_show(it->base.view);
1198    _sizing_eval(obj);
1199
1200    return it;
1201 }
1202
1203 /**
1204  * Get the first item in the toolbar
1205  *
1206  * @param obj The toolbar object
1207  * @return The first item, or NULL if none
1208  *
1209  * @ingroup Toolbar
1210  */
1211 EAPI Elm_Toolbar_Item *
1212 elm_toolbar_first_item_get(const Evas_Object *obj)
1213 {
1214    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1215    Widget_Data *wd = elm_widget_data_get(obj);
1216    if (!wd || !wd->items) return NULL;
1217    Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1218    return it;
1219 }
1220
1221 /**
1222  * Get the last item in the toolbar
1223  *
1224  * @return The last item, or NULL if none
1225  *
1226  * @ingroup Toolbar
1227  */
1228 EAPI Elm_Toolbar_Item *
1229 elm_toolbar_last_item_get(const Evas_Object *obj)
1230 {
1231    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232    Widget_Data *wd = elm_widget_data_get(obj);
1233    if (!wd || !wd->items) return NULL;
1234    Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1235    return it;
1236 }
1237
1238 /**
1239  * Get the next item in the toolbar
1240  *
1241  * This returns the item after the item @p it.
1242  *
1243  * @param item The item
1244  * @return The item after @p it, or NULL if none
1245  *
1246  * @ingroup Toolbar
1247  */
1248 EAPI Elm_Toolbar_Item *
1249 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1250 {
1251    Elm_Toolbar_Item *next;
1252    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1253    next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1254    return next;
1255 }
1256
1257 /**
1258  * Get the previous item in the toolbar
1259  *
1260  * This returns the item before the item @p it.
1261  *
1262  * @param item The item
1263  * @return The item before @p it, or NULL if none
1264  *
1265  * @ingroup Toolbar
1266  */
1267 EAPI Elm_Toolbar_Item *
1268 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1269 {
1270    Elm_Toolbar_Item *prev;
1271    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1272    prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1273    return prev;
1274 }
1275
1276 /**
1277  * Get the toolbar object from an item
1278  *
1279  * This returns the toolbar object itself that an item belongs to.
1280  *
1281  * @param item The item
1282  * @return The toolbar object
1283  *
1284  * @ingroup Toolbar
1285  */
1286 EAPI Evas_Object *
1287 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1288 {
1289    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1290    return item->base.widget;
1291 }
1292
1293 /**
1294  * Sets the priority of a toolbar item. This is used only when the toolbar
1295  * shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
1296  * when space is at a premium, items with low priority will be removed from
1297  * the toolbar and added to a dynamically-created menu, while items with
1298  * higher priority will remain on the toolbar, with the same order they were
1299  * added.
1300  *
1301  * @param item The toolbar item.
1302  * @param priority The item priority. The default is zero.
1303  *
1304  * @ingroup Toolbar
1305  */
1306 EAPI void
1307 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1308 {
1309    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1310    if (item->prio.priority == priority) return;
1311    item->prio.priority = priority;
1312    _resize(item->base.widget, NULL, NULL, NULL);
1313 }
1314
1315 /**
1316  * Gets the priority of a toolbar item.
1317  *
1318  * @param item The toolbar item.
1319  * @return The item priority, or 0 if an error occurred.
1320  *
1321  * @ingroup Toolbar
1322  */
1323 EAPI int
1324 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1325 {
1326    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1327    return item->prio.priority;
1328 }
1329
1330 /**
1331  * Get the string used to set the icon of @p item.
1332  *
1333  * @param item The toolbar item
1334  * @return The string associated with the icon object.
1335  *
1336  * @see elm_toolbar_item_icon_set()
1337  *
1338  * @ingroup Toolbar
1339  */
1340 EAPI const char *
1341 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1342 {
1343    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1344    return item->icon_str;
1345 }
1346
1347 /**
1348  * Get the label associated with @p item.
1349  *
1350  * @param item The toolbar item
1351  * @return The label
1352  *
1353  * @ingroup Toolbar
1354  */
1355 EAPI const char *
1356 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1357 {
1358    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1359    return item->label;
1360 }
1361
1362 static void
1363 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1364 {
1365    Evas_Coord mw = -1, mh = -1;
1366    edje_object_part_text_set(item->base.view, "elm.text", item->label);
1367
1368    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1369    edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1370    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1371    evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1372    evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1373    evas_object_size_hint_min_set(item->base.view, mw, mh);
1374 }
1375
1376 static void
1377 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1378 {
1379    Elm_Toolbar_Item *item = data;
1380    _elm_toolbar_item_label_update(item);
1381    edje_object_signal_callback_del(obj, emission, source,
1382                                    _elm_toolbar_item_label_set_cb);
1383    edje_object_signal_emit (item->base.view, "elm,state,label,reset", "elm");
1384 }
1385
1386 static void
1387 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1388 {
1389    const char *s;
1390
1391    if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1392
1393    eina_stringshare_replace(&item->label, label);
1394    s = edje_object_data_get(item->base.view, "transition_animation_on");
1395    if ((s) && (atoi(s)))
1396      {
1397         edje_object_part_text_set(item->base.view, "elm.text_new", item->label);
1398         edje_object_signal_emit (item->base.view, signal, "elm");
1399         edje_object_signal_callback_add(item->base.view,
1400                                         "elm,state,label_set,done", "elm",
1401                                         _elm_toolbar_item_label_set_cb, item);
1402      }
1403    else
1404      _elm_toolbar_item_label_update(item);
1405    _resize(item->base.widget, NULL, NULL, NULL);
1406 }
1407
1408 /**
1409  * Set the label associated with @p item.
1410  *
1411  * @param item The toolbar item
1412  * @param label The label of @p item
1413  *
1414  * @ingroup Toolbar
1415  */
1416 EAPI void
1417 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1418 {
1419    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1420    _item_label_set(item, label, "elm,state,label_set");
1421 }
1422
1423 static void
1424 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1425 {
1426    Elm_Toolbar_Item_State *it_state;
1427    Eina_List *l;
1428    Evas_Coord mw = -1, mh = -1;
1429    Evas_Object *old_icon = edje_object_part_swallow_get(item->base.view,
1430                                                         "elm.swallow.icon");
1431    elm_widget_sub_object_del(item->base.view, old_icon);
1432    evas_object_hide(old_icon);
1433    edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1434    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1435    edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1436    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1437    evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1438    evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1439    evas_object_size_hint_min_set(item->base.view, mw, mh);
1440
1441    EINA_LIST_FOREACH(item->states, l, it_state)
1442       if (it_state->icon == old_icon)
1443         return;
1444    evas_object_del(old_icon);
1445 }
1446
1447 /**
1448  * Get the selected state of @p item.
1449  *
1450  * @param item The toolbar item
1451  * @return If true, the item is selected
1452  *
1453  * @ingroup Toolbar
1454  */
1455 EAPI Eina_Bool
1456 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1457 {
1458    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1459    return item->selected;
1460 }
1461
1462 /**
1463  * Set the selected state of an item
1464  *
1465  * This sets the selected state (1 selected, 0 not selected) of the given
1466  * item @p it. If a new item is selected the previosly selected will be
1467  * unselected.
1468  *
1469  * @param item The item
1470  * @param selected The selected state
1471  *
1472  * @ingroup Toolbar
1473  */
1474 EAPI void
1475 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1476 {
1477    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1478    Widget_Data *wd = elm_widget_data_get(item->base.widget);
1479    if (!wd) return;
1480
1481    if (item->selected == selected) return;
1482
1483    if (selected)
1484      _item_select(item);
1485    else
1486      _item_unselect(item);
1487 }
1488
1489 /**
1490  * Get the selectd item in the toolbar
1491  *
1492  * If no item is selected, NULL is returned.
1493  *
1494  * @param obj The toolbar object
1495  * @return The selected item, or NULL if none.
1496  *
1497  * @ingroup Toolbar
1498  */
1499 EAPI Elm_Toolbar_Item *
1500 elm_toolbar_selected_item_get(const Evas_Object *obj)
1501 {
1502    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1503    Widget_Data *wd = elm_widget_data_get(obj);
1504    if (!wd) return NULL;
1505    return wd->selected_item;
1506 }
1507
1508 static void
1509 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1510 {
1511    Elm_Toolbar_Item *item = data;
1512    edje_object_part_unswallow(item->base.view, item->icon);
1513    _elm_toolbar_item_icon_update(item);
1514    edje_object_signal_callback_del(obj, emission, source,
1515                                    _elm_toolbar_item_icon_set_cb);
1516    edje_object_signal_emit (item->base.view, "elm,state,icon,reset", "elm");
1517 }
1518
1519 static void
1520 _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal)
1521 {
1522    Evas_Object *old_icon;
1523    int ms = 0;
1524    const char *s;
1525
1526    if (icon_str)
1527      eina_stringshare_replace(&item->icon_str, icon_str);
1528    else
1529      {
1530         eina_stringshare_del(item->icon_str);
1531         item->icon_str = NULL;
1532      }
1533    item->icon = icon_obj;
1534    if (icon_obj)
1535      {
1536         ms = (icon_size * _elm_config->scale);
1537         evas_object_size_hint_min_set(item->icon, ms, ms);
1538         evas_object_size_hint_max_set(item->icon, ms, ms);
1539         evas_object_show(item->icon);
1540         elm_widget_sub_object_add(obj, item->icon);
1541      }
1542    s = edje_object_data_get(item->base.view, "transition_animation_on");
1543    if ((s) && (atoi(s)))
1544      {
1545         old_icon = edje_object_part_swallow_get(item->base.view,
1546                                                 "elm.swallow.icon_new");
1547         if (old_icon)
1548           {
1549              elm_widget_sub_object_del(item->base.view, old_icon);
1550              evas_object_hide(old_icon);
1551           }
1552         edje_object_part_swallow(item->base.view, "elm.swallow.icon_new",
1553                                  item->icon);
1554         edje_object_signal_emit (item->base.view, signal, "elm");
1555         edje_object_signal_callback_add(item->base.view,
1556                                         "elm,state,icon_set,done", "elm",
1557                                         _elm_toolbar_item_icon_set_cb, item);
1558      }
1559    else
1560      _elm_toolbar_item_icon_update(item);
1561    _resize(obj, NULL, NULL, NULL);
1562 }
1563
1564 /**
1565  * Set the icon associated with @p item.
1566  *
1567  * Toolbar will load icon image from fdo or current theme.
1568  * This behavior can be set by elm_toolbar_icon_order_lookup_set() function.
1569  * If an absolute path is provided it will load it direct from a file.
1570  *
1571  * @param obj The parent of this item
1572  * @param item The toolbar item
1573  * @param icon A string with icon name or the absolute path of an image file.
1574  *
1575  * @see elm_toolbar_icon_order_lookup_set(), elm_toolbar_icon_order_lookup_get()
1576  *
1577  * @ingroup Toolbar
1578  */
1579 EAPI void
1580 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1581 {
1582    Evas_Object *icon_obj;
1583    Widget_Data *wd;
1584    Evas_Object *obj = item->base.widget;
1585
1586    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1587    wd = elm_widget_data_get(obj);
1588    if (!wd) return;
1589    if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1590
1591    icon_obj = elm_icon_add(obj);
1592    if (!icon_obj) return;
1593    if (_item_icon_set(icon_obj, "toolbar/", icon))
1594      _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1595                                     "elm,state,icon_set");
1596    else
1597      {
1598         _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1599                                        "elm,state,icon_set");
1600         evas_object_del(icon_obj);
1601      }
1602 }
1603
1604 /**
1605  * Delete a toolbar item.
1606  *
1607  * @param item The toolbar item
1608  *
1609  * @ingroup Toolbar
1610  */
1611 EAPI void
1612 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1613 {
1614    Widget_Data *wd;
1615    Evas_Object *obj2;
1616
1617    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1618    wd = elm_widget_data_get(item->base.widget);
1619    if (!wd) return;
1620    obj2 = item->base.widget;
1621    wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1622    _item_del(item);
1623    _theme_hook(obj2);
1624 }
1625
1626 /**
1627  * Set the function called when a toolbar item is freed.
1628  *
1629  * @param item The item to set the callback on
1630  * @param func The function called
1631  *
1632  * @ingroup Toolbar
1633  */
1634 EAPI void
1635 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1636 {
1637    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1638    elm_widget_item_del_cb_set(item, func);
1639 }
1640
1641 /**
1642  * Get the disabled state of @p item.
1643  *
1644  * @param item The toolbar item
1645  * @return If true, the item is disabled
1646  *
1647  * @ingroup Toolbar
1648  */
1649 EAPI Eina_Bool
1650 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1651 {
1652    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1653    return item->disabled;
1654 }
1655
1656 /**
1657  * Set the disabled state of @p item.
1658  *
1659  * @param item The toolbar item
1660  * @param disabled If true, the item is disabled
1661  *
1662  * @ingroup Toolbar
1663  */
1664 EAPI void
1665 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1666 {
1667    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1668    _item_disable(item, disabled);
1669    _resize(item->base.widget, NULL, NULL, NULL);
1670 }
1671
1672 /**
1673  * Get the separator state of @p item.
1674  *
1675  * @param item The toolbar item
1676  * @param separator If true, the item is a separator
1677  *
1678  * @ingroup Toolbar
1679  */
1680 EAPI void
1681 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1682 {
1683    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1684    if (item->separator == separator) return;
1685    item->separator = separator;
1686    _theme_hook(item->base.view);
1687 }
1688
1689 /**
1690  * Set the separator state of @p item.
1691  *
1692  * @param item The toolbar item
1693  * @return If true, the item is a separator
1694  *
1695  * @ingroup Toolbar
1696  */
1697 EAPI Eina_Bool
1698 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1699 {
1700    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1701    return item->separator;
1702 }
1703
1704 /**
1705  * Set the shrink state of toolbar @p obj.
1706  *
1707  * @param obj The toolbar object
1708  * @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
1709  * but will enforce a minimun size so all the items will fit, won't scroll
1710  * and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
1711  * will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
1712  * pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
1713  *
1714  * @ingroup Toolbar
1715  */
1716 EAPI void
1717 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1718 {
1719    ELM_CHECK_WIDTYPE(obj, widtype);
1720    Widget_Data *wd = elm_widget_data_get(obj);
1721    Eina_Bool bounce;
1722
1723    if (!wd) return;
1724    wd->shrink_mode = shrink_mode;
1725    bounce = (_elm_config->thumbscroll_bounce_enable) &&
1726       (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1727    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1728
1729    if (wd->more_item)
1730      {
1731         _item_del(wd->more_item);
1732         wd->more_item = NULL;
1733      }
1734
1735    if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1736      {
1737         elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1738
1739         wd->more_item = _item_new(obj, "more_menu", "More",
1740                                   NULL, NULL);
1741      }
1742    else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1743      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1744                                    ELM_SMART_SCROLLER_POLICY_OFF);
1745    else
1746      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1747                                    ELM_SMART_SCROLLER_POLICY_OFF);
1748    _sizing_eval(obj);
1749 }
1750
1751 /**
1752  * Get the shrink mode of toolbar @p obj.
1753  *
1754  * @param obj The toolbar object
1755  * @return See elm_toolbar_mode_shrink_set.
1756  *
1757  * @ingroup Toolbar
1758  */
1759 EAPI Elm_Toolbar_Shrink_Mode
1760 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1761 {
1762    ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1763    Widget_Data *wd = elm_widget_data_get(obj);
1764
1765    if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1766    return wd->shrink_mode;
1767 }
1768
1769 /**
1770  * Set the homogenous mode of toolbar @p obj.
1771  *
1772  * @param obj The toolbar object
1773  * @param homogenous If true, the toolbar items will be uniform in size
1774  *
1775  * @ingroup Toolbar
1776  */
1777 EAPI void
1778 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1779 {
1780    ELM_CHECK_WIDTYPE(obj, widtype);
1781    Widget_Data *wd = elm_widget_data_get(obj);
1782
1783    if (!wd) return;
1784    wd->homogeneous = !!homogenous;
1785    evas_object_smart_calculate(wd->bx);
1786 }
1787
1788 /**
1789  * Get the homogenous mode of toolbar @p obj.
1790  *
1791  * @param obj The toolbar object
1792  * @return If true, the toolbar items are uniform in size
1793  *
1794  * @ingroup Toolbar
1795  */
1796 EAPI Eina_Bool
1797 elm_toolbar_homogenous_get(const Evas_Object *obj)
1798 {
1799    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1800    Widget_Data *wd = elm_widget_data_get(obj);
1801
1802    if (!wd) return EINA_FALSE;
1803    return wd->homogeneous;
1804 }
1805
1806 /**
1807  * Set the parent object of the toolbar menu
1808  *
1809  * @param obj The toolbar object
1810  * @param parent The parent of the menu object
1811  *
1812  * @ingroup Toolbar
1813  */
1814 EAPI void
1815 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1816 {
1817    Elm_Toolbar_Item *it;
1818    ELM_CHECK_WIDTYPE(obj, widtype);
1819    Widget_Data *wd = elm_widget_data_get(obj);
1820
1821    if (!wd) return;
1822    EINA_SAFETY_ON_NULL_RETURN(parent);
1823    wd->menu_parent = parent;
1824    EINA_INLIST_FOREACH(wd->items, it)
1825      {
1826         if (it->o_menu)
1827           elm_menu_parent_set(it->o_menu, wd->menu_parent);
1828      }
1829    if ((wd->more_item) && (wd->more_item->o_menu))
1830      elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1831 }
1832
1833 /**
1834  * Get the parent object of the toolbar menu
1835  *
1836  * @param obj The toolbar object
1837  * @return The parent of the menu object
1838  *
1839  * @ingroup Toolbar
1840  */
1841 EAPI Evas_Object *
1842 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1843 {
1844    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1845    Widget_Data *wd = elm_widget_data_get(obj);
1846
1847    if (!wd) return NULL;
1848    return wd->menu_parent;
1849 }
1850
1851 /**
1852  * Set the alignment of the items.
1853  *
1854  * @param obj The toolbar object
1855  * @param align The new alignment. (left) 0.0 ... 1.0 (right)
1856  *
1857  * @ingroup Toolbar
1858  */
1859 EAPI void
1860 elm_toolbar_align_set(Evas_Object *obj, double align)
1861 {
1862    ELM_CHECK_WIDTYPE(obj, widtype);
1863    Widget_Data *wd = elm_widget_data_get(obj);
1864
1865    if (!wd) return;
1866    if (wd->align != align)
1867      evas_object_size_hint_align_set(wd->bx, align, 0.5);
1868    wd->align = align;
1869 }
1870
1871 /**
1872  * Get the alignment of the items.
1873  *
1874  * @param obj The toolbar object
1875  * @return The alignment. (left) 0.0 ... 1.0 (right)
1876  *
1877  * @ingroup Toolbar
1878  */
1879 EAPI double
1880 elm_toolbar_align_get(const Evas_Object *obj)
1881 {
1882    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1883    Widget_Data *wd = elm_widget_data_get(obj);
1884
1885    if (!wd) return 0.0;
1886    return wd->align;
1887 }
1888
1889 /**
1890  * Set whether the toolbar item opens a menu.
1891  *
1892  * @param item The toolbar item
1893  * @param menu If true, @p item will open a menu when selected
1894  *
1895  * @ingroup Toolbar
1896  */
1897 EAPI void
1898 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1899 {
1900    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1901    Widget_Data *wd = elm_widget_data_get(item->base.widget);
1902    if (!wd) return;
1903
1904    if (item->menu == menu) return;
1905    item->menu = menu;
1906    if (menu) _item_menu_create(wd, item);
1907    else _item_menu_destroy(item);
1908 }
1909
1910 /**
1911  * Set the text to be shown in the toolbar item.
1912  *
1913  * @param item Target item
1914  * @param text The text to set in the content
1915  *
1916  * Setup the text as tooltip to object. The item can have only one tooltip,
1917  * so any previous tooltip data is removed.
1918  *
1919  * @ingroup Toolbar
1920  */
1921 EAPI void
1922 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1923 {
1924    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1925    elm_widget_item_tooltip_text_set(item, text);
1926 }
1927
1928 /**
1929  * Set the content to be shown in the tooltip item
1930  *
1931  * Setup the tooltip to item. The item can have only one tooltip,
1932  * so any previous tooltip data is removed. @p func(with @p data) will
1933  * be called every time that need show the tooltip and it should
1934  * return a valid Evas_Object. This object is then managed fully by
1935  * tooltip system and is deleted when the tooltip is gone.
1936  *
1937  * @param item the toolbar item being attached a tooltip.
1938  * @param func the function used to create the tooltip contents.
1939  * @param data what to provide to @a func as callback data/context.
1940  * @param del_cb called when data is not needed anymore, either when
1941  *        another callback replaces @func, the tooltip is unset with
1942  *        elm_toolbar_item_tooltip_unset() or the owner @a item
1943  *        dies. This callback receives as the first parameter the
1944  *        given @a data, and @c event_info is the item.
1945  *
1946  * @ingroup Toolbar
1947  */
1948 EAPI void
1949 elm_toolbar_item_tooltip_content_cb_set(Elm_Toolbar_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1950 {
1951    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1952    elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1953 }
1954
1955 /**
1956  * Unset tooltip from item
1957  *
1958  * @param item toolbar item to remove previously set tooltip.
1959  *
1960  * Remove tooltip from item. The callback provided as del_cb to
1961  * elm_toolbar_item_tooltip_content_cb_set() will be called to notify
1962  * it is not used anymore.
1963  *
1964  * @see elm_toolbar_item_tooltip_content_cb_set()
1965  *
1966  * @ingroup Toolbar
1967  */
1968 EAPI void
1969 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1970 {
1971    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1972    elm_widget_item_tooltip_unset(item);
1973 }
1974
1975 /**
1976  * Sets a different style for this item tooltip.
1977  *
1978  * @note before you set a style you should define a tooltip with
1979  *       elm_toolbar_item_tooltip_content_cb_set() or
1980  *       elm_toolbar_item_tooltip_text_set()
1981  *
1982  * @param item toolbar item with tooltip already set.
1983  * @param style the theme style to use (default, transparent, ...)
1984  *
1985  * @ingroup Toolbar
1986  */
1987 EAPI void
1988 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
1989 {
1990    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1991    elm_widget_item_tooltip_style_set(item, style);
1992 }
1993
1994 /**
1995  * Get the style for this item tooltip.
1996  *
1997  * @param item toolbar item with tooltip already set.
1998  * @return style the theme style in use, defaults to "default". If the
1999  *         object does not have a tooltip set, then NULL is returned.
2000  *
2001  * @ingroup Toolbar
2002  */
2003 EAPI const char *
2004 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
2005 {
2006    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2007    return elm_widget_item_tooltip_style_get(item);
2008 }
2009
2010 /**
2011  * Set the cursor to be shown when mouse is over the toolbar item
2012  *
2013  * @param item Target item
2014  * @param cursor the cursor name to be used.
2015  *
2016  * @see elm_object_cursor_set()
2017  * @ingroup Toolbar
2018  */
2019 EAPI void
2020 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
2021 {
2022    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2023    elm_widget_item_cursor_set(item, cursor);
2024 }
2025
2026 /**
2027  * Get the cursor to be shown when mouse is over the toolbar item
2028  *
2029  * @param item toolbar item with cursor already set.
2030  * @return the cursor name.
2031  *
2032  * @ingroup Toolbar
2033  */
2034 EAPI const char *
2035 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
2036 {
2037    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2038    return elm_widget_item_cursor_get(item);
2039 }
2040
2041 /**
2042  * Unset the cursor to be shown when mouse is over the toolbar item
2043  *
2044  * @param item Target item
2045  *
2046  * @see elm_object_cursor_unset()
2047  * @ingroup Toolbar
2048  */
2049 EAPI void
2050 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
2051 {
2052    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2053    elm_widget_item_cursor_unset(item);
2054 }
2055
2056 /**
2057  * Sets a different style for this item cursor.
2058  *
2059  * @note before you set a style you should define a cursor with
2060  *       elm_toolbar_item_cursor_set()
2061  *
2062  * @param item toolbar item with cursor already set.
2063  * @param style the theme style to use (default, transparent, ...)
2064  *
2065  * @ingroup Toolbar
2066  */
2067 EAPI void
2068 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
2069 {
2070    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2071    elm_widget_item_cursor_style_set(item, style);
2072 }
2073
2074 /**
2075  * Get the style for this item cursor.
2076  *
2077  * @param item toolbar item with cursor already set.
2078  * @return style the theme style in use, defaults to "default". If the
2079  *         object does not have a cursor set, then NULL is returned.
2080  *
2081  * @ingroup Toolbar
2082  */
2083 EAPI const char *
2084 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
2085 {
2086    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2087    return elm_widget_item_cursor_style_get(item);
2088 }
2089
2090 /**
2091  * Set if the cursor set should be searched on the theme or should use
2092  * the provided by the engine, only.
2093  *
2094  * @note before you set if should look on theme you should define a cursor
2095  * with elm_object_cursor_set(). By default it will only look for cursors
2096  * provided by the engine.
2097  *
2098  * @param item widget item with cursor already set.
2099  * @param engine_only boolean to define it cursors should be looked only
2100  * between the provided by the engine or searched on widget's theme as well.
2101  *
2102  * @ingroup Toolbar
2103  */
2104 EAPI void
2105 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
2106 {
2107    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2108    elm_widget_item_cursor_engine_only_set(item, engine_only);
2109 }
2110
2111 /**
2112  * Get the cursor engine only usage for this item cursor.
2113  *
2114  * @param item widget item with cursor already set.
2115  * @return engine_only boolean to define it cursors should be looked only
2116  * between the provided by the engine or searched on widget's theme as well. If
2117  *         the object does not have a cursor set, then EINA_FALSE is returned.
2118  *
2119  * @ingroup Toolbar
2120  */
2121 EAPI Eina_Bool
2122 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
2123 {
2124    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2125    return elm_widget_item_cursor_engine_only_get(item);
2126 }
2127
2128 /**
2129  * Get whether the toolbar item opens a menu.
2130  *
2131  * @param item The toolbar item
2132  * @return If true, @p item opens a menu when selected
2133  *
2134  * @ingroup Toolbar
2135  */
2136 EAPI Evas_Object *
2137 elm_toolbar_item_menu_get(Elm_Toolbar_Item *item)
2138 {
2139    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2140    Widget_Data *wd = elm_widget_data_get(item->base.widget);
2141    if (!wd) return NULL;
2142    /* FIXME: It's not ok. This function needs to be reviewed. And should
2143     * receive a const item */
2144    elm_toolbar_item_menu_set(item, 1);
2145    return item->o_menu;
2146 }
2147
2148 /**
2149  * Returns a pointer to a toolbar item by its label
2150  *
2151  * @param obj The toolbar object
2152  * @param label The label of the item to find
2153  *
2154  * @return The pointer to the toolbar item matching @p label
2155  * Returns NULL on failure.
2156  *
2157  * @ingroup Toolbar
2158  */
2159 EAPI Elm_Toolbar_Item *
2160 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
2161 {
2162    Elm_Toolbar_Item *it;
2163    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2164    Widget_Data *wd = elm_widget_data_get(obj);
2165
2166    if (!wd) return NULL;
2167    EINA_INLIST_FOREACH(wd->items, it)
2168      {
2169         if (!strcmp(it->label, label)) return it;
2170      }
2171
2172    return NULL;
2173 }
2174
2175 /**
2176  * Set the data item from the toolbar item
2177  *
2178  * This set the data value passed on the elm_toolbar_item_append() and
2179  * related item addition calls.
2180  *
2181  * @param item The item
2182  * @param data The new data pointer to set
2183  *
2184  * @ingroup Toolbar
2185  */
2186 EAPI void
2187 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
2188 {
2189    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2190    elm_widget_item_data_set(item, data);
2191 }
2192
2193 /**
2194  * Get the data item from the toolbar item
2195  *
2196  * This returns the data value passed on the elm_toolbar_item_append() and
2197  * related item addition calls.
2198  *
2199  * @param item The item
2200  * @return The data pointer provided when created
2201  *
2202  * @ingroup Toolbar
2203  */
2204 EAPI void *
2205 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
2206 {
2207    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2208    return elm_widget_item_data_get(item);
2209 }
2210
2211 /**
2212  * Set no select mode.
2213  *
2214  * This will turn off the ability to select items entirely and they will
2215  * neither appear selected nor emit selected signals. The clicked
2216  * callback function will still be called.
2217  *
2218  * @param obj The Toolbar object
2219  * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2220  *
2221  * @ingroup Toolbar
2222  */
2223 EAPI void
2224 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2225 {
2226    ELM_CHECK_WIDTYPE(obj, widtype);
2227    Widget_Data *wd = elm_widget_data_get(obj);
2228    if (!wd) return;
2229    wd->no_select = no_select;
2230 }
2231
2232 /**
2233  * Gets no select mode.
2234  *
2235  * @param obj The Toolbar object
2236  * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2237  *
2238  * @ingroup Toolbar
2239  */
2240 EAPI Eina_Bool
2241 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2242 {
2243    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2244    Widget_Data *wd = elm_widget_data_get(obj);
2245    if (!wd) return EINA_FALSE;
2246    return wd->no_select;
2247 }
2248
2249 /**
2250  * Sets icon lookup order, for icons used in this toolbar.
2251  * Icons added before calling this function will not be affected.
2252  * The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.
2253  *
2254  * @param obj The toolbar object
2255  * @param order The icon lookup order
2256  *
2257  * @ingroup Toolbar
2258  */
2259 EAPI void
2260 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2261 {
2262    ELM_CHECK_WIDTYPE(obj, widtype);
2263    Elm_Toolbar_Item *it;
2264    Widget_Data *wd = elm_widget_data_get(obj);
2265    if (!wd) return;
2266
2267    wd->lookup_order = order;
2268    EINA_INLIST_FOREACH(wd->items, it)
2269       elm_icon_order_lookup_set(it->icon, order);
2270    if (wd->more_item)
2271      elm_icon_order_lookup_set(wd->more_item->icon, order);
2272 }
2273
2274 /**
2275  * Gets the icon lookup order.
2276  *
2277  * @param obj The Toolbar object
2278  * @return The icon lookup order
2279  *
2280  * @ingroup Toolbar
2281  */
2282 EAPI Elm_Icon_Lookup_Order
2283 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2284 {
2285    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2286    Widget_Data *wd = elm_widget_data_get(obj);
2287    if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2288    return wd->lookup_order;
2289 }