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