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