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