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