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