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