1 #include <Elementary.h>
5 * @defgroup SegmentControl SegmentControl
8 * SegmentControl object is a horizontal control made of multiple segments,
9 * each segment item functioning as a discrete button. A segmented control affords a compact means to group together a number of controls.
10 * A segmented control can display a title or an image. The UISegmentedControl object automatically resizes segment items to fit proportionally
11 * within their superview unless they have a specific width set. When you add and remove segments,
12 * you can request that the action be animated with sliding and fading effects.
14 typedef struct _Widget_Data Widget_Data;
20 Elm_Segment_Item *ani_it;
27 int max_height, w_pad, h_pad;
29 unsigned int insert_index;
30 unsigned int del_index;
31 unsigned int cur_seg_id;
33 Eina_Bool selected : 1;
36 struct _Elm_Segment_Item
41 Evas_Object *label_wd;
44 Eina_Bool delete_me : 1;
47 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
48 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
49 static void _signal_segment_on(void *data);
50 static void _signal_segment_off(void *data);
51 static void _theme_hook(Evas_Object *obj);
52 static void _item_free(Evas_Object *obj, Elm_Segment_Item *it);
53 static void _del_hook(Evas_Object *obj);
54 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
55 static void _segment_resizing(void *data);
56 static void _object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
57 static void _update_list(Evas_Object *obj);
58 static void _refresh_segment_ids(Evas_Object *obj);
59 static void _state_value_set(Evas_Object *obj);
61 static Elm_Segment_Item* _item_new(Evas_Object *obj, const char *label, Evas_Object *icon);
62 static Elm_Segment_Item *_item_find(Evas_Object *obj, unsigned int index);
64 static int * _animator_animate_add_cb(Evas_Object *obj);
65 static int * _animator_animate_del_cb(Evas_Object *obj);
68 _on_focus_hook(void *data, Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
73 if (elm_widget_focus_get(obj))
74 evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 1);
76 evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 0);
80 _signal_segment_off(void *data)
82 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
83 Widget_Data *wd = elm_widget_data_get(item->obj);
86 edje_object_signal_emit(item->base, "elm,action,unfocus", "elm");
87 edje_object_signal_emit(item->base, "elm,state,segment,off", "elm");
88 if(!item->label_wd && item->label)
90 edje_object_signal_emit(item->base, "elm,state,text,visible", "elm");
94 elm_label_text_color_set(item->label_wd, 0xff,0xff, 0xff, 0xff);
101 _signal_segment_on(void *data)
103 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
104 Elm_Segment_Item *it;
107 Widget_Data *wd = elm_widget_data_get(item->obj);
110 wd->selected = EINA_TRUE;
112 edje_object_signal_emit(item->base, "elm,state,segment,on", "elm");
113 edje_object_signal_emit(item->base, "elm,action,focus", "elm");
115 edje_object_signal_emit(item->base, "elm,state,text,change", "elm");
117 if (item->segment_id == wd->cur_seg_id) return;
119 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
121 if (it->segment_id == wd->cur_seg_id)
123 _signal_segment_off (it);
127 wd->cur_seg_id = item->segment_id;
128 evas_object_smart_callback_call(item->obj, "changed", (void*)wd->cur_seg_id);
134 _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
136 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
137 Widget_Data *wd = elm_widget_data_get(item->obj);
139 Evas_Coord wrap_width = 0, wrap_height = 0, w = 0, h = 0;
141 if (item->segment_id == wd->cur_seg_id)
143 wd->selected = EINA_TRUE;
146 _signal_segment_on((void*)item);
148 elm_label_text_color_set(item->label_wd, 0x00,0x00, 0x00, 0xff);
150 wd->selected = EINA_FALSE;
156 _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
158 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
159 Widget_Data *wd = elm_widget_data_get(item->obj);
163 edje_object_signal_emit(item->base, "elm,action,focus", "elm");
168 _theme_hook(Evas_Object *obj)
170 _elm_theme_object_set(obj, obj, "segmented-control", "base", elm_widget_style_get(obj));
176 _item_free(Evas_Object *obj, Elm_Segment_Item *it)
178 Widget_Data *wd = elm_widget_data_get(obj);
182 wd->seg_ctrl = eina_list_remove(wd->seg_ctrl, it);
184 if(it->icon) evas_object_del(it->icon);
187 evas_object_del(it->label_wd);
189 if (edje_object_part_swallow_get(it->base, "elm.swallow.label.content") == NULL)
191 edje_object_part_unswallow(it->base, it->label_wd);
194 if(it->base) evas_object_del(it->base);
195 if(it->label) eina_stringshare_del(it->label);
204 _del_hook(Evas_Object *obj)
206 Widget_Data *wd = elm_widget_data_get(obj);
207 Elm_Segment_Item *it;
208 Eina_List *l, *clear = NULL;
210 EINA_LIST_FOREACH(wd->seg_ctrl, l, it) clear = eina_list_append(clear, it);
211 EINA_LIST_FREE(clear, it) _item_free(obj, it);
221 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
223 Widget_Data *wd = data;
225 _els_box_layout(o, priv, 1, 0); /* making box layout non homogenous */
231 _segment_resizing(void *data)
233 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
235 Evas_Coord w = 0, h = 0;
237 evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
238 wd->item_width = wd->width = w;
241 _state_value_set((Evas_Object *)data);
245 _object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
249 wd = elm_widget_data_get((Evas_Object *)data);
252 ecore_job_add(_segment_resizing, (Evas_Object *)data);
256 _segment_item_resizing(void *data)
259 Elm_Segment_Item *it = (Elm_Segment_Item *)data;
260 wd = elm_widget_data_get(it->obj);
263 Evas_Coord w = 0, h = 0;
265 _update_list(it->obj);
266 evas_object_geometry_get(it->base, NULL, NULL, &w, &h);
268 if(wd->max_height == 1) wd->max_height = h;
272 elm_label_wrap_width_set(it->label_wd, w-wd->w_pad);
273 elm_label_wrap_height_set(it->label_wd, wd->max_height-wd->h_pad);
274 if (it->segment_id == wd->cur_seg_id)
276 elm_label_text_color_set(it->label_wd, 0x00,0x00, 0x00, 0xff);
279 elm_label_text_color_set(it->label_wd, 0xFF,0xFF, 0xFF, 0xff);
280 if (edje_object_part_swallow_get(it->base, "elm.swallow.label.content") == NULL)
282 edje_object_part_unswallow(it->base, it->label_wd);
284 edje_object_part_swallow(it->base, "elm.swallow.label.content", it->label_wd);
285 edje_object_signal_emit(it->base, "elm,state,label,visible", "elm");
286 if (it->segment_id == wd->cur_seg_id)
288 elm_label_text_color_set(it->label_wd, 0x00,0x00, 0x00, 0xff);
291 elm_label_text_color_set(it->label_wd, 0xFF,0xFF, 0xFF, 0xff);
296 _object_item_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
298 ecore_job_add(_segment_item_resizing, (Evas_Object *)data);
301 static Elm_Segment_Item*
302 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon)
304 Elm_Segment_Item *it;
306 Widget_Data *wd = elm_widget_data_get(obj);
307 if (!wd) return NULL;
309 it = calloc(1, sizeof( Elm_Segment_Item));
310 if (!it) return NULL;
312 if(obj) it->obj = obj;
313 it->delete_me = EINA_FALSE;
314 it->segment_id = wd->id;
317 it->base = edje_object_add(evas_object_evas_get(obj));
318 _elm_theme_object_set(obj, it->obj, "segment", "base/default", elm_object_style_get(it->obj));
320 if (it->label) eina_stringshare_del(it->label);
323 it->label = eina_stringshare_add(label);
326 if ((it->icon != icon) && (it->icon))
327 elm_widget_sub_object_del(obj, it->icon);
331 elm_widget_sub_object_add(obj, icon);
332 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
333 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
334 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
336 evas_object_size_hint_weight_set(it->base, 1.0, -1.0);
337 evas_object_size_hint_align_set(it->base, 1.0, -1.0);
338 evas_object_size_hint_min_set(it->base, -1, -1);
339 evas_object_size_hint_max_set(it->base, maxw, maxh);
342 edje_object_size_min_restricted_calc(obj, &mw, &mh, 0, 0);
343 evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
344 evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
351 _update_list(Evas_Object *obj)
353 Elm_Segment_Item *it;
357 Widget_Data *wd = elm_widget_data_get(obj);
360 wd->count = eina_list_count(wd->seg_ctrl);
363 it = _item_find(obj, 0);
364 _elm_theme_object_set(obj, it->base, "segment", "base/single", elm_object_style_get(it->obj));
\r
365 edje_object_signal_emit(it->base, "elm,state,segment,on", "elm");
366 if(it->label && !it->label_wd)
368 edje_object_signal_emit(it->base, "elm,state,text,change", "elm");
369 edje_object_part_text_set(it->base, "elm.text", it->label);
372 edje_object_signal_emit(it->base, "elm,state,text,hidden", "elm");
373 if (it->icon && edje_object_part_swallow_get(it->base, "elm.swallow.content") == NULL)
377 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
378 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
381 edje_object_signal_emit(it->base, "elm,state,icon,hidden", "elm");
383 edje_object_message_signal_process(it->base);
388 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
392 _elm_theme_object_set(obj, it->base, "segment", "base/first", elm_object_style_get(it->obj));
394 else if(i==wd->count-1)
396 _elm_theme_object_set(obj, it->base, "segment", "base/last", elm_object_style_get(it->obj));
400 _elm_theme_object_set(obj, it->base, "segment", "base/default", elm_object_style_get(it->obj));
404 if(it->label && !it->label_wd)
406 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
407 edje_object_part_text_set(it->base, "elm.text", it->label);
410 edje_object_signal_emit(it->base, "elm,state,text,hidden", "elm");
412 if (it->icon && edje_object_part_swallow_get(it->base, "elm.swallow.content") == NULL)
416 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
417 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
420 edje_object_signal_emit(it->base, "elm,state,icon,hidden", "elm");
422 edje_object_message_signal_process(it->base);
426 if(wd->data && wd->selected)
428 _signal_segment_on(wd->data);
429 wd->selected = EINA_FALSE;
435 _refresh_segment_ids(Evas_Object *obj)
437 Elm_Segment_Item *it;
440 Widget_Data *wd = elm_widget_data_get(obj);
443 if (wd->insert_index && wd->cur_seg_id >= wd->insert_index)
446 wd->insert_index = 0;
450 if (wd->cur_seg_id >= wd->del_index)
455 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
463 _state_value_set(Evas_Object *obj)
465 Elm_Segment_Item *it;
467 Evas_Coord mw, mh, x, y;
471 Widget_Data *wd = elm_widget_data_get(obj);
474 count = eina_list_count(wd->seg_ctrl);
476 wd->item_width = wd->width/count;
479 evas_object_geometry_get(wd->ani_it->base, &x, &y, &w1, NULL);
480 if (wd->ani_it->delete_me)
482 w1-=(wd->item_width/5);
487 w1+=(wd->item_width/5);
488 if( w1 > wd->item_width )
491 w2 = (wd->width-w1)/(count -1);
496 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
498 edje_object_size_min_restricted_calc(it->base, &mw, &mh, 0, 0);
499 evas_object_size_hint_weight_set(it->base, 1.0, 1.0);
500 evas_object_size_hint_align_set(it->base, -1.0, -1.0);
503 if(wd->ani_it && it == wd->ani_it)
505 evas_object_resize(it->base, w1, wd->height);
506 evas_object_size_hint_min_set(it->base, w1, wd->height);
507 evas_object_size_hint_max_set(it->base, w1, wd->height);
511 evas_object_resize(it->base, w2, wd->height);
512 evas_object_size_hint_min_set(it->base, w2, wd->height);
513 evas_object_size_hint_max_set(it->base, w2, wd->height);
523 _animator_animate_add_cb(Evas_Object *obj)
526 Widget_Data *wd = elm_widget_data_get(obj);
529 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
530 if( w < wd->item_width )
532 _state_value_set(obj);
533 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
534 return (int*) ECORE_CALLBACK_RENEW;
538 ecore_animator_del(wd->ani);
541 return (int*) ECORE_CALLBACK_CANCEL;
547 _animator_animate_del_cb(Evas_Object *obj)
550 Widget_Data *wd = elm_widget_data_get(obj);
553 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
556 _state_value_set(obj);
557 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
558 return (int*) ECORE_CALLBACK_RENEW;
562 _item_free(obj, wd->ani_it );
563 _refresh_segment_ids(obj);
564 ecore_animator_del(wd->ani);
568 wd->id = eina_list_count(wd->seg_ctrl);
569 return (int*) ECORE_CALLBACK_CANCEL;
573 static Elm_Segment_Item *
574 _item_find(Evas_Object *obj, unsigned int index)
576 Elm_Segment_Item *it;
579 Widget_Data *wd = elm_widget_data_get(obj);
580 if (!wd) return NULL;
582 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
584 if (i == index) return it;
591 static Elm_Segment_Item *
592 _item_search(Evas_Object *obj, Elm_Segment_Item *item)
594 Elm_Segment_Item *it;
596 Widget_Data *wd = elm_widget_data_get(obj);
600 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
611 * Add a new segmentcontrol to the parent
612 * @param parent The parent object
613 * @return The new object or NULL if it cannot be created
615 * @ingroup SegmentControl SegmentControl
618 elm_segment_control_add(Evas_Object *parent)
624 const char *deffont, *maxheight, *wpad, *hpad;
626 wd = ELM_NEW(Widget_Data);
627 e = evas_object_evas_get(parent);
629 obj = elm_widget_add(e);
630 elm_widget_type_set(obj, "segmented-control");
631 elm_widget_sub_object_add(parent, obj);
632 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
633 elm_widget_data_set(obj, wd);
634 elm_widget_del_hook_set(obj, _del_hook);
635 elm_widget_theme_hook_set(obj, _theme_hook);
637 wd->base = edje_object_add(e);
638 _elm_theme_object_set(obj, wd->base, "segmented-control", "base", "default");
639 elm_widget_resize_object_set(obj, wd->base);
640 wd->box = evas_object_box_add(e);
641 evas_object_box_layout_set(wd->box, _layout, wd, NULL);
642 elm_widget_sub_object_add(obj, wd->box);
643 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
644 evas_object_show(wd->box);
646 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _object_resize, obj);
649 wd->insert_index = 0;
651 wd->selected = EINA_FALSE;
653 deffont = edje_object_data_get(wd->base, "default_font_size");
654 if (deffont) wd->cur_fontsize = atoi(deffont);
655 else wd->cur_fontsize = 1;
657 maxheight = edje_object_data_get(wd->base, "max_height");
658 if (maxheight) wd->max_height = atoi(maxheight);
659 else wd->max_height = 1;
661 wpad = edje_object_data_get(wd->base, "w_pad");
662 if (wpad) wd->w_pad = atoi(wpad);
665 hpad = edje_object_data_get(wd->base, "h_pad");
666 if (hpad) wd->h_pad = atoi(hpad);
672 EAPI Elm_Segment_Item *
673 elm_segment_control_item_add(Evas_Object *obj, Evas_Object *icon, const char *label, Eina_Bool animate)
675 Elm_Segment_Item *it;
676 Widget_Data *wd = elm_widget_data_get(obj);
679 it = _item_new(obj, label, icon);
682 wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
683 wd->id = eina_list_count(wd->seg_ctrl);
685 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
686 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
687 evas_object_event_callback_add(it->base, EVAS_CALLBACK_RESIZE, _object_item_resize, it);
688 wd->insert_index = 0;
690 _refresh_segment_ids(obj);
692 if(animate && it->segment_id && wd->ani_it == NULL)
694 evas_object_resize(it->base, 1, wd->height);
696 wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
699 _state_value_set(obj);
700 evas_object_show( it->base);
702 evas_object_box_append(wd->box, it->base);
703 evas_object_smart_calculate(wd->box);
709 * Add a new segment item to segmentcontrol
710 * @param obj The SegmentControl object
711 * @param icon The icon object for added segment item
712 * @param label The label for added segment item
713 * @param animate If 1 the action be animated with sliding effects default 0.
714 * @return The new segment item or NULL if it cannot be created
716 * @ingroup SegmentControl SegmentControl
718 EAPI Elm_Segment_Item *
719 elm_segment_control_add_segment(Evas_Object *obj, Evas_Object *icon, const char *label, Eina_Bool animate)
721 Elm_Segment_Item * it;
722 it = elm_segment_control_item_add(obj, icon, label, animate);
727 EAPI Elm_Segment_Item *
728 elm_segment_control_item_insert_at(Evas_Object *obj, Evas_Object *icon, const char *label, unsigned int index, Eina_Bool animate)
730 Elm_Segment_Item *it, *it_rel;
731 Widget_Data *wd = elm_widget_data_get(obj);
734 it = _item_new(obj, label, icon);
735 it_rel = _item_find(obj, index);
738 wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
742 if (!it) return NULL;
743 wd->seg_ctrl = eina_list_prepend_relative(wd->seg_ctrl, it, it_rel);
745 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
746 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
747 evas_object_event_callback_add(it->base, EVAS_CALLBACK_RESIZE, _object_item_resize, it);
748 wd->insert_index = index;
749 wd->id = eina_list_count(wd->seg_ctrl);
750 _refresh_segment_ids(obj);
753 if(animate && it->segment_id && wd->ani_it == NULL)
756 evas_object_resize(it->base, 1, wd->height);
757 wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
760 _state_value_set(obj);
762 evas_object_show( it->base);
764 if(index >= wd->id-1)
766 evas_object_box_append(wd->box, it->base);
770 evas_object_box_insert_at(wd->box, it->base, index);
773 evas_object_smart_calculate(wd->box);
778 * Insert a new segment item to segmentcontrol
779 * @param obj The SegmentControl object
780 * @param icon The icon object for added segment item
781 * @param label The label for added segment item
782 * @param index The position at which segment item to be inserted
783 * @param animate If 1 the action be animated with sliding effects default 0.
784 * @return The new segment item or NULL if it cannot be created
786 * @ingroup SegmentControl SegmentControl
789 elm_segment_control_insert_segment_at(Evas_Object *obj, Evas_Object *icon, const char *label, unsigned int index, Eina_Bool animate)
791 Elm_Segment_Item *it;
792 it = elm_segment_control_item_insert_at(obj, icon, label, index, animate);
798 elm_segment_control_item_del(Evas_Object *obj, Elm_Segment_Item *item, Eina_Bool animate)
800 Elm_Segment_Item *it;
801 Widget_Data *wd = elm_widget_data_get(obj);
805 // it = _item_search(obj, item);
809 wd->del_index = it->segment_id;
810 if(animate && it->segment_id && wd->ani_it == NULL)
812 it->delete_me = EINA_TRUE;
814 wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
818 evas_object_box_remove(wd->box, it->base);
819 evas_object_smart_calculate(wd->box);
822 _refresh_segment_ids(obj);
823 _state_value_set(obj);
826 wd->id = eina_list_count(wd->seg_ctrl);
831 * Delete a segment item to segmentcontrol
832 * @param obj The SegmentControl object
833 * @param index The position at which segment item to be deleted
834 * @param animate If 1 the action be animated with sliding effects default 0.
836 * @ingroup SegmentControl SegmentControl
839 elm_segment_control_delete_segment(Evas_Object *obj, Elm_Segment_Item *item, Eina_Bool animate)
841 elm_segment_control_item_del(obj, item, animate);
847 elm_segment_control_item_del_at(Evas_Object *obj, unsigned int index, Eina_Bool animate)
849 Elm_Segment_Item *it;
850 Widget_Data *wd = elm_widget_data_get(obj);
853 it = _item_find(obj, index);
857 wd->del_index = index;
858 if(animate && it->segment_id)
860 if(wd->ani_it == NULL)
863 it->delete_me = EINA_TRUE;
864 wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
869 evas_object_box_remove(wd->box, it->base);
870 evas_object_smart_calculate(wd->box);
872 _refresh_segment_ids(obj);
873 _state_value_set(obj);
876 wd->id = eina_list_count(wd->seg_ctrl);
881 * Delete a segment item of given index to segmentcontrol
882 * @param obj The SegmentControl object
883 * @param index The position at which segment item to be deleted
884 * @param animate If 1 the action be animated with sliding effects default 0.
886 * @ingroup SegmentControl SegmentControl
889 elm_segment_control_delete_segment_at(Evas_Object *obj, unsigned int index, Eina_Bool animate)
891 elm_segment_control_item_del_at( obj, index, animate);
898 elm_segment_control_item_label_get(Evas_Object *obj, unsigned int index)
900 Elm_Segment_Item *it_rel;
901 Widget_Data *wd = elm_widget_data_get(obj);
904 it_rel = _item_find(obj, index);
906 if(it_rel) return it_rel->label;
912 * Get the label of a segment item of segmentcontrol
913 * @param obj The SegmentControl object
914 * @param index The index of the segment item
915 * @return The label of the segment item
917 * @ingroup SegmentControl SegmentControl
920 elm_segment_control_get_segment_label_at(Evas_Object *obj, unsigned int index)
923 label = elm_segment_control_item_label_get( obj, index);
929 elm_segment_control_item_icon_get(Evas_Object *obj, unsigned int index)
931 Elm_Segment_Item *seg_rel;
932 Widget_Data *wd = elm_widget_data_get(obj);
935 seg_rel = _item_find(obj, index);
937 if(seg_rel) return seg_rel->icon;
943 * Get the icon of a segment item of segmentcontrol
944 * @param obj The SegmentControl object
945 * @param index The index of the segment item
946 * @return The icon object or NULL if it is not found.
948 * @ingroup SegmentControl SegmentControl
951 elm_segment_control_get_segment_icon_at(Evas_Object *obj, unsigned int index)
954 icon = elm_segment_control_item_icon_get( obj, index);
959 EAPI Elm_Segment_Item *
960 elm_segment_control_item_selected_get(const Evas_Object *obj)
962 Elm_Segment_Item *it;
964 Widget_Data *wd = elm_widget_data_get(obj);
965 if(!wd || !wd->seg_ctrl) return NULL;
967 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
969 if(it->segment_id == wd->cur_seg_id)
976 * Get the currently selected segment item of segmentcontrol
977 * @param obj The SegmentControl object
978 * @return The selected Segment item
980 * @ingroup SegmentControl SegmentControl
982 EAPI Elm_Segment_Item *
983 elm_segment_control_selected_segment_get(const Evas_Object *obj, int *value)
985 Elm_Segment_Item *it;
986 it = elm_segment_control_item_selected_get( obj);
987 *value = it->segment_id;
994 elm_segment_control_item_count_get(Evas_Object *obj)
996 Widget_Data *wd = elm_widget_data_get(obj);
1003 * Get the count of segments of segmentcontrol
1004 * @param obj The SegmentControl object
1005 * @return The count of Segment items
1007 * @ingroup SegmentControl SegmentControl
1010 elm_segment_control_get_segment_count(Evas_Object *obj)
1013 id = elm_segment_control_item_count_get( obj);
1019 * Get the base object of segment item in segmentcontrol
1020 * @param obj The Segment item
1021 * @return obj The base object of the segment item
1023 * @ingroup SegmentControl SegmentControl
1026 elm_segment_control_item_object_get(Elm_Segment_Item *it)
1028 if (!it) return NULL;
1034 * Select/unselect a particular segment item of segmentcontrol
1035 * @param item The Segment item that is to be selected or unselected.
1036 * @param select If 1 the segment item is selected and if 0 it will be unselected.
1038 * @ingroup SegmentControl SegmentControl
1041 elm_segment_control_item_selected_set( Elm_Segment_Item *item, Eina_Bool select)
1044 Widget_Data *wd = elm_widget_data_get(item->obj);
1049 if(item->segment_id == wd->cur_seg_id) return;
1050 wd->selected = EINA_TRUE;
1053 evas_object_del((Evas_Object *)wd->data);
1059 else if(item->segment_id == wd->cur_seg_id)
1061 wd->selected = EINA_FALSE;
1062 wd->cur_seg_id = -1;
1063 _signal_segment_off(item);
1071 * Get a particular indexed segment item of segmentcontrol
1072 * @param obj The Segment control object.
1073 * @param index The index of the segment item.
1074 * @return The corresponding Segment item.
1076 * @ingroup SegmentControl SegmentControl
1078 EAPI Elm_Segment_Item *
1079 elm_segment_control_item_get_at(Evas_Object *obj, unsigned int index)
1081 Elm_Segment_Item *it;
1082 it = _item_find(obj, index);
1088 * Get the index of a Segment item of Segmentcontrol
1089 * @param item The Segment item.
1090 * @return The corresponding index of the Segment item.
1092 * @ingroup SegmentControl SegmentControl
1095 elm_segment_control_item_index_get(Elm_Segment_Item *item)
1097 if(!item) return -1;
1098 Widget_Data *wd = elm_widget_data_get(item->obj);
1101 return item->segment_id;
1105 * Set The Label widget to a Segment item of Segmentcontrol
1106 * @param item The Segment item.
1107 * @param label The Label.
1108 * @return Evas_Object The Label widget.
1110 * @ingroup SegmentControl SegmentControl
1113 elm_segment_control_item_label_object_set(Elm_Segment_Item *item, char *label)
1115 if(!item) return NULL;
1116 Widget_Data *wd = elm_widget_data_get(item->obj);
1117 if(!wd) return NULL;
1118 if(!label) return NULL;
1120 item->label_wd = elm_label_add(item->obj);
1121 elm_label_label_set(item->label_wd, label);
1122 elm_label_text_align_set(item->label_wd, "middle");
1123 elm_label_ellipsis_set(item->label_wd, 1);
1124 elm_label_line_wrap_set(item->label_wd, 1);
1125 eina_stringshare_replace(&item->label, label);
1127 return item->label_wd;