elm toolbar: Applied the API change - elm_menu_item_disabled_set to elm_object_item_d...
[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_Object_Item *menu_it;
537                             menu_it = elm_menu_item_add(menu, NULL,
538                                                 it->icon_str, it->label,
539                                                 _elm_toolbar_item_menu_cb, it);
540                             elm_object_item_disabled_set(menu_it, it->disabled);
541                             if (it->o_menu)
542                               elm_menu_clone(it->o_menu, menu, menu_it);
543                          }
544                        evas_object_hide(VIEW(it));
545                     }
546                   else
547                     {
548                        evas_object_box_append(wd->bx, VIEW(it));
549                        evas_object_show(VIEW(it));
550                     }
551                }
552
553              evas_object_box_append(wd->bx, wd->VIEW(more_item));
554              evas_object_show(wd->VIEW(more_item));
555           }
556         else
557           {
558              /* All items are visible, show them all (except for the "More"
559               * button, of course). */
560              EINA_INLIST_FOREACH(wd->items, it)
561                {
562                   evas_object_show(VIEW(it));
563                   evas_object_box_append(wd->bx, VIEW(it));
564                }
565              evas_object_hide(wd->VIEW(more_item));
566           }
567      }
568    else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
569      {
570         Evas_Coord iw = 0;
571
572         evas_object_resize(wd->bx, vw, h);
573         _fix_items_visibility(wd, &iw, vw);
574         evas_object_box_remove_all(wd->bx, EINA_FALSE);
575         if (iw > vw)
576           {
577              EINA_INLIST_FOREACH(wd->items, it)
578                {
579                   if (!it->prio.visible)
580                     evas_object_hide(VIEW(it));
581                   else
582                     {
583                        evas_object_box_append(wd->bx, VIEW(it));
584                        evas_object_show(VIEW(it));
585                     }
586                }
587           }
588         else
589           {
590              /* All items are visible, show them all */
591              EINA_INLIST_FOREACH(wd->items, it)
592                {
593                   evas_object_show(VIEW(it));
594                   evas_object_box_append(wd->bx, VIEW(it));
595                }
596           }
597      }
598    else
599      {
600         if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
601         EINA_INLIST_FOREACH(wd->items, it)
602           {
603              if (it->selected)
604                {
605                   _item_show(it);
606                   break;
607                }
608           }
609      }
610
611    _mirrored_set(obj, elm_widget_mirrored_get(obj));
612 }
613
614 static void
615 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
616 {
617    _sizing_eval(data);
618    _resize(data, NULL, NULL, NULL);
619 }
620
621 static void
622 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
623 {
624    Widget_Data *wd = elm_widget_data_get(data);
625    if (!wd->resize_job)
626      wd->resize_job = ecore_job_add(_resize_job, data);
627 }
628
629 static void
630 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
631 {
632    int button;
633    char buf[sizeof("elm,action,click,") + 1];
634
635    button = atoi(emission + sizeof("mouse,clicked,") - 1);
636    if (button == 1) return; /* regular left click event */
637    snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
638    edje_object_signal_emit(VIEW(it), buf, "elm");
639 }
640
641 static void
642 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
643 {
644    Elm_Toolbar_Item *it = data;
645
646    if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
647        (_elm_access_2nd_click_timeout(VIEW(it))))
648      {
649         if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
650            _elm_access_say(E_("Selected"));
651         _item_select(it);
652      }
653 }
654
655 static Eina_Bool
656 _long_press(Elm_Toolbar_Item *it)
657 {
658    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
659    wd->long_timer = NULL;
660    wd->long_press = EINA_TRUE;
661    evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
662    return ECORE_CALLBACK_CANCEL;
663 }
664
665 static void
666 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
667 {
668    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
669    if (!wd) return;
670    if (ev->button != 1) return;
671    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
672      evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
673    wd->long_press = EINA_FALSE;
674    if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
675    else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
676 }
677
678 static void
679 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
680 {
681    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
682    if (!wd) return;
683    if (ev->button != 1) return;
684    if (wd->long_timer)
685      {
686         ecore_timer_del(wd->long_timer);
687         wd->long_timer = NULL;
688      }
689 }
690
691 static void
692 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
693 {
694    Elm_Toolbar_Item *it = data;
695    edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
696    elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
697 }
698
699 static void
700 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
701 {
702    Elm_Toolbar_Item *it = data;
703    edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
704    elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
705 }
706
707 static void
708 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
709 {
710    Evas_Object *obj = (Evas_Object *) data;
711    Widget_Data *wd = elm_widget_data_get(obj);
712    if (!wd) return;
713    _els_box_layout(o, priv, !wd->vertical, wd->homogeneous, elm_widget_mirrored_get(obj));
714 }
715
716 static char *
717 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
718 {
719    Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
720    const char *txt = item->access_info;
721    if (!txt) txt = it->label;
722    if (txt) return strdup(txt);
723    return NULL;
724 }
725
726 static char *
727 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
728 {
729    Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
730    if (it->separator)
731       return strdup(E_("Separator"));
732    else if (it->disabled)
733       return strdup(E_("State: Disabled"));
734    else if (it->selected)
735       return strdup(E_("State: Selected"));
736    else if (it->menu)
737       return strdup(E_("Has menu"));
738    return NULL;
739 }
740
741 static Elm_Toolbar_Item *
742 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
743 {
744    Widget_Data *wd = elm_widget_data_get(obj);
745    Evas_Object *icon_obj;
746    Evas_Coord mw, mh;
747    Elm_Toolbar_Item *it;
748
749    icon_obj = elm_icon_add(obj);
750    elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
751    if (!icon_obj) return NULL;
752    it = elm_widget_item_new(obj, Elm_Toolbar_Item);
753    if (!it)
754      {
755         evas_object_del(icon_obj);
756         return NULL;
757      }
758    it->label = eina_stringshare_add(label);
759    it->prio.visible = 1;
760    it->prio.priority = 0;
761    it->func = func;
762    it->separator = EINA_FALSE;
763    it->base.data = data;
764    VIEW(it) = edje_object_add(evas_object_evas_get(obj));
765    _elm_access_item_register(&it->base, VIEW(it));
766    _elm_access_text_set(_elm_access_item_get(&it->base),
767                         ELM_ACCESS_TYPE, E_("Tool Item"));
768    _elm_access_callback_set(_elm_access_item_get(&it->base),
769                             ELM_ACCESS_INFO, _access_info_cb, it);
770    _elm_access_callback_set(_elm_access_item_get(&it->base),
771                             ELM_ACCESS_STATE, _access_state_cb, it);
772
773    if (_item_icon_set(icon_obj, "toolbar/", icon))
774      {
775         it->icon = icon_obj;
776         it->icon_str = eina_stringshare_add(icon);
777      }
778    else
779      {
780         it->icon = NULL;
781         it->icon_str = NULL;
782         evas_object_del(icon_obj);
783      }
784
785    _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
786                          elm_widget_style_get(obj));
787    edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
788                                    _select, it);
789    edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
790                                    (Edje_Signal_Cb)_select_filter, it);
791    edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
792                                    _mouse_in, it);
793    edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
794                                    _mouse_out, it);
795    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
796                                   (Evas_Object_Event_Cb)_mouse_down, it);
797    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
798                                   (Evas_Object_Event_Cb)_mouse_up, it);
799    elm_widget_sub_object_add(obj, VIEW(it));
800    if (it->icon)
801      {
802         int ms = 0;
803
804         ms = ((double)wd->icon_size * _elm_config->scale);
805         evas_object_size_hint_min_set(it->icon, ms, ms);
806         evas_object_size_hint_max_set(it->icon, ms, ms);
807         edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
808         evas_object_show(it->icon);
809         elm_widget_sub_object_add(obj, it->icon);
810      }
811    edje_object_part_text_set(VIEW(it), "elm.text", it->label);
812    mw = mh = -1;
813    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
814    edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
815    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
816    if (wd->vertical)
817      {
818         evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
819         evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
820      }
821    else
822      {
823         evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
824         evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
825      }
826    evas_object_size_hint_min_set(VIEW(it), mw, mh);
827    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
828                                   _resize_item, obj);
829    if ((!wd->items) && wd->always_select) _item_select(it);
830    return it;
831 }
832
833 EAPI Evas_Object *
834 elm_toolbar_add(Evas_Object *parent)
835 {
836    Evas_Object *obj;
837    Evas *e;
838    Widget_Data *wd;
839
840    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
841
842    ELM_SET_WIDTYPE(widtype, "toolbar");
843    elm_widget_type_set(obj, "toolbar");
844    elm_widget_sub_object_add(parent, obj);
845    elm_widget_data_set(obj, wd);
846    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
847    elm_widget_del_hook_set(obj, _del_hook);
848    elm_widget_theme_hook_set(obj, _theme_hook);
849    elm_widget_translate_hook_set(obj, _translate_hook);
850    elm_widget_can_focus_set(obj, EINA_FALSE);
851
852    wd->more_item = NULL;
853    wd->selected_item = NULL;
854    wd->scr = elm_smart_scroller_add(e);
855    elm_smart_scroller_widget_set(wd->scr, obj);
856    elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
857    elm_smart_scroller_bounce_allow_set(wd->scr,
858                                        _elm_config->thumbscroll_bounce_enable,
859                                        EINA_FALSE);
860    elm_widget_resize_object_set(obj, wd->scr);
861    elm_smart_scroller_policy_set(wd->scr,
862                                  ELM_SMART_SCROLLER_POLICY_AUTO,
863                                  ELM_SMART_SCROLLER_POLICY_OFF);
864
865
866    wd->icon_size = _elm_toolbar_icon_size_get(wd);
867
868
869    wd->homogeneous = EINA_TRUE;
870    wd->align = 0.5;
871
872    wd->bx = evas_object_box_add(e);
873    evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
874    evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
875    elm_widget_sub_object_add(obj, wd->bx);
876    elm_smart_scroller_child_set(wd->scr, wd->bx);
877    evas_object_show(wd->bx);
878
879    elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
880    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
881    evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
882    elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
883
884    evas_object_smart_callbacks_descriptions_set(obj, _signals);
885
886    _sizing_eval(obj);
887    return obj;
888 }
889
890 EAPI void
891 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
892 {
893    ELM_CHECK_WIDTYPE(obj, widtype);
894    Widget_Data *wd = elm_widget_data_get(obj);
895    if (!wd) return;
896    if (wd->icon_size == icon_size) return;
897    wd->icon_size = icon_size;
898    _theme_hook(obj);
899 }
900
901 EAPI int
902 elm_toolbar_icon_size_get(const Evas_Object *obj)
903 {
904    ELM_CHECK_WIDTYPE(obj, widtype) 0;
905    Widget_Data *wd = elm_widget_data_get(obj);
906    if (!wd) return 0;
907    return wd->icon_size;
908 }
909
910 EAPI Elm_Toolbar_Item *
911 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
912 {
913    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
914    Widget_Data *wd = elm_widget_data_get(obj);
915    if (!wd) return NULL;
916
917    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
918    if (!it) return NULL;
919    double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
920
921    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
922    evas_object_box_append(wd->bx, VIEW(it));
923    evas_object_show(VIEW(it));
924
925    _theme_hook_item(obj, it, scale, wd->icon_size);
926    _sizing_eval(obj);
927
928    return it;
929 }
930
931 static void
932 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
933 {
934    Elm_Toolbar_Item *it = event_info;
935    Elm_Toolbar_Item_State *it_state;
936
937    it_state = eina_list_data_get(it->current_state);
938    if (it_state->func)
939      it_state->func((void *)it_state->data, obj, event_info);
940 }
941
942 EAPI Elm_Toolbar_Item_State *
943 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
944 {
945    Widget_Data *wd;
946    Evas_Object *obj;
947    Eina_List *next_state;
948    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
949
950    obj = WIDGET(item);
951    wd = elm_widget_data_get(obj);
952    if (!wd) return NULL;
953    if (!item->states) return NULL;
954
955    next_state = eina_list_next(item->current_state);
956    if (!next_state)
957      next_state = eina_list_next(item->states);
958    return eina_list_data_get(next_state);
959 }
960
961 EAPI Elm_Toolbar_Item_State *
962 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
963 {
964    Widget_Data *wd;
965    Evas_Object *obj;
966    Eina_List *prev_state;
967    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
968
969    obj = WIDGET(item);
970    wd = elm_widget_data_get(obj);
971    if (!wd) return NULL;
972    if (!item->states) return NULL;
973
974    prev_state = eina_list_prev(item->current_state);
975    if ((!prev_state) || (prev_state == item->states))
976      prev_state = eina_list_last(item->states);
977    return eina_list_data_get(prev_state);
978 }
979
980 EAPI void
981 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
982 {
983    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
984    elm_toolbar_item_state_set(it, NULL);
985 }
986
987 EAPI Eina_Bool
988 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
989 {
990    Widget_Data *wd;
991    Eina_List *next_state;
992    Elm_Toolbar_Item_State *it_state;
993    Evas_Object *obj;
994    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
995
996    obj = WIDGET(it);
997    wd = elm_widget_data_get(obj);
998    if (!wd) return EINA_FALSE;
999    if (!it->states) return EINA_FALSE;
1000
1001    if (state)
1002      {
1003         next_state = eina_list_data_find_list(it->states, state);
1004         if (!next_state) return EINA_FALSE;
1005      }
1006    else
1007      next_state = it->states;
1008
1009    if (next_state == it->current_state) return EINA_TRUE;
1010
1011    it_state = eina_list_data_get(next_state);
1012    if (eina_list_data_find(it->current_state, state))
1013      {
1014         _item_label_set(it, it_state->label, "elm,state,label_set,forward");
1015         _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
1016                                        wd->icon_size, "elm,state,icon_set,forward");
1017      }
1018    else
1019      {
1020         _item_label_set(it, it_state->label, "elm,state,label_set,backward");
1021         _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
1022                                        wd->icon_size, "elm,state,icon_set,backward");
1023      }
1024    if (it->disabled)
1025      elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
1026    else
1027      elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
1028
1029    it->current_state = next_state;
1030    return EINA_TRUE;
1031 }
1032
1033 EAPI Elm_Toolbar_Item_State *
1034 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
1035 {
1036    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1037    if ((!it->states) || (!it->current_state)) return NULL;
1038    if (it->current_state == it->states) return NULL;
1039
1040    return eina_list_data_get(it->current_state);
1041 }
1042
1043 static Elm_Toolbar_Item_State *
1044 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1045 {
1046    Elm_Toolbar_Item_State *it_state;
1047    it_state = ELM_NEW(Elm_Toolbar_Item_State);
1048    it_state->label = eina_stringshare_add(label);
1049    it_state->icon_str = eina_stringshare_add(icon_str);
1050    it_state->icon = icon;
1051    it_state->func = func;
1052    it_state->data = data;
1053    return it_state;
1054 }
1055
1056 EAPI Elm_Toolbar_Item_State *
1057 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1058 {
1059    Elm_Toolbar_Item_State *it_state;
1060    Evas_Object *icon_obj;
1061    Evas_Object *obj;
1062    Widget_Data *wd;
1063    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1064    obj = WIDGET(item);
1065    wd = elm_widget_data_get(WIDGET(item));
1066    if (!wd) return NULL;
1067
1068    if (!item->states)
1069      {
1070         it_state = _item_state_new(item->label, item->icon_str, item->icon,
1071                                    item->func, item->base.data);
1072         item->states = eina_list_append(item->states, it_state);
1073         item->current_state = item->states;
1074      }
1075
1076    icon_obj = elm_icon_add(obj);
1077    elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1078    if (!icon_obj) goto error_state_add;
1079
1080    if (!_item_icon_set(icon_obj, "toolbar/", icon))
1081      {
1082         evas_object_del(icon_obj);
1083         icon_obj = NULL;
1084         icon = NULL;
1085      }
1086
1087    it_state = _item_state_new(label, icon, icon_obj, func, data);
1088    item->states = eina_list_append(item->states, it_state);
1089    item->func = _elm_toolbar_item_state_cb;
1090    item->base.data = NULL;
1091
1092    return it_state;
1093
1094 error_state_add:
1095    if (item->states && !eina_list_next(item->states))
1096      {
1097         eina_stringshare_del(item->label);
1098         eina_stringshare_del(item->icon_str);
1099         free(eina_list_data_get(item->states));
1100         eina_list_free(item->states);
1101         item->states = NULL;
1102      }
1103    return NULL;
1104 }
1105
1106 EAPI Eina_Bool
1107 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1108 {
1109    Eina_List *del_state;
1110    Elm_Toolbar_Item_State *it_state;
1111    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1112
1113    if (!state) return EINA_FALSE;
1114    if (!item->states) return EINA_FALSE;
1115
1116    del_state = eina_list_data_find_list(item->states, state);
1117    if (del_state == item->states) return EINA_FALSE;
1118    if (del_state == item->current_state)
1119      elm_toolbar_item_state_unset(item);
1120
1121    eina_stringshare_del(state->label);
1122    eina_stringshare_del(state->icon_str);
1123    if (state->icon) evas_object_del(state->icon);
1124    free(state);
1125    item->states = eina_list_remove_list(item->states, del_state);
1126    if (item->states && !eina_list_next(item->states))
1127      {
1128         it_state = eina_list_data_get(item->states);
1129         item->base.data = it_state->data;
1130         item->func = it_state->func;
1131         eina_stringshare_del(it_state->label);
1132         eina_stringshare_del(it_state->icon_str);
1133         free(eina_list_data_get(item->states));
1134         eina_list_free(item->states);
1135         item->states = NULL;
1136      }
1137    return EINA_TRUE;
1138 }
1139
1140 EAPI Elm_Toolbar_Item *
1141 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1142 {
1143    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1144    Widget_Data *wd = elm_widget_data_get(obj);
1145    if (!wd) return NULL;
1146
1147    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1148    if (!it) return NULL;
1149    double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1150
1151    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1152    evas_object_box_prepend(wd->bx, VIEW(it));
1153    evas_object_show(VIEW(it));
1154    _theme_hook_item(obj, it, scale, wd->icon_size);
1155    _sizing_eval(obj);
1156
1157    return it;
1158 }
1159
1160 EAPI Elm_Toolbar_Item *
1161 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)
1162 {
1163    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1164    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1165    Widget_Data *wd = elm_widget_data_get(obj);
1166    if (!wd) return NULL;
1167
1168    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1169    if (!it) return NULL;
1170    double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1171
1172    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1173                                             EINA_INLIST_GET(before));
1174    evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(before));
1175    evas_object_show(VIEW(it));
1176    _theme_hook_item(obj, it, scale, wd->icon_size);
1177    _sizing_eval(obj);
1178
1179    return it;
1180 }
1181
1182 EAPI Elm_Toolbar_Item *
1183 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)
1184 {
1185    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1186    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1187    Widget_Data *wd = elm_widget_data_get(obj);
1188    if (!wd) return NULL;
1189
1190    Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1191    if (!it) return NULL;
1192    double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1193
1194    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1195                                            EINA_INLIST_GET(after));
1196    evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(after));
1197    evas_object_show(VIEW(it));
1198    _theme_hook_item(obj, it, scale, wd->icon_size);
1199    _sizing_eval(obj);
1200
1201    return it;
1202 }
1203
1204 EAPI Elm_Toolbar_Item *
1205 elm_toolbar_first_item_get(const Evas_Object *obj)
1206 {
1207    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1208    Widget_Data *wd = elm_widget_data_get(obj);
1209    if (!wd || !wd->items) return NULL;
1210    Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1211    return it;
1212 }
1213
1214 EAPI Elm_Toolbar_Item *
1215 elm_toolbar_last_item_get(const Evas_Object *obj)
1216 {
1217    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1218    Widget_Data *wd = elm_widget_data_get(obj);
1219    if (!wd || !wd->items) return NULL;
1220    Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1221    return it;
1222 }
1223
1224 EAPI Elm_Toolbar_Item *
1225 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1226 {
1227    Elm_Toolbar_Item *next;
1228    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1229    next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1230    return next;
1231 }
1232
1233 EAPI Elm_Toolbar_Item *
1234 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1235 {
1236    Elm_Toolbar_Item *prev;
1237    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1238    prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1239    return prev;
1240 }
1241
1242 EAPI Evas_Object *
1243 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1244 {
1245    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1246    return WIDGET(item);
1247 }
1248
1249 EAPI void
1250 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1251 {
1252    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1253    if (item->prio.priority == priority) return;
1254    item->prio.priority = priority;
1255    _resize(WIDGET(item), NULL, NULL, NULL);
1256 }
1257
1258 EAPI int
1259 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1260 {
1261    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1262    return item->prio.priority;
1263 }
1264
1265 EAPI const char *
1266 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1267 {
1268    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1269    return item->icon_str;
1270 }
1271
1272 EAPI const char *
1273 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1274 {
1275    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1276    return item->label;
1277 }
1278
1279 static void
1280 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1281 {
1282    Evas_Coord mw = -1, mh = -1;
1283    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1284    edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1285
1286    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1287    edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1288    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1289    if (wd->vertical)
1290      {
1291         evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1292         evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1293      }
1294    else
1295      {
1296         evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1297         evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1298      }
1299    evas_object_size_hint_min_set(VIEW(item), mw, mh);
1300 }
1301
1302 static void
1303 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1304 {
1305    Elm_Toolbar_Item *item = data;
1306    _elm_toolbar_item_label_update(item);
1307    edje_object_signal_callback_del(obj, emission, source,
1308                                    _elm_toolbar_item_label_set_cb);
1309    edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1310 }
1311
1312 static void
1313 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1314 {
1315    const char *s;
1316
1317    if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1318
1319    eina_stringshare_replace(&item->label, label);
1320    s = edje_object_data_get(VIEW(item), "transition_animation_on");
1321    if ((s) && (atoi(s)))
1322      {
1323         edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1324         edje_object_signal_emit (VIEW(item), signal, "elm");
1325         edje_object_signal_callback_add(VIEW(item),
1326                                         "elm,state,label_set,done", "elm",
1327                                         _elm_toolbar_item_label_set_cb, item);
1328      }
1329    else
1330      _elm_toolbar_item_label_update(item);
1331    _resize(WIDGET(item), NULL, NULL, NULL);
1332 }
1333
1334 EAPI void
1335 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1336 {
1337    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1338    _item_label_set(item, label, "elm,state,label_set");
1339 }
1340
1341 static void
1342 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1343 {
1344    Elm_Toolbar_Item_State *it_state;
1345    Eina_List *l;
1346    Evas_Coord mw = -1, mh = -1;
1347    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1348    Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1349                                                         "elm.swallow.icon");
1350    elm_widget_sub_object_del(VIEW(item), old_icon);
1351    evas_object_hide(old_icon);
1352    edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1353    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1354    edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1355    elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1356    if (wd->vertical)
1357      {
1358         evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1359         evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1360      }
1361    else
1362      {
1363         evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1364         evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1365      }
1366    evas_object_size_hint_min_set(VIEW(item), mw, mh);
1367
1368    EINA_LIST_FOREACH(item->states, l, it_state)
1369       if (it_state->icon == old_icon)
1370         return;
1371    evas_object_del(old_icon);
1372 }
1373
1374 EAPI Eina_Bool
1375 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1376 {
1377    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1378    return item->selected;
1379 }
1380
1381 EAPI void
1382 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1383 {
1384    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1385    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1386    if (!wd) return;
1387
1388    if (item->selected == selected) return;
1389
1390    if (selected)
1391      _item_select(item);
1392    else
1393      _item_unselect(item);
1394 }
1395
1396 EAPI Elm_Toolbar_Item *
1397 elm_toolbar_selected_item_get(const Evas_Object *obj)
1398 {
1399    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1400    Widget_Data *wd = elm_widget_data_get(obj);
1401    if (!wd) return NULL;
1402    return wd->selected_item;
1403 }
1404
1405 static void
1406 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1407 {
1408    Elm_Toolbar_Item *item = data;
1409    edje_object_part_unswallow(VIEW(item), item->icon);
1410    _elm_toolbar_item_icon_update(item);
1411    edje_object_signal_callback_del(obj, emission, source,
1412                                    _elm_toolbar_item_icon_set_cb);
1413    edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1414 }
1415
1416 static void
1417 _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)
1418 {
1419    Evas_Object *old_icon;
1420    int ms = 0;
1421    const char *s;
1422
1423    if (icon_str)
1424      eina_stringshare_replace(&item->icon_str, icon_str);
1425    else
1426      {
1427         eina_stringshare_del(item->icon_str);
1428         item->icon_str = NULL;
1429      }
1430    item->icon = icon_obj;
1431    if (icon_obj)
1432      {
1433         ms = (icon_size * _elm_config->scale);
1434         evas_object_size_hint_min_set(item->icon, ms, ms);
1435         evas_object_size_hint_max_set(item->icon, ms, ms);
1436         evas_object_show(item->icon);
1437         elm_widget_sub_object_add(obj, item->icon);
1438      }
1439    s = edje_object_data_get(VIEW(item), "transition_animation_on");
1440    if ((s) && (atoi(s)))
1441      {
1442         old_icon = edje_object_part_swallow_get(VIEW(item),
1443                                                 "elm.swallow.icon_new");
1444         if (old_icon)
1445           {
1446              elm_widget_sub_object_del(VIEW(item), old_icon);
1447              evas_object_hide(old_icon);
1448           }
1449         edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1450                                  item->icon);
1451         edje_object_signal_emit (VIEW(item), signal, "elm");
1452         edje_object_signal_callback_add(VIEW(item),
1453                                         "elm,state,icon_set,done", "elm",
1454                                         _elm_toolbar_item_icon_set_cb, item);
1455      }
1456    else
1457      _elm_toolbar_item_icon_update(item);
1458    _resize(obj, NULL, NULL, NULL);
1459 }
1460
1461 EAPI void
1462 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1463 {
1464    Evas_Object *icon_obj;
1465    Widget_Data *wd;
1466    Evas_Object *obj;
1467
1468    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1469    obj = WIDGET(item);
1470    wd = elm_widget_data_get(obj);
1471    if (!wd) return;
1472    if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1473
1474    icon_obj = elm_icon_add(obj);
1475    if (!icon_obj) return;
1476    if (_item_icon_set(icon_obj, "toolbar/", icon))
1477      _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1478                                     "elm,state,icon_set");
1479    else
1480      {
1481         _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1482                                        "elm,state,icon_set");
1483         evas_object_del(icon_obj);
1484      }
1485 }
1486
1487 EAPI Eina_Bool
1488 elm_toolbar_item_icon_memfile_set(Elm_Toolbar_Item *item, const void *img, size_t size, const char *format, const char *key)
1489 {
1490    Evas_Object *icon_obj;
1491    Widget_Data *wd;
1492    Evas_Object *obj;
1493    Eina_Bool ret;
1494
1495    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1496    obj = WIDGET(item);
1497    wd = elm_widget_data_get(obj);
1498    if (!wd) return EINA_FALSE;
1499
1500    if (img && size)
1501      {
1502         icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1503         evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1504         ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1505         if (!ret)
1506           {
1507              evas_object_del(icon_obj);
1508              return EINA_FALSE;
1509           }
1510         _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1511                                          "elm,state,icon_set");
1512      }
1513    else
1514      _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1515    return EINA_TRUE;
1516 }
1517
1518 EAPI Evas_Object *
1519 elm_toolbar_item_object_get(const Elm_Toolbar_Item *item)
1520 {
1521    Widget_Data *wd;
1522    Evas_Object *obj;
1523
1524    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1525    obj = WIDGET(item);
1526    wd = elm_widget_data_get(obj);
1527    if (!wd) return NULL;
1528
1529    return VIEW(item);
1530 }
1531
1532 EAPI Evas_Object *
1533 elm_toolbar_item_icon_object_get(Elm_Toolbar_Item *item)
1534 {
1535    Widget_Data *wd;
1536    Evas_Object *obj;
1537
1538    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1539    obj = WIDGET(item);
1540    wd = elm_widget_data_get(obj);
1541    if (!wd) return NULL;
1542
1543    return item->icon;
1544 }
1545
1546 EAPI void
1547 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1548 {
1549    Widget_Data *wd;
1550    Evas_Object *obj2;
1551    Elm_Toolbar_Item *next;
1552
1553    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1554    wd = elm_widget_data_get(WIDGET(item));
1555    if (!wd) return;
1556    obj2 = WIDGET(item);
1557    next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1558    wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1559    if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1560    if (wd->always_select && item->selected && next) _item_select(next);
1561    _item_del(item);
1562    _theme_hook(obj2);
1563 }
1564
1565 EAPI void
1566 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1567 {
1568    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1569    elm_widget_item_del_cb_set(item, func);
1570 }
1571
1572 EAPI Eina_Bool
1573 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1574 {
1575    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1576    return item->disabled;
1577 }
1578
1579 EAPI void
1580 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1581 {
1582    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1583    _item_disable(item, disabled);
1584    _resize(WIDGET(item), NULL, NULL, NULL);
1585 }
1586
1587 EAPI void
1588 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1589 {
1590    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1591    Evas_Object *obj = WIDGET(item);
1592    Widget_Data *wd = elm_widget_data_get(obj);
1593    double scale;
1594    if (item->separator == separator) return;
1595    item->separator = separator;
1596    scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1597    _theme_hook_item(obj, item, scale, wd->icon_size);
1598 }
1599
1600 EAPI Eina_Bool
1601 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1602 {
1603    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1604    return item->separator;
1605 }
1606
1607 EAPI void
1608 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1609 {
1610    ELM_CHECK_WIDTYPE(obj, widtype);
1611    Widget_Data *wd = elm_widget_data_get(obj);
1612    Eina_Bool bounce;
1613
1614    if (!wd) return;
1615    wd->shrink_mode = shrink_mode;
1616    bounce = (_elm_config->thumbscroll_bounce_enable) &&
1617       (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1618    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1619
1620    if (wd->more_item)
1621      {
1622         _item_del(wd->more_item);
1623         wd->more_item = NULL;
1624      }
1625
1626    if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1627      {
1628         elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1629
1630         wd->more_item = _item_new(obj, "more_menu", "More",
1631                                   NULL, NULL);
1632      }
1633    else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1634      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1635                                    ELM_SMART_SCROLLER_POLICY_OFF);
1636    else
1637      elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1638                                    ELM_SMART_SCROLLER_POLICY_OFF);
1639    _sizing_eval(obj);
1640 }
1641
1642 EAPI Elm_Toolbar_Shrink_Mode
1643 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1644 {
1645    ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1646    Widget_Data *wd = elm_widget_data_get(obj);
1647
1648    if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1649    return wd->shrink_mode;
1650 }
1651
1652 EAPI void
1653 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1654 {
1655    ELM_CHECK_WIDTYPE(obj, widtype);
1656    Widget_Data *wd = elm_widget_data_get(obj);
1657
1658    if (!wd) return;
1659    wd->homogeneous = !!homogeneous;
1660    evas_object_smart_calculate(wd->bx);
1661 }
1662
1663 EINA_DEPRECATED EAPI void
1664 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1665 {
1666    elm_toolbar_homogeneous_set(obj, homogenous);
1667 }
1668
1669 EAPI Eina_Bool
1670 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1671 {
1672    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1673    Widget_Data *wd = elm_widget_data_get(obj);
1674
1675    if (!wd) return EINA_FALSE;
1676    return wd->homogeneous;
1677 }
1678
1679 EINA_DEPRECATED EAPI Eina_Bool
1680 elm_toolbar_homogenous_get(const Evas_Object *obj)
1681 {
1682    return elm_toolbar_homogeneous_get(obj);
1683 }
1684
1685 EAPI void
1686 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1687 {
1688    Elm_Toolbar_Item *it;
1689    ELM_CHECK_WIDTYPE(obj, widtype);
1690    Widget_Data *wd = elm_widget_data_get(obj);
1691
1692    if (!wd) return;
1693    EINA_SAFETY_ON_NULL_RETURN(parent);
1694    wd->menu_parent = parent;
1695    EINA_INLIST_FOREACH(wd->items, it)
1696      {
1697         if (it->o_menu)
1698           elm_menu_parent_set(it->o_menu, wd->menu_parent);
1699      }
1700    if ((wd->more_item) && (wd->more_item->o_menu))
1701      elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1702 }
1703
1704 EAPI Evas_Object *
1705 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1706 {
1707    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1708    Widget_Data *wd = elm_widget_data_get(obj);
1709
1710    if (!wd) return NULL;
1711    return wd->menu_parent;
1712 }
1713
1714 EAPI void
1715 elm_toolbar_align_set(Evas_Object *obj, double align)
1716 {
1717    ELM_CHECK_WIDTYPE(obj, widtype);
1718    Widget_Data *wd = elm_widget_data_get(obj);
1719
1720    if (!wd) return;
1721    if (wd->align != align)
1722      evas_object_size_hint_align_set(wd->bx, align, 0.5);
1723    wd->align = align;
1724 }
1725
1726 EAPI double
1727 elm_toolbar_align_get(const Evas_Object *obj)
1728 {
1729    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1730    Widget_Data *wd = elm_widget_data_get(obj);
1731
1732    if (!wd) return 0.0;
1733    return wd->align;
1734 }
1735
1736 EAPI void
1737 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1738 {
1739    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1740    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1741    if (!wd) return;
1742
1743    if (item->menu == menu) return;
1744    if (menu) _item_menu_create(wd, item);
1745    else _item_menu_destroy(item);
1746 }
1747
1748 EAPI void
1749 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1750 {
1751    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1752    elm_widget_item_tooltip_text_set(item, text);
1753 }
1754
1755 EAPI void
1756 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)
1757 {
1758    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1759    elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1760 }
1761
1762 EAPI void
1763 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1764 {
1765    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1766    elm_widget_item_tooltip_unset(item);
1767 }
1768
1769 EAPI void
1770 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
1771 {
1772    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1773    elm_widget_item_tooltip_style_set(item, style);
1774 }
1775
1776 EAPI const char *
1777 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
1778 {
1779    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1780    return elm_widget_item_tooltip_style_get(item);
1781 }
1782
1783 EAPI void
1784 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
1785 {
1786    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1787    elm_widget_item_cursor_set(item, cursor);
1788 }
1789
1790 EAPI const char *
1791 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
1792 {
1793    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1794    return elm_widget_item_cursor_get(item);
1795 }
1796
1797 EAPI void
1798 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
1799 {
1800    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1801    elm_widget_item_cursor_unset(item);
1802 }
1803
1804 EAPI void
1805 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
1806 {
1807    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1808    elm_widget_item_cursor_style_set(item, style);
1809 }
1810
1811 EAPI const char *
1812 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
1813 {
1814    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1815    return elm_widget_item_cursor_style_get(item);
1816 }
1817
1818 EAPI void
1819 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
1820 {
1821    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1822    elm_widget_item_cursor_engine_only_set(item, engine_only);
1823 }
1824
1825 EAPI Eina_Bool
1826 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
1827 {
1828    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1829    return elm_widget_item_cursor_engine_only_get(item);
1830 }
1831
1832 EAPI Evas_Object *
1833 elm_toolbar_item_menu_get(const Elm_Toolbar_Item *item)
1834 {
1835    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1836    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1837    if ((!wd) || (!item->menu)) return NULL;
1838    return item->o_menu;
1839 }
1840
1841 EAPI Elm_Toolbar_Item *
1842 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1843 {
1844    Elm_Toolbar_Item *it;
1845    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1846    Widget_Data *wd = elm_widget_data_get(obj);
1847
1848    if (!wd) return NULL;
1849    EINA_INLIST_FOREACH(wd->items, it)
1850      {
1851         if (!strcmp(it->label, label)) return it;
1852      }
1853
1854    return NULL;
1855 }
1856
1857 EAPI void
1858 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
1859 {
1860    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1861    elm_widget_item_data_set(item, data);
1862 }
1863
1864 EAPI void *
1865 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
1866 {
1867    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1868    return elm_widget_item_data_get(item);
1869 }
1870
1871 EAPI void
1872 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1873 {
1874    ELM_CHECK_WIDTYPE(obj, widtype);
1875    Widget_Data *wd = elm_widget_data_get(obj);
1876    if (!wd) return;
1877    if (always_select && (!wd->always_select) && wd->items)
1878      _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
1879    wd->always_select = always_select;
1880 }
1881
1882 EAPI Eina_Bool
1883 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
1884 {
1885    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1886    Widget_Data *wd = elm_widget_data_get(obj);
1887    if (!wd) return EINA_FALSE;
1888    return wd->always_select;
1889 }
1890
1891 EAPI void
1892 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
1893 {
1894    ELM_CHECK_WIDTYPE(obj, widtype);
1895    Widget_Data *wd = elm_widget_data_get(obj);
1896    if (!wd) return;
1897    wd->no_select = no_select;
1898 }
1899
1900 EAPI Eina_Bool
1901 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
1902 {
1903    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1904    Widget_Data *wd = elm_widget_data_get(obj);
1905    if (!wd) return EINA_FALSE;
1906    return wd->no_select;
1907 }
1908
1909 EAPI void
1910 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1911 {
1912    ELM_CHECK_WIDTYPE(obj, widtype);
1913    Elm_Toolbar_Item *it;
1914    Widget_Data *wd = elm_widget_data_get(obj);
1915    if (!wd) return;
1916
1917    wd->lookup_order = order;
1918    EINA_INLIST_FOREACH(wd->items, it)
1919       elm_icon_order_lookup_set(it->icon, order);
1920    if (wd->more_item)
1921      elm_icon_order_lookup_set(wd->more_item->icon, order);
1922 }
1923
1924 EAPI Elm_Icon_Lookup_Order
1925 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1926 {
1927    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
1928    Widget_Data *wd = elm_widget_data_get(obj);
1929    if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
1930    return wd->lookup_order;
1931 }
1932
1933 EINA_DEPRECATED EAPI void
1934 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
1935 {
1936    elm_toolbar_horizontal_set(obj, !vertical);
1937 }
1938
1939 EINA_DEPRECATED EAPI Eina_Bool
1940 elm_toolbar_orientation_get(const Evas_Object *obj)
1941 {
1942    return !elm_toolbar_horizontal_get(obj);
1943 }
1944
1945 EAPI void
1946 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1947 {
1948    ELM_CHECK_WIDTYPE(obj, widtype);
1949    Widget_Data *wd = elm_widget_data_get(obj);
1950    if (!wd) return;
1951    wd->vertical = !horizontal;
1952    _sizing_eval(obj);
1953 }
1954
1955 EAPI Eina_Bool
1956 elm_toolbar_horizontal_get(const Evas_Object *obj)
1957 {
1958    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1959    Widget_Data *wd = elm_widget_data_get(obj);
1960    if (!wd) return EINA_FALSE;
1961    return !wd->vertical;
1962 }
1963
1964