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