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