3ad3b7d10fab3a89c627721af2ceae1324d98eca
[framework/uifw/elementary.git] / src / lib / elm_controlbar.c
1 /**
2  * @defgroup Controlbar Controlbar
3  * @ingroup Elementary
4  *
5  * This is a Controlbar. It can contain label and icon objects.
6  * In edit mode, you can change the location of items.
7  */
8
9 #include <string.h>
10 #include <math.h>
11
12 #include <Elementary.h>
13 #include "elm_priv.h"
14
15 #ifndef EAPI
16 #define EAPI __attribute__ ((visibility("default")))
17 #endif
18
19 #define ELM_MAX(v1, v2)    (((v1) > (v2)) ? (v1) : (v2))
20 #define _EDJ(x) (Evas_Object *)elm_layout_edje_get(x)
21
22 #define TABBAR 0
23 #define TOOLBAR 1
24 #define OBJECT 2
25
26 typedef struct _Animation_Data Animation_Data;
27
28 struct _Animation_Data
29 {
30    Evas_Object * obj;
31    Evas_Coord fx;
32    Evas_Coord fy;
33    Evas_Coord fw;
34    Evas_Coord fh;
35    Evas_Coord tx;
36    Evas_Coord ty;
37    Evas_Coord tw;
38    Evas_Coord th;
39    double start_time;
40    double time;
41    void (*func) (void *data, Evas_Object * obj);
42    void *data;
43    Ecore_Animator * timer;
44 };
45
46 // internal data structure of controlbar object
47 typedef struct _Widget_Data Widget_Data;
48
49 struct _Widget_Data
50 {
51    Evas_Object * object;
52    Evas_Object * parent;
53    Evas_Object * view;
54    Evas_Object * edje;
55    Evas_Object * bg;
56    Evas_Object * box;
57
58    Elm_Controlbar_Item * more_item;
59    Elm_Controlbar_Item * pre_item;
60    Elm_Controlbar_Item * cur_item;
61    Evas_Coord x, y, w, h;
62    Eina_Bool disabled;
63    Eina_Bool vertical;
64    Eina_Bool auto_align;
65    int mode;
66    int alpha;
67    int num;
68    int animating;
69    Eina_List * items;
70    Eina_List * visible_items;
71
72    void (*ani_func) (void *data, Evas_Object * obj, void *event_info);
73    void *ani_data;
74    Ecore_Timer *effect_timer;
75    Eina_Bool selected_animation;
76    Animation_Data *ad;
77
78    const char *pressed_signal;
79    const char *selected_signal;
80 };
81
82 struct _Elm_Controlbar_Item
83 {
84    Widget_Data * wd;
85    Evas_Object * obj;
86    Evas_Object * base;
87    Evas_Object * base_item;
88    Evas_Object * view;
89    Evas_Object * icon;
90    const char *icon_path;
91    const char *text;
92    void (*func) (void *data, Evas_Object * obj, void *event_info);
93    void *data;
94    int order;
95    int sel;
96    int style;
97    Eina_Bool selected;
98    Eina_Bool disabled;
99 };
100
101 static const char *widtype = NULL;
102 // prototype
103 static void _sizing_eval(Evas_Object * obj);
104 static int _check_bar_item_number(Widget_Data *wd);
105 static void _select_box(Elm_Controlbar_Item * it);
106 static void _cancel_selected_box(Widget_Data *wd);
107 static void _check_toolbar_line(Widget_Data *wd);
108 static Eina_Bool _press_box(Elm_Controlbar_Item * it);
109
110 ///////////////////////////////////////////////////////////////////
111 //
112 //  Smart Object basic function
113 //
114 ////////////////////////////////////////////////////////////////////
115
116 static void
117 _controlbar_move(void *data, Evas_Object * obj __UNUSED__)
118 {
119    Widget_Data * wd;
120    Evas_Coord x, y, x_, y_, width;
121    if (!data) return;
122    wd = elm_widget_data_get((Evas_Object *) data);
123    if (!wd) return;
124    evas_object_geometry_get(wd->edje, &x, &y, NULL, NULL);
125    wd->x = x;
126    wd->y = y;
127    evas_object_move(wd->edje, x, y);
128    evas_object_geometry_get(elm_layout_content_get(wd->edje, "bg_image"), NULL, NULL, &width, NULL);
129    evas_object_geometry_get(wd->edje, &x_, &y_, NULL, NULL);
130    switch(wd->mode)
131      {
132       case ELM_CONTROLBAR_MODE_LEFT:
133          evas_object_move(wd->view, x + width, y);
134          break;
135       case ELM_CONTROLBAR_MODE_RIGHT:
136       default:
137          evas_object_move(wd->view, x, y);
138          break;
139      }
140 }
141
142 static void
143 _controlbar_resize(void *data, Evas_Object * obj __UNUSED__)
144 {
145    Widget_Data * wd;
146    Evas_Coord x, y, x_, y_, w, h, width, height;
147    if (!data) return;
148    wd = elm_widget_data_get((Evas_Object *) data);
149    if (!wd) return;
150    evas_object_geometry_get(wd->edje, &x, &y, &w, &h);
151    wd->w = w;
152    wd->h = h;
153    evas_object_resize(wd->edje, w, h);
154    evas_object_geometry_get(elm_layout_content_get(wd->edje, "bg_image"), NULL, NULL, &width, &height);
155    evas_object_geometry_get(wd->edje, &x_, &y_, NULL, NULL);
156    switch(wd->mode)
157      {
158       case ELM_CONTROLBAR_MODE_LEFT:
159          evas_object_move(wd->view, x + width, y);
160       case ELM_CONTROLBAR_MODE_RIGHT:
161          evas_object_resize(wd->view, w - width, h);
162          break;
163       default:
164          evas_object_resize(wd->view, w, h - height + 1);
165          evas_object_move(wd->view, x, y);
166          break;
167      }
168 }
169
170 static void
171 _controlbar_object_move(void *data, Evas * e __UNUSED__, Evas_Object * obj,
172                         void *event_info __UNUSED__)
173 {
174    _controlbar_move(data, obj);
175 }
176
177 static void
178 _controlbar_object_resize(void *data, Evas * e __UNUSED__, Evas_Object * obj,
179                           void *event_info __UNUSED__)
180 {
181    _controlbar_resize(data, obj);
182 }
183
184 static void
185 _controlbar_object_show(void *data, Evas * e __UNUSED__, Evas_Object * obj __UNUSED__,
186                         void *event_info __UNUSED__)
187 {
188    Widget_Data * wd;
189    if (!data) return;
190    wd = elm_widget_data_get((Evas_Object *) data);
191    if (!wd) return;
192    evas_object_show(wd->view);
193    evas_object_show(wd->edje);
194    evas_object_show(wd->box);
195 }
196
197 static void
198 _controlbar_object_hide(void *data, Evas * e __UNUSED__, Evas_Object * obj __UNUSED__,
199                         void *event_info __UNUSED__)
200 {
201    Widget_Data * wd;
202    if (!data) return;
203    wd = elm_widget_data_get((Evas_Object *) data);
204    if (!wd) return;
205    evas_object_hide(wd->view);
206    evas_object_hide(wd->edje);
207    evas_object_hide(wd->box);
208
209    _cancel_selected_box(wd);
210 }
211
212 static void
213 _item_del(Elm_Controlbar_Item *it)
214 {
215    if (!it) return;
216    Widget_Data *wd = elm_widget_data_get(it->obj);
217    if (!wd) return;
218
219    if (it->text)
220      eina_stringshare_del(it->text);
221    if (it->icon_path)
222      eina_stringshare_del(it->icon_path);
223    if (it->icon)
224      evas_object_del(it->icon);
225    if (it->base)
226      evas_object_del(it->base);
227    if (it->base_item)
228      evas_object_del(it->base_item);
229    if (it->view)
230      evas_object_del(it->view);
231 }
232
233 static void
234 _del_hook(Evas_Object * obj)
235 {
236    Widget_Data * wd = elm_widget_data_get(obj);
237    Elm_Controlbar_Item * item;
238    if (!wd) return;
239
240    EINA_LIST_FREE(wd->items, item)
241      {
242         _item_del(item);
243         free(item);
244         item = NULL;
245      }
246    if (wd->bg)
247      {
248         evas_object_del(wd->bg);
249         wd->bg = NULL;
250      }
251    if (wd->box)
252      {
253         evas_object_del(wd->box);
254         wd->box = NULL;
255      }
256    if (wd->edje)
257      {
258         evas_object_del(wd->edje);
259         wd->edje = NULL;
260      }
261    if (wd->effect_timer)
262      {
263         ecore_timer_del(wd->effect_timer);
264         wd->effect_timer = NULL;
265      }
266    if (wd->ad)
267      {
268         if (wd->ad->timer) ecore_animator_del(wd->ad->timer);
269         wd->ad->timer = NULL;
270         free(wd->ad);
271         wd->ad = NULL;
272      }
273    if (wd->view)
274      {
275         evas_object_del(wd->view);
276         wd->view = NULL;
277      }
278
279    free(wd);
280    wd = NULL;
281 }
282
283 static void
284 _theme_hook(Evas_Object * obj)
285 {
286    const Eina_List *l;
287
288    Elm_Controlbar_Item * item;
289    int r, g, b;
290
291    Widget_Data * wd = elm_widget_data_get(obj);
292    if (!wd) return;
293    elm_layout_theme_set(wd->edje, "controlbar", "base",
294                          elm_widget_style_get(obj));
295    elm_layout_theme_set(wd->bg, "controlbar", "background",
296                          elm_widget_style_get(obj));
297    evas_object_color_get(wd->bg, &r, &g, &b, NULL);
298    evas_object_color_set(wd->bg, r, g, b, (int)(255 * wd->alpha / 100));
299    elm_layout_theme_set(wd->view, "controlbar", "view", elm_widget_style_get(obj));
300    EINA_LIST_FOREACH(wd->items, l, item)
301      {
302         elm_layout_theme_set(item->base, "controlbar", "item_bg", elm_widget_style_get(obj));
303         if (item->selected)
304           _select_box(item);
305      }
306    elm_controlbar_mode_set(obj, wd->mode);
307    _check_toolbar_line(wd);
308 }
309
310 static void
311 _disable_hook(Evas_Object * obj)
312 {
313    Widget_Data * wd = elm_widget_data_get(obj);
314    if (!wd) return;
315    const Eina_List *l;
316    Elm_Controlbar_Item * item;
317    Eina_Bool disabled;
318
319    wd->disabled = elm_widget_disabled_get(obj);
320
321    EINA_LIST_FOREACH(wd->items, l, item)
322      {
323         if (wd->disabled)
324           disabled = wd->disabled;
325         else
326           disabled = item->disabled;
327
328         if (item->base_item) elm_widget_disabled_set(item->base_item, disabled);
329      }
330 }
331
332 static void
333 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
334 {
335    Widget_Data *wd = elm_widget_data_get(obj);
336    Evas_Object *sub = event_info;
337    Evas_Object *content;
338    if (!wd) return;
339
340    if (sub == wd->view)
341      {
342         content = elm_layout_content_unset(wd->view, "elm.swallow.view");
343         evas_object_hide(content);
344      }
345 }
346
347 static void
348 _sizing_eval(Evas_Object * obj)
349 {
350    Widget_Data * wd = elm_widget_data_get(obj);
351    if (!wd) return;
352    _controlbar_move(obj, obj);
353    _controlbar_resize(obj, obj);
354 }
355
356 /////////////////////////////////////////////////////////////
357 //
358 // animation function
359 //
360 /////////////////////////////////////////////////////////////
361
362 static Eina_Bool
363 _move_evas_object(void *data)
364 {
365    Evas_Object *bg_image;
366    double t = 0.0, vx = 0.0, vy = 0.0, vw = 0.0, vh = 0.0;
367    int dx = 0 , dy = 0, dw = 0, dh = 0;
368    int px = 0, py = 0, pw = 0, ph = 0;
369    int ox = 0, oy = 0, ow = 0, oh = 0;
370    int x = 0, y = 0, w = 0, h = 0;
371
372    Animation_Data * ad = (Animation_Data *) data;
373    bg_image = edje_object_part_object_get(_EDJ(ad->obj), "bg_image");
374    if (bg_image) evas_object_geometry_get(bg_image, &ox, &oy, &ow, &oh);
375    t = ELM_MAX(0.0, ecore_loop_time_get() - ad->start_time);
376    dx = ad->tx - ad->fx;
377    dy = ad->ty - ad->fy;
378    dw = ad->tw - ad->fw;
379    dh = ad->th - ad->fh;
380    if (t <= ad->time)
381      {
382         x = (1 * sin((t / ad->time) * (M_PI / 2)) * dx);
383         y = (1 * sin((t / ad->time) * (M_PI / 2)) * dy);
384         w = (1 * sin((t / ad->time) * (M_PI / 2)) * dw);
385         h = (1 * sin((t / ad->time) * (M_PI / 2)) * dh);
386      }
387    else
388      {
389         x = dx;
390         y = dy;
391         w = dw;
392         h = dh;
393      }
394    px = ad->fx + x;
395    py = ad->fy + y;
396    pw = ad->fw + w;
397    ph = ad->fh + h;
398
399    if ((ow - pw) == 0)
400      vx = 0;
401    else
402      vx = (double)(px - ox) / (double)(ow - pw);
403    if ((oh - ph) == 0)
404      vy = 0;
405    else
406      vy = (double)(py - oy) / (double)(oh - ph);
407    vw = (double)pw / (double)ow;
408    vh = (double)ph / (double)oh;
409
410    if ((x == dx) && (y == dy) && (w == dw) && (h == dh))
411      {
412         if (ad->timer) ecore_animator_del(ad->timer);
413         ad->timer = NULL;
414         edje_object_part_drag_size_set(_EDJ(ad->obj), "elm.dragable.box", vw, vh);
415         edje_object_part_drag_value_set(_EDJ(ad->obj), "elm.dragable.box", vx, vy);
416         if (ad->func != NULL)
417           ad->func(ad->data, ad->obj);
418         return ECORE_CALLBACK_CANCEL;
419      }
420    else
421      {
422         edje_object_part_drag_size_set(_EDJ(ad->obj), "elm.dragable.box", vw, vh);
423         edje_object_part_drag_value_set(_EDJ(ad->obj), "elm.dragable.box", vx, vy);
424      }
425    return ECORE_CALLBACK_RENEW;
426 }
427
428 static Animation_Data*
429 _move_object_with_animation(Evas_Object * obj, Evas_Coord x, Evas_Coord y,
430                            Evas_Coord w, Evas_Coord h, Evas_Coord x_,
431                            Evas_Coord y_, Evas_Coord w_, Evas_Coord h_,
432                            double time, Eina_Bool (*mv_func) (void *data),
433                            void (*func) (void *data,
434                                          Evas_Object * obj), void *data)
435 {
436    Animation_Data * ad = (Animation_Data *) malloc(sizeof(Animation_Data));
437    if (!ad) return NULL;
438    ad->obj = obj;
439    ad->fx = x;
440    ad->fy = y;
441    ad->fw = w;
442    ad->fh = h;
443    ad->tx = x_;
444    ad->ty = y_;
445    ad->tw = w_;
446    ad->th = h_;
447    ad->start_time = ecore_loop_time_get();
448    ad->time = time;
449    ad->func = func;
450    ad->data = data;
451    ad->timer = ecore_animator_add(mv_func, ad);
452
453    return ad;
454 }
455
456 /////////////////////////////////////////////////////////////
457 //
458 // callback function
459 //
460 /////////////////////////////////////////////////////////////
461
462 static int
463 _sort_cb(const void *d1, const void *d2)
464 {
465    Elm_Controlbar_Item * item1, *item2;
466    item1 = (Elm_Controlbar_Item *) d1;
467    item2 = (Elm_Controlbar_Item *) d2;
468    if (item1->order <= 0) return 1;
469    if (item2->order <= 0) return -1;
470    return item1->order > item2->order ? 1 : -1;
471 }
472
473 ///////////////////////////////////////////////////////////////////
474 //
475 //  basic utility function
476 //
477 ////////////////////////////////////////////////////////////////////
478
479 static Eina_Bool
480 _check_item(Widget_Data *wd, Elm_Controlbar_Item *item)
481 {
482    const Eina_List *l;
483    Elm_Controlbar_Item *it;
484
485    if (!wd) return EINA_FALSE;
486    if (!wd->items) return EINA_FALSE;
487
488    EINA_LIST_FOREACH(wd->items, l, it)
489       if (it == item) return EINA_TRUE;
490
491    return EINA_FALSE;
492 }
493
494 static void
495 _check_background(Widget_Data *wd)
496 {
497    if (!wd) return;
498    Eina_List *l;
499    Elm_Controlbar_Item *it;
500
501    EINA_LIST_FOREACH(wd->items, l, it)
502      {
503         if (it->style == TABBAR)
504           {
505              if (wd->mode == ELM_CONTROLBAR_MODE_LEFT)
506                edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar_left", "elm");
507              else if (wd->mode == ELM_CONTROLBAR_MODE_RIGHT)
508                edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar_right", "elm");
509              else
510                edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar", "elm");
511              return;
512           }
513      }
514    edje_object_signal_emit(_EDJ(wd->bg), "elm,state,toolbar", "elm");
515 }
516
517 static void
518 _check_toolbar_line(Widget_Data *wd)
519 {
520    if (!wd) return;
521    Eina_List *l;
522    Elm_Controlbar_Item *it, *it2;
523
524    EINA_LIST_FOREACH(wd->items, l, it)
525      {
526         it2 = elm_controlbar_item_prev(it);
527         if (!it2) continue;
528         if (it->style != TOOLBAR || it2->style != TOOLBAR) continue;
529
530         if (wd->vertical)
531           {
532              edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_hide", "elm");
533              edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_hide", "elm");
534
535              if ((it->icon || it->text) && (it2->icon || it2->text))
536                {
537                   edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_show", "elm");
538                   edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_show", "elm");
539                }
540              else
541                {
542                   edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_hide", "elm");
543                   edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_hide", "elm");
544                }
545           }
546         else
547           {
548              edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_hide", "elm");
549              edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_hide", "elm");
550
551              if ((it->icon || it->text) && (it2->icon || it2->text))
552                {
553                   edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_show", "elm");
554                   edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_show", "elm");
555                }
556              else
557                {
558                   edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_hide", "elm");
559                   edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_hide", "elm");
560                }
561           }
562      }
563 }
564
565 static int
566 _check_bar_item_number(Widget_Data *wd)
567 {
568    const Eina_List *l;
569    Elm_Controlbar_Item * item;
570    int num = 0;
571
572    EINA_LIST_FOREACH(wd->items, l, item)
573       if (item->order > 0) num++;
574
575    return num;
576 }
577
578 static void
579 _insert_item_in_bar(Elm_Controlbar_Item * it, int order)
580 {
581    const Eina_List *l;
582    Elm_Controlbar_Item * item;
583    Widget_Data * wd = elm_widget_data_get(it->obj);
584    if (!wd) return;
585    int check = 0;
586
587    if (order == 0) return;
588
589    EINA_LIST_FOREACH(wd->items, l, item)
590      {
591         if ((item->order == order) && (item != it))
592           check = 1;
593      }
594    if (check)
595      {
596         EINA_LIST_FOREACH(wd->items, l, item)
597           {
598              if (item->order > 0)
599                elm_table_unpack(wd->box, item->base);
600           }
601         EINA_LIST_FOREACH(wd->items, l, item)
602           {
603              if (item->order > 0)
604                {
605                   if (item->order >= order)
606                     item->order += 1;
607                   if (!wd->vertical)
608                     elm_table_pack(wd->box, item->base, item->order - 1, 0, 1, 1);
609                   else
610                     elm_table_pack(wd->box, item->base, 0, item->order - 1, 1, 1);
611                   evas_object_show(item->base);
612                }
613           }
614      }
615    it->order = order;
616    if (!wd->vertical)
617      elm_table_pack(wd->box, it->base, it->order - 1, 0, 1, 1);
618    else
619      elm_table_pack(wd->box, it->base, 0, it->order - 1, 1, 1);
620    evas_object_show(it->base);
621 }
622
623 static void
624 _delete_item_in_bar(Elm_Controlbar_Item * it)
625 {
626    const Eina_List *l;
627    Elm_Controlbar_Item * item;
628    Widget_Data * wd = elm_widget_data_get(it->obj);
629    if (!wd) return;
630    int i = 0;
631
632    EINA_LIST_FOREACH(wd->items, l, item)
633      {
634         if (item == it)
635           {
636              i = it->order;
637              it->order = 0;
638              elm_table_unpack(wd->box, it->base);
639              evas_object_hide(it->base);
640           }
641      }
642    if (i)
643      {
644         EINA_LIST_FOREACH(wd->items, l, item)
645           {
646              if (item->order > i)
647                {
648                   item->order--;
649                   elm_table_unpack(wd->box, item->base);
650                   if (!wd->vertical)
651                     elm_table_pack(wd->box, item->base, item->order - 1, 0, 1, 1);
652                   else
653                     elm_table_pack(wd->box, item->base, 0, item->order - 1, 1, 1);
654                }
655           }
656      }
657 }
658
659 static void
660 _set_item_visible(Elm_Controlbar_Item *it, Eina_Bool visible)
661 {
662    Elm_Controlbar_Item *item;
663    Eina_Bool check = EINA_TRUE;
664
665    if (!it) return;
666    if (it->obj == NULL) return;
667    Widget_Data * wd = elm_widget_data_get(it->obj);
668    if (!wd || !wd->items) return;
669    if (it->order <= 0) check = EINA_FALSE;
670    if (check == visible) return;
671    if (visible)
672      {
673         item = elm_controlbar_last_item_get(it->obj);
674         if (!item) return;
675         while (!elm_controlbar_item_visible_get(item)){
676              item = elm_controlbar_item_prev(item);
677         }
678         _insert_item_in_bar(it, item->order + 1);
679      }
680    else
681      {
682         _delete_item_in_bar(it);
683      }
684    wd->items = eina_list_sort(wd->items, eina_list_count(wd->items), _sort_cb);
685    _sizing_eval(it->obj);
686 }
687
688 static Eina_Bool
689 _hide_selected_box(void *data)
690 {
691    Evas_Object *base = (Evas_Object *)data;
692
693    edje_object_part_drag_size_set(_EDJ(base), "elm.dragable.box", 0.0, 0.0);
694
695    return ECORE_CALLBACK_CANCEL;
696 }
697
698 static void
699 _end_selected_box(void *data, Evas_Object *obj __UNUSED__)
700 {
701    Widget_Data * wd = (Widget_Data *)data;
702
703    if (_check_item(wd, wd->cur_item))
704      {
705         edje_object_signal_emit(_EDJ(wd->cur_item->base), wd->selected_signal, "elm");
706      }
707
708    wd->animating--;
709    if (wd->animating < 0)
710      {
711         printf("animation error\n");
712         wd->animating = 0;
713      }
714
715    ecore_idler_add(_hide_selected_box, wd->edje);
716 }
717
718 static void
719 _move_selected_box(Widget_Data *wd, Elm_Controlbar_Item * fit, Elm_Controlbar_Item * tit)
720 {
721    Evas_Coord fx, fy, fw, fh, tx, ty, tw, th;
722    Evas_Object *from, *to;
723
724    if ((fit->order <= 0) && (wd->auto_align))
725      fit = wd->more_item;
726
727    from = (Evas_Object *) edje_object_part_object_get(_EDJ(fit->base), "bg_img");
728    evas_object_geometry_get(from, &fx, &fy, &fw, &fh);
729
730    to = (Evas_Object *) edje_object_part_object_get(_EDJ(tit->base), "bg_img");
731    evas_object_geometry_get(to, &tx, &ty, &tw, &th);
732
733    if (_check_item(wd, wd->pre_item))
734      {
735         edje_object_signal_emit(_EDJ(wd->pre_item->base), "elm,state,unselected", "elm");
736      }
737    if (_check_item(wd, wd->cur_item))
738      edje_object_signal_emit(_EDJ(wd->cur_item->base), "elm,state,unselected", "elm");
739
740    wd->animating++;
741    if (wd->ad)
742      {
743         if (wd->ad->timer) ecore_animator_del(wd->ad->timer);
744         wd->ad->timer = NULL;
745         free(wd->ad);
746         wd->ad = NULL;
747      }
748    wd->ad = _move_object_with_animation(wd->edje, fx, fy, fw, fh, tx, ty, tw, th,
749                                        0.3, _move_evas_object, _end_selected_box, wd);
750 }
751
752 static void
753 _select_box(Elm_Controlbar_Item * it)
754 {
755    if (!it) return;
756    Widget_Data * wd = elm_widget_data_get(it->obj);
757    if (!wd) return;
758    const Eina_List *l;
759    Elm_Controlbar_Item * item, *fit = NULL;
760    Evas_Object * content;
761
762    if (wd->animating) return;
763
764    wd->cur_item = it;
765
766    if (it->style == TABBAR)
767      {
768         content = elm_layout_content_unset(wd->view, "elm.swallow.view");
769         if (content) evas_object_hide(content);
770
771         EINA_LIST_FOREACH(wd->items, l, item){
772              if (item->selected) {
773                   fit = item;
774                   wd->pre_item = fit;
775              }
776              item->selected = EINA_FALSE;
777         }
778         it->selected = EINA_TRUE;
779
780         if ((fit != NULL) && (fit != it))
781           {
782              _move_selected_box(wd, fit, it);
783           }
784         else
785           {
786              edje_object_signal_emit(_EDJ(it->base), wd->selected_signal, "elm");
787           }
788
789         if (fit != it)
790           {
791              if (wd->more_item != it)
792                evas_object_smart_callback_call(it->obj, "view,change,before", it);
793           }
794
795         elm_layout_content_set(wd->view, "elm.swallow.view", it->view);
796      }
797    else if (it->style == TOOLBAR)
798      {
799         edje_object_signal_emit(_EDJ(it->base), "elm,state,text_unselected", "elm");
800         if (it->func)
801           it->func(it->data, it->obj, it);
802      }
803 }
804
805 static void
806 _cancel_selected_box(Widget_Data *wd)
807 {
808    const Eina_List *l;
809    Elm_Controlbar_Item * item;
810
811    EINA_LIST_FOREACH(wd->items, l, item)
812      {
813         if (item->style == TABBAR)
814           {
815              if (item->selected)
816                {
817                   edje_object_signal_emit(_EDJ(item->base), wd->selected_signal, "elm");
818                }
819              else
820                {
821                   edje_object_signal_emit(_EDJ(item->base), "elm,state,unselected", "elm");
822                }
823           }
824         else if (item->style == TOOLBAR)
825           {
826              edje_object_signal_emit(_EDJ(item->base), "elm,state,unselected", "elm");
827           }
828      }
829 }
830
831 static void
832 _unpress_box_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
833 {
834    Widget_Data * wd = (Widget_Data *) data;
835    Evas_Event_Mouse_Up * ev = event_info;
836    Evas_Coord x, y, w, h;
837
838    evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_UP, _unpress_box_cb);
839
840    _cancel_selected_box(wd);
841
842    if (_check_item(wd, wd->pre_item))
843      {
844         evas_object_geometry_get(wd->pre_item->base, &x, &y, &w, &h);
845         if ((ev->output.x > x) && (ev->output.x < x+w) && (ev->output.y > y) && (ev->output.y < y+h))
846           {
847              _select_box(wd->pre_item);
848           }
849      }
850    return;
851 }
852
853 static Eina_Bool
854 _press_box(Elm_Controlbar_Item * it)
855 {
856    Widget_Data * wd = elm_widget_data_get(it->obj);
857    if (!wd) return EINA_FALSE;
858    int check = 0;
859    const Eina_List *l;
860    Elm_Controlbar_Item * item;
861
862    if (wd->animating) return EINA_FALSE;
863
864    if (wd->disabled || it->disabled) return EINA_FALSE;
865
866    EINA_LIST_FOREACH(wd->items, l, item)
867      {
868         if (it == item)
869           {
870              if (it->style == TABBAR)
871                {
872                   edje_object_signal_emit(_EDJ(it->base), wd->pressed_signal, "elm");
873                }
874              else if (it->style == TOOLBAR)
875                {
876                   edje_object_signal_emit(_EDJ(it->base), "elm,state,toolbar_pressed", "elm");
877                }
878              evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP, _unpress_box_cb, (void *)wd);
879
880              check = EINA_TRUE;
881           }
882      }
883    if (!check)
884      return EINA_FALSE;
885
886    wd->pre_item = it;
887
888    return EINA_TRUE;
889 }
890
891 static Evas_Object *
892 _create_item_icon(Evas_Object *obj, Elm_Controlbar_Item * it, char *part)
893 {
894
895    Evas_Object *icon;
896    icon = elm_icon_add(obj);
897    if (!elm_icon_standard_set(icon, it->icon_path))
898      {
899         elm_icon_file_set(icon, it->icon_path, NULL);
900      }
901
902    evas_object_size_hint_min_set(icon, 40, 40);
903    evas_object_size_hint_max_set(icon, 100, 100);
904    evas_object_show(icon);
905    if (obj && part)
906      elm_button_icon_set(obj, icon);
907
908    return icon;
909 }
910
911 static Evas_Object *
912 _create_item_layout(Evas_Object * parent, Elm_Controlbar_Item * it, Evas_Object **item, Evas_Object **icon)
913 {
914
915    Evas_Object * obj;
916    obj = elm_layout_add(parent);
917    if (obj == NULL)
918      {
919         fprintf(stderr, "Cannot load bg edj\n");
920         return NULL;
921      }
922    elm_layout_theme_set(obj, "controlbar", "item_bg",
923                         elm_widget_style_get(it->obj));
924    evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
925    evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
926
927    *item = elm_button_add(parent);
928    if (*item == NULL) return NULL;
929    elm_object_style_set(*item, "controlbar/vertical");
930    elm_layout_content_set(obj, "item", *item);
931
932    if (it->text)
933      elm_object_text_set(*item, it->text);
934    if (it->icon_path)
935      *icon = _create_item_icon(*item, it, "elm.swallow.icon");
936
937    return obj;
938 }
939
940 static void
941 _bar_item_down_cb(void *data, Evas * evas __UNUSED__, Evas_Object * obj, void *event_info __UNUSED__)
942 {
943    Widget_Data * wd = (Widget_Data *) data;
944    const Eina_List *l;
945    Elm_Controlbar_Item * item;
946    if (wd->animating) return;
947
948    EINA_LIST_FOREACH(wd->items, l, item)
949       if (item->base == obj) break;
950
951    if (item == NULL) return;
952
953    _press_box(item);
954 }
955
956 static Elm_Controlbar_Item *
957 _create_tab_item(Evas_Object * obj, const char *icon_path, const char *label,
958                 Evas_Object * view)
959 {
960    Elm_Controlbar_Item * it;
961    Widget_Data * wd;
962    if (obj == NULL)
963      {
964         fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
965         return NULL;
966      }
967    wd = elm_widget_data_get(obj);
968    if (!wd)
969      {
970         fprintf(stderr, "Cannot get smart data\n");
971         return NULL;
972      }
973    it = ELM_NEW(Elm_Controlbar_Item);
974    if (!it) return NULL;
975    it->wd = wd;
976    it->obj = obj;
977    it->text = eina_stringshare_add(label);
978    it->icon_path = eina_stringshare_add(icon_path);
979    it->selected = EINA_FALSE;
980    it->sel = 1;
981    it->view = view;
982    it->style = TABBAR;
983    it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
984    evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN,
985                                   _bar_item_down_cb, wd);
986    evas_object_show(it->base);
987
988    return it;
989 }
990
991 static Elm_Controlbar_Item *
992 _create_tool_item(Evas_Object * obj, const char *icon_path, const char *label,
993                  void (*func) (void *data, Evas_Object * obj,
994                                void *event_info), void *data)
995 {
996
997    Elm_Controlbar_Item * it;
998    Widget_Data * wd;
999    if (obj == NULL)
1000      {
1001         fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
1002         return NULL;
1003      }
1004    wd = elm_widget_data_get(obj);
1005    if (!wd)
1006      {
1007         fprintf(stderr, "Cannot get smart data\n");
1008         return NULL;
1009      }
1010    it = ELM_NEW(Elm_Controlbar_Item);
1011    if (!it)
1012      return NULL;
1013    it->wd = wd;
1014    it->obj = obj;
1015    it->text = eina_stringshare_add(label);
1016    it->icon_path = eina_stringshare_add(icon_path);
1017    it->selected = EINA_FALSE;
1018    it->sel = 1;
1019    it->func = func;
1020    it->data = data;
1021    it->style = TOOLBAR;
1022    it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
1023    evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN,
1024                                   _bar_item_down_cb, wd);
1025    evas_object_show(it->base);
1026
1027    return it;
1028 }
1029
1030 static Elm_Controlbar_Item *
1031 _create_object_item(Evas_Object * obj, Evas_Object * obj_item, const int sel)
1032 {
1033    Elm_Controlbar_Item * it;
1034    Widget_Data * wd;
1035    if (obj == NULL)
1036      {
1037         fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
1038         return NULL;
1039      }
1040    wd = elm_widget_data_get(obj);
1041    if (!wd)
1042      {
1043         fprintf(stderr, "Cannot get smart data\n");
1044         return NULL;
1045      }
1046    it = ELM_NEW(Elm_Controlbar_Item);
1047    if (!it)
1048      return NULL;
1049    it->wd = wd;
1050    it->obj = obj;
1051    it->sel = sel;
1052    it->style = OBJECT;
1053    it->base = elm_layout_add(wd->edje);
1054    elm_layout_theme_set(it->base, "controlbar", "item_bg",
1055                         elm_widget_style_get(it->obj));
1056    evas_object_size_hint_weight_set(it->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1057    evas_object_size_hint_align_set(it->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
1058    it->base_item = obj_item;
1059    elm_layout_content_set(it->base, "item", it->base_item);
1060    evas_object_show(it->base);
1061    return it;
1062 }
1063
1064 static void
1065 _repack_items(Widget_Data *wd)
1066 {
1067    const Eina_List *l;
1068    Elm_Controlbar_Item * item;
1069
1070    EINA_LIST_FOREACH(wd->items, l, item)
1071      {
1072         if (item->order > 0)
1073           {
1074              elm_table_unpack(wd->box, item->base);
1075              if (!wd->vertical)
1076                elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
1077              else
1078                elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
1079           }
1080      }
1081 }
1082
1083 static void
1084 _set_items_position(Evas_Object * obj, Elm_Controlbar_Item * it,
1085                    Elm_Controlbar_Item * mit, Eina_Bool bar)
1086 {
1087    Widget_Data * wd;
1088    const Eina_List *l;
1089    Elm_Controlbar_Item * item;
1090    int check = EINA_FALSE;
1091    int order = 1;
1092
1093    if (obj == NULL)
1094      {
1095         fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
1096         return;
1097      }
1098    wd = elm_widget_data_get(obj);
1099    if (!wd)
1100      {
1101         fprintf(stderr, "Cannot get smart data\n");
1102         return;
1103      }
1104
1105    EINA_LIST_FOREACH(wd->items, l, item)
1106      {
1107         if ((item == mit) && (item->order > 0))
1108           {
1109              check = EINA_TRUE;
1110              it->order = mit->order;
1111           }
1112         if (check)
1113           {
1114              if (item->order > 0)
1115                {
1116                   elm_table_unpack(wd->box, item->base);
1117                   item->order += it->sel;
1118                   if (!wd->vertical)
1119                     elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
1120                   else
1121                     elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
1122                }
1123           }
1124         if (item->order > 0) order += item->sel;
1125      }
1126    if (!check)
1127      {
1128         if (bar)
1129           it->order = order;
1130         else
1131           it->order = 0;
1132      }
1133    wd->num++;
1134
1135    if (bar)
1136      {
1137         if (!wd->vertical)
1138           elm_table_pack(wd->box, it->base, it->order - 1, 0, it->sel, 1);
1139         else
1140           elm_table_pack(wd->box, it->base, 0, it->order - 1, it->sel, 1);
1141      }
1142    else
1143      evas_object_hide(it->base);
1144 }
1145
1146 static void
1147 _list_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1148 {
1149    Elm_Controlbar_Item *item = (Elm_Controlbar_Item *)data;
1150    Elm_Controlbar_Item *it;
1151    const Eina_List *l;
1152    Widget_Data *wd;
1153    Evas_Object *content;
1154    Elm_List_Item *lit = (Elm_List_Item *) elm_list_selected_item_get(obj);
1155    if (!lit) return;
1156
1157    elm_list_item_selected_set(lit, 0);
1158
1159    if (!item) return;
1160
1161    wd = elm_widget_data_get(item->obj);
1162    if (!wd) return;
1163
1164    EINA_LIST_FOREACH(wd->items, l, it)
1165      {
1166         it->selected = EINA_FALSE;
1167      }
1168
1169    if (item->style == TABBAR)
1170      {
1171         content = elm_layout_content_unset(wd->view, "elm.swallow.view");
1172         evas_object_hide(content);
1173         item->selected = EINA_TRUE;
1174         evas_object_smart_callback_call(item->obj, "view,change,before", item);
1175         elm_layout_content_set(wd->view, "elm.swallow.view", item->view);
1176      }
1177
1178    if ((item->style == TOOLBAR) && (item->func))
1179      item->func(item->data, item->obj, item);
1180 }
1181
1182 static Evas_Object *
1183 _create_more_view(Widget_Data *wd)
1184 {
1185    Evas_Object *list;
1186    Elm_Controlbar_Item *item;
1187    const Eina_List *l;
1188    Evas_Object *icon;
1189
1190    list = elm_list_add( wd->object );
1191    elm_list_mode_set( list, ELM_LIST_COMPRESS );
1192
1193    EINA_LIST_FOREACH(wd->items, l, item)
1194      {
1195         if (item->order <= 0)
1196           {
1197              icon = NULL;
1198              if (item->icon_path)
1199                {
1200                   icon = _create_item_icon(list, item, NULL);
1201                   evas_object_color_set(icon, 0, 0, 0, 255);
1202                }
1203              elm_list_item_append(list, item->text, icon, NULL, _list_clicked, item);
1204           }
1205      }
1206
1207    elm_list_go( list );
1208
1209    return list;
1210 }
1211
1212 static void _ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
1213 {
1214    Elm_Controlbar_Item *it;
1215    const Eina_List *l;
1216    Evas_Object *ctxpopup = obj;
1217    char * label;
1218    Widget_Data *wd = (Widget_Data *)data;
1219
1220    EINA_LIST_FOREACH(wd->items, l, it)
1221      {
1222         label = elm_ctxpopup_item_label_get((Elm_Object_Item *) event_info);
1223         if ((label) && (!strcmp(it->text, label))) break;
1224      }
1225
1226    if (it->func)
1227      it->func(it->data, it->obj, it);
1228
1229    if (_check_item(wd, it)) evas_object_smart_callback_call(it->obj, "clicked", it);
1230
1231    evas_object_del(ctxpopup);
1232    ctxpopup = NULL;
1233 }
1234
1235 static void _ctxpopup_dismissed_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1236 {
1237    Evas_Object *ctxpopup = obj;
1238
1239    evas_object_del(ctxpopup);
1240    ctxpopup = NULL;
1241 }
1242
1243 static void
1244 _create_more_func(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1245 {
1246    Evas_Object *ctxpopup;
1247    Elm_Controlbar_Item *item;
1248    const Eina_List *l;
1249    Evas_Object *icon;
1250    Evas_Coord x, y, w, h;
1251    Widget_Data *wd = elm_widget_data_get(obj);
1252    if (!wd) return;
1253
1254    ctxpopup = elm_ctxpopup_add(wd->parent);
1255    evas_object_smart_callback_add( ctxpopup, "dismissed", _ctxpopup_dismissed_cb, wd);
1256
1257    EINA_LIST_FOREACH(wd->items, l, item)
1258      {
1259         if (item->order <= 0)
1260           {
1261              icon = NULL;
1262              if (item->icon_path)
1263                {
1264                   icon = _create_item_icon(ctxpopup, item, NULL);
1265                   evas_object_color_set(icon, 0, 0, 0, 255);
1266                }
1267              elm_ctxpopup_item_append(ctxpopup, item->text, icon, _ctxpopup_cb, wd);
1268           }
1269      }
1270
1271    evas_object_geometry_get(wd->more_item->base, &x, &y, &w, &h);
1272    evas_object_move(ctxpopup, x + w/2, y + h/2);
1273
1274    evas_object_show(ctxpopup);
1275 }
1276
1277 static Elm_Controlbar_Item *
1278 _create_more_item(Widget_Data *wd, int style)
1279 {
1280    Elm_Controlbar_Item * it;
1281
1282    it = ELM_NEW(Elm_Controlbar_Item);
1283    if (!it) return NULL;
1284    it->obj = wd->object;
1285    it->text = eina_stringshare_add("more");
1286    it->icon_path = eina_stringshare_add(CONTROLBAR_SYSTEM_ICON_MORE);
1287    it->selected = EINA_FALSE;
1288    it->sel = 1;
1289    it->view = _create_more_view(wd);
1290    it->func = _create_more_func;
1291    it->style = style;
1292    it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
1293    evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN,
1294                                   _bar_item_down_cb, wd);
1295    evas_object_show(it->base);
1296
1297    _set_items_position(it->obj, it, NULL, EINA_TRUE);
1298    wd->items = eina_list_append(wd->items, it);
1299    wd->more_item = it;
1300    wd->items = eina_list_sort(wd->items, eina_list_count(wd->items), _sort_cb);
1301
1302    return it;
1303 }
1304
1305 ///////////////////////////////////////////////////////////////////
1306 //
1307 //  API function
1308 //
1309 ////////////////////////////////////////////////////////////////////
1310
1311 /**
1312  * Add a new controlbar object
1313  *
1314  * @param parent The parent object
1315  * @return The new object or NULL if it cannot be created
1316  *
1317  * @ingroup Controlbar
1318  */
1319 EAPI Evas_Object * elm_controlbar_add(Evas_Object * parent)
1320 {
1321    if (parent == NULL) return NULL;
1322    Evas_Object * obj = NULL;
1323    Evas_Object * bg = NULL;
1324    Widget_Data * wd = NULL;
1325    Evas_Coord x, y, w, h;
1326    Evas *e;
1327    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1328    ELM_SET_WIDTYPE(widtype, "controlbar");
1329    elm_widget_type_set(obj, "controlbar");
1330    elm_widget_sub_object_add(parent, obj);
1331    elm_widget_data_set(obj, wd);
1332    elm_widget_del_hook_set(obj, _del_hook);
1333    elm_widget_can_focus_set(obj, EINA_FALSE);
1334    elm_widget_theme_hook_set(obj, _theme_hook);
1335    elm_widget_disable_hook_set(obj, _disable_hook);
1336
1337    // initialization
1338    wd->parent = parent;
1339    evas_object_geometry_get(parent, &x, &y, &w, &h);
1340    wd->object = obj;
1341    wd->x = x;
1342    wd->y = y;
1343    wd->w = w;
1344    wd->h = h;
1345    wd->mode = ELM_CONTROLBAR_MODE_DEFAULT;
1346    wd->alpha = 100;
1347    wd->num = 0;
1348    wd->animating = 0;
1349    wd->vertical = EINA_FALSE;
1350    wd->auto_align = EINA_FALSE;
1351    wd->selected_animation = EINA_FALSE;
1352    wd->pressed_signal = eina_stringshare_add("elm,state,pressed");
1353    wd->selected_signal = eina_stringshare_add("elm,state,selected");
1354    wd->view = elm_layout_add(wd->parent);
1355    elm_layout_theme_set(wd->view, "controlbar", "view", "default");
1356    if (wd->view == NULL)
1357      {
1358         printf("Cannot load bg edj\n");
1359         return NULL;
1360      }
1361    evas_object_show(wd->view);
1362
1363    /* load background edj */
1364    wd->edje = elm_layout_add(obj);
1365    elm_layout_theme_set(wd->edje, "controlbar", "base", "default");
1366    if (wd->edje == NULL)
1367      {
1368         printf("Cannot load base edj\n");
1369         return NULL;
1370      }
1371    evas_object_show(wd->edje);
1372
1373    wd->bg = elm_layout_add(wd->edje);
1374    elm_layout_theme_set(wd->bg, "controlbar", "background", "default");
1375    if (wd->bg == NULL)
1376      {
1377         printf("Cannot load bg edj\n");
1378         return NULL;
1379      }
1380    elm_layout_content_set(wd->edje, "bg_image", wd->bg);
1381
1382    // initialization
1383    evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_RESIZE,
1384                                   _controlbar_object_resize, obj);
1385    evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_MOVE,
1386                                   _controlbar_object_move, obj);
1387    evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_SHOW,
1388                                   _controlbar_object_show, obj);
1389    evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_HIDE,
1390                                   _controlbar_object_hide, obj);
1391
1392    bg = elm_layout_content_get(wd->edje, "bg_image");
1393    evas_object_event_callback_add(bg, EVAS_CALLBACK_MOVE, _controlbar_object_move, obj);
1394    evas_object_event_callback_add(bg, EVAS_CALLBACK_RESIZE, _controlbar_object_resize, obj);
1395
1396    // items container
1397    wd->box = elm_table_add(wd->edje);
1398    elm_table_homogeneous_set(wd->box, EINA_TRUE);
1399    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1400                                     EVAS_HINT_EXPAND);
1401    evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1402    elm_layout_content_set(wd->edje, "elm.swallow.items", wd->box);
1403    evas_object_show(wd->box);
1404
1405    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1406
1407    evas_object_smart_member_add(wd->view, obj);
1408    elm_widget_resize_object_set(obj, wd->edje);
1409
1410    _sizing_eval(obj);
1411
1412    return obj;
1413 }
1414
1415 /**
1416  * Append new tab item
1417  *
1418  * @param       obj The controlbar object
1419  * @param       icon_path The icon path of item
1420  * @param       label The label of item
1421  * @param       view The view of item
1422  * @return      The item of controlbar
1423  *
1424  * @ingroup Controlbar
1425  */
1426 EAPI Elm_Controlbar_Item * elm_controlbar_tab_item_append(Evas_Object * obj,
1427                                                           const char
1428                                                           *icon_path,
1429                                                           const char *label,
1430                                                           Evas_Object *
1431                                                           view)
1432 {
1433    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1434    Elm_Controlbar_Item * it;
1435    Elm_Controlbar_Item * lit;
1436    Widget_Data * wd;
1437    it = _create_tab_item(obj, icon_path, label, view);
1438    if (!it) return NULL;
1439    wd = elm_widget_data_get(obj);
1440    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1441      {
1442         if (!wd->more_item) {
1443              lit = elm_controlbar_last_item_get(obj);
1444              _set_item_visible(lit, EINA_FALSE);
1445              _create_more_item(wd, TABBAR);
1446         }
1447         _set_items_position(obj, it, NULL, EINA_FALSE);
1448    }
1449    else{
1450         _set_items_position(obj, it, NULL, EINA_TRUE);
1451    }
1452    wd->items = eina_list_append(wd->items, it);
1453    if (wd->more_item)
1454      elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1455
1456    _check_background(wd);
1457    _sizing_eval(obj);
1458    return it;
1459 }
1460
1461 /**
1462  * Prepend new tab item
1463  *
1464  * @param       obj The controlbar object
1465  * @param       icon_path The icon path of item
1466  * @param       label The label of item
1467  * @param       view The view of item
1468  * @return      The item of controlbar
1469  *
1470  * @ingroup Controlbar
1471  */
1472 EAPI Elm_Controlbar_Item * elm_controlbar_tab_item_prepend(Evas_Object *
1473                                                            obj,
1474                                                            const char
1475                                                            *icon_path,
1476                                                            const char
1477                                                            *label,
1478                                                            Evas_Object *
1479                                                            view)
1480 {
1481    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1482    Widget_Data * wd;
1483    Elm_Controlbar_Item * it;
1484    Elm_Controlbar_Item * lit;
1485    Elm_Controlbar_Item * item;
1486    it = _create_tab_item(obj, icon_path, label, view);
1487    if (!it) return NULL;
1488    wd = elm_widget_data_get(obj);
1489    item = eina_list_data_get(wd->items);
1490    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1491      {
1492         if (!wd->more_item) {
1493              lit = elm_controlbar_last_item_get(obj);
1494              _set_item_visible(lit, EINA_FALSE);
1495              _create_more_item(wd, TABBAR);
1496         }
1497         lit = elm_controlbar_item_prev(wd->more_item);
1498         _set_item_visible(lit, EINA_FALSE);
1499         _set_items_position(obj, it, item, EINA_TRUE);
1500    }
1501    else{
1502         _set_items_position(obj, it, item, EINA_TRUE);
1503    }
1504    wd->items = eina_list_prepend(wd->items, it);
1505    if (wd->more_item)
1506      elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1507
1508    _check_background(wd);
1509    _sizing_eval(obj);
1510    return it;
1511 }
1512
1513 /**
1514  * Insert new tab item before given item
1515  *
1516  * @param       obj The controlbar object
1517  * @param       before The given item
1518  * @param       icon_path The icon path of item
1519  * @param       label The label of item
1520  * @param       view The view of item
1521  * @return      The item of controlbar
1522  *
1523  * @ingroup Controlbar
1524  */
1525 EAPI Elm_Controlbar_Item *
1526 elm_controlbar_tab_item_insert_before(Evas_Object * obj,
1527                                       Elm_Controlbar_Item * before,
1528                                       const char *icon_path,
1529                                       const char *label, Evas_Object * view)
1530 {
1531    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1532    Widget_Data * wd;
1533    Elm_Controlbar_Item * it;
1534    Elm_Controlbar_Item * lit;
1535    if (!before) return NULL;
1536    it = _create_tab_item(obj, icon_path, label, view);
1537    if (!it) return NULL;
1538    wd = elm_widget_data_get(obj);
1539    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1540      {
1541         if (!wd->more_item)
1542           {
1543              lit = elm_controlbar_last_item_get(obj);
1544              _set_item_visible(lit, EINA_FALSE);
1545              _create_more_item(wd, TABBAR);
1546           }
1547         before = wd->more_item;
1548         if (before->order > 0)
1549           {
1550              lit = elm_controlbar_item_prev(wd->more_item);
1551              _set_item_visible(lit, EINA_FALSE);
1552              _set_items_position(obj, it, before, EINA_TRUE);
1553           }
1554         else
1555           {
1556              _set_items_position(obj, it, before, EINA_FALSE);
1557           }
1558    }
1559    else{
1560         _set_items_position(obj, it, before, EINA_TRUE);
1561    }
1562    wd->items = eina_list_prepend_relative(wd->items, it, before);
1563    if (wd->more_item)
1564      elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1565
1566    _check_background(wd);
1567    _sizing_eval(obj);
1568    return it;
1569 }
1570
1571 /**
1572  * Insert new tab item after given item
1573  *
1574  * @param       obj The controlbar object
1575  * @param       after The given item
1576  * @param       icon_path The icon path of item
1577  * @param       label The label of item
1578  * @param       view The view of item
1579  * @return      The item of controlbar
1580  *
1581  * @ingroup Controlbar
1582  */
1583 EAPI Elm_Controlbar_Item *
1584 elm_controlbar_tab_item_insert_after(Evas_Object * obj,
1585                                      Elm_Controlbar_Item * after,
1586                                      const char *icon_path, const char *label,
1587                                      Evas_Object * view)
1588 {
1589    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1590    Widget_Data * wd;
1591    Elm_Controlbar_Item * it;
1592    Elm_Controlbar_Item * lit;
1593    Elm_Controlbar_Item * item;
1594    if (!after) return NULL;
1595    it = _create_tab_item(obj, icon_path, label, view);
1596    if (!it) return NULL;
1597    wd = elm_widget_data_get(obj);
1598    item = elm_controlbar_item_next(after);
1599    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1600      {
1601         if (!wd->more_item)
1602           {
1603              lit = elm_controlbar_last_item_get(obj);
1604              _set_item_visible(lit, EINA_FALSE);
1605              _create_more_item(wd, TABBAR);
1606           }
1607         lit = elm_controlbar_item_prev(wd->more_item);
1608         if ((lit != after) && (item->order > 0))
1609           {
1610              _set_item_visible(lit, EINA_FALSE);
1611              _set_items_position(obj, it, item, EINA_TRUE);
1612           }
1613         else
1614           {
1615              _set_items_position(obj, it, NULL, EINA_FALSE);
1616           }
1617    }
1618    else{
1619         _set_items_position(obj, it, item, EINA_TRUE);
1620    }
1621    wd->items = eina_list_append_relative(wd->items, it, after);
1622    if (wd->more_item)
1623      elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1624
1625    _check_background(wd);
1626    _sizing_eval(obj);
1627    return it;
1628 }
1629
1630 /**
1631  * Append new tool item
1632  *
1633  * @param       obj The controlbar object
1634  * @param       icon_path The icon path of item
1635  * @param       label The label of item
1636  * @param       func Callback function of item
1637  * @param       data The data of callback function
1638  * @return      The item of controlbar
1639  *
1640  * @ingroup Controlbar
1641  */
1642 EAPI Elm_Controlbar_Item * elm_controlbar_tool_item_append(Evas_Object *
1643                                                            obj,
1644                                                            const char
1645                                                            *icon_path,
1646                                                            const char
1647                                                            *label,
1648                                                            void (*func)
1649                                                            (void *data,
1650                                                             Evas_Object *
1651                                                             obj,
1652                                                             void
1653                                                             *event_info),
1654                                                            void *data)
1655
1656 {
1657    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1658    Elm_Controlbar_Item * it;
1659    Elm_Controlbar_Item * lit;
1660    Widget_Data * wd;
1661    it = _create_tool_item(obj, icon_path, label, func, data);
1662    if (!it) return NULL;
1663    wd = elm_widget_data_get(obj);
1664    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1665      {
1666         if (!wd->more_item) {
1667              lit = elm_controlbar_last_item_get(obj);
1668              _set_item_visible(lit, EINA_FALSE);
1669              _create_more_item(wd, TOOLBAR);
1670         }
1671         _set_items_position(obj, it, NULL, EINA_FALSE);
1672    }
1673    else{
1674         _set_items_position(obj, it, NULL, EINA_TRUE);
1675    }
1676    wd->items = eina_list_append(wd->items, it);
1677    _check_toolbar_line(wd);
1678    _sizing_eval(obj);
1679    return it;
1680 }
1681
1682 /**
1683  * Prepend new tool item
1684  *
1685  * @param       obj The controlbar object
1686  * @param       icon_path The icon path of item
1687  * @param       label The label of item
1688  * @param       func Callback function of item
1689  * @param       data The data of callback function
1690  * @return      The item of controlbar
1691  *
1692  * @ingroup Controlbar
1693  */
1694 EAPI Elm_Controlbar_Item * elm_controlbar_tool_item_prepend(Evas_Object *
1695                                                             obj,
1696                                                             const char
1697                                                             *icon_path,
1698                                                             const char
1699                                                             *label,
1700                                                             void (*func)
1701                                                             (void
1702                                                              *data,
1703                                                              Evas_Object *
1704                                                              obj,
1705                                                              void
1706                                                              *event_info),
1707                                                             void
1708                                                             *data)
1709 {
1710    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1711    Widget_Data * wd;
1712    Elm_Controlbar_Item * it;
1713    Elm_Controlbar_Item * lit;
1714    Elm_Controlbar_Item * item;
1715    it = _create_tool_item(obj, icon_path, label, func, data);
1716    if (!it) return NULL;
1717    wd = elm_widget_data_get(obj);
1718    item = eina_list_data_get(wd->items);
1719    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1720      {
1721         if (!wd->more_item) {
1722              lit = elm_controlbar_last_item_get(obj);
1723              _set_item_visible(lit, EINA_FALSE);
1724              _create_more_item(wd, TOOLBAR);
1725         }
1726         lit = elm_controlbar_item_prev(wd->more_item);
1727         _set_item_visible(lit, EINA_FALSE);
1728         _set_items_position(obj, it, item, EINA_TRUE);
1729    }
1730    else{
1731         _set_items_position(obj, it, item, EINA_TRUE);
1732    }
1733    wd->items = eina_list_prepend(wd->items, it);
1734    _check_toolbar_line(wd);
1735    _sizing_eval(obj);
1736    return it;
1737 }
1738
1739 /**
1740  * Insert new tool item before given item
1741  *
1742  * @param       obj The controlbar object
1743  * @param       before The given item
1744  * @param       icon_path The icon path of item
1745  * @param       label The label of item
1746  * @param       func Callback function of item
1747  * @param       data The data of callback function
1748  * @return      The item of controlbar
1749  *
1750  * @ingroup Controlbar
1751  */
1752 EAPI Elm_Controlbar_Item *
1753 elm_controlbar_tool_item_insert_before(Evas_Object * obj,
1754                                        Elm_Controlbar_Item * before,
1755                                        const char *icon_path,
1756                                        const char *label,
1757                                        void (*func) (void *data,
1758                                                      Evas_Object * obj,
1759                                                      void *event_info),
1760                                        void *data)
1761 {
1762    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1763    Widget_Data * wd;
1764    Elm_Controlbar_Item * it;
1765    Elm_Controlbar_Item * lit;
1766    if (!before) return NULL;
1767    it = _create_tool_item(obj, icon_path, label, func, data);
1768    if (!it) return NULL;
1769    wd = elm_widget_data_get(obj);
1770    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1771      {
1772         if (!wd->more_item)
1773           {
1774              lit = elm_controlbar_last_item_get(obj);
1775              _set_item_visible(lit, EINA_FALSE);
1776              _create_more_item(wd, TOOLBAR);
1777           }
1778         before = wd->more_item;
1779         if (before->order > 0)
1780           {
1781              lit = elm_controlbar_item_prev(wd->more_item);
1782              _set_item_visible(lit, EINA_FALSE);
1783              _set_items_position(obj, it, before, EINA_TRUE);
1784           }
1785         else
1786           {
1787              _set_items_position(obj, it, before, EINA_FALSE);
1788           }
1789    }
1790    else{
1791         _set_items_position(obj, it, before, EINA_TRUE);
1792    }
1793    wd->items = eina_list_prepend_relative(wd->items, it, before);
1794    _check_toolbar_line(wd);
1795    _sizing_eval(obj);
1796    return it;
1797 }
1798
1799 /**
1800  * Insert new tool item after given item
1801  *
1802  * @param       obj The controlbar object
1803  * @param       after The given item
1804  * @param       icon_path The icon path of item
1805  * @param       label The label of item
1806  * @param       func Callback function of item
1807  * @param       data The data of callback function
1808  * @return      The item of controlbar
1809  *
1810  * @ingroup Controlbar
1811  */
1812 EAPI Elm_Controlbar_Item *
1813 elm_controlbar_tool_item_insert_after(Evas_Object * obj,
1814                                       Elm_Controlbar_Item * after,
1815                                       const char *icon_path,
1816                                       const char *label,
1817                                       void (*func) (void *data,
1818                                                     Evas_Object * obj,
1819                                                     void *event_info),
1820                                       void *data)
1821 {
1822    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1823    Widget_Data * wd;
1824    Elm_Controlbar_Item * it;
1825    Elm_Controlbar_Item * lit;
1826    Elm_Controlbar_Item * item;
1827    if (!after) return NULL;
1828    it = _create_tool_item(obj, icon_path, label, func, data);
1829    if (!it) return NULL;
1830    wd = elm_widget_data_get(obj);
1831    item = elm_controlbar_item_next(after);
1832    if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1833      {
1834         if (!wd->more_item)
1835           {
1836              lit = elm_controlbar_last_item_get(obj);
1837              _set_item_visible(lit, EINA_FALSE);
1838              _create_more_item(wd, TOOLBAR);
1839           }
1840         lit = elm_controlbar_item_prev(wd->more_item);
1841         if ((lit != after) && (item->order > 0))
1842           {
1843              _set_item_visible(lit, EINA_FALSE);
1844              _set_items_position(obj, it, item, EINA_TRUE);
1845           }
1846         else
1847           {
1848              _set_items_position(obj, it, NULL, EINA_FALSE);
1849           }
1850    }
1851    else{
1852         _set_items_position(obj, it, item, EINA_TRUE);
1853    }
1854    wd->items = eina_list_append_relative(wd->items, it, after);
1855    _check_toolbar_line(wd);
1856    _sizing_eval(obj);
1857    return it;
1858 }
1859
1860 /**
1861  * Append new object item
1862  *
1863  * @param       obj The controlbar object
1864  * @param       obj_item The object of item
1865  * @param       sel The number of sel occupied
1866  * @return  The item of controlbar
1867  *
1868  * @ingroup Controlbar
1869  */
1870 EAPI Elm_Controlbar_Item * elm_controlbar_object_item_append(Evas_Object *
1871                                                              obj,
1872                                                              Evas_Object *
1873                                                              obj_item,
1874                                                              const int sel)
1875 {
1876    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1877    Widget_Data * wd;
1878    Elm_Controlbar_Item * it;
1879    wd = elm_widget_data_get(obj);
1880    if (!wd) return NULL;
1881    it = _create_object_item(obj, obj_item, sel);
1882    if (!it) return NULL;
1883    _set_items_position(obj, it, NULL, EINA_TRUE);
1884    wd->items = eina_list_append(wd->items, it);
1885    _sizing_eval(obj);
1886    return it;
1887 }
1888
1889 /**
1890  * Prepend new object item
1891  *
1892  * @param       obj The controlbar object
1893  * @param       obj_item The object of item
1894  * @param       sel The number of sel occupied
1895  * @return  The item of controlbar
1896  *
1897  * @ingroup Controlbar
1898  */
1899 EAPI Elm_Controlbar_Item * elm_controlbar_object_item_prepend(Evas_Object *
1900                                                               obj,
1901                                                               Evas_Object *
1902                                                               obj_item,
1903                                                               const int sel)
1904 {
1905    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1906    Widget_Data * wd;
1907    Elm_Controlbar_Item * it;
1908    Elm_Controlbar_Item * item;
1909    wd = elm_widget_data_get(obj);
1910    if (!wd) return NULL;
1911    it = _create_object_item(obj, obj_item, sel);
1912    if (!it) return NULL;
1913    item = eina_list_data_get(wd->items);
1914    _set_items_position(obj, it, item, EINA_TRUE);
1915    wd->items = eina_list_prepend(wd->items, it);
1916    _sizing_eval(obj);
1917    return it;
1918 }
1919
1920 /**
1921  * Insert new object item before given item
1922  *
1923  * @param       obj The controlbar object
1924  * @param       before The given item
1925  * @param       obj_item The object of item
1926  * @param       sel The number of sel occupied
1927  * @return  The item of controlbar
1928  *
1929  * @ingroup Controlbar
1930  */
1931 EAPI Elm_Controlbar_Item *
1932 elm_controlbar_object_item_insert_before(Evas_Object * obj,
1933                                          Elm_Controlbar_Item * before,
1934                                          Evas_Object * obj_item, const int sel)
1935 {
1936    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1937    Widget_Data * wd;
1938    Elm_Controlbar_Item * it;
1939    wd = elm_widget_data_get(obj);
1940    if (!wd) return NULL;
1941    if (!before) return NULL;
1942    it = _create_object_item(obj, obj_item, sel);
1943    if (!it) return NULL;
1944    _set_items_position(obj, it, before, EINA_TRUE);
1945    wd->items = eina_list_prepend_relative(wd->items, it, before);
1946    _sizing_eval(obj);
1947    return it;
1948 }
1949
1950 /**
1951  * Insert new object item after given item
1952  *
1953  * @param       obj The controlbar object
1954  * @param       after The given item
1955  * @param       obj_item The object of item
1956  * @param       sel The number of sel occupied
1957  * @return  The item of controlbar
1958  *
1959  * @ingroup Controlbar
1960  */
1961 EAPI Elm_Controlbar_Item *
1962 elm_controlbar_object_item_insert_after(Evas_Object * obj,
1963                                         Elm_Controlbar_Item * after,
1964                                         Evas_Object * obj_item, const int sel)
1965 {
1966    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1967    Widget_Data * wd;
1968    Elm_Controlbar_Item * it;
1969    Elm_Controlbar_Item * item;
1970    wd = elm_widget_data_get(obj);
1971    if (!wd) return NULL;
1972    if (!after) return NULL;
1973    it = _create_object_item(obj, obj_item, sel);
1974    if (!it) return NULL;
1975    item = elm_controlbar_item_next(after);
1976    _set_items_position(obj, it, item, EINA_TRUE);
1977    wd->items = eina_list_append_relative(wd->items, it, after);
1978    _sizing_eval(obj);
1979    return it;
1980 }
1981
1982 /**
1983  * Get the object of the object item
1984  *
1985  * @param       it The item of controlbar
1986  * @return      The object of the object item
1987  *
1988  * @ingroup Controlbar
1989  */
1990 EAPI Evas_Object *
1991 elm_controlbar_object_item_object_get(const Elm_Controlbar_Item * it)
1992 {
1993    if (!it) return NULL;
1994    if (it->style != OBJECT) return NULL;
1995    if (!it->base_item) return NULL;
1996    return it->base_item;
1997 }
1998
1999 /**
2000  * Delete item from controlbar
2001  *
2002  * @param       it The item of controlbar
2003
2004  * @ingroup Controlbar
2005  */
2006 EAPI void
2007 elm_controlbar_item_del(Elm_Controlbar_Item * it)
2008 {
2009    Evas_Object * obj;
2010    Widget_Data * wd;
2011    const Eina_List *l;
2012
2013    Elm_Controlbar_Item * item;
2014
2015    int sel = 1;
2016
2017    if (!it) return;
2018
2019    obj = it->obj;
2020    if (it->obj == NULL)
2021      {
2022         printf("Invalid argument: controlbar object is NULL\n");
2023         return;
2024      }
2025    wd = elm_widget_data_get(it->obj);
2026    if (!wd)
2027      {
2028         printf("Cannot get smart data\n");
2029         return;
2030      }
2031
2032    // unpack base item
2033    if (it->order > 0)
2034      {
2035         if (it->base)
2036           elm_table_unpack(wd->box, it->base);
2037         sel = it->sel;
2038         EINA_LIST_FOREACH(wd->items, l, item)
2039           {
2040              if (it != item)
2041                {
2042                   if (item->order > it->order)
2043                     {
2044                        if (item->base)
2045                          elm_table_unpack(wd->box, item->base);
2046                        item->order -= sel;
2047                        if (!wd->vertical)
2048                          elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
2049                        else
2050                          elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
2051                     }
2052                }
2053           }
2054      }
2055
2056    // delete item in list
2057    _item_del(it);
2058    wd->items = eina_list_remove(wd->items, it);
2059    free(it);
2060    it = NULL;
2061    wd->num = wd->num - 1;
2062    _sizing_eval(obj);
2063 }
2064
2065 /**
2066  * Select item in controlbar
2067  *
2068  * @param       it The item of controlbar
2069
2070  * @ingroup Controlbar
2071  */
2072 EAPI void
2073 elm_controlbar_item_select(Elm_Controlbar_Item * it)
2074 {
2075    if (!it) return;
2076    if (it->obj == NULL) return;
2077    Widget_Data * wd = elm_widget_data_get(it->obj);
2078    if (!wd) return;
2079
2080    _select_box(it);
2081 }
2082
2083 /**
2084  * Set the icon of item
2085  *
2086  * @param       it The item of controlbar
2087  * @param       icon_path The icon path of the item
2088  * @return      The icon object
2089  *
2090  * @ingroup Controlbar
2091  */
2092 EAPI void
2093 elm_controlbar_item_icon_set(Elm_Controlbar_Item * it, const char *icon_path)
2094 {
2095    if (!it) return;
2096    if (it->style == OBJECT) return;
2097    if (it->icon_path)
2098      {
2099         eina_stringshare_del(it->icon_path);
2100         it->icon_path = NULL;
2101      }
2102    if (it->icon)
2103      {
2104         evas_object_del(it->icon);
2105         it->icon = NULL;
2106      }
2107    if (icon_path != NULL)
2108      {
2109         it->icon_path = eina_stringshare_add(icon_path);
2110         it->icon = _create_item_icon(it->base_item, it, "elm.swallow.icon");
2111      }
2112    if (it->wd->disabled || it->disabled)
2113      elm_widget_disabled_set(it->base_item, EINA_TRUE);
2114    else
2115      elm_widget_disabled_set(it->base_item, EINA_FALSE);
2116 }
2117
2118 /**
2119  * Get the icon of item
2120  *
2121  * @param       it The item of controlbar
2122  * @return      The icon object
2123  *
2124  * @ingroup Controlbar
2125  */
2126 EAPI Evas_Object *
2127 elm_controlbar_item_icon_get(const Elm_Controlbar_Item * it)
2128 {
2129    if (!it) return NULL;
2130    return it->icon;
2131 }
2132
2133 /**
2134  * Set the label of item
2135  *
2136  * @param       it The item of controlbar
2137  * @param       label The label of item
2138  *
2139  * @ingroup Controlbar
2140  */
2141 EAPI void
2142 elm_controlbar_item_label_set(Elm_Controlbar_Item * it, const char *label)
2143 {
2144    if (!it) return;
2145    if (it->style == OBJECT) return;
2146    if (it->text)
2147      {
2148         eina_stringshare_del(it->text);
2149         it->text = NULL;
2150      }
2151    if (label != NULL)
2152      {
2153         it->text = eina_stringshare_add(label);
2154         elm_object_text_set(it->base_item, it->text);
2155      }
2156    if (it->wd->disabled || it->disabled)
2157      elm_widget_disabled_set(it->base_item, EINA_TRUE);
2158    else
2159      elm_widget_disabled_set(it->base_item, EINA_FALSE);
2160 }
2161
2162 /**
2163  * Get the label of item
2164  *
2165  * @param       it The item of controlbar
2166  * @return The label of item
2167  *
2168  * @ingroup Controlbar
2169  */
2170 EAPI const char *
2171 elm_controlbar_item_label_get(const Elm_Controlbar_Item * it)
2172 {
2173    if (!it) return NULL;
2174    return it->text;
2175 }
2176
2177 /**
2178  * Get the selected item
2179  *
2180  * @param       obj The controlbar object
2181  * @return              The item of controlbar
2182  *
2183  * @ingroup Controlbar
2184  */
2185 EAPI Elm_Controlbar_Item * elm_controlbar_selected_item_get(const Evas_Object *
2186                                                             obj)
2187 {
2188    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2189    const Eina_List *l;
2190
2191    Elm_Controlbar_Item * item;
2192    if (obj == NULL) return NULL;
2193    Widget_Data * wd = elm_widget_data_get(obj);
2194    if (!wd || !wd->items) return NULL;
2195    EINA_LIST_FOREACH(wd->items, l, item)
2196      {
2197         if (item->selected) return item;
2198      }
2199    return NULL;
2200 }
2201
2202 /**
2203  * Get the first item
2204  *
2205  * @param       obj The controlbar object
2206  * @return              The item of controlbar
2207  *
2208  * @ingroup Controlbar
2209  */
2210 EAPI Elm_Controlbar_Item * elm_controlbar_first_item_get(const Evas_Object * obj)
2211 {
2212    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2213    Widget_Data * wd = elm_widget_data_get(obj);
2214    if (!wd || !wd->items) return NULL;
2215    return eina_list_data_get(wd->items);
2216 }
2217
2218 /**
2219  * Get the last item
2220  *
2221  * @param       obj The controlbar object
2222  * @return              The item of controlbar
2223  *
2224  * @ingroup Controlbar
2225  */
2226 EAPI Elm_Controlbar_Item * elm_controlbar_last_item_get(const Evas_Object * obj)
2227 {
2228    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2229    Widget_Data * wd = elm_widget_data_get(obj);
2230    if (!wd || !wd->items) return NULL;
2231    return eina_list_data_get(eina_list_last(wd->items));
2232 }
2233
2234 /**
2235  * Get the items
2236  *
2237  * @param       obj The controlbar object
2238  * @return      The list of the items
2239  *
2240  * @ingroup Controlbar
2241  */
2242 EAPI const Eina_List * elm_controlbar_items_get(const Evas_Object * obj)
2243 {
2244    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2245    Widget_Data * wd = elm_widget_data_get(obj);
2246    if (!wd || !wd->items) return NULL;
2247    return wd->items;
2248 }
2249
2250 /**
2251  * Get the previous item
2252  *
2253  * @param       it The item of controlbar
2254  * @return      The previous item of the parameter item
2255  *
2256  * @ingroup Controlbar
2257  */
2258 EAPI Elm_Controlbar_Item * elm_controlbar_item_prev(Elm_Controlbar_Item *
2259                                                     it)
2260 {
2261    if (!it) return NULL;
2262    const Eina_List *l;
2263
2264    Elm_Controlbar_Item * item;
2265    if (it->obj == NULL) return NULL;
2266    Widget_Data * wd = elm_widget_data_get(it->obj);
2267    if (!wd || !wd->items) return NULL;
2268    EINA_LIST_FOREACH(wd->items, l, item)
2269      {
2270         if (it == item)
2271           {
2272              l = eina_list_prev(l);
2273              if (!l) return NULL;
2274              return eina_list_data_get(l);
2275           }
2276      }
2277    return NULL;
2278 }
2279
2280 /**
2281  * Get the next item
2282  *
2283  * @param       obj The controlbar object
2284  * @return      The next item of the parameter item
2285  *
2286  * @ingroup Controlbar
2287  */
2288 EAPI Elm_Controlbar_Item * elm_controlbar_item_next(Elm_Controlbar_Item *
2289                                                     it)
2290 {
2291    if (!it) return NULL;
2292    const Eina_List *l;
2293
2294    Elm_Controlbar_Item * item;
2295    if (it->obj == NULL) return NULL;
2296    Widget_Data * wd = elm_widget_data_get(it->obj);
2297    if (!wd || !wd->items) return NULL;
2298    EINA_LIST_FOREACH(wd->items, l, item)
2299      {
2300         if (it == item)
2301           {
2302              l = eina_list_next(l);
2303              if (!l) return NULL;
2304              return eina_list_data_get(l);
2305           }
2306      }
2307    return NULL;
2308 }
2309
2310 /**
2311  * Set the visible status of item in bar
2312  *
2313  * @param       it The item of controlbar
2314  * @param       bar EINA_TRUE or EINA_FALSE
2315  *
2316  * @ingroup Controlbar
2317  */
2318 EAPI void
2319 elm_controlbar_item_visible_set(Elm_Controlbar_Item * it, Eina_Bool visible)
2320 {
2321    if (!it) return;
2322    if (it->obj == NULL) return;
2323    Widget_Data * wd = elm_widget_data_get(it->obj);
2324    if (!wd) return;
2325
2326    if (!wd->auto_align)
2327      _set_item_visible(it, visible);
2328 }
2329
2330 /**
2331  * Get the result which or not item is visible in bar
2332  *
2333  * @param       it The item of controlbar
2334  * @return      EINA_TRUE or EINA_FALSE
2335  *
2336  * @ingroup Controlbar
2337  */
2338 EAPI Eina_Bool
2339 elm_controlbar_item_visible_get(const Elm_Controlbar_Item * it)
2340 {
2341    if (!it) return EINA_FALSE;
2342    if (it->obj == NULL) return EINA_FALSE;
2343    Widget_Data * wd = elm_widget_data_get(it->obj);
2344    if (!wd) return EINA_FALSE;
2345    if (it->order <= 0) return EINA_FALSE;
2346
2347    return EINA_TRUE;
2348 }
2349
2350 /**
2351  * Set item disable
2352  *
2353  * @param       it The item of controlbar
2354  * @param       bar EINA_TRUE or EINA_FALSE
2355  *
2356  * @ingroup Controlbar
2357  */
2358 EAPI void
2359 elm_controlbar_item_disabled_set(Elm_Controlbar_Item * it, Eina_Bool disabled)
2360 {
2361    if (!it) return;
2362
2363    if (it->disabled == disabled) return;
2364
2365    it->disabled = disabled;
2366
2367    if ((it->wd) && (it->wd->disabled)) return;
2368
2369    if (it->base_item) elm_widget_disabled_set(it->base_item, disabled);
2370 }
2371
2372 /**
2373  * Get item disable
2374  *
2375  * @param       it The item of controlbar
2376  * @return      EINA_TRUE or EINA_FALSE
2377  *
2378  * @ingroup Controlbar
2379  */
2380 EAPI Eina_Bool
2381 elm_controlbar_item_disabled_get(const Elm_Controlbar_Item * it)
2382 {
2383    if (!it) return EINA_FALSE;
2384
2385    return it->disabled;
2386 }
2387
2388 /**
2389  * Set the view of the item
2390  *
2391  * @param       it The item of controlbar
2392  * @param       view The view for the item
2393  *
2394  * @ingroup Controlbar
2395  */
2396 EAPI void
2397 elm_controlbar_item_view_set(Elm_Controlbar_Item *it, Evas_Object * view)
2398 {
2399    if (!it) return;
2400    if (it->view == view) return;
2401
2402    evas_object_del(it->view);
2403    it->view = view;
2404 }
2405
2406 /**
2407  * Get the view of the item
2408  *
2409  * @param       it The item of controlbar
2410  * @return      The view for the item
2411  *
2412  * @ingroup Controlbar
2413  */
2414 EAPI Evas_Object *
2415 elm_controlbar_item_view_get(const Elm_Controlbar_Item *it)
2416 {
2417    if (!it) return NULL;
2418
2419    return it->view;
2420 }
2421
2422 /**
2423  * Unset the view of the item
2424  *
2425  * @param       it The item of controlbar
2426  * @return      The view for the item
2427  *
2428  * @ingroup Controlbar
2429  */
2430 EAPI Evas_Object *
2431 elm_controlbar_item_view_unset(Elm_Controlbar_Item *it)
2432 {
2433    if (!it) return NULL;
2434    if (it->obj == NULL) return NULL;
2435    Widget_Data * wd = elm_widget_data_get(it->obj);
2436    if (!wd) return NULL;
2437    Evas_Object *content;
2438
2439    if (it->view == elm_layout_content_get(wd->view, "elm.swallow.view"))
2440      {
2441         content = elm_layout_content_unset(wd->view, "elm.swallow.view");
2442         if (content) evas_object_hide(content);
2443      }
2444    else
2445      content = it->view;
2446
2447    it->view = NULL;
2448
2449    return content;
2450 }
2451
2452 /**
2453  * Set the mode of the controlbar
2454  *
2455  * @param       obj The object of the controlbar
2456  * @param       mode The mode of the controlbar
2457  *
2458  * @ingroup Controlbar
2459  */
2460 EAPI void
2461 elm_controlbar_mode_set(Evas_Object *obj, int mode)
2462 {
2463    ELM_CHECK_WIDTYPE(obj, widtype);
2464    Widget_Data *wd = elm_widget_data_get(obj);
2465    if (!wd)
2466      {
2467         fprintf(stderr, "Cannot get smart data\n");
2468         return;
2469      }
2470    Evas_Object *selected_box;
2471
2472    wd->mode = mode;
2473
2474    switch(wd->mode)
2475      {
2476       case ELM_CONTROLBAR_MODE_DEFAULT:
2477          edje_object_signal_emit(_EDJ(wd->edje), "elm,state,default", "elm");
2478          break;
2479       case ELM_CONTROLBAR_MODE_TRANSLUCENCE:
2480          elm_controlbar_alpha_set(obj, 85);
2481          break;
2482       case ELM_CONTROLBAR_MODE_TRANSPARENCY:
2483          elm_controlbar_alpha_set(obj, 0);
2484          break;
2485       case ELM_CONTROLBAR_MODE_LARGE:
2486          edje_object_signal_emit(_EDJ(wd->edje), "elm,state,large", "elm");
2487          break;
2488       case ELM_CONTROLBAR_MODE_SMALL:
2489          edje_object_signal_emit(_EDJ(wd->edje), "elm,state,small", "elm");
2490          break;
2491       case ELM_CONTROLBAR_MODE_LEFT:
2492          selected_box = elm_layout_content_get(wd->edje, "elm.dragable.box");
2493          if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,left", "elm");
2494          wd->selected_signal = eina_stringshare_add("elm,state,selected_left");
2495          wd->pressed_signal = eina_stringshare_add("elm,state,pressed_left");
2496          edje_object_signal_emit(_EDJ(wd->edje), "elm,state,left", "elm");
2497          _check_background(wd);
2498          _sizing_eval(obj);
2499          return;
2500       case ELM_CONTROLBAR_MODE_RIGHT:
2501          selected_box = elm_layout_content_get(wd->edje, "elm.dragable.box");
2502          if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,right", "elm");
2503          wd->selected_signal = eina_stringshare_add("elm,state,selected_right");
2504          wd->pressed_signal = eina_stringshare_add("elm,state,pressed_right");
2505          edje_object_signal_emit(_EDJ(wd->edje), "elm,state,right", "elm");
2506          _check_background(wd);
2507          _sizing_eval(obj);
2508          return;
2509       default:
2510          break;
2511      }
2512    selected_box = elm_layout_content_get(wd->edje, "elm.dragable.box");
2513    if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,default", "elm");
2514    wd->selected_signal = eina_stringshare_add("elm,state,selected");
2515    wd->pressed_signal = eina_stringshare_add("elm,state,pressed");
2516    _check_background(wd);
2517    _sizing_eval(obj);
2518 }
2519
2520 /**
2521  * Set the alpha of the controlbar
2522  *
2523  * @param       obj The object of the controlbar
2524  * @param       alpha The alpha value of the controlbar (0-100)
2525  *
2526  * @ingroup Controlbar
2527  */
2528 EAPI void
2529 elm_controlbar_alpha_set(Evas_Object *obj, int alpha)
2530 {
2531    ELM_CHECK_WIDTYPE(obj, widtype);
2532    int r, g, b;
2533    Widget_Data *wd = elm_widget_data_get(obj);
2534    if (!wd)
2535      {
2536         fprintf(stderr, "Cannot get smart data\n");
2537         return;
2538      }
2539
2540    if (alpha < 0) wd->alpha = 0;
2541    else if (alpha > 100) wd->alpha = 100;
2542    else wd->alpha = alpha;
2543
2544    evas_object_color_get(wd->bg, &r, &g, &b, NULL);
2545    evas_object_color_set(wd->bg, r, g, b, (int)(255 * wd->alpha / 100));
2546 }
2547
2548
2549 /**
2550  * Set auto-align mode of the controlbar(It's not prepared yet)
2551  * If you set the auto-align and add items more than 5,
2552  * the "more" item will be made and the items more than 5 will be unvisible.
2553  *
2554  * @param       obj The object of the controlbar
2555  * @param       auto_align The dicision that the controlbar use the auto-align
2556  *
2557  * @ingroup Controlbar
2558  */
2559 EAPI void
2560 elm_controlbar_item_auto_align_set(Evas_Object *obj, Eina_Bool auto_align)
2561 {
2562    ELM_CHECK_WIDTYPE(obj, widtype);
2563    Widget_Data *wd = elm_widget_data_get(obj);
2564    Elm_Controlbar_Item *item;
2565    const Eina_List *l;
2566    int i;
2567    if (!wd)
2568      {
2569         fprintf(stderr, "Cannot get smart data\n");
2570         return;
2571      }
2572
2573    if (wd->auto_align == auto_align) return;
2574
2575    if (auto_align)
2576      {
2577         if ((_check_bar_item_number(wd)) >= 5 && (!wd->more_item))
2578           {
2579              i = 0;
2580              EINA_LIST_FOREACH(wd->items, l, item)
2581                {
2582                   if (elm_controlbar_item_visible_get(item))
2583                     i++;
2584                   if (i >= 5){
2585                        _delete_item_in_bar(item);
2586                   }
2587                }
2588              item = elm_controlbar_last_item_get(obj);
2589              while (!elm_controlbar_item_visible_get(item)){
2590                   item = elm_controlbar_item_prev(item);
2591              }
2592              _create_more_item(wd, item->style);
2593           }
2594      }
2595    else
2596      {
2597         if (wd->more_item)
2598           {
2599              // delete more item
2600              if (wd->more_item->view)
2601                evas_object_del(wd->more_item->view);
2602              wd->items = eina_list_remove(wd->items, wd->more_item);
2603              eina_stringshare_del(wd->more_item->text);
2604              if (wd->more_item->icon)
2605                evas_object_del(wd->more_item->icon);
2606              if (wd->more_item->base)
2607                evas_object_del(wd->more_item->base);
2608              if (wd->more_item->base_item)
2609                evas_object_del(wd->more_item->base_item);
2610              free(wd->more_item);
2611              wd->more_item = NULL;
2612
2613              // make all item is visible
2614              i = 1;
2615              EINA_LIST_FOREACH(wd->items, l, item)
2616                {
2617                   if (!elm_controlbar_item_visible_get(item))
2618                     _insert_item_in_bar(item, i);
2619                   i++;
2620                }
2621           }
2622      }
2623    wd->auto_align = auto_align;
2624    _sizing_eval(obj);
2625 }
2626
2627 /**
2628  * Set the vertical mode of the controlbar
2629  *
2630  * @param       obj The object of the controlbar
2631  * @param       vertical The vertical mode of the controlbar (TRUE = vertical, FALSE = horizontal)
2632  *
2633  * @ingroup Controlbar
2634  */
2635 EAPI void
2636 elm_controlbar_vertical_set(Evas_Object *obj, Eina_Bool vertical)
2637 {
2638    ELM_CHECK_WIDTYPE(obj, widtype);
2639    Widget_Data *wd = elm_widget_data_get(obj);
2640    if (!wd)
2641      {
2642         fprintf(stderr, "Cannot get smart data\n");
2643         return;
2644      }
2645
2646    if (wd->vertical == vertical) return;
2647    wd->vertical = vertical;
2648
2649    if (_check_bar_item_number(wd) > 1)
2650      {
2651         _repack_items(wd);
2652      }
2653    _check_toolbar_line(wd);
2654 }
2655
2656 /**
2657  * Get the button object of the item
2658  *
2659  * @param       it The item of controlbar
2660  * @return  button object of the item
2661  *
2662  * @ingroup Controlbar
2663  */
2664 EAPI Evas_Object *
2665 elm_controlbar_item_button_get(const Elm_Controlbar_Item *it)
2666 {
2667    if (!it) return NULL;
2668    if (it->style == OBJECT) return NULL;
2669
2670    if (it->base_item) return it->base_item;
2671
2672    return NULL;
2673 }