2 * @defgroup Controlbar Controlbar
5 * This is a Controlbar. It can contain label and icon objects.
6 * In edit mode, you can change the location of items.
12 #include <Elementary.h>
16 #define EAPI __attribute__ ((visibility("default")))
19 #define ELM_MAX(v1, v2) (((v1) > (v2)) ? (v1) : (v2))
20 #define _EDJ(x) (Evas_Object *)elm_layout_edje_get(x)
26 typedef struct _Animation_Data Animation_Data;
28 struct _Animation_Data
41 void (*func) (void *data, Evas_Object * obj);
43 Ecore_Animator * timer;
46 // internal data structure of controlbar object
47 typedef struct _Widget_Data Widget_Data;
58 Elm_Controlbar_Item * more_item;
59 Elm_Controlbar_Item * pre_item;
60 Elm_Controlbar_Item * cur_item;
61 Evas_Coord x, y, w, h;
70 Eina_List * visible_items;
72 void (*ani_func) (void *data, Evas_Object * obj, void *event_info);
74 Ecore_Timer *effect_timer;
75 Eina_Bool selected_animation;
78 const char *pressed_signal;
79 const char *selected_signal;
82 struct _Elm_Controlbar_Item
87 Evas_Object * base_item;
90 const char *icon_path;
92 void (*func) (void *data, Evas_Object * obj, void *event_info);
101 static const char *widtype = NULL;
103 static void _sizing_eval(Evas_Object * obj);
104 static int _check_bar_item_number(Widget_Data *wd);
105 static void _select_box(Elm_Controlbar_Item * it);
106 static void _cancel_selected_box(Widget_Data *wd);
107 static void _check_toolbar_line(Widget_Data *wd);
108 static Eina_Bool _press_box(Elm_Controlbar_Item * it);
110 ///////////////////////////////////////////////////////////////////
112 // Smart Object basic function
114 ////////////////////////////////////////////////////////////////////
117 _controlbar_move(void *data, Evas_Object * obj __UNUSED__)
120 Evas_Coord x, y, x_, y_, width;
122 wd = elm_widget_data_get((Evas_Object *) data);
124 evas_object_geometry_get(wd->edje, &x, &y, NULL, NULL);
127 evas_object_move(wd->edje, x, y);
128 evas_object_geometry_get(elm_object_content_part_get(wd->edje, "bg_image"), NULL, NULL, &width, NULL);
129 evas_object_geometry_get(wd->edje, &x_, &y_, NULL, NULL);
133 _controlbar_resize(void *data, Evas_Object * obj __UNUSED__)
136 Evas_Coord x, y, x_, y_, w, h, width, height;
138 wd = elm_widget_data_get((Evas_Object *) data);
140 evas_object_geometry_get(wd->edje, &x, &y, &w, &h);
143 evas_object_resize(wd->edje, w, h);
144 evas_object_geometry_get(elm_object_content_part_get(wd->edje, "bg_image"), NULL, NULL, &width, &height);
145 evas_object_geometry_get(wd->edje, &x_, &y_, NULL, NULL);
149 _controlbar_object_move(void *data, Evas * e __UNUSED__, Evas_Object * obj,
150 void *event_info __UNUSED__)
152 _controlbar_move(data, obj);
156 _controlbar_object_resize(void *data, Evas * e __UNUSED__, Evas_Object * obj,
157 void *event_info __UNUSED__)
159 _controlbar_resize(data, obj);
163 _controlbar_object_show(void *data, Evas * e __UNUSED__, Evas_Object * obj __UNUSED__,
164 void *event_info __UNUSED__)
168 wd = elm_widget_data_get((Evas_Object *) data);
170 evas_object_show(wd->edje);
171 evas_object_show(wd->box);
175 _controlbar_object_hide(void *data, Evas * e __UNUSED__, Evas_Object * obj __UNUSED__,
176 void *event_info __UNUSED__)
180 wd = elm_widget_data_get((Evas_Object *) data);
182 evas_object_hide(wd->edje);
183 evas_object_hide(wd->box);
185 _cancel_selected_box(wd);
189 _item_del(Elm_Controlbar_Item *it)
192 Widget_Data *wd = elm_widget_data_get(it->obj);
196 eina_stringshare_del(it->text);
198 eina_stringshare_del(it->icon_path);
200 evas_object_del(it->icon);
202 evas_object_del(it->base);
204 evas_object_del(it->base_item);
206 evas_object_del(it->view);
210 _del_hook(Evas_Object * obj)
212 Widget_Data * wd = elm_widget_data_get(obj);
213 Elm_Controlbar_Item * item;
216 EINA_LIST_FREE(wd->items, item)
224 evas_object_del(wd->bg);
229 evas_object_del(wd->box);
234 evas_object_del(wd->edje);
237 if (wd->effect_timer)
239 ecore_timer_del(wd->effect_timer);
240 wd->effect_timer = NULL;
244 if (wd->ad->timer) ecore_animator_del(wd->ad->timer);
245 wd->ad->timer = NULL;
255 _theme_hook(Evas_Object * obj)
259 Elm_Controlbar_Item * item;
262 Widget_Data * wd = elm_widget_data_get(obj);
264 elm_layout_theme_set(wd->edje, "controlbar", "base",
265 elm_widget_style_get(obj));
266 elm_layout_theme_set(wd->bg, "controlbar", "background",
267 elm_widget_style_get(obj));
268 evas_object_color_get(wd->bg, &r, &g, &b, NULL);
269 evas_object_color_set(wd->bg, r, g, b, (int)(255 * wd->alpha / 100));
270 EINA_LIST_FOREACH(wd->items, l, item)
272 elm_layout_theme_set(item->base, "controlbar", "item_bg", elm_widget_style_get(obj));
276 elm_controlbar_mode_set(obj, wd->mode);
277 _check_toolbar_line(wd);
281 _disable_hook(Evas_Object * obj)
283 Widget_Data * wd = elm_widget_data_get(obj);
286 Elm_Controlbar_Item * item;
289 wd->disabled = elm_widget_disabled_get(obj);
291 EINA_LIST_FOREACH(wd->items, l, item)
294 disabled = wd->disabled;
296 disabled = item->disabled;
298 if (item->base_item) elm_widget_disabled_set(item->base_item, disabled);
303 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
308 _sizing_eval(Evas_Object * obj)
310 Widget_Data * wd = elm_widget_data_get(obj);
312 _controlbar_move(obj, obj);
313 _controlbar_resize(obj, obj);
316 /////////////////////////////////////////////////////////////
318 // animation function
320 /////////////////////////////////////////////////////////////
323 _move_evas_object(void *data)
325 const Evas_Object *bg_image;
326 double t = 0.0, vx = 0.0, vy = 0.0, vw = 0.0, vh = 0.0;
327 int dx = 0 , dy = 0, dw = 0, dh = 0;
328 int px = 0, py = 0, pw = 0, ph = 0;
329 int ox = 0, oy = 0, ow = 0, oh = 0;
330 int x = 0, y = 0, w = 0, h = 0;
332 Animation_Data * ad = (Animation_Data *) data;
333 bg_image = edje_object_part_object_get(_EDJ(ad->obj), "bg_image");
334 if (bg_image) evas_object_geometry_get(bg_image, &ox, &oy, &ow, &oh);
335 t = ELM_MAX(0.0, ecore_loop_time_get() - ad->start_time);
336 dx = ad->tx - ad->fx;
337 dy = ad->ty - ad->fy;
338 dw = ad->tw - ad->fw;
339 dh = ad->th - ad->fh;
342 x = (1 * sin((t / ad->time) * (M_PI / 2)) * dx);
343 y = (1 * sin((t / ad->time) * (M_PI / 2)) * dy);
344 w = (1 * sin((t / ad->time) * (M_PI / 2)) * dw);
345 h = (1 * sin((t / ad->time) * (M_PI / 2)) * dh);
362 vx = (double)(px - ox) / (double)(ow - pw);
366 vy = (double)(py - oy) / (double)(oh - ph);
367 vw = (double)pw / (double)ow;
368 vh = (double)ph / (double)oh;
370 if ((x == dx) && (y == dy) && (w == dw) && (h == dh))
372 if (ad->timer) ecore_animator_del(ad->timer);
374 edje_object_part_drag_size_set(_EDJ(ad->obj), "elm.dragable.box", vw, vh);
375 edje_object_part_drag_value_set(_EDJ(ad->obj), "elm.dragable.box", vx, vy);
376 if (ad->func != NULL)
377 ad->func(ad->data, ad->obj);
378 return ECORE_CALLBACK_CANCEL;
382 edje_object_part_drag_size_set(_EDJ(ad->obj), "elm.dragable.box", vw, vh);
383 edje_object_part_drag_value_set(_EDJ(ad->obj), "elm.dragable.box", vx, vy);
385 return ECORE_CALLBACK_RENEW;
388 static Animation_Data*
389 _move_object_with_animation(Evas_Object * obj, Evas_Coord x, Evas_Coord y,
390 Evas_Coord w, Evas_Coord h, Evas_Coord x_,
391 Evas_Coord y_, Evas_Coord w_, Evas_Coord h_,
392 double time, Eina_Bool (*mv_func) (void *data),
393 void (*func) (void *data,
394 Evas_Object * obj), void *data)
396 Animation_Data * ad = (Animation_Data *) malloc(sizeof(Animation_Data));
397 if (!ad) return NULL;
407 ad->start_time = ecore_loop_time_get();
411 ad->timer = ecore_animator_add(mv_func, ad);
416 /////////////////////////////////////////////////////////////
420 /////////////////////////////////////////////////////////////
423 _sort_cb(const void *d1, const void *d2)
425 Elm_Controlbar_Item * item1, *item2;
426 item1 = (Elm_Controlbar_Item *) d1;
427 item2 = (Elm_Controlbar_Item *) d2;
428 if (item1->order <= 0) return 1;
429 if (item2->order <= 0) return -1;
430 return item1->order > item2->order ? 1 : -1;
433 ///////////////////////////////////////////////////////////////////
435 // basic utility function
437 ////////////////////////////////////////////////////////////////////
440 _check_item(Widget_Data *wd, Elm_Controlbar_Item *item)
443 Elm_Controlbar_Item *it;
445 if (!wd) return EINA_FALSE;
446 if (!wd->items) return EINA_FALSE;
448 EINA_LIST_FOREACH(wd->items, l, it)
449 if (it == item) return EINA_TRUE;
455 _check_background(Widget_Data *wd)
459 Elm_Controlbar_Item *it;
461 EINA_LIST_FOREACH(wd->items, l, it)
463 if (it->style == TABBAR)
465 if (wd->mode == ELM_CONTROLBAR_MODE_LEFT)
466 edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar_left", "elm");
467 else if (wd->mode == ELM_CONTROLBAR_MODE_RIGHT)
468 edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar_right", "elm");
470 edje_object_signal_emit(_EDJ(wd->bg), "elm,state,tabbar", "elm");
474 edje_object_signal_emit(_EDJ(wd->bg), "elm,state,toolbar", "elm");
478 _check_toolbar_line(Widget_Data *wd)
482 Elm_Controlbar_Item *it, *it2;
484 EINA_LIST_FOREACH(wd->items, l, it)
486 it2 = elm_controlbar_item_prev(it);
488 if (it->style != TOOLBAR || it2->style != TOOLBAR) continue;
492 edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_hide", "elm");
493 edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_hide", "elm");
495 if ((it->icon || it->text) && (it2->icon || it2->text))
497 edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_show", "elm");
498 edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_show", "elm");
502 edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_hide", "elm");
503 edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_hide", "elm");
508 edje_object_signal_emit(_EDJ(it2->base), "elm,state,bottom_line_hide", "elm");
509 edje_object_signal_emit(_EDJ(it->base), "elm,state,top_line_hide", "elm");
511 if ((it->icon || it->text) && (it2->icon || it2->text))
513 edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_show", "elm");
514 edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_show", "elm");
518 edje_object_signal_emit(_EDJ(it2->base), "elm,state,right_line_hide", "elm");
519 edje_object_signal_emit(_EDJ(it->base), "elm,state,left_line_hide", "elm");
526 _check_bar_item_number(Widget_Data *wd)
529 Elm_Controlbar_Item * item;
532 EINA_LIST_FOREACH(wd->items, l, item)
533 if (item->order > 0) num++;
539 _insert_item_in_bar(Elm_Controlbar_Item * it, int order)
542 Elm_Controlbar_Item * item;
543 Widget_Data * wd = elm_widget_data_get(it->obj);
547 if (order == 0) return;
549 EINA_LIST_FOREACH(wd->items, l, item)
551 if ((item->order == order) && (item != it))
556 EINA_LIST_FOREACH(wd->items, l, item)
559 elm_table_unpack(wd->box, item->base);
561 EINA_LIST_FOREACH(wd->items, l, item)
565 if (item->order >= order)
568 elm_table_pack(wd->box, item->base, item->order - 1, 0, 1, 1);
570 elm_table_pack(wd->box, item->base, 0, item->order - 1, 1, 1);
571 evas_object_show(item->base);
577 elm_table_pack(wd->box, it->base, it->order - 1, 0, 1, 1);
579 elm_table_pack(wd->box, it->base, 0, it->order - 1, 1, 1);
580 evas_object_show(it->base);
584 _delete_item_in_bar(Elm_Controlbar_Item * it)
587 Elm_Controlbar_Item * item;
588 Widget_Data * wd = elm_widget_data_get(it->obj);
592 EINA_LIST_FOREACH(wd->items, l, item)
598 elm_table_unpack(wd->box, it->base);
599 evas_object_hide(it->base);
604 EINA_LIST_FOREACH(wd->items, l, item)
609 elm_table_unpack(wd->box, item->base);
611 elm_table_pack(wd->box, item->base, item->order - 1, 0, 1, 1);
613 elm_table_pack(wd->box, item->base, 0, item->order - 1, 1, 1);
620 _set_item_visible(Elm_Controlbar_Item *it, Eina_Bool visible)
622 Elm_Controlbar_Item *item;
623 Eina_Bool check = EINA_TRUE;
626 if (it->obj == NULL) return;
627 Widget_Data * wd = elm_widget_data_get(it->obj);
628 if (!wd || !wd->items) return;
629 if (it->order <= 0) check = EINA_FALSE;
630 if (check == visible) return;
633 item = elm_controlbar_last_item_get(it->obj);
635 while (!elm_controlbar_item_visible_get(item)){
636 item = elm_controlbar_item_prev(item);
638 _insert_item_in_bar(it, item->order + 1);
642 _delete_item_in_bar(it);
644 wd->items = eina_list_sort(wd->items, eina_list_count(wd->items), _sort_cb);
645 _sizing_eval(it->obj);
649 _hide_selected_box(void *data)
651 Evas_Object *base = (Evas_Object *)data;
653 edje_object_part_drag_size_set(_EDJ(base), "elm.dragable.box", 0.0, 0.0);
655 return ECORE_CALLBACK_CANCEL;
659 _end_selected_box(void *data, Evas_Object *obj __UNUSED__)
661 Widget_Data * wd = (Widget_Data *)data;
663 if (_check_item(wd, wd->cur_item))
665 edje_object_signal_emit(_EDJ(wd->cur_item->base), wd->selected_signal, "elm");
669 if (wd->animating < 0)
671 printf("animation error\n");
675 ecore_idler_add(_hide_selected_box, wd->edje);
679 _move_selected_box(Widget_Data *wd, Elm_Controlbar_Item * fit, Elm_Controlbar_Item * tit)
681 Evas_Coord fx, fy, fw, fh, tx, ty, tw, th;
682 Evas_Object *from, *to;
684 if ((fit->order <= 0) && (wd->auto_align))
687 from = (Evas_Object *) edje_object_part_object_get(_EDJ(fit->base), "bg_img");
688 evas_object_geometry_get(from, &fx, &fy, &fw, &fh);
690 to = (Evas_Object *) edje_object_part_object_get(_EDJ(tit->base), "bg_img");
691 evas_object_geometry_get(to, &tx, &ty, &tw, &th);
693 if (_check_item(wd, wd->pre_item))
695 edje_object_signal_emit(_EDJ(wd->pre_item->base), "elm,state,unselected", "elm");
697 if (_check_item(wd, wd->cur_item))
698 edje_object_signal_emit(_EDJ(wd->cur_item->base), "elm,state,unselected", "elm");
703 if (wd->ad->timer) ecore_animator_del(wd->ad->timer);
704 wd->ad->timer = NULL;
708 wd->ad = _move_object_with_animation(wd->edje, fx, fy, fw, fh, tx, ty, tw, th,
709 0.3, _move_evas_object, _end_selected_box, wd);
713 _select_box(Elm_Controlbar_Item * it)
716 Widget_Data * wd = elm_widget_data_get(it->obj);
719 Elm_Controlbar_Item * item, *fit = NULL;
720 Evas_Object * content;
722 if (wd->animating) return;
726 if (it->style == TABBAR)
728 content = elm_object_content_part_unset(wd->edje, "elm.swallow.view");
729 if (content) evas_object_hide(content);
731 EINA_LIST_FOREACH(wd->items, l, item){
732 if (item->selected) {
736 item->selected = EINA_FALSE;
738 it->selected = EINA_TRUE;
740 if ((fit != NULL) && (fit != it))
742 _move_selected_box(wd, fit, it);
746 edje_object_signal_emit(_EDJ(it->base), wd->selected_signal, "elm");
751 if (wd->more_item != it)
752 evas_object_smart_callback_call(it->obj, "view,change,before", it);
755 elm_object_content_part_set(wd->edje, "elm.swallow.view", it->view);
757 else if (it->style == TOOLBAR)
759 edje_object_signal_emit(_EDJ(it->base), "elm,state,text_unselected", "elm");
761 it->func(it->data, it->obj, it);
766 _cancel_selected_box(Widget_Data *wd)
769 Elm_Controlbar_Item * item;
771 EINA_LIST_FOREACH(wd->items, l, item)
773 if (item->style == TABBAR)
777 edje_object_signal_emit(_EDJ(item->base), wd->selected_signal, "elm");
781 edje_object_signal_emit(_EDJ(item->base), "elm,state,unselected", "elm");
784 else if (item->style == TOOLBAR)
786 edje_object_signal_emit(_EDJ(item->base), "elm,state,unselected", "elm");
792 _unpress_box_cb(void *data, Evas_Object *obj, void *event_info)
794 Widget_Data * wd = (Widget_Data *) data;
797 _cancel_selected_box(wd);
801 _clicked_box_cb(void *data, Evas_Object *obj, void *event_info)
803 Widget_Data * wd = (Widget_Data *) data;
806 _select_box(wd->pre_item);
810 _press_box(Elm_Controlbar_Item * it)
812 Widget_Data * wd = elm_widget_data_get(it->obj);
813 if (!wd) return EINA_FALSE;
816 Elm_Controlbar_Item * item;
818 if (wd->animating) return EINA_FALSE;
820 if (wd->disabled || it->disabled) return EINA_FALSE;
822 EINA_LIST_FOREACH(wd->items, l, item)
826 if (it->style == TABBAR)
828 edje_object_signal_emit(_EDJ(it->base), wd->pressed_signal, "elm");
830 else if (it->style == TOOLBAR)
832 edje_object_signal_emit(_EDJ(it->base), "elm,state,toolbar_pressed", "elm");
847 _create_item_icon(Evas_Object *obj, Elm_Controlbar_Item * it, char *part)
851 icon = elm_icon_add(obj);
852 if (!elm_icon_standard_set(icon, it->icon_path))
854 elm_icon_file_set(icon, it->icon_path, NULL);
857 evas_object_size_hint_min_set(icon, 40, 40);
858 evas_object_size_hint_max_set(icon, 100, 100);
859 evas_object_show(icon);
861 elm_object_content_set(obj, icon);
867 _create_item_layout(Evas_Object * parent, Elm_Controlbar_Item * it, Evas_Object **item, Evas_Object **icon)
871 obj = elm_layout_add(parent);
874 fprintf(stderr, "Cannot load bg edj\n");
877 elm_layout_theme_set(obj, "controlbar", "item_bg",
878 elm_widget_style_get(it->obj));
879 evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
880 evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
882 *item = elm_button_add(parent);
883 if (*item == NULL) return NULL;
884 elm_object_style_set(*item, "controlbar/vertical");
885 elm_object_content_part_set(obj, "item", *item);
888 elm_object_text_set(*item, it->text);
890 *icon = _create_item_icon(*item, it, "elm.swallow.icon");
896 _bar_item_down_cb(void *data, Evas_Object * obj, void *event_info __UNUSED__)
898 Widget_Data * wd = (Widget_Data *) data;
900 Elm_Controlbar_Item * item;
901 if (wd->animating) return;
903 EINA_LIST_FOREACH(wd->items, l, item)
904 if (item->base_item == obj) break;
906 if (item == NULL) return;
911 static Elm_Controlbar_Item *
912 _create_tab_item(Evas_Object * obj, const char *icon_path, const char *label,
915 Elm_Controlbar_Item * it;
919 fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
922 wd = elm_widget_data_get(obj);
925 fprintf(stderr, "Cannot get smart data\n");
928 it = ELM_NEW(Elm_Controlbar_Item);
929 if (!it) return NULL;
932 it->text = eina_stringshare_add(label);
933 it->icon_path = eina_stringshare_add(icon_path);
934 it->selected = EINA_FALSE;
938 it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
939 evas_object_smart_callback_add(it->base_item, "pressed",
940 _bar_item_down_cb, wd);
941 evas_object_smart_callback_add(it->base_item, "unpressed", _unpress_box_cb, wd);
942 evas_object_smart_callback_add(it->base_item, "clicked", _clicked_box_cb, wd);
943 evas_object_show(it->base);
948 static Elm_Controlbar_Item *
949 _create_tool_item(Evas_Object * obj, const char *icon_path, const char *label,
950 void (*func) (void *data, Evas_Object * obj,
951 void *event_info), void *data)
954 Elm_Controlbar_Item * it;
958 fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
961 wd = elm_widget_data_get(obj);
964 fprintf(stderr, "Cannot get smart data\n");
967 it = ELM_NEW(Elm_Controlbar_Item);
972 it->text = eina_stringshare_add(label);
973 it->icon_path = eina_stringshare_add(icon_path);
974 it->selected = EINA_FALSE;
979 it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
980 evas_object_smart_callback_add(it->base_item, "pressed",
981 _bar_item_down_cb, wd);
982 evas_object_smart_callback_add(it->base_item, "unpressed", _unpress_box_cb, wd);
983 evas_object_smart_callback_add(it->base_item, "clicked", _clicked_box_cb, wd);
984 evas_object_show(it->base);
989 static Elm_Controlbar_Item *
990 _create_object_item(Evas_Object * obj, Evas_Object * obj_item, const int sel)
992 Elm_Controlbar_Item * it;
996 fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
999 wd = elm_widget_data_get(obj);
1002 fprintf(stderr, "Cannot get smart data\n");
1005 it = ELM_NEW(Elm_Controlbar_Item);
1012 it->base = elm_layout_add(wd->edje);
1013 elm_layout_theme_set(it->base, "controlbar", "item_bg",
1014 elm_widget_style_get(it->obj));
1015 evas_object_size_hint_weight_set(it->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1016 evas_object_size_hint_align_set(it->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
1017 it->base_item = obj_item;
1018 elm_object_content_part_set(it->base, "item", it->base_item);
1019 evas_object_show(it->base);
1024 _repack_items(Widget_Data *wd)
1027 Elm_Controlbar_Item * item;
1029 EINA_LIST_FOREACH(wd->items, l, item)
1031 if (item->order > 0)
1033 elm_table_unpack(wd->box, item->base);
1035 elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
1037 elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
1043 _set_items_position(Evas_Object * obj, Elm_Controlbar_Item * it,
1044 Elm_Controlbar_Item * mit, Eina_Bool bar)
1048 Elm_Controlbar_Item * item;
1049 int check = EINA_FALSE;
1054 fprintf(stderr, "Invalid argument: controlbar object is NULL\n");
1057 wd = elm_widget_data_get(obj);
1060 fprintf(stderr, "Cannot get smart data\n");
1064 EINA_LIST_FOREACH(wd->items, l, item)
1066 if ((item == mit) && (item->order > 0))
1069 it->order = mit->order;
1073 if (item->order > 0)
1075 elm_table_unpack(wd->box, item->base);
1076 item->order += it->sel;
1078 elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
1080 elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
1083 if (item->order > 0) order += item->sel;
1097 elm_table_pack(wd->box, it->base, it->order - 1, 0, it->sel, 1);
1099 elm_table_pack(wd->box, it->base, 0, it->order - 1, it->sel, 1);
1102 evas_object_hide(it->base);
1106 _list_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1108 Elm_Controlbar_Item *item = (Elm_Controlbar_Item *)data;
1109 Elm_Controlbar_Item *it;
1112 Evas_Object *content;
1113 Elm_List_Item *lit = (Elm_List_Item *) elm_list_selected_item_get(obj);
1116 elm_list_item_selected_set(lit, 0);
1120 wd = elm_widget_data_get(item->obj);
1123 EINA_LIST_FOREACH(wd->items, l, it)
1125 it->selected = EINA_FALSE;
1128 if (item->style == TABBAR)
1130 content = elm_object_content_part_unset(wd->edje, "elm.swallow.view");
1131 evas_object_hide(content);
1132 item->selected = EINA_TRUE;
1133 evas_object_smart_callback_call(item->obj, "view,change,before", item);
1134 elm_object_content_part_set(wd->edje, "elm.swallow.view", item->view);
1137 if ((item->style == TOOLBAR) && (item->func))
1138 item->func(item->data, item->obj, item);
1141 static Evas_Object *
1142 _create_more_view(Widget_Data *wd)
1145 Elm_Controlbar_Item *item;
1149 list = elm_list_add( wd->object );
1150 elm_list_mode_set( list, ELM_LIST_COMPRESS );
1152 EINA_LIST_FOREACH(wd->items, l, item)
1154 if (item->order <= 0)
1157 if (item->icon_path)
1159 icon = _create_item_icon(list, item, NULL);
1160 evas_object_color_set(icon, 0, 0, 0, 255);
1162 elm_list_item_append(list, item->text, icon, NULL, _list_clicked, item);
1166 elm_list_go( list );
1171 static void _ctxpopup_cb(void *data, Evas_Object *obj, void *event_info)
1173 Elm_Controlbar_Item *it;
1175 Evas_Object *ctxpopup = obj;
1177 Widget_Data *wd = (Widget_Data *)data;
1179 EINA_LIST_FOREACH(wd->items, l, it)
1181 label = elm_ctxpopup_item_label_get((Elm_Ctxpopup_Item *) event_info);
1182 if ((label) && (!strcmp(it->text, label))) break;
1186 it->func(it->data, it->obj, it);
1188 if (_check_item(wd, it)) evas_object_smart_callback_call(it->obj, "clicked", it);
1190 evas_object_del(ctxpopup);
1194 static void _ctxpopup_dismissed_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1196 Evas_Object *ctxpopup = obj;
1198 evas_object_del(ctxpopup);
1203 _create_more_func(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1205 Evas_Object *ctxpopup;
1206 Elm_Controlbar_Item *item;
1209 Evas_Coord x, y, w, h;
1210 Widget_Data *wd = elm_widget_data_get(obj);
1213 ctxpopup = elm_ctxpopup_add(wd->parent);
1214 evas_object_smart_callback_add( ctxpopup, "dismissed", _ctxpopup_dismissed_cb, wd);
1216 EINA_LIST_FOREACH(wd->items, l, item)
1218 if (item->order <= 0)
1221 if (item->icon_path)
1223 icon = _create_item_icon(ctxpopup, item, NULL);
1224 evas_object_color_set(icon, 0, 0, 0, 255);
1226 elm_ctxpopup_item_append(ctxpopup, item->text, icon, _ctxpopup_cb, wd);
1230 evas_object_geometry_get(wd->more_item->base, &x, &y, &w, &h);
1231 evas_object_move(ctxpopup, x + w/2, y + h/2);
1233 evas_object_show(ctxpopup);
1236 static Elm_Controlbar_Item *
1237 _create_more_item(Widget_Data *wd, int style)
1239 Elm_Controlbar_Item * it;
1241 it = ELM_NEW(Elm_Controlbar_Item);
1242 if (!it) return NULL;
1243 it->obj = wd->object;
1244 it->text = eina_stringshare_add("more");
1245 it->icon_path = eina_stringshare_add(CONTROLBAR_SYSTEM_ICON_MORE);
1246 it->selected = EINA_FALSE;
1248 it->view = _create_more_view(wd);
1249 it->func = _create_more_func;
1251 it->base = _create_item_layout(wd->edje, it, &(it->base_item), &(it->icon));
1252 evas_object_smart_callback_add(it->base_item, "pressed",
1253 _bar_item_down_cb, wd);
1254 evas_object_smart_callback_add(it->base_item, "unpressed", _unpress_box_cb, wd);
1255 evas_object_smart_callback_add(it->base_item, "clicked", _clicked_box_cb, wd);
1256 evas_object_show(it->base);
1258 _set_items_position(it->obj, it, NULL, EINA_TRUE);
1259 wd->items = eina_list_append(wd->items, it);
1261 wd->items = eina_list_sort(wd->items, eina_list_count(wd->items), _sort_cb);
1266 ///////////////////////////////////////////////////////////////////
1270 ////////////////////////////////////////////////////////////////////
1273 * Add a new controlbar object
1275 * @param parent The parent object
1276 * @return The new object or NULL if it cannot be created
1278 * @ingroup Controlbar
1280 EAPI Evas_Object * elm_controlbar_add(Evas_Object * parent)
1282 if (parent == NULL) return NULL;
1283 Evas_Object * obj = NULL;
1284 Evas_Object * bg = NULL;
1285 Widget_Data * wd = NULL;
1286 Evas_Coord x, y, w, h;
1288 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1289 ELM_SET_WIDTYPE(widtype, "controlbar");
1290 elm_widget_type_set(obj, "controlbar");
1291 elm_widget_sub_object_add(parent, obj);
1292 elm_widget_data_set(obj, wd);
1293 elm_widget_del_hook_set(obj, _del_hook);
1294 elm_widget_can_focus_set(obj, EINA_FALSE);
1295 elm_widget_theme_hook_set(obj, _theme_hook);
1296 elm_widget_disable_hook_set(obj, _disable_hook);
1299 wd->parent = parent;
1300 evas_object_geometry_get(parent, &x, &y, &w, &h);
1306 wd->mode = ELM_CONTROLBAR_MODE_DEFAULT;
1310 wd->vertical = EINA_FALSE;
1311 wd->auto_align = EINA_FALSE;
1312 wd->selected_animation = EINA_FALSE;
1313 wd->pressed_signal = eina_stringshare_add("elm,state,pressed");
1314 wd->selected_signal = eina_stringshare_add("elm,state,selected");
1316 /* load background edj */
1317 wd->edje = elm_layout_add(obj);
1318 elm_layout_theme_set(wd->edje, "controlbar", "base", "default");
1319 if (wd->edje == NULL)
1321 printf("Cannot load base edj\n");
1324 evas_object_show(wd->edje);
1326 wd->bg = elm_layout_add(wd->edje);
1327 elm_layout_theme_set(wd->bg, "controlbar", "background", "default");
1330 printf("Cannot load bg edj\n");
1333 elm_object_content_part_set(wd->edje, "bg_image", wd->bg);
1336 evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_RESIZE,
1337 _controlbar_object_resize, obj);
1338 evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_MOVE,
1339 _controlbar_object_move, obj);
1340 evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_SHOW,
1341 _controlbar_object_show, obj);
1342 evas_object_event_callback_add(wd->edje, EVAS_CALLBACK_HIDE,
1343 _controlbar_object_hide, obj);
1345 bg = elm_object_content_part_get(wd->edje, "bg_image");
1346 evas_object_event_callback_add(bg, EVAS_CALLBACK_MOVE, _controlbar_object_move, obj);
1347 evas_object_event_callback_add(bg, EVAS_CALLBACK_RESIZE, _controlbar_object_resize, obj);
1350 wd->box = elm_table_add(wd->edje);
1351 elm_table_homogeneous_set(wd->box, EINA_TRUE);
1352 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1354 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1355 elm_object_content_part_set(wd->edje, "elm.swallow.items", wd->box);
1356 evas_object_show(wd->box);
1358 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1360 elm_widget_resize_object_set(obj, wd->edje);
1368 * Append new tab item
1370 * @param obj The controlbar object
1371 * @param icon_path The icon path of item
1372 * @param label The label of item
1373 * @param view The view of item
1374 * @return The item of controlbar
1376 * @ingroup Controlbar
1378 EAPI Elm_Controlbar_Item * elm_controlbar_tab_item_append(Evas_Object * obj,
1385 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1386 Elm_Controlbar_Item * it;
1387 Elm_Controlbar_Item * lit;
1389 it = _create_tab_item(obj, icon_path, label, view);
1390 if (!it) return NULL;
1391 wd = elm_widget_data_get(obj);
1392 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1394 if (!wd->more_item) {
1395 lit = elm_controlbar_last_item_get(obj);
1396 _set_item_visible(lit, EINA_FALSE);
1397 _create_more_item(wd, TABBAR);
1399 _set_items_position(obj, it, NULL, EINA_FALSE);
1402 _set_items_position(obj, it, NULL, EINA_TRUE);
1404 wd->items = eina_list_append(wd->items, it);
1406 elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1408 _check_background(wd);
1414 * Prepend new tab item
1416 * @param obj The controlbar object
1417 * @param icon_path The icon path of item
1418 * @param label The label of item
1419 * @param view The view of item
1420 * @return The item of controlbar
1422 * @ingroup Controlbar
1424 EAPI Elm_Controlbar_Item * elm_controlbar_tab_item_prepend(Evas_Object *
1433 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1435 Elm_Controlbar_Item * it;
1436 Elm_Controlbar_Item * lit;
1437 Elm_Controlbar_Item * item;
1438 it = _create_tab_item(obj, icon_path, label, view);
1439 if (!it) return NULL;
1440 wd = elm_widget_data_get(obj);
1441 item = eina_list_data_get(wd->items);
1442 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1444 if (!wd->more_item) {
1445 lit = elm_controlbar_last_item_get(obj);
1446 _set_item_visible(lit, EINA_FALSE);
1447 _create_more_item(wd, TABBAR);
1449 lit = elm_controlbar_item_prev(wd->more_item);
1450 _set_item_visible(lit, EINA_FALSE);
1451 _set_items_position(obj, it, item, EINA_TRUE);
1454 _set_items_position(obj, it, item, EINA_TRUE);
1456 wd->items = eina_list_prepend(wd->items, it);
1458 elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1460 _check_background(wd);
1466 * Insert new tab item before given item
1468 * @param obj The controlbar object
1469 * @param before The given item
1470 * @param icon_path The icon path of item
1471 * @param label The label of item
1472 * @param view The view of item
1473 * @return The item of controlbar
1475 * @ingroup Controlbar
1477 EAPI Elm_Controlbar_Item *
1478 elm_controlbar_tab_item_insert_before(Evas_Object * obj,
1479 Elm_Controlbar_Item * before,
1480 const char *icon_path,
1481 const char *label, Evas_Object * view)
1483 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1485 Elm_Controlbar_Item * it;
1486 Elm_Controlbar_Item * lit;
1487 if (!before) return NULL;
1488 it = _create_tab_item(obj, icon_path, label, view);
1489 if (!it) return NULL;
1490 wd = elm_widget_data_get(obj);
1491 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1495 lit = elm_controlbar_last_item_get(obj);
1496 _set_item_visible(lit, EINA_FALSE);
1497 _create_more_item(wd, TABBAR);
1499 before = wd->more_item;
1500 if (before->order > 0)
1502 lit = elm_controlbar_item_prev(wd->more_item);
1503 _set_item_visible(lit, EINA_FALSE);
1504 _set_items_position(obj, it, before, EINA_TRUE);
1508 _set_items_position(obj, it, before, EINA_FALSE);
1512 _set_items_position(obj, it, before, EINA_TRUE);
1514 wd->items = eina_list_prepend_relative(wd->items, it, before);
1516 elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1518 _check_background(wd);
1524 * Insert new tab item after given item
1526 * @param obj The controlbar object
1527 * @param after The given item
1528 * @param icon_path The icon path of item
1529 * @param label The label of item
1530 * @param view The view of item
1531 * @return The item of controlbar
1533 * @ingroup Controlbar
1535 EAPI Elm_Controlbar_Item *
1536 elm_controlbar_tab_item_insert_after(Evas_Object * obj,
1537 Elm_Controlbar_Item * after,
1538 const char *icon_path, const char *label,
1541 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1543 Elm_Controlbar_Item * it;
1544 Elm_Controlbar_Item * lit;
1545 Elm_Controlbar_Item * item;
1546 if (!after) return NULL;
1547 it = _create_tab_item(obj, icon_path, label, view);
1548 if (!it) return NULL;
1549 wd = elm_widget_data_get(obj);
1550 item = elm_controlbar_item_next(after);
1551 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1555 lit = elm_controlbar_last_item_get(obj);
1556 _set_item_visible(lit, EINA_FALSE);
1557 _create_more_item(wd, TABBAR);
1559 lit = elm_controlbar_item_prev(wd->more_item);
1560 if ((lit != after) && (item->order > 0))
1562 _set_item_visible(lit, EINA_FALSE);
1563 _set_items_position(obj, it, item, EINA_TRUE);
1567 _set_items_position(obj, it, NULL, EINA_FALSE);
1571 _set_items_position(obj, it, item, EINA_TRUE);
1573 wd->items = eina_list_append_relative(wd->items, it, after);
1575 elm_controlbar_item_view_set(wd->more_item, _create_more_view(wd));
1577 _check_background(wd);
1583 * Append new tool item
1585 * @param obj The controlbar object
1586 * @param icon_path The icon path of item
1587 * @param label The label of item
1588 * @param func Callback function of item
1589 * @param data The data of callback function
1590 * @return The item of controlbar
1592 * @ingroup Controlbar
1594 EAPI Elm_Controlbar_Item * elm_controlbar_tool_item_append(Evas_Object *
1609 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1610 Elm_Controlbar_Item * it;
1611 Elm_Controlbar_Item * lit;
1613 it = _create_tool_item(obj, icon_path, label, func, data);
1614 if (!it) return NULL;
1615 wd = elm_widget_data_get(obj);
1616 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1618 if (!wd->more_item) {
1619 lit = elm_controlbar_last_item_get(obj);
1620 _set_item_visible(lit, EINA_FALSE);
1621 _create_more_item(wd, TOOLBAR);
1623 _set_items_position(obj, it, NULL, EINA_FALSE);
1626 _set_items_position(obj, it, NULL, EINA_TRUE);
1628 wd->items = eina_list_append(wd->items, it);
1629 _check_toolbar_line(wd);
1635 * Prepend new tool item
1637 * @param obj The controlbar object
1638 * @param icon_path The icon path of item
1639 * @param label The label of item
1640 * @param func Callback function of item
1641 * @param data The data of callback function
1642 * @return The item of controlbar
1644 * @ingroup Controlbar
1646 EAPI Elm_Controlbar_Item * elm_controlbar_tool_item_prepend(Evas_Object *
1662 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1664 Elm_Controlbar_Item * it;
1665 Elm_Controlbar_Item * lit;
1666 Elm_Controlbar_Item * item;
1667 it = _create_tool_item(obj, icon_path, label, func, data);
1668 if (!it) return NULL;
1669 wd = elm_widget_data_get(obj);
1670 item = eina_list_data_get(wd->items);
1671 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1673 if (!wd->more_item) {
1674 lit = elm_controlbar_last_item_get(obj);
1675 _set_item_visible(lit, EINA_FALSE);
1676 _create_more_item(wd, TOOLBAR);
1678 lit = elm_controlbar_item_prev(wd->more_item);
1679 _set_item_visible(lit, EINA_FALSE);
1680 _set_items_position(obj, it, item, EINA_TRUE);
1683 _set_items_position(obj, it, item, EINA_TRUE);
1685 wd->items = eina_list_prepend(wd->items, it);
1686 _check_toolbar_line(wd);
1692 * Insert new tool item before given item
1694 * @param obj The controlbar object
1695 * @param before The given item
1696 * @param icon_path The icon path of item
1697 * @param label The label of item
1698 * @param func Callback function of item
1699 * @param data The data of callback function
1700 * @return The item of controlbar
1702 * @ingroup Controlbar
1704 EAPI Elm_Controlbar_Item *
1705 elm_controlbar_tool_item_insert_before(Evas_Object * obj,
1706 Elm_Controlbar_Item * before,
1707 const char *icon_path,
1709 void (*func) (void *data,
1714 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1716 Elm_Controlbar_Item * it;
1717 Elm_Controlbar_Item * lit;
1718 if (!before) return NULL;
1719 it = _create_tool_item(obj, icon_path, label, func, data);
1720 if (!it) return NULL;
1721 wd = elm_widget_data_get(obj);
1722 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1726 lit = elm_controlbar_last_item_get(obj);
1727 _set_item_visible(lit, EINA_FALSE);
1728 _create_more_item(wd, TOOLBAR);
1730 before = wd->more_item;
1731 if (before->order > 0)
1733 lit = elm_controlbar_item_prev(wd->more_item);
1734 _set_item_visible(lit, EINA_FALSE);
1735 _set_items_position(obj, it, before, EINA_TRUE);
1739 _set_items_position(obj, it, before, EINA_FALSE);
1743 _set_items_position(obj, it, before, EINA_TRUE);
1745 wd->items = eina_list_prepend_relative(wd->items, it, before);
1746 _check_toolbar_line(wd);
1752 * Insert new tool item after given item
1754 * @param obj The controlbar object
1755 * @param after The given item
1756 * @param icon_path The icon path of item
1757 * @param label The label of item
1758 * @param func Callback function of item
1759 * @param data The data of callback function
1760 * @return The item of controlbar
1762 * @ingroup Controlbar
1764 EAPI Elm_Controlbar_Item *
1765 elm_controlbar_tool_item_insert_after(Evas_Object * obj,
1766 Elm_Controlbar_Item * after,
1767 const char *icon_path,
1769 void (*func) (void *data,
1774 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1776 Elm_Controlbar_Item * it;
1777 Elm_Controlbar_Item * lit;
1778 Elm_Controlbar_Item * item;
1779 if (!after) return NULL;
1780 it = _create_tool_item(obj, icon_path, label, func, data);
1781 if (!it) return NULL;
1782 wd = elm_widget_data_get(obj);
1783 item = elm_controlbar_item_next(after);
1784 if ((_check_bar_item_number(wd) >= 5) && (wd->auto_align))
1788 lit = elm_controlbar_last_item_get(obj);
1789 _set_item_visible(lit, EINA_FALSE);
1790 _create_more_item(wd, TOOLBAR);
1792 lit = elm_controlbar_item_prev(wd->more_item);
1793 if ((lit != after) && (item->order > 0))
1795 _set_item_visible(lit, EINA_FALSE);
1796 _set_items_position(obj, it, item, EINA_TRUE);
1800 _set_items_position(obj, it, NULL, EINA_FALSE);
1804 _set_items_position(obj, it, item, EINA_TRUE);
1806 wd->items = eina_list_append_relative(wd->items, it, after);
1807 _check_toolbar_line(wd);
1813 * Append new object item
1815 * @param obj The controlbar object
1816 * @param obj_item The object of item
1817 * @param sel The number of sel occupied
1818 * @return The item of controlbar
1820 * @ingroup Controlbar
1822 EAPI Elm_Controlbar_Item * elm_controlbar_object_item_append(Evas_Object *
1828 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1830 Elm_Controlbar_Item * it;
1831 wd = elm_widget_data_get(obj);
1832 if (!wd) return NULL;
1833 it = _create_object_item(obj, obj_item, sel);
1834 if (!it) return NULL;
1835 _set_items_position(obj, it, NULL, EINA_TRUE);
1836 wd->items = eina_list_append(wd->items, it);
1842 * Prepend new object item
1844 * @param obj The controlbar object
1845 * @param obj_item The object of item
1846 * @param sel The number of sel occupied
1847 * @return The item of controlbar
1849 * @ingroup Controlbar
1851 EAPI Elm_Controlbar_Item * elm_controlbar_object_item_prepend(Evas_Object *
1857 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1859 Elm_Controlbar_Item * it;
1860 Elm_Controlbar_Item * item;
1861 wd = elm_widget_data_get(obj);
1862 if (!wd) return NULL;
1863 it = _create_object_item(obj, obj_item, sel);
1864 if (!it) return NULL;
1865 item = eina_list_data_get(wd->items);
1866 _set_items_position(obj, it, item, EINA_TRUE);
1867 wd->items = eina_list_prepend(wd->items, it);
1873 * Insert new object item before given item
1875 * @param obj The controlbar object
1876 * @param before The given item
1877 * @param obj_item The object of item
1878 * @param sel The number of sel occupied
1879 * @return The item of controlbar
1881 * @ingroup Controlbar
1883 EAPI Elm_Controlbar_Item *
1884 elm_controlbar_object_item_insert_before(Evas_Object * obj,
1885 Elm_Controlbar_Item * before,
1886 Evas_Object * obj_item, const int sel)
1888 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1890 Elm_Controlbar_Item * it;
1891 wd = elm_widget_data_get(obj);
1892 if (!wd) return NULL;
1893 if (!before) return NULL;
1894 it = _create_object_item(obj, obj_item, sel);
1895 if (!it) return NULL;
1896 _set_items_position(obj, it, before, EINA_TRUE);
1897 wd->items = eina_list_prepend_relative(wd->items, it, before);
1903 * Insert new object item after given item
1905 * @param obj The controlbar object
1906 * @param after The given item
1907 * @param obj_item The object of item
1908 * @param sel The number of sel occupied
1909 * @return The item of controlbar
1911 * @ingroup Controlbar
1913 EAPI Elm_Controlbar_Item *
1914 elm_controlbar_object_item_insert_after(Evas_Object * obj,
1915 Elm_Controlbar_Item * after,
1916 Evas_Object * obj_item, const int sel)
1918 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1920 Elm_Controlbar_Item * it;
1921 Elm_Controlbar_Item * item;
1922 wd = elm_widget_data_get(obj);
1923 if (!wd) return NULL;
1924 if (!after) return NULL;
1925 it = _create_object_item(obj, obj_item, sel);
1926 if (!it) return NULL;
1927 item = elm_controlbar_item_next(after);
1928 _set_items_position(obj, it, item, EINA_TRUE);
1929 wd->items = eina_list_append_relative(wd->items, it, after);
1935 * Get the object of the object item
1937 * @param it The item of controlbar
1938 * @return The object of the object item
1940 * @ingroup Controlbar
1943 elm_controlbar_object_item_object_get(const Elm_Controlbar_Item * it)
1945 if (!it) return NULL;
1946 if (it->style != OBJECT) return NULL;
1947 if (!it->base_item) return NULL;
1948 return it->base_item;
1952 * Delete item from controlbar
1954 * @param it The item of controlbar
1956 * @ingroup Controlbar
1959 elm_controlbar_item_del(Elm_Controlbar_Item * it)
1965 Elm_Controlbar_Item * item;
1972 if (it->obj == NULL)
1974 printf("Invalid argument: controlbar object is NULL\n");
1977 wd = elm_widget_data_get(it->obj);
1980 printf("Cannot get smart data\n");
1988 elm_table_unpack(wd->box, it->base);
1990 EINA_LIST_FOREACH(wd->items, l, item)
1994 if (item->order > it->order)
1997 elm_table_unpack(wd->box, item->base);
2000 elm_table_pack(wd->box, item->base, item->order - 1, 0, item->sel, 1);
2002 elm_table_pack(wd->box, item->base, 0, item->order - 1, item->sel, 1);
2008 // delete item in list
2010 wd->items = eina_list_remove(wd->items, it);
2013 wd->num = wd->num - 1;
2018 * Select item in controlbar
2020 * @param it The item of controlbar
2022 * @ingroup Controlbar
2025 elm_controlbar_item_select(Elm_Controlbar_Item * it)
2028 if (it->obj == NULL) return;
2029 Widget_Data * wd = elm_widget_data_get(it->obj);
2036 * Set the icon of item
2038 * @param it The item of controlbar
2039 * @param icon_path The icon path of the item
2040 * @return The icon object
2042 * @ingroup Controlbar
2045 elm_controlbar_item_icon_set(Elm_Controlbar_Item * it, const char *icon_path)
2048 if (it->style == OBJECT) return;
2051 eina_stringshare_del(it->icon_path);
2052 it->icon_path = NULL;
2056 evas_object_del(it->icon);
2059 if (icon_path != NULL)
2061 it->icon_path = eina_stringshare_add(icon_path);
2062 it->icon = _create_item_icon(it->base_item, it, "elm.swallow.icon");
2064 if (it->wd->disabled || it->disabled)
2065 elm_widget_disabled_set(it->base_item, EINA_TRUE);
2067 elm_widget_disabled_set(it->base_item, EINA_FALSE);
2071 * Get the icon of item
2073 * @param it The item of controlbar
2074 * @return The icon object
2076 * @ingroup Controlbar
2079 elm_controlbar_item_icon_get(const Elm_Controlbar_Item * it)
2081 if (!it) return NULL;
2086 * Set the label of item
2088 * @param it The item of controlbar
2089 * @param label The label of item
2091 * @ingroup Controlbar
2094 elm_controlbar_item_label_set(Elm_Controlbar_Item * it, const char *label)
2097 if (it->style == OBJECT) return;
2100 eina_stringshare_del(it->text);
2105 it->text = eina_stringshare_add(label);
2106 elm_object_text_set(it->base_item, it->text);
2108 if (it->wd->disabled || it->disabled)
2109 elm_widget_disabled_set(it->base_item, EINA_TRUE);
2111 elm_widget_disabled_set(it->base_item, EINA_FALSE);
2115 * Get the label of item
2117 * @param it The item of controlbar
2118 * @return The label of item
2120 * @ingroup Controlbar
2123 elm_controlbar_item_label_get(const Elm_Controlbar_Item * it)
2125 if (!it) return NULL;
2130 * Get the selected item
2132 * @param obj The controlbar object
2133 * @return The item of controlbar
2135 * @ingroup Controlbar
2137 EAPI Elm_Controlbar_Item * elm_controlbar_selected_item_get(const Evas_Object *
2140 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2143 Elm_Controlbar_Item * item;
2144 if (obj == NULL) return NULL;
2145 Widget_Data * wd = elm_widget_data_get(obj);
2146 if (!wd || !wd->items) return NULL;
2147 EINA_LIST_FOREACH(wd->items, l, item)
2149 if (item->selected) return item;
2155 * Get the first item
2157 * @param obj The controlbar object
2158 * @return The item of controlbar
2160 * @ingroup Controlbar
2162 EAPI Elm_Controlbar_Item * elm_controlbar_first_item_get(const Evas_Object * obj)
2164 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2165 Widget_Data * wd = elm_widget_data_get(obj);
2166 if (!wd || !wd->items) return NULL;
2167 return eina_list_data_get(wd->items);
2173 * @param obj The controlbar object
2174 * @return The item of controlbar
2176 * @ingroup Controlbar
2178 EAPI Elm_Controlbar_Item * elm_controlbar_last_item_get(const Evas_Object * obj)
2180 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2181 Widget_Data * wd = elm_widget_data_get(obj);
2182 if (!wd || !wd->items) return NULL;
2183 return eina_list_data_get(eina_list_last(wd->items));
2189 * @param obj The controlbar object
2190 * @return The list of the items
2192 * @ingroup Controlbar
2194 EAPI const Eina_List * elm_controlbar_items_get(const Evas_Object * obj)
2196 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2197 Widget_Data * wd = elm_widget_data_get(obj);
2198 if (!wd || !wd->items) return NULL;
2203 * Get the previous item
2205 * @param it The item of controlbar
2206 * @return The previous item of the parameter item
2208 * @ingroup Controlbar
2210 EAPI Elm_Controlbar_Item * elm_controlbar_item_prev(Elm_Controlbar_Item *
2213 if (!it) return NULL;
2216 Elm_Controlbar_Item * item;
2217 if (it->obj == NULL) return NULL;
2218 Widget_Data * wd = elm_widget_data_get(it->obj);
2219 if (!wd || !wd->items) return NULL;
2220 EINA_LIST_FOREACH(wd->items, l, item)
2224 l = eina_list_prev(l);
2225 if (!l) return NULL;
2226 return eina_list_data_get(l);
2235 * @param obj The controlbar object
2236 * @return The next item of the parameter item
2238 * @ingroup Controlbar
2240 EAPI Elm_Controlbar_Item * elm_controlbar_item_next(Elm_Controlbar_Item *
2243 if (!it) return NULL;
2246 Elm_Controlbar_Item * item;
2247 if (it->obj == NULL) return NULL;
2248 Widget_Data * wd = elm_widget_data_get(it->obj);
2249 if (!wd || !wd->items) return NULL;
2250 EINA_LIST_FOREACH(wd->items, l, item)
2254 l = eina_list_next(l);
2255 if (!l) return NULL;
2256 return eina_list_data_get(l);
2263 * Set the visible status of item in bar
2265 * @param it The item of controlbar
2266 * @param bar EINA_TRUE or EINA_FALSE
2268 * @ingroup Controlbar
2271 elm_controlbar_item_visible_set(Elm_Controlbar_Item * it, Eina_Bool visible)
2274 if (it->obj == NULL) return;
2275 Widget_Data * wd = elm_widget_data_get(it->obj);
2278 if (!wd->auto_align)
2279 _set_item_visible(it, visible);
2283 * Get the result which or not item is visible in bar
2285 * @param it The item of controlbar
2286 * @return EINA_TRUE or EINA_FALSE
2288 * @ingroup Controlbar
2291 elm_controlbar_item_visible_get(const Elm_Controlbar_Item * it)
2293 if (!it) return EINA_FALSE;
2294 if (it->obj == NULL) return EINA_FALSE;
2295 Widget_Data * wd = elm_widget_data_get(it->obj);
2296 if (!wd) return EINA_FALSE;
2297 if (it->order <= 0) return EINA_FALSE;
2305 * @param it The item of controlbar
2306 * @param bar EINA_TRUE or EINA_FALSE
2308 * @ingroup Controlbar
2311 elm_controlbar_item_disabled_set(Elm_Controlbar_Item * it, Eina_Bool disabled)
2315 if (it->disabled == disabled) return;
2317 it->disabled = disabled;
2319 if ((it->wd) && (it->wd->disabled)) return;
2321 if (it->base_item) elm_widget_disabled_set(it->base_item, disabled);
2327 * @param it The item of controlbar
2328 * @return EINA_TRUE or EINA_FALSE
2330 * @ingroup Controlbar
2333 elm_controlbar_item_disabled_get(const Elm_Controlbar_Item * it)
2335 if (!it) return EINA_FALSE;
2337 return it->disabled;
2341 * Set the view of the item
2343 * @param it The item of controlbar
2344 * @param view The view for the item
2346 * @ingroup Controlbar
2349 elm_controlbar_item_view_set(Elm_Controlbar_Item *it, Evas_Object * view)
2352 if (it->view == view) return;
2354 evas_object_del(it->view);
2359 * Get the view of the item
2361 * @param it The item of controlbar
2362 * @return The view for the item
2364 * @ingroup Controlbar
2367 elm_controlbar_item_view_get(const Elm_Controlbar_Item *it)
2369 if (!it) return NULL;
2375 * Unset the view of the item
2377 * @param it The item of controlbar
2378 * @return The view for the item
2380 * @ingroup Controlbar
2383 elm_controlbar_item_view_unset(Elm_Controlbar_Item *it)
2385 if (!it) return NULL;
2386 if (it->obj == NULL) return NULL;
2387 Widget_Data * wd = elm_widget_data_get(it->obj);
2388 if (!wd) return NULL;
2389 Evas_Object *content;
2391 if (it->view == elm_object_content_part_get(wd->edje, "elm.swallow.view"))
2393 content = elm_object_content_part_unset(wd->edje, "elm.swallow.view");
2394 if (content) evas_object_hide(content);
2405 * Set the mode of the controlbar
2407 * @param obj The object of the controlbar
2408 * @param mode The mode of the controlbar
2410 * @ingroup Controlbar
2413 elm_controlbar_mode_set(Evas_Object *obj, int mode)
2415 ELM_CHECK_WIDTYPE(obj, widtype);
2416 Widget_Data *wd = elm_widget_data_get(obj);
2419 fprintf(stderr, "Cannot get smart data\n");
2422 Evas_Object *selected_box;
2428 case ELM_CONTROLBAR_MODE_DEFAULT:
2429 edje_object_signal_emit(_EDJ(wd->edje), "elm,state,default", "elm");
2431 case ELM_CONTROLBAR_MODE_TRANSLUCENCE:
2432 elm_controlbar_alpha_set(obj, 85);
2434 case ELM_CONTROLBAR_MODE_TRANSPARENCY:
2435 elm_controlbar_alpha_set(obj, 0);
2437 case ELM_CONTROLBAR_MODE_LARGE:
2438 edje_object_signal_emit(_EDJ(wd->edje), "elm,state,large", "elm");
2440 case ELM_CONTROLBAR_MODE_SMALL:
2441 edje_object_signal_emit(_EDJ(wd->edje), "elm,state,small", "elm");
2443 case ELM_CONTROLBAR_MODE_LEFT:
2444 selected_box = elm_object_content_part_get(wd->edje, "elm.dragable.box");
2445 if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,left", "elm");
2446 wd->selected_signal = eina_stringshare_add("elm,state,selected_left");
2447 wd->pressed_signal = eina_stringshare_add("elm,state,pressed_left");
2448 edje_object_signal_emit(_EDJ(wd->edje), "elm,state,left", "elm");
2449 _check_background(wd);
2452 case ELM_CONTROLBAR_MODE_RIGHT:
2453 selected_box = elm_object_content_part_get(wd->edje, "elm.dragable.box");
2454 if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,right", "elm");
2455 wd->selected_signal = eina_stringshare_add("elm,state,selected_right");
2456 wd->pressed_signal = eina_stringshare_add("elm,state,pressed_right");
2457 edje_object_signal_emit(_EDJ(wd->edje), "elm,state,right", "elm");
2458 _check_background(wd);
2464 selected_box = elm_object_content_part_get(wd->edje, "elm.dragable.box");
2465 if (selected_box) edje_object_signal_emit(_EDJ(selected_box), "elm,state,default", "elm");
2466 wd->selected_signal = eina_stringshare_add("elm,state,selected");
2467 wd->pressed_signal = eina_stringshare_add("elm,state,pressed");
2468 _check_background(wd);
2473 * Set the alpha of the controlbar
2475 * @param obj The object of the controlbar
2476 * @param alpha The alpha value of the controlbar (0-100)
2478 * @ingroup Controlbar
2481 elm_controlbar_alpha_set(Evas_Object *obj, int alpha)
2483 ELM_CHECK_WIDTYPE(obj, widtype);
2485 Widget_Data *wd = elm_widget_data_get(obj);
2488 fprintf(stderr, "Cannot get smart data\n");
2492 if (alpha < 0) wd->alpha = 0;
2493 else if (alpha > 100) wd->alpha = 100;
2494 else wd->alpha = alpha;
2496 evas_object_color_get(wd->bg, &r, &g, &b, NULL);
2497 evas_object_color_set(wd->bg, r, g, b, (int)(255 * wd->alpha / 100));
2502 * Set auto-align mode of the controlbar(It's not prepared yet)
2503 * If you set the auto-align and add items more than 5,
2504 * the "more" item will be made and the items more than 5 will be unvisible.
2506 * @param obj The object of the controlbar
2507 * @param auto_align The dicision that the controlbar use the auto-align
2509 * @ingroup Controlbar
2512 elm_controlbar_item_auto_align_set(Evas_Object *obj, Eina_Bool auto_align)
2514 ELM_CHECK_WIDTYPE(obj, widtype);
2515 Widget_Data *wd = elm_widget_data_get(obj);
2516 Elm_Controlbar_Item *item;
2521 fprintf(stderr, "Cannot get smart data\n");
2525 if (wd->auto_align == auto_align) return;
2529 if ((_check_bar_item_number(wd)) >= 5 && (!wd->more_item))
2532 EINA_LIST_FOREACH(wd->items, l, item)
2534 if (elm_controlbar_item_visible_get(item))
2537 _delete_item_in_bar(item);
2540 item = elm_controlbar_last_item_get(obj);
2541 while (!elm_controlbar_item_visible_get(item)){
2542 item = elm_controlbar_item_prev(item);
2544 _create_more_item(wd, item->style);
2552 if (wd->more_item->view)
2553 evas_object_del(wd->more_item->view);
2554 wd->items = eina_list_remove(wd->items, wd->more_item);
2555 eina_stringshare_del(wd->more_item->text);
2556 if (wd->more_item->icon)
2557 evas_object_del(wd->more_item->icon);
2558 if (wd->more_item->base)
2559 evas_object_del(wd->more_item->base);
2560 if (wd->more_item->base_item)
2561 evas_object_del(wd->more_item->base_item);
2562 free(wd->more_item);
2563 wd->more_item = NULL;
2565 // make all item is visible
2567 EINA_LIST_FOREACH(wd->items, l, item)
2569 if (!elm_controlbar_item_visible_get(item))
2570 _insert_item_in_bar(item, i);
2575 wd->auto_align = auto_align;
2580 * Set the vertical mode of the controlbar
2582 * @param obj The object of the controlbar
2583 * @param vertical The vertical mode of the controlbar (TRUE = vertical, FALSE = horizontal)
2585 * @ingroup Controlbar
2588 elm_controlbar_vertical_set(Evas_Object *obj, Eina_Bool vertical)
2590 ELM_CHECK_WIDTYPE(obj, widtype);
2591 Widget_Data *wd = elm_widget_data_get(obj);
2594 fprintf(stderr, "Cannot get smart data\n");
2598 if (wd->vertical == vertical) return;
2599 wd->vertical = vertical;
2601 if (_check_bar_item_number(wd) > 1)
2605 _check_toolbar_line(wd);
2609 * Get the button object of the item
2611 * @param it The item of controlbar
2612 * @return button object of the item
2614 * @ingroup Controlbar
2617 elm_controlbar_item_button_get(const Elm_Controlbar_Item *it)
2619 if (!it) return NULL;
2620 if (it->style == OBJECT) return NULL;
2622 if (it->base_item) return it->base_item;