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