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