Delete the object, when the item is deleted.
[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 Evas_Object *
1430 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1431 {
1432    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1433    return elm_object_item_widget_get(it);
1434 }
1435
1436 EAPI void
1437 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1438 {
1439    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1440    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1441    if (item->prio.priority == priority) return;
1442    item->prio.priority = priority;
1443    _resize(WIDGET(item), NULL, NULL, NULL);
1444 }
1445
1446 EAPI int
1447 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1448 {
1449    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1450    return ((Elm_Toolbar_Item *)it)->prio.priority;
1451 }
1452
1453 EAPI const char *
1454 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1455 {
1456    return _item_text_get_hook(it, NULL);
1457 }
1458
1459 EAPI void
1460 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1461 {
1462    _item_text_set_hook(it, NULL, label);
1463 }
1464
1465 EAPI void *
1466 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1467 {
1468    return elm_object_item_data_get(it);
1469 }
1470
1471 EAPI void
1472 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1473 {
1474    elm_object_item_data_set(it, (void *) data);
1475 }
1476
1477 EAPI Elm_Object_Item *
1478 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1479 {
1480    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1481    Elm_Toolbar_Item *it;
1482    Widget_Data *wd = elm_widget_data_get(obj);
1483    if (!wd) return NULL;
1484
1485    EINA_INLIST_FOREACH(wd->items, it)
1486      {
1487         if (!strcmp(it->label, label))
1488           return (Elm_Object_Item *)it;
1489      }
1490    return NULL;
1491 }
1492
1493 EAPI void
1494 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1495 {
1496    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1497    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1498    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1499    if (!wd) return;
1500
1501    if (item->selected == selected) return;
1502    if (selected) _item_select(item);
1503    else _item_unselect(item);
1504 }
1505
1506 EAPI Eina_Bool
1507 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1508 {
1509    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1510    return ((Elm_Toolbar_Item *)it)->selected;
1511 }
1512
1513 EAPI Elm_Object_Item *
1514 elm_toolbar_selected_item_get(const Evas_Object *obj)
1515 {
1516    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1517    Widget_Data *wd = elm_widget_data_get(obj);
1518    if (!wd) return NULL;
1519    return (Elm_Object_Item *) wd->selected_item;
1520 }
1521
1522 EAPI void
1523 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1524 {
1525    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1526
1527    Evas_Object *icon_obj;
1528    Widget_Data *wd;
1529    Evas_Object *obj;
1530    Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1531
1532    obj = WIDGET(item);
1533    wd = elm_widget_data_get(obj);
1534    if (!wd) return;
1535    if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1536
1537    icon_obj = elm_icon_add(obj);
1538    if (!icon_obj) return;
1539    if (_item_icon_set(icon_obj, "toolbar/", icon))
1540      _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1541                                     "elm,state,icon_set");
1542    else
1543      {
1544         _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1545                                        "elm,state,icon_set");
1546         evas_object_del(icon_obj);
1547      }
1548 }
1549
1550 EAPI const char *
1551 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1552 {
1553    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1554    return ((Elm_Toolbar_Item *)it)->icon_str;
1555 }
1556
1557 EAPI Evas_Object *
1558 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1559 {
1560    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1561
1562    Widget_Data *wd;
1563    Evas_Object *obj;
1564    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1565
1566    obj = WIDGET(item);
1567    wd = elm_widget_data_get(obj);
1568    if (!wd) return NULL;
1569
1570    return VIEW(item);
1571 }
1572
1573 EAPI Evas_Object *
1574 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1575 {
1576    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1577    return ((Elm_Toolbar_Item *)it)->icon;
1578 }
1579
1580 EAPI Eina_Bool
1581 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1582 {
1583    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1584
1585    Evas_Object *icon_obj;
1586    Widget_Data *wd;
1587    Evas_Object *obj;
1588    Eina_Bool ret;
1589    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1590
1591    obj = WIDGET(item);
1592    wd = elm_widget_data_get(obj);
1593    if (!wd) return EINA_FALSE;
1594
1595    if (img && size)
1596      {
1597         icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1598         evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1599         ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1600         if (!ret)
1601           {
1602              evas_object_del(icon_obj);
1603              return EINA_FALSE;
1604           }
1605         _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1606                                          "elm,state,icon_set");
1607      }
1608    else
1609      _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1610    return EINA_TRUE;
1611 }
1612
1613 EAPI Eina_Bool
1614 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1615 {
1616    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1617
1618    Evas_Object *icon_obj;
1619    Widget_Data *wd;
1620    Evas_Object *obj;
1621    Eina_Bool ret;
1622    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1623
1624    obj = WIDGET(item);
1625    wd = elm_widget_data_get(obj);
1626    if (!wd) return EINA_FALSE;
1627
1628    if (file)
1629      {
1630         icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1631         evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1632         ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1633         if (!ret)
1634           {
1635              evas_object_del(icon_obj);
1636              return EINA_FALSE;
1637           }
1638         _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1639                                          "elm,state,icon_set");
1640      }
1641    else
1642      _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1643    return EINA_TRUE;
1644 }
1645
1646 EAPI void
1647 elm_toolbar_item_del(Elm_Object_Item *it)
1648 {
1649    elm_object_item_del(it);
1650 }
1651
1652 EAPI void
1653 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1654 {
1655    elm_object_item_del_cb_set(it, func);
1656 }
1657
1658 EAPI Eina_Bool
1659 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1660 {
1661    return elm_object_item_disabled_get(it);
1662 }
1663
1664 EAPI void
1665 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1666 {
1667    elm_object_item_disabled_set(it, disabled);
1668 }
1669
1670 EAPI void
1671 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1672 {
1673    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1674    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1675    Evas_Object *obj = WIDGET(item);
1676    Widget_Data *wd = elm_widget_data_get(obj);
1677    double scale;
1678    if (item->separator == separator) return;
1679    item->separator = separator;
1680    scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1681    _theme_hook_item(obj, item, scale, wd->icon_size);
1682 }
1683
1684 EAPI Eina_Bool
1685 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1686 {
1687    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1688    return ((Elm_Toolbar_Item *)it)->separator;
1689 }
1690
1691 EAPI void
1692 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1693 {
1694    ELM_CHECK_WIDTYPE(obj, widtype);
1695    Widget_Data *wd = elm_widget_data_get(obj);
1696    Eina_Bool bounce;
1697
1698    if (!wd) return;
1699    wd->shrink_mode = shrink_mode;
1700    bounce = (_elm_config->thumbscroll_bounce_enable) &&
1701       (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1702    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1703
1704    if (wd->more_item)
1705      {
1706         _item_del(wd->more_item);
1707         elm_widget_item_free(wd->more_item);
1708         wd->more_item = NULL;
1709      }
1710
1711    if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1712      {
1713         elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1714                                       ELM_SMART_SCROLLER_POLICY_OFF);
1715         wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1716      }
1717    else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1718      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1719                                    ELM_SMART_SCROLLER_POLICY_OFF);
1720    else
1721      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1722                                    ELM_SMART_SCROLLER_POLICY_OFF);
1723    _sizing_eval(obj);
1724 }
1725
1726 EAPI Elm_Toolbar_Shrink_Mode
1727 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1728 {
1729    ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1730    Widget_Data *wd = elm_widget_data_get(obj);
1731
1732    if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1733    return wd->shrink_mode;
1734 }
1735
1736 EAPI void
1737 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1738 {
1739    ELM_CHECK_WIDTYPE(obj, widtype);
1740    Widget_Data *wd = elm_widget_data_get(obj);
1741
1742    if (!wd) return;
1743    wd->homogeneous = !!homogeneous;
1744    evas_object_smart_calculate(wd->bx);
1745 }
1746
1747 EAPI Eina_Bool
1748 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1749 {
1750    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1751    Widget_Data *wd = elm_widget_data_get(obj);
1752
1753    if (!wd) return EINA_FALSE;
1754    return wd->homogeneous;
1755 }
1756
1757 EAPI void
1758 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1759 {
1760    Elm_Toolbar_Item *it;
1761    ELM_CHECK_WIDTYPE(obj, widtype);
1762    Widget_Data *wd = elm_widget_data_get(obj);
1763
1764    if (!wd) return;
1765    EINA_SAFETY_ON_NULL_RETURN(parent);
1766    wd->menu_parent = parent;
1767    EINA_INLIST_FOREACH(wd->items, it)
1768      {
1769         if (it->o_menu)
1770           elm_menu_parent_set(it->o_menu, wd->menu_parent);
1771      }
1772    if ((wd->more_item) && (wd->more_item->o_menu))
1773      elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1774 }
1775
1776 EAPI Evas_Object *
1777 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1778 {
1779    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1780    Widget_Data *wd = elm_widget_data_get(obj);
1781
1782    if (!wd) return NULL;
1783    return wd->menu_parent;
1784 }
1785
1786 EAPI void
1787 elm_toolbar_align_set(Evas_Object *obj, double align)
1788 {
1789    ELM_CHECK_WIDTYPE(obj, widtype);
1790    Widget_Data *wd = elm_widget_data_get(obj);
1791
1792    if (!wd) return;
1793    if (wd->vertical)
1794      {
1795         if (wd->align != align)
1796           evas_object_size_hint_align_set(wd->bx, 0.5, align);
1797      }
1798    else
1799      {
1800         if (wd->align != align)
1801           evas_object_size_hint_align_set(wd->bx, align, 0.5);
1802      }
1803    wd->align = align;
1804 }
1805
1806 EAPI double
1807 elm_toolbar_align_get(const Evas_Object *obj)
1808 {
1809    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1810    Widget_Data *wd = elm_widget_data_get(obj);
1811
1812    if (!wd) return 0.0;
1813    return wd->align;
1814 }
1815
1816 EAPI void
1817 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1818 {
1819    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1820    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1821    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1822    if (!wd) return;
1823
1824    if (item->menu == menu) return;
1825    if (menu) _item_menu_create(wd, item);
1826    else _item_menu_destroy(item);
1827 }
1828
1829 EAPI Evas_Object *
1830 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1831 {
1832    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1833    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1834    if (!item->menu) return NULL;
1835    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1836    if (!wd) return NULL;
1837    return item->o_menu;
1838 }
1839
1840 EAPI Elm_Toolbar_Item_State *
1841 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1842 {
1843    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1844
1845    Elm_Toolbar_Item_State *it_state;
1846    Evas_Object *icon_obj;
1847    Evas_Object *obj;
1848    Widget_Data *wd;
1849    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1850    obj = WIDGET(item);
1851    wd = elm_widget_data_get(WIDGET(item));
1852    if (!wd) return NULL;
1853
1854    if (!item->states)
1855      {
1856         it_state = _item_state_new(item->label, item->icon_str, item->icon,
1857                                    item->func, item->base.data);
1858         item->states = eina_list_append(item->states, it_state);
1859         item->current_state = item->states;
1860      }
1861
1862    icon_obj = elm_icon_add(obj);
1863    elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1864    if (!icon_obj) goto error_state_add;
1865
1866    if (!_item_icon_set(icon_obj, "toolbar/", icon))
1867      {
1868         evas_object_del(icon_obj);
1869         icon_obj = NULL;
1870         icon = NULL;
1871      }
1872
1873    it_state = _item_state_new(label, icon, icon_obj, func, data);
1874    item->states = eina_list_append(item->states, it_state);
1875    item->func = _elm_toolbar_item_state_cb;
1876    item->base.data = NULL;
1877
1878    return it_state;
1879
1880 error_state_add:
1881    if (item->states && !eina_list_next(item->states))
1882      {
1883         eina_stringshare_del(item->label);
1884         eina_stringshare_del(item->icon_str);
1885         free(eina_list_data_get(item->states));
1886         eina_list_free(item->states);
1887         item->states = NULL;
1888      }
1889    return NULL;
1890 }
1891
1892 EAPI Eina_Bool
1893 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1894 {
1895    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1896
1897    Eina_List *del_state;
1898    Elm_Toolbar_Item_State *it_state;
1899    Elm_Toolbar_Item *item;
1900
1901    if (!state) return EINA_FALSE;
1902
1903    item = (Elm_Toolbar_Item *)it;
1904    if (!item->states) return EINA_FALSE;
1905
1906    del_state = eina_list_data_find_list(item->states, state);
1907    if (del_state == item->states) return EINA_FALSE;
1908    if (del_state == item->current_state)
1909      elm_toolbar_item_state_unset(it);
1910
1911    eina_stringshare_del(state->label);
1912    eina_stringshare_del(state->icon_str);
1913    if (state->icon) evas_object_del(state->icon);
1914    free(state);
1915    item->states = eina_list_remove_list(item->states, del_state);
1916    if (item->states && !eina_list_next(item->states))
1917      {
1918         it_state = eina_list_data_get(item->states);
1919         item->base.data = it_state->data;
1920         item->func = it_state->func;
1921         eina_stringshare_del(it_state->label);
1922         eina_stringshare_del(it_state->icon_str);
1923         free(eina_list_data_get(item->states));
1924         eina_list_free(item->states);
1925         item->states = NULL;
1926      }
1927    return EINA_TRUE;
1928 }
1929
1930 EAPI Eina_Bool
1931 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1932 {
1933    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1934
1935    Widget_Data *wd;
1936    Eina_List *next_state;
1937    Elm_Toolbar_Item_State *it_state;
1938    Evas_Object *obj;
1939    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1940
1941    obj = WIDGET(item);
1942    wd = elm_widget_data_get(obj);
1943    if (!wd) return EINA_FALSE;
1944    if (!item->states) return EINA_FALSE;
1945
1946    if (state)
1947      {
1948         next_state = eina_list_data_find_list(item->states, state);
1949         if (!next_state) return EINA_FALSE;
1950      }
1951    else
1952      next_state = item->states;
1953
1954    if (next_state == item->current_state) return EINA_TRUE;
1955
1956    it_state = eina_list_data_get(next_state);
1957    if (eina_list_data_find(item->current_state, state))
1958      {
1959         _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1960         _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1961                                        wd->icon_size, "elm,state,icon_set,forward");
1962      }
1963    else
1964      {
1965         _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1966         _elm_toolbar_item_icon_obj_set(obj,
1967                                        item,
1968                                        it_state->icon,
1969                                        it_state->icon_str,
1970                                        wd->icon_size,
1971                                        "elm,state,icon_set,backward");
1972      }
1973    if (elm_widget_item_disabled_get(item))
1974      elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1975    else
1976      elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1977
1978    item->current_state = next_state;
1979    return EINA_TRUE;
1980 }
1981
1982 EAPI void
1983 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1984 {
1985    elm_toolbar_item_state_set(it, NULL);
1986 }
1987
1988 EAPI Elm_Toolbar_Item_State *
1989 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1990 {
1991    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1992    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1993
1994    if ((!item->states) || (!item->current_state)) return NULL;
1995    if (item->current_state == item->states) return NULL;
1996
1997    return eina_list_data_get(item->current_state);
1998 }
1999
2000 EAPI Elm_Toolbar_Item_State *
2001 elm_toolbar_item_state_next(Elm_Object_Item *it)
2002 {
2003    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2004
2005    Widget_Data *wd;
2006    Evas_Object *obj;
2007    Eina_List *next_state;
2008    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2009
2010    obj = WIDGET(item);
2011    wd = elm_widget_data_get(obj);
2012    if (!wd) return NULL;
2013    if (!item->states) return NULL;
2014
2015    next_state = eina_list_next(item->current_state);
2016    if (!next_state)
2017      next_state = eina_list_next(item->states);
2018    return eina_list_data_get(next_state);
2019 }
2020
2021 EAPI Elm_Toolbar_Item_State *
2022 elm_toolbar_item_state_prev(Elm_Object_Item *it)
2023 {
2024    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2025
2026    Widget_Data *wd;
2027    Evas_Object *obj;
2028    Eina_List *prev_state;
2029    Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2030
2031    obj = WIDGET(item);
2032    wd = elm_widget_data_get(obj);
2033    if (!wd) return NULL;
2034    if (!item->states) return NULL;
2035
2036    prev_state = eina_list_prev(item->current_state);
2037    if ((!prev_state) || (prev_state == item->states))
2038      prev_state = eina_list_last(item->states);
2039    return eina_list_data_get(prev_state);
2040 }
2041
2042 EAPI void
2043 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
2044 {
2045    elm_object_item_tooltip_text_set(it, text);
2046 }
2047
2048 EAPI void
2049 elm_toolbar_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
2050 {
2051    elm_object_item_tooltip_content_cb_set(it, func, data, del_cb);
2052 }
2053
2054 EAPI void
2055 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
2056 {
2057    elm_object_item_tooltip_unset(it);
2058 }
2059
2060 EAPI void
2061 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
2062 {
2063    elm_object_item_tooltip_style_set(it, style);
2064 }
2065
2066 EAPI const char *
2067 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
2068 {
2069    return elm_object_item_tooltip_style_get(it);
2070 }
2071
2072 EAPI void
2073 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
2074 {
2075    elm_object_item_cursor_set(it, cursor);
2076 }
2077
2078 EAPI const char *
2079 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
2080 {
2081    return elm_object_item_cursor_get(it);
2082 }
2083
2084 EAPI void
2085 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
2086 {
2087    elm_object_item_cursor_unset(it);
2088 }
2089
2090 EAPI void
2091 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
2092 {
2093    elm_object_item_cursor_style_set(it, style);
2094 }
2095
2096 EAPI const char *
2097 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
2098 {
2099    return elm_object_item_cursor_style_get(it);
2100 }
2101
2102 EAPI void
2103 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
2104 {
2105    elm_object_item_cursor_engine_only_set(it, engine_only);
2106 }
2107
2108 EAPI Eina_Bool
2109 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
2110 {
2111    return elm_object_item_cursor_engine_only_get(it);
2112 }
2113
2114 EINA_DEPRECATED EAPI void
2115 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
2116 {
2117    ELM_CHECK_WIDTYPE(obj, widtype);
2118    Widget_Data *wd = elm_widget_data_get(obj);
2119    if (!wd) return;
2120    if (always_select)
2121      elm_toolbar_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
2122    else
2123      {
2124         Elm_Object_Select_Mode oldmode = elm_toolbar_select_mode_get(obj);
2125         if (oldmode == ELM_OBJECT_SELECT_MODE_ALWAYS)
2126           elm_toolbar_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
2127      }
2128 }
2129
2130 EINA_DEPRECATED EAPI Eina_Bool
2131 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
2132 {
2133    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2134    Widget_Data *wd = elm_widget_data_get(obj);
2135    if (!wd) return EINA_FALSE;
2136    Elm_Object_Select_Mode oldmode = elm_toolbar_select_mode_get(obj);
2137    if (oldmode == ELM_OBJECT_SELECT_MODE_ALWAYS)
2138      return EINA_TRUE;
2139    else
2140      return EINA_FALSE;
2141 }
2142
2143 EINA_DEPRECATED EAPI void
2144 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2145 {
2146    ELM_CHECK_WIDTYPE(obj, widtype);
2147    Widget_Data *wd = elm_widget_data_get(obj);
2148    if (!wd) return;
2149    if (no_select)
2150      elm_toolbar_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_NONE);
2151    else
2152      {
2153         Elm_Object_Select_Mode oldmode = elm_toolbar_select_mode_get(obj);
2154         if (oldmode == ELM_OBJECT_SELECT_MODE_NONE)
2155           elm_toolbar_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
2156      }
2157 }
2158
2159 EINA_DEPRECATED EAPI Eina_Bool
2160 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2161 {
2162    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2163    Widget_Data *wd = elm_widget_data_get(obj);
2164    if (!wd) return EINA_FALSE;
2165    Elm_Object_Select_Mode oldmode = elm_toolbar_select_mode_get(obj);
2166    if (oldmode == ELM_OBJECT_SELECT_MODE_NONE)
2167      return EINA_TRUE;
2168    else
2169      return EINA_FALSE;
2170 }
2171
2172 EAPI void
2173 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2174 {
2175    ELM_CHECK_WIDTYPE(obj, widtype);
2176    Elm_Toolbar_Item *it;
2177    Widget_Data *wd = elm_widget_data_get(obj);
2178    if (!wd) return;
2179
2180    wd->lookup_order = order;
2181    EINA_INLIST_FOREACH(wd->items, it)
2182       elm_icon_order_lookup_set(it->icon, order);
2183    if (wd->more_item)
2184      elm_icon_order_lookup_set(wd->more_item->icon, order);
2185 }
2186
2187 EAPI Elm_Icon_Lookup_Order
2188 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2189 {
2190    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2191    Widget_Data *wd = elm_widget_data_get(obj);
2192    if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2193    return wd->lookup_order;
2194 }
2195
2196 EINA_DEPRECATED EAPI void
2197 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
2198 {
2199    elm_toolbar_horizontal_set(obj, !vertical);
2200 }
2201
2202 EINA_DEPRECATED EAPI Eina_Bool
2203 elm_toolbar_orientation_get(const Evas_Object *obj)
2204 {
2205    return !elm_toolbar_horizontal_get(obj);
2206 }
2207
2208 EAPI void
2209 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2210 {
2211    ELM_CHECK_WIDTYPE(obj, widtype);
2212    Widget_Data *wd = elm_widget_data_get(obj);
2213    if (!wd) return;
2214    wd->vertical = !horizontal;
2215    if (wd->vertical)
2216      evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2217    else
2218      evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2219    _sizing_eval(obj);
2220 }
2221
2222 EAPI Eina_Bool
2223 elm_toolbar_horizontal_get(const Evas_Object *obj)
2224 {
2225    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2226    Widget_Data *wd = elm_widget_data_get(obj);
2227    if (!wd) return EINA_FALSE;
2228    return !wd->vertical;
2229 }
2230
2231 EAPI unsigned int
2232 elm_toolbar_items_count(const Evas_Object *obj)
2233 {
2234    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2235    Widget_Data *wd = elm_widget_data_get(obj);
2236    if (!wd) return 0;
2237    return wd->item_count;
2238 }
2239
2240 EINA_DEPRECATED EAPI void
2241 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2242 {
2243    elm_toolbar_shrink_mode_set(obj, shrink_mode);
2244 }
2245
2246 EINA_DEPRECATED EAPI Elm_Toolbar_Shrink_Mode
2247 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
2248 {
2249    return elm_toolbar_shrink_mode_get(obj);
2250 }
2251
2252 EAPI void
2253 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2254 {
2255    ELM_CHECK_WIDTYPE(obj, widtype);
2256    Widget_Data *wd = elm_widget_data_get(obj);
2257    if (!wd) return;
2258    if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2259      return;
2260    if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2261        (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2262        wd->items)
2263      _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2264    if (wd->select_mode != mode)
2265      wd->select_mode = mode;
2266 }
2267
2268 EAPI Elm_Object_Select_Mode
2269 elm_toolbar_select_mode_get(const Evas_Object *obj)
2270 {
2271    ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2272    Widget_Data *wd = elm_widget_data_get(obj);
2273    if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2274    return wd->select_mode;
2275 }
2276