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