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