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