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