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