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