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