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