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