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