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