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