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