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;
24 Elm_Segment_Item *ani_it;
27 unsigned int insert_index;
28 unsigned int del_index;
29 unsigned int cur_seg_id;
31 Eina_Bool selected : 1;
34 struct _Elm_Segment_Item
40 Evas_Object *label_wd;
41 Eina_Bool delete_me : 1;
45 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
46 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _signal_segment_on(void *data);
48 static void _signal_segment_off(void *data);
49 static void _theme_hook(Evas_Object *obj);
50 static void _item_free(Evas_Object *obj, Elm_Segment_Item *it);
51 static void _del_hook(Evas_Object *obj);
52 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
53 static void _segment_resizing(void *data);
54 static void _object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
55 static void _update_list(Evas_Object *obj);
56 static void _refresh_segment_ids(Evas_Object *obj);
57 static void _state_value_set(Evas_Object *obj);
59 static Elm_Segment_Item* _item_new(Evas_Object *obj, const char *label, Evas_Object *icon);
60 static Elm_Segment_Item *_item_find(Evas_Object *obj, unsigned int index);
62 static int * _animator_animate_add_cb(Evas_Object *obj);
63 static int * _animator_animate_del_cb(Evas_Object *obj);
66 _on_focus_hook(void *data, Evas_Object *obj)
68 Widget_Data *wd = elm_widget_data_get(obj);
71 if (elm_widget_focus_get(obj))
72 evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 1);
74 evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 0);
78 _signal_segment_off(void *data)
80 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
81 Widget_Data *wd = elm_widget_data_get(item->obj);
84 edje_object_signal_emit(item->base, "elm,action,unfocus", "elm");
85 edje_object_signal_emit(item->base, "elm,state,segment,off", "elm");
88 edje_object_signal_emit(item->base, "elm,state,text,visible", "elm");
92 elm_label_text_color_set(item->label_wd, 0xff,0xff, 0xff, 0xff);
99 _signal_segment_on(void *data)
101 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
102 Elm_Segment_Item *it;
105 Widget_Data *wd = elm_widget_data_get(item->obj);
108 wd->selected = EINA_TRUE;
110 edje_object_signal_emit(item->base, "elm,state,segment,on", "elm");
112 edje_object_signal_emit(item->base, "elm,state,text,change", "elm");
114 if (item->segment_id == wd->cur_seg_id) return;
116 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
118 if (it->segment_id == wd->cur_seg_id)
120 _signal_segment_off (it);
124 wd->cur_seg_id = item->segment_id;
125 evas_object_smart_callback_call(item->obj, "changed", (void*)wd->cur_seg_id);
131 _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
133 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
134 Widget_Data *wd = elm_widget_data_get(item->obj);
136 Evas_Coord wrap_width = 0, wrap_height = 0;
138 if (item->segment_id == wd->cur_seg_id)
140 wd->selected = EINA_TRUE;
143 _signal_segment_on(item);
146 wrap_width = elm_label_wrap_width_get(item->label_wd);
147 wrap_height = elm_label_wrap_height_get(item->label_wd);
148 elm_label_wrap_width_set(item->label_wd, wrap_width);
149 elm_label_wrap_height_set(item->label_wd, wrap_height);
150 elm_label_text_color_set(item->label_wd, 0x00,0x00, 0x00, 0xff);
153 wd->selected = EINA_FALSE;
159 _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
161 Elm_Segment_Item *item = (Elm_Segment_Item *) data;
162 Widget_Data *wd = elm_widget_data_get(item->obj);
166 edje_object_signal_emit(item->base, "elm,action,focus", "elm");
171 _theme_hook(Evas_Object *obj)
173 _elm_theme_object_set(obj, obj, "segmented-control", "base", elm_widget_style_get(obj));
179 _item_free(Evas_Object *obj, Elm_Segment_Item *it)
181 Widget_Data *wd = elm_widget_data_get(obj);
185 wd->seg_ctrl = eina_list_remove(wd->seg_ctrl, it);
187 if(it->icon) evas_object_del(it->icon);
190 evas_object_del(it->label_wd);
192 if (edje_object_part_swallow_get(it->base, "elm.swallow.label.content") == NULL)
194 edje_object_part_unswallow(it->base, it->label_wd);
197 if(it->base) evas_object_del(it->base);
198 if(it->label) eina_stringshare_del(it->label);
207 _del_hook(Evas_Object *obj)
209 Widget_Data *wd = elm_widget_data_get(obj);
210 Elm_Segment_Item *it;
211 Eina_List *l, *clear = NULL;
213 EINA_LIST_FOREACH(wd->seg_ctrl, l, it) clear = eina_list_append(clear, it);
214 EINA_LIST_FREE(clear, it) _item_free(obj, it);
224 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
226 Widget_Data *wd = data;
228 _els_box_layout(o, priv, 1, 0); /* making box layout non homogenous */
234 _segment_resizing(void *data)
236 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
238 Evas_Coord w = 0, h = 0;
240 evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
241 wd->item_width = wd->width = w;
244 _state_value_set((Evas_Object *)data);
248 _object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
252 wd = elm_widget_data_get((Evas_Object *)data);
255 ecore_job_add(_segment_resizing, (Evas_Object *)data);
259 _segment_item_resizing(void *data)
262 Elm_Segment_Item *it = (Elm_Segment_Item *)data;
263 wd = elm_widget_data_get(it->obj);
266 Evas_Coord w = 0, h = 0, vw, vh;
267 const char *minfont, *deffont, *maxfont;
268 int minfontsize, maxfontsize, cur_fontsize = 0;
270 minfont = edje_object_data_get(wd->base, "min_font_size");
271 if (minfont) minfontsize = atoi(minfont);
272 else minfontsize = 1;
274 maxfont = edje_object_data_get(wd->base, "max_font_size");
275 if (maxfont) maxfontsize = atoi(maxfont);
276 else maxfontsize = 1;
278 deffont = edje_object_data_get(wd->base, "default_font_size");
279 if (deffont) cur_fontsize = atoi(deffont);
280 else cur_fontsize = 1;
282 _update_list(it->obj);
283 evas_object_geometry_get(it->base, NULL, NULL, &w, &h);
284 evas_object_geometry_get(it->label_wd, NULL, NULL, &vw, &vh);
288 elm_label_fontsize_set(it->label_wd, cur_fontsize);
289 elm_label_wrap_width_set(it->label_wd, w-4);
290 elm_label_wrap_height_set(it->label_wd, h-6);
291 elm_label_text_color_set(it->label_wd, 0xFF,0xFF, 0xFF, 0xff);
292 if (edje_object_part_swallow_get(it->base, "elm.swallow.label.content") == NULL)
294 edje_object_part_unswallow(it->base, it->label_wd);
296 edje_object_part_swallow(it->base, "elm.swallow.label.content", it->label_wd);
297 edje_object_signal_emit(it->base, "elm,state,label,visible", "elm");
302 _object_item_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
304 ecore_job_add(_segment_item_resizing, (Evas_Object *)data);
307 static Elm_Segment_Item*
308 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon)
310 Elm_Segment_Item *it;
312 Widget_Data *wd = elm_widget_data_get(obj);
313 if (!wd) return NULL;
315 it = calloc(1, sizeof( Elm_Segment_Item));
316 if (!it) return NULL;
318 if(obj) it->obj = obj;
319 it->delete_me = EINA_FALSE;
320 it->segment_id = wd->id;
323 it->base = edje_object_add(evas_object_evas_get(obj));
324 _elm_theme_object_set(obj, it->base, "segment", "base", elm_object_style_get(it->base));
326 if (it->label) eina_stringshare_del(it->label);
329 it->label = eina_stringshare_add(label);
335 if ((it->icon != icon) && (it->icon))
336 elm_widget_sub_object_del(obj, it->icon);
340 elm_widget_sub_object_add(obj, icon);
341 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
342 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
343 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
345 evas_object_size_hint_weight_set(it->base, 1.0, -1.0);
346 evas_object_size_hint_align_set(it->base, 1.0, -1.0);
347 evas_object_size_hint_min_set(it->base, -1, -1);
348 evas_object_size_hint_max_set(it->base, maxw, maxh);
351 edje_object_size_min_restricted_calc(obj, &mw, &mh, 0, 0);
352 evas_object_size_hint_weight_set(obj, 1.0, 1.0);
353 evas_object_size_hint_align_set(obj, -1.0, -1.0);
360 _update_list(Evas_Object *obj)
362 Elm_Segment_Item *it;
366 Widget_Data *wd = elm_widget_data_get(obj);
369 wd->count = eina_list_count(wd->seg_ctrl);
372 it = _item_find(obj, 0);
373 _elm_theme_object_set(obj, it->base, "segment", "base", "single");
\r
374 edje_object_signal_emit(it->base, "elm,state,segment,on", "elm");
377 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
378 edje_object_signal_emit(it->base, "elm,state,text,change", "elm");
380 edje_object_message_signal_process(it->base);
383 edje_object_part_text_set(it->base, "elm.text", it->label);
385 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
386 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
391 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
395 _elm_theme_object_set(obj, it->base, "segment", "base", "first");
397 else if(i==wd->count-1)
399 _elm_theme_object_set(obj, it->base, "segment", "base", "last");
403 _elm_theme_object_set(obj, it->base, "segment", "base", "default");
409 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
411 edje_object_message_signal_process(it->base);
414 edje_object_part_text_set(it->base, "elm.text", it->label);
416 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
417 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
425 _refresh_segment_ids(Evas_Object *obj)
427 Elm_Segment_Item *it;
430 Widget_Data *wd = elm_widget_data_get(obj);
433 if (wd->insert_index && wd->cur_seg_id >= wd->insert_index)
436 wd->insert_index = 0;
440 if (wd->cur_seg_id >= wd->del_index)
445 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
453 _state_value_set(Evas_Object *obj)
455 Elm_Segment_Item *it;
457 Evas_Coord mw, mh, x, y, w, h, xx = 0, yy;
461 Widget_Data *wd = elm_widget_data_get(obj);
464 count = eina_list_count(wd->seg_ctrl);
466 wd->item_width = wd->width/count;
469 evas_object_geometry_get(wd->ani_it->base, &x, &y, &w1, NULL);
470 if (wd->ani_it->delete_me)
472 w1-=(wd->item_width/5);
477 w1+=(wd->item_width/5);
478 if( w1 > wd->item_width )
481 w2 = (wd->width-w1)/(count -1);
486 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
488 edje_object_size_min_restricted_calc(it->base, &mw, &mh, 0, 0);
489 evas_object_size_hint_weight_set(it->base, 1.0, 1.0);
490 evas_object_size_hint_align_set(it->base, -1.0, -1.0);
491 evas_object_geometry_get(wd->base, &x, &y, &w, &h);
498 if(wd->ani_it && it == wd->ani_it)
500 evas_object_resize(it->base, w1, wd->height);
501 evas_object_size_hint_min_set(it->base, w1, wd->height);
502 evas_object_size_hint_max_set(it->base, w1, wd->height);
504 evas_object_move(it->base, xx, yy);
510 evas_object_resize(it->base, w2, wd->height);
511 evas_object_size_hint_min_set(it->base, w2, wd->height);
512 evas_object_size_hint_max_set(it->base, w2, wd->height);
514 evas_object_move(it->base, xx, yy);
526 _animator_animate_add_cb(Evas_Object *obj)
529 Widget_Data *wd = elm_widget_data_get(obj);
532 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
533 if( w < wd->item_width )
535 _state_value_set(obj);
536 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
537 return ECORE_CALLBACK_RENEW;
541 ecore_animator_del(wd->ani);
544 return ECORE_CALLBACK_CANCEL;
550 _animator_animate_del_cb(Evas_Object *obj)
553 Widget_Data *wd = elm_widget_data_get(obj);
556 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
559 _state_value_set(obj);
560 evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
561 return ECORE_CALLBACK_RENEW;
565 _item_free(obj, wd->ani_it );
566 _refresh_segment_ids(obj);
567 ecore_animator_del(wd->ani);
571 wd->id = eina_list_count(wd->seg_ctrl);
572 return ECORE_CALLBACK_CANCEL;
576 static Elm_Segment_Item *
577 _item_find(Evas_Object *obj, unsigned int index)
579 Elm_Segment_Item *it;
582 Widget_Data *wd = elm_widget_data_get(obj);
583 if (!wd) return NULL;
585 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
587 if (i == index) return it;
594 static Elm_Segment_Item *
595 _item_search(Evas_Object *obj, Elm_Segment_Item *item)
597 Elm_Segment_Item *it;
599 Widget_Data *wd = elm_widget_data_get(obj);
603 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
614 * Add a new segmentcontrol to the parent
615 * @param parent The parent object
616 * @return The new object or NULL if it cannot be created
618 * @ingroup SegmentControl SegmentControl
621 elm_segment_control_add(Evas_Object *parent)
627 wd = ELM_NEW(Widget_Data);
628 e = evas_object_evas_get(parent);
630 obj = elm_widget_add(e);
631 elm_widget_type_set(obj, "segmented-control");
632 elm_widget_sub_object_add(parent, obj);
633 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
634 elm_widget_data_set(obj, wd);
635 elm_widget_del_hook_set(obj, _del_hook);
636 elm_widget_theme_hook_set(obj, _theme_hook);
638 wd->base = edje_object_add(e);
639 _elm_theme_object_set(obj, wd->base, "segmented-control", "base", "default");
640 elm_widget_resize_object_set(obj, wd->base);
641 wd->box = evas_object_box_add(e);
642 evas_object_box_layout_set(wd->box, _layout, wd, NULL);
643 elm_widget_sub_object_add(obj, wd->box);
644 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
645 evas_object_show(wd->box);
647 wd->box = elm_layout_add(e);
648 elm_layout_theme_set(wd->box, "segmented-control", "base", "default");
649 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
650 evas_object_show(wd->box);
653 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _object_resize, obj);
656 wd->insert_index = 0;
658 wd->selected = EINA_FALSE;
664 * Add a new segment item to segmentcontrol
665 * @param obj The SegmentControl object
666 * @param icon The icon object for added segment item
667 * @param label The label for added segment item
668 * @param animate If 1 the action be animated with sliding effects default 0.
669 * @return The new segment item or NULL if it cannot be created
671 * @ingroup SegmentControl SegmentControl
674 EAPI Elm_Segment_Item *
675 elm_segment_control_item_add(Evas_Object *obj, Evas_Object *icon, const char *label, Eina_Bool animate)
677 Elm_Segment_Item *it;
678 Widget_Data *wd = elm_widget_data_get(obj);
681 it = _item_new(obj, label, icon);
684 wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
685 wd->id = eina_list_count(wd->seg_ctrl);
687 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
688 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
689 evas_object_event_callback_add(it->base, EVAS_CALLBACK_RESIZE, _object_item_resize, it);
690 wd->insert_index = 0;
692 _refresh_segment_ids(obj);
694 if(animate && it->segment_id && wd->ani_it == NULL)
696 evas_object_resize(it->base, 1, wd->height);
698 wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
701 _state_value_set(obj);
702 evas_object_show( it->base);
704 evas_object_box_append(wd->box, it->base);
706 elm_layout_content_set(wd->box, "elm.swallow.content", it->base);
708 evas_object_smart_calculate(wd->box);
714 * Add a new segment item to segmentcontrol
715 * @param obj The SegmentControl object
716 * @param icon The icon object for added segment item
717 * @param label The label for added segment item
718 * @param animate If 1 the action be animated with sliding effects default 0.
719 * @return The new segment item or NULL if it cannot be created
721 * @ingroup SegmentControl SegmentControl
724 EAPI Elm_Segment_Item *
725 elm_segment_control_add_segment(Evas_Object *obj, Evas_Object *icon, const char *label, Eina_Bool animate)
727 EAPI Elm_Segment_Item * it;
728 it = elm_segment_control_item_add(obj, icon, label, animate);
734 * Insert a new segment item to segmentcontrol
735 * @param obj The SegmentControl object
736 * @param icon The icon object for added segment item
737 * @param label The label for added segment item
738 * @param index The position at which segment item to be inserted
739 * @param animate If 1 the action be animated with sliding effects default 0.
740 * @return The new segment item or NULL if it cannot be created
742 * @ingroup SegmentControl SegmentControl
745 EAPI Elm_Segment_Item *
746 elm_segment_control_item_insert_at(Evas_Object *obj, Evas_Object *icon, const char *label, unsigned int index, Eina_Bool animate)
748 Elm_Segment_Item *it, *it_rel;
749 Widget_Data *wd = elm_widget_data_get(obj);
752 it = _item_new(obj, label, icon);
753 it_rel = _item_find(obj, index);
756 wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
760 if (!it) return NULL;
761 wd->seg_ctrl = eina_list_prepend_relative(wd->seg_ctrl, it, it_rel);
763 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
764 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
765 evas_object_event_callback_add(it->base, EVAS_CALLBACK_RESIZE, _object_item_resize, it);
766 wd->insert_index = index;
767 wd->id = eina_list_count(wd->seg_ctrl);
768 _refresh_segment_ids(obj);
771 if(animate && it->segment_id && wd->ani_it == NULL)
774 evas_object_resize(it->base, 1, wd->height);
775 wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
778 _state_value_set(obj);
780 evas_object_show( it->base);
782 if(index >= wd->id-1)
784 evas_object_box_append(wd->box, it->base);
788 evas_object_box_insert_at(wd->box, it->base, index);
791 evas_object_smart_calculate(wd->box);
797 * Insert a new segment item to segmentcontrol
798 * @param obj The SegmentControl object
799 * @param icon The icon object for added segment item
800 * @param label The label for added segment item
801 * @param index The position at which segment item to be inserted
802 * @param animate If 1 the action be animated with sliding effects default 0.
804 * @ingroup SegmentControl SegmentControl
808 elm_segment_control_insert_segment_at(Evas_Object *obj, Evas_Object *icon, const char *label, unsigned int index, Eina_Bool animate)
810 Elm_Segment_Item *it;
811 it = elm_segment_control_item_insert_at(obj, icon, label, index, animate);
817 * Delete a segment item to segmentcontrol
818 * @param obj The SegmentControl object
819 * @param item The Segment item to be deleted
820 * @param animate If 1 the action be animated with sliding effects default 0.
822 * @ingroup SegmentControl SegmentControl
825 elm_segment_control_item_del(Evas_Object *obj, Elm_Segment_Item *item, Eina_Bool animate)
827 Elm_Segment_Item *it;
828 Widget_Data *wd = elm_widget_data_get(obj);
833 it = _item_search(obj, item);
836 wd->del_index = it->segment_id;
837 if(animate && it->segment_id && wd->ani_it == NULL)
839 it->delete_me = EINA_TRUE;
841 wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
845 evas_object_box_remove(wd->box, it->base);
846 evas_object_smart_calculate(wd->box);
848 elm_layout_content_unset(wd->box, "elm.swallow.content");
851 _refresh_segment_ids(obj);
852 _state_value_set(obj);
855 wd->id = eina_list_count(wd->seg_ctrl);
860 * Delete a segment item to segmentcontrol
861 * @param obj The SegmentControl object
862 * @param item The Segment item to be deleted
863 * @param animate If 1 the action be animated with sliding effects default 0.
865 * @ingroup SegmentControl SegmentControl
869 elm_segment_control_delete_segment(Evas_Object *obj, Elm_Segment_Item *item, Eina_Bool animate)
871 elm_segment_control_item_del(obj, item, animate);
877 * Delete a segment item to segmentcontrol
878 * @param obj The SegmentControl object
879 * @param index The position at which segment item to be deleted
880 * @param animate If 1 the action be animated with sliding effects default 0.
882 * @ingroup SegmentControl SegmentControl
886 elm_segment_control_item_del_at(Evas_Object *obj, unsigned int index, Eina_Bool animate)
888 Elm_Segment_Item *it;
889 Widget_Data *wd = elm_widget_data_get(obj);
892 it = _item_find(obj, index);
896 wd->del_index = index;
897 if(animate && it->segment_id)
899 if(wd->ani_it == NULL)
902 it->delete_me = EINA_TRUE;
903 wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
908 evas_object_box_remove(wd->box, it->base);
909 evas_object_smart_calculate(wd->box);
911 _refresh_segment_ids(obj);
912 _state_value_set(obj);
915 wd->id = eina_list_count(wd->seg_ctrl);
920 * Delete a segment item to segmentcontrol
921 * @param obj The SegmentControl object
922 * @param index The position at which segment item to be deleted
923 * @param animate If 1 the action be animated with sliding effects default 0.
925 * @ingroup SegmentControl SegmentControl
929 elm_segment_control_delete_segment_at(Evas_Object *obj, unsigned int index, Eina_Bool animate)
931 elm_segment_control_item_del_at( obj, index, animate);
937 * Get the label of a segment item of segmentcontrol
938 * @param obj The SegmentControl object
939 * @param index The index of the segment item
940 * @return The label of the segment item
942 * @ingroup SegmentControl SegmentControl
946 elm_segment_control_item_label_get(Evas_Object *obj, unsigned int index)
948 Elm_Segment_Item *it_rel;
949 Widget_Data *wd = elm_widget_data_get(obj);
952 it_rel = _item_find(obj, index);
954 if(it_rel) return it_rel->label;
960 * Get the label of a segment item of segmentcontrol
961 * @param obj The SegmentControl object
962 * @param index The index of the segment item
963 * @return The label of the segment item
965 * @ingroup SegmentControl SegmentControl
969 elm_segment_control_get_segment_label_at(Evas_Object *obj, unsigned int index)
972 label = elm_segment_control_item_label_get( obj, index);
978 * Get the icon of a segment item of segmentcontrol
979 * @param obj The SegmentControl object
980 * @param index The index of the segment item
981 * @return The icon object or NULL if it is not found.
983 * @ingroup SegmentControl SegmentControl
987 elm_segment_control_item_icon_get(Evas_Object *obj, unsigned int index)
989 Elm_Segment_Item *seg_rel;
990 Widget_Data *wd = elm_widget_data_get(obj);
993 seg_rel = _item_find(obj, index);
995 if(seg_rel) return seg_rel->icon;
1001 * Get the icon of a segment item of segmentcontrol
1002 * @param obj The SegmentControl object
1003 * @param index The index of the segment item
1004 * @return The icon object or NULL if it is not found.
1006 * @ingroup SegmentControl SegmentControl
1010 elm_segment_control_get_segment_icon_at(Evas_Object *obj, unsigned int index)
1013 icon = elm_segment_control_item_icon_get( obj, index);
1019 * Get the currently selected segment item of segmentcontrol
1020 * @param obj The SegmentControl object
1021 * @return The selected Segment item
1023 * @ingroup SegmentControl SegmentControl
1026 EAPI Elm_Segment_Item *
1027 elm_segment_control_item_selected_get(const Evas_Object *obj)
1029 Elm_Segment_Item *it;
1031 Widget_Data *wd = elm_widget_data_get(obj);
1032 if(!wd || !wd->seg_ctrl) return NULL;
1034 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
1036 if(it->segment_id == wd->cur_seg_id)
1043 * Get the currently selected segment item of segmentcontrol
1044 * @param obj The SegmentControl object
1045 * @param value The current segment item id
1046 * @return The selected Segment item
1048 * @ingroup SegmentControl SegmentControl
1051 EAPI Elm_Segment_Item *
1052 elm_segment_control_selected_segment_get(const Evas_Object *obj, int *value)
1054 Elm_Segment_Item *it;
1055 it = elm_segment_control_item_selected_get( obj);
1056 *value = it->segment_id;
1062 * Get the count of segments of segmentcontrol
1063 * @param obj The SegmentControl object
1064 * @return The count of Segment items
1066 * @ingroup SegmentControl SegmentControl
1070 elm_segment_control_item_count_get(Evas_Object *obj)
1072 Widget_Data *wd = elm_widget_data_get(obj);
1079 * Get the count of segments of segmentcontrol
1080 * @param obj The SegmentControl object
1081 * @return The count of Segment items
1083 * @ingroup SegmentControl SegmentControl
1087 elm_segment_control_get_segment_count(Evas_Object *obj)
1090 id = elm_segment_control_item_count_get( obj);
1096 * Get the base object of segment item in segmentcontrol
1097 * @param obj The Segment item
1098 * @return obj The base object of the segment item
1100 * @ingroup SegmentControl SegmentControl
1104 elm_segment_control_item_object_get(Elm_Segment_Item *it)
1106 if (!it) return NULL;
1112 * Select/unselect a particular segment item of segmentcontrol
1113 * @param item The Segment item that is to be selected or unselected.
1114 * @param select If 1 the segment item is selected and if 0 it will be unselected.
1116 * @ingroup SegmentControl SegmentControl
1120 elm_segment_control_item_selected_set( Elm_Segment_Item *item, Eina_Bool select)
1123 Widget_Data *wd = elm_widget_data_get(item->obj);
1128 if(item->segment_id == wd->cur_seg_id) return;
1132 edje_object_signal_emit(item->base, "elm,action,focus", "elm");
1133 edje_object_signal_emit(item->base, "elm,state,text,visible", "elm");
1135 _signal_segment_on(item);
1138 else if(item->segment_id == wd->cur_seg_id)
1140 wd->selected = EINA_FALSE;
1141 wd->cur_seg_id = -1;
1142 _signal_segment_off(item);
1150 * Get a particular indexed segment item of segmentcontrol
1151 * @param obj The Segment control object.
1152 * @param index The index of the segment item.
1153 * @return The corresponding Segment item.
1155 * @ingroup SegmentControl SegmentControl
1158 EAPI Elm_Segment_Item *
1159 elm_segment_control_item_get_at(Evas_Object *obj, unsigned int index)
1161 Elm_Segment_Item *it;
1162 it = _item_find(obj, index);
1168 * Select the index of a Segment item of Segmentcontrol
1169 * @param item The Segment item.
1170 * @return The corresponding index of the Segment item.
1172 * @ingroup SegmentControl SegmentControl
1176 elm_segment_control_item_index_get(Elm_Segment_Item *item)
1179 Widget_Data *wd = elm_widget_data_get(item->obj);
1180 if(!wd) return NULL;
1182 return item->segment_id;
1186 * Set The Label widget to a Segment item of Segmentcontrol
1187 * @param item The Segment item.
1188 * @param label The Label.
1191 * @ingroup SegmentControl SegmentControl
1195 elm_segment_control_label_set(Elm_Segment_Item *item, char *label)
1198 Widget_Data *wd = elm_widget_data_get(item->obj);
1202 item->label_wd = elm_label_add(item->obj);
1203 elm_label_label_set(item->label_wd, label);
1204 elm_label_text_align_set(item->label_wd, "middle");
1205 elm_label_ellipsis_set(item->label_wd, 1);
1206 elm_label_line_wrap_set(item->label_wd, 1);