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