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