EFL migration revision 67547
[framework/uifw/elementary.git] / src / lib / elm_segment_control.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Segment_Item Elm_Segment_Item;
6
7 struct _Widget_Data
8 {
9    Evas_Object *obj;
10    Evas_Object *base;
11    Eina_List *seg_items;
12    int item_count;
13    Elm_Segment_Item *selected_item;
14    int item_width;
15 };
16
17 struct _Elm_Segment_Item
18 {
19    ELM_WIDGET_ITEM;
20    Evas_Object *icon;
21    const char *label;
22    int seg_index;
23 };
24
25 static const char *widtype = NULL;
26 static void _sizing_eval(Evas_Object *obj);
27 static void _del_hook(Evas_Object *obj);
28 static void _theme_hook(Evas_Object *obj);
29 static void _disable_hook(Evas_Object *obj);
30 static void _item_free(Elm_Segment_Item *it);
31 static void _segment_off(Elm_Segment_Item *it);
32 static void _segment_on(Elm_Segment_Item *it);
33 static void _position_items(Widget_Data *wd);
34 static void _on_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj
35                             __UNUSED__, void *event_info __UNUSED__);
36 static void _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj
37                       __UNUSED__, void *event_info __UNUSED__);
38 static void _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj
39                         __UNUSED__, void *event_info __UNUSED__);
40 static void _swallow_item_objects(Elm_Segment_Item *it);
41 static void _update_list(Widget_Data *wd);
42 static Elm_Segment_Item * _item_find(const Evas_Object *obj, int index);
43 static Elm_Segment_Item* _item_new(Evas_Object *obj, Evas_Object *icon,
44                                    const char *label);
45
46 static const char SIG_CHANGED[] = "changed";
47
48 static const Evas_Smart_Cb_Description _signals[] = {
49    {SIG_CHANGED, ""},
50    {NULL, NULL}
51 };
52
53 static void
54 _sizing_eval(Evas_Object *obj)
55 {
56    Widget_Data *wd;
57    Evas_Coord minw = -1, minh = -1;
58    Evas_Coord w, h;
59
60    wd = elm_widget_data_get(obj);
61    if (!wd) return;
62
63    elm_coords_finger_size_adjust(wd->item_count, &minw, 1, &minh);
64    edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
65    elm_coords_finger_size_adjust(wd->item_count, &minw, 1, &minh);
66
67    evas_object_size_hint_min_get(obj, &w, &h);
68    if (w > minw) minw = w;
69    if (h > minh) minh = h;
70    evas_object_size_hint_min_set(obj, minw, minh);
71 }
72
73 static void
74 _del_hook(Evas_Object *obj)
75 {
76    Elm_Segment_Item *it;
77    Widget_Data *wd;
78
79    wd = elm_widget_data_get(obj);
80    if (!wd) return;
81
82    EINA_LIST_FREE(wd->seg_items, it)
83      {
84         _item_free(it);
85         elm_widget_item_free(it);
86      }
87
88    free(wd);
89 }
90
91 static void
92 _theme_hook(Evas_Object *obj)
93 {
94    Eina_List *l;
95    Eina_Bool rtl;
96    Elm_Segment_Item *it;
97    Widget_Data *wd;
98
99    wd = elm_widget_data_get(obj);
100    if (!wd) return;
101
102    _elm_widget_mirrored_reload(obj);
103    rtl = elm_widget_mirrored_get(obj);
104    edje_object_mirrored_set(wd->base, rtl);
105
106    _elm_theme_object_set(obj, wd->base, "segment_control", "base",
107                          elm_widget_style_get(obj));
108    edje_object_scale_set(wd->base, elm_widget_scale_get(wd->base)
109                          *_elm_config->scale);
110
111    EINA_LIST_FOREACH(wd->seg_items, l, it)
112      {
113         _elm_theme_object_set(obj, VIEW(it), "segment_control",
114                               "item", elm_widget_style_get(obj));
115         edje_object_scale_set(VIEW(it), elm_widget_scale_get(VIEW(it))
116                               *_elm_config->scale);
117         edje_object_mirrored_set(VIEW(it), rtl);
118      }
119
120    _update_list(wd);
121 }
122
123 static void
124 _disable_hook(Evas_Object *obj)
125 {
126    Widget_Data *wd;
127
128    wd = elm_widget_data_get(obj);
129    if (!wd) return;
130    _update_list(wd);
131 }
132
133 // TODO:  Elm_widget elm_widget_focus_list_next_get  supports only Elm_widget list,
134 // Not the Elm_Widget_item. Focus switching with in widget not supported until
135 // it is supported in elm_widget
136 #if 0
137 static void *
138 _elm_list_data_get(const Eina_List *list)
139 {
140    Elm_Segment_Item *it = eina_list_data_get(list);
141
142    if (it) return NULL;
143
144    edje_object_signal_emit(VIEW(it), "elm,state,segment,selected", "elm");
145    return VIEW(it);
146 }
147
148 static Eina_Bool
149 _focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir,
150                  Evas_Object **next)
151 {
152    static int count=0;
153    Widget_Data *;
154    const Eina_List *items;
155    void *(*list_data_get) (const Eina_List *list);
156
157    wd = elm_widget_data_get(obj);
158    if ((!wd)) return EINA_FALSE;
159
160    /* Focus chain */
161    /* TODO: Change this to use other chain */
162    if ((items = elm_widget_focus_custom_chain_get(obj)))
163      list_data_get = eina_list_data_get;
164    else
165      {
166         items = wd->seg_items;
167         list_data_get = _elm_list_data_get;
168         if (!items) return EINA_FALSE;
169      }
170    return elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
171 }
172 #endif
173
174 static void
175 _item_free(Elm_Segment_Item *it)
176 {
177    Widget_Data *wd;
178
179    if (!it) return;
180
181    wd = elm_widget_item_data_get(it);
182    if (!wd) return;
183
184    if (wd->selected_item == it) wd->selected_item = NULL;
185    if (wd->seg_items) wd->seg_items = eina_list_remove(wd->seg_items, it);
186
187    if (it->icon) evas_object_del(it->icon);
188    if (it->label) eina_stringshare_del(it->label);
189 }
190
191 static void
192 _segment_off(Elm_Segment_Item *it)
193 {
194    Widget_Data *wd;
195
196    if (!it) return;
197
198    wd = elm_widget_item_data_get(it);
199    if (!wd) return;
200
201    edje_object_signal_emit(VIEW(it), "elm,state,segment,normal", "elm");
202
203    if (wd->selected_item == it) wd->selected_item = NULL;
204 }
205
206 static void
207 _segment_on(Elm_Segment_Item *it)
208 {
209    Widget_Data *wd;
210
211    if (!it) return;
212
213    wd = elm_widget_item_data_get(it);
214    if (!wd) return;
215    if (it == wd->selected_item) return;
216
217    if (wd->selected_item) _segment_off(wd->selected_item);
218
219    edje_object_signal_emit(VIEW(it), "elm,state,segment,selected", "elm");
220
221    wd->selected_item = it;
222    evas_object_smart_callback_call(wd->obj, SIG_CHANGED, it);
223 }
224
225 static void
226 _position_items(Widget_Data *wd)
227 {
228    Eina_List *l;
229    Elm_Segment_Item *it;
230    Eina_Bool rtl;
231    int bx, by, bw, bh, pos;
232
233    wd->item_count = eina_list_count(wd->seg_items);
234    if (wd->item_count <= 0) return;
235
236    evas_object_geometry_get(wd->base, &bx, &by, &bw, &bh);
237    wd->item_width = bw / wd->item_count;
238    rtl = elm_widget_mirrored_get(wd->obj);
239
240    if (rtl)
241      pos = bx + bw - wd->item_width;
242    else
243      pos = bx;
244
245    EINA_LIST_FOREACH(wd->seg_items, l, it)
246      {
247         evas_object_move(VIEW(it), pos, by);
248         evas_object_resize(VIEW(it), wd->item_width, bh);
249         if (rtl)
250           pos -= wd->item_width;
251         else
252           pos += wd->item_width;
253      }
254    _sizing_eval(wd->obj);
255 }
256
257 static void
258 _on_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
259                 void *event_info __UNUSED__)
260 {
261    Widget_Data *wd;
262
263    wd = elm_widget_data_get(data);
264    if (!wd) return;
265
266    _position_items(wd);
267
268 }
269
270 static void
271 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
272           void *event_info)
273 {
274    Widget_Data *wd;
275    Elm_Segment_Item *it;
276    Evas_Event_Mouse_Up *ev;
277    Evas_Coord x, y, w, h;
278
279    it = data;
280    if (!it) return;
281
282    wd = elm_widget_item_data_get(it);
283    if (!wd) return;
284
285    if (elm_widget_disabled_get(wd->obj)) return;
286
287    if (it == wd->selected_item) return;
288
289    ev = event_info;
290    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
291
292    if ((ev->canvas.x >= x) && (ev->output.x <= (x + w)) && (ev->canvas.y >= y)
293        && (ev->canvas.y <= (y + h)))
294      _segment_on(it);
295    else
296      edje_object_signal_emit(VIEW(it), "elm,state,segment,normal", "elm");
297 }
298
299 static void
300 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
301             void *event_info __UNUSED__)
302 {
303    Widget_Data *wd;
304    Elm_Segment_Item *it;
305
306    it = data;
307    if (!it) return;
308
309    wd = elm_widget_item_data_get(it);
310    if (!wd) return;
311
312    if (elm_widget_disabled_get(wd->obj)) return;
313
314    if (it == wd->selected_item) return;
315
316    edje_object_signal_emit(VIEW(it), "elm,state,segment,pressed", "elm");
317 }
318
319 static void
320 _swallow_item_objects(Elm_Segment_Item *it)
321 {
322    if (!it) return;
323
324    if (it->icon)
325      {
326         edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
327         edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
328      }
329    else
330      edje_object_signal_emit(VIEW(it), "elm,state,icon,hidden", "elm");
331
332    if (it->label)
333      {
334         edje_object_part_text_set(VIEW(it), "elm.text", it->label);
335         edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
336      }
337    else
338      edje_object_signal_emit(VIEW(it), "elm,state,text,hidden", "elm");
339    edje_object_message_signal_process(VIEW(it));
340 }
341
342 static void
343 _update_list(Widget_Data *wd)
344 {
345    Eina_List *l;
346    Elm_Segment_Item *it;
347    Eina_Bool rtl;
348    int idx = 0;
349
350    _position_items(wd);
351
352    if (wd->item_count == 1)
353      {
354         it = eina_list_nth(wd->seg_items, 0);
355         it->seg_index = 0;
356
357         //Set the segment type
358         edje_object_signal_emit(VIEW(it),
359                                 "elm,type,segment,single", "elm");
360
361         //Set the segment state
362         if (wd->selected_item == it)
363           edje_object_signal_emit(VIEW(it),
364                                   "elm,state,segment,selected", "elm");
365         else
366           edje_object_signal_emit(VIEW(it),
367                                   "elm,state,segment,normal", "elm");
368
369         if (elm_widget_disabled_get(wd->obj))
370           edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
371         else
372           edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
373
374         _swallow_item_objects(it);
375         return;
376      }
377
378    rtl = elm_widget_mirrored_get(wd->obj);
379    EINA_LIST_FOREACH(wd->seg_items, l, it)
380      {
381         it->seg_index = idx;
382
383         //Set the segment type
384         if (idx == 0)
385           {
386              if (rtl)
387                edje_object_signal_emit(VIEW(it),
388                                        "elm,type,segment,right", "elm");
389              else
390                edje_object_signal_emit(VIEW(it),
391                                        "elm,type,segment,left", "elm");
392           }
393         else if (idx == (wd->item_count - 1))
394           {
395              if (rtl)
396                edje_object_signal_emit(VIEW(it),
397                                        "elm,type,segment,left", "elm");
398              else
399                edje_object_signal_emit(VIEW(it),
400                                        "elm,type,segment,right", "elm");
401           }
402         else
403           edje_object_signal_emit(VIEW(it),
404                                   "elm,type,segment,middle", "elm");
405
406         //Set the segment state
407         if (wd->selected_item == it)
408           edje_object_signal_emit(VIEW(it),
409                                   "elm,state,segment,selected", "elm");
410         else
411           edje_object_signal_emit(VIEW(it),
412                                   "elm,state,segment,normal", "elm");
413
414         if (elm_widget_disabled_get(wd->obj))
415           edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
416         else
417           edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
418
419         _swallow_item_objects(it);
420         idx++;
421      }
422 }
423
424 static Elm_Segment_Item *
425 _item_find(const Evas_Object *obj, int idx)
426 {
427    Widget_Data *wd;
428    Elm_Segment_Item *it;
429
430    wd = elm_widget_data_get(obj);
431    if (!wd) return NULL;
432
433    it = eina_list_nth(wd->seg_items, idx);
434    return it;
435 }
436
437 static void
438 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
439 {
440    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
441    Widget_Data *wd;
442    Elm_Segment_Item *item;
443
444    if (part && strcmp(part, "default")) return;
445
446    item = (Elm_Segment_Item *) it;
447    wd = elm_widget_item_data_get(item);
448    if (!wd) return;
449
450    eina_stringshare_replace(&item->label, label);
451    if (item->label)
452      edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
453    else
454      edje_object_signal_emit(VIEW(item), "elm,state,text,hidden", "elm");
455    edje_object_message_signal_process(VIEW(item));
456    //label can be NULL also.
457    edje_object_part_text_set(VIEW(item), "elm.text", item->label);
458 }
459
460 static const char *
461 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
462 {
463    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
464    if (part && strcmp(part, "default")) return NULL;
465    return ((Elm_Segment_Item *) it)->label;
466 }
467
468 static void
469 _item_content_set_hook(Elm_Object_Item *it,
470                        const char *part,
471                        Evas_Object *content)
472 {
473    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
474    Elm_Segment_Item *item;
475
476    if (part && strcmp(part, "icon")) return;
477
478    item = (Elm_Segment_Item *) it;
479
480    //Remove the existing icon
481    if (item->icon)
482      {
483         edje_object_part_unswallow(VIEW(item), item->icon);
484         evas_object_del(item->icon);
485         item->icon = NULL;
486      }
487    item->icon = content;
488    if (item->icon)
489      {
490         elm_widget_sub_object_add(VIEW(item), item->icon);
491         edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
492         edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
493      }
494    else
495      edje_object_signal_emit(VIEW(item), "elm,state,icon,hidden", "elm");
496 }
497
498 static Evas_Object *
499 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
500 {
501    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
502    if (part && strcmp(part, "icon")) return NULL;
503    return ((Elm_Segment_Item *) it)->icon;
504 }
505
506 static Eina_Bool
507 _item_del_pre_hook(Elm_Object_Item *it)
508 {
509    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
510    Widget_Data *wd;
511    Elm_Segment_Item *item = (Elm_Segment_Item *) it;
512
513    wd = elm_widget_item_data_get(item);
514    if (!wd) return EINA_FALSE;
515
516    _item_free(item);
517    _update_list(wd);
518
519    return EINA_TRUE;
520 }
521
522 static Elm_Segment_Item*
523 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label)
524 {
525    Elm_Segment_Item *it;
526    Widget_Data *wd;
527
528    wd = elm_widget_data_get(obj);
529    if (!wd) return NULL;
530
531    it = elm_widget_item_new(obj, Elm_Segment_Item);
532    if (!it) return NULL;
533    elm_widget_item_data_set(it, wd);
534    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
535    elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
536    elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
537    elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
538    elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
539
540    VIEW(it) = edje_object_add(evas_object_evas_get(obj));
541    edje_object_scale_set(VIEW(it), elm_widget_scale_get(VIEW(it))
542                          *_elm_config->scale);
543    evas_object_smart_member_add(VIEW(it), obj);
544    elm_widget_sub_object_add(obj, VIEW(it));
545    evas_object_clip_set(VIEW(it), evas_object_clip_get(obj));
546
547    _elm_theme_object_set(obj, VIEW(it), "segment_control", "item",
548                          elm_object_style_get(obj));
549    edje_object_mirrored_set(VIEW(it),
550                             elm_widget_mirrored_get(WIDGET(it)));
551
552    if (label)
553      eina_stringshare_replace(&it->label, label);
554    if (it->label)
555      edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
556    else
557      edje_object_signal_emit(VIEW(it), "elm,state,text,hidden", "elm");
558    edje_object_message_signal_process(VIEW(it));
559    edje_object_part_text_set(VIEW(it), "elm.text", label);
560
561    it->icon = icon;
562    if (it->icon) elm_widget_sub_object_add(VIEW(it), it->icon);
563    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
564                                   _mouse_down, it);
565    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
566                                   _mouse_up, it);
567    evas_object_show(VIEW(it));
568
569    return it;
570 }
571
572 EAPI Evas_Object *
573 elm_segment_control_add(Evas_Object *parent)
574 {
575    Evas_Object *obj;
576    Evas *e;
577    Widget_Data *wd;
578
579    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
580
581    ELM_SET_WIDTYPE(widtype, "segment_control");
582    elm_widget_type_set(obj, "segment_control");
583    elm_widget_sub_object_add(parent, obj);
584    elm_widget_data_set(obj, wd);
585    elm_widget_del_hook_set(obj, _del_hook);
586    elm_widget_theme_hook_set(obj, _theme_hook);
587    elm_widget_disable_hook_set(obj, _disable_hook);
588
589    // TODO: Focus switch support to Elm_widget_Item not supported yet.
590 #if 0
591    elm_widget_focus_next_hook_set(obj, _focus_next_hook);
592 #endif
593
594    wd->obj = obj;
595
596    wd->base = edje_object_add(e);
597    edje_object_scale_set(wd->base, elm_widget_scale_get(wd->base)
598                          *_elm_config->scale);
599    _elm_theme_object_set(obj, wd->base, "segment_control", "base", "default");
600    elm_widget_resize_object_set(obj, wd->base);
601
602    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
603                                   _on_move_resize, obj);
604    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
605                                   _on_move_resize, obj);
606
607    evas_object_smart_callbacks_descriptions_set(obj, _signals);
608
609    return obj;
610 }
611
612 EAPI Elm_Object_Item *
613 elm_segment_control_item_add(Evas_Object *obj, Evas_Object *icon,
614                              const char *label)
615 {
616    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
617    Elm_Segment_Item *it;
618    Widget_Data *wd;
619
620    wd = elm_widget_data_get(obj);
621    if (!wd) return NULL;
622
623    it = _item_new(obj, icon, label);
624    if (!it) return NULL;
625
626    wd->seg_items = eina_list_append(wd->seg_items, it);
627    _update_list(wd);
628
629    return (Elm_Object_Item *) it;
630 }
631
632 EAPI Elm_Object_Item *
633 elm_segment_control_item_insert_at(Evas_Object *obj, Evas_Object *icon,
634                                    const char *label, int idx)
635 {
636    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
637    Elm_Segment_Item *it, *it_rel;
638    Widget_Data *wd;
639
640    wd = elm_widget_data_get(obj);
641    if (!wd) return NULL;
642    if (idx < 0) idx = 0;
643
644    it = _item_new(obj, icon, label);
645    if (!it) return NULL;
646
647    it_rel = _item_find(obj, idx);
648    if (it_rel)
649      wd->seg_items = eina_list_prepend_relative(wd->seg_items, it, it_rel);
650    else
651      wd->seg_items = eina_list_append(wd->seg_items, it);
652
653    _update_list(wd);
654    return (Elm_Object_Item *) it;
655 }
656
657 EAPI void
658 elm_segment_control_item_del(Elm_Object_Item *it)
659 {
660    elm_object_item_del(it);
661 }
662
663 EAPI void
664 elm_segment_control_item_del_at(Evas_Object *obj, int idx)
665 {
666    ELM_CHECK_WIDTYPE(obj, widtype);
667    Elm_Segment_Item *it;
668    Widget_Data *wd;
669
670    wd = elm_widget_data_get(obj);
671    if (!wd) return;
672
673    it = _item_find(obj, idx);
674    if (!it) return;
675    elm_object_item_del((Elm_Object_Item *) it);
676 }
677
678 EAPI const char*
679 elm_segment_control_item_label_get(const Evas_Object *obj, int idx)
680 {
681    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
682    Elm_Segment_Item *it = _item_find(obj, idx);
683    if (it) return it->label;
684    return NULL;
685 }
686
687 EAPI void
688 elm_segment_control_item_label_set(Elm_Object_Item* it, const char* label)
689 {
690    _item_text_set_hook(it, NULL, label);
691 }
692
693 EAPI Evas_Object *
694 elm_segment_control_item_icon_get(const Evas_Object *obj, int idx)
695 {
696    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
697    Elm_Segment_Item *it = _item_find(obj, idx);
698    if (it) return it->icon;
699    return NULL;
700 }
701
702 EAPI void
703 elm_segment_control_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
704 {
705    _item_content_set_hook(it, NULL, icon);
706 }
707
708 EAPI int
709 elm_segment_control_item_count_get(const Evas_Object *obj)
710 {
711    ELM_CHECK_WIDTYPE(obj, widtype) 0;
712    Widget_Data *wd;
713
714    wd = elm_widget_data_get(obj);
715    if (!wd) return 0;
716
717    return eina_list_count(wd->seg_items);
718 }
719
720 EAPI Evas_Object*
721 elm_segment_control_item_object_get(const Elm_Object_Item *it)
722 {
723    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
724    return VIEW(it);
725 }
726
727 EAPI Elm_Object_Item*
728 elm_segment_control_item_selected_get(const Evas_Object *obj)
729 {
730    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
731    Widget_Data *wd = elm_widget_data_get(obj);
732    if (!wd) return NULL;
733    return (Elm_Object_Item *) wd->selected_item;
734 }
735
736 EAPI void
737 elm_segment_control_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
738 {
739    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
740    Widget_Data *wd;
741    Elm_Segment_Item *item = (Elm_Segment_Item *) it;
742
743    wd = elm_widget_item_data_get(item);
744    if (!wd) return;
745
746    if (item == wd->selected_item)
747      {
748         //already in selected state.
749         if (selected) return;
750
751         //unselect case
752         _segment_off(item);
753      }
754    else if (selected)
755      _segment_on(item);
756
757    return;
758 }
759
760 EAPI Elm_Object_Item *
761 elm_segment_control_item_get(const Evas_Object *obj, int idx)
762 {
763    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
764    return (Elm_Object_Item *) _item_find(obj, idx);
765 }
766
767 EAPI int
768 elm_segment_control_item_index_get(const Elm_Object_Item *it)
769 {
770    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, -1);
771    return ((Elm_Segment_Item *) it)->seg_index;
772 }