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