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