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