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