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