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