Merge branch 'master' of hyoyoung.chang@165.213.180.234:/git/slp/pkgs/elementary
[framework/uifw/elementary.git] / src / lib / elm_segment_control.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup SegmentControl SegmentControl
6  * @ingroup Elementary
7  *
8  * SegmentControl object is a horizontal control made of multiple segments,
9  * each segment 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 segments 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.
13  */
14 typedef struct _Widget_Data Widget_Data;
15 struct _Widget_Data
16 {
17    Evas_Object *box;
18    Evas_Object *base;
19    Eina_List *seg_ctrl;
20    Eina_List *queue;
21    int width, height;
22    int id;
23    int item_width;
24
25    Elm_Segment_Item *ani_it;
26    Ecore_Animator *ani;
27    unsigned int count;
28    unsigned int insert_index;
29    unsigned int del_index;
30    unsigned int cur_seg_id;
31    double scale_factor;
32 };
33
34 struct _Elm_Segment_Item
35 {
36    Evas_Object *obj;
37    Evas_Object *base;
38    Evas_Object *icon;
39    const char *label;
40         Eina_Bool delete_me : 1;
41    int segment_id;
42 };
43
44 static void _signal_segment_on(void *data, Evas_Object *obj, const char *emission, const char *source);
45 static void _theme_hook(Evas_Object *obj);
46 static void _item_free(Evas_Object *obj, Elm_Segment_Item *it);
47 static void _del_hook(Evas_Object *obj);
48 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
49 static Elm_Segment_Item * _item_find(Evas_Object *obj, unsigned int index);
50 static void _update_list(Evas_Object *obj);
51 static void _refresh_segment_ids(Evas_Object *obj);
52 static void _state_value_set(Evas_Object *obj);
53
54 static Elm_Segment_Item* _item_new(Evas_Object *obj, const char *label, Evas_Object *icon);
55 static Elm_Segment_Item *_item_find(Evas_Object *obj, unsigned int index);
56
57 static int * _animator_animate_add_cb(Evas_Object *obj);
58 static int * _animator_animate_del_cb(Evas_Object *obj);
59
60 static void
61 _on_focus_hook(void *data, Evas_Object *obj)
62 {
63    Widget_Data *wd = elm_widget_data_get(obj);
64    if (!wd) return;
65         Elm_Segment_Item *it;
66         Eina_List *l;
67
68    if (elm_widget_focus_get(obj))
69      {
70            edje_object_signal_emit((Evas_Object *)wd->seg_ctrl, "elm,action,focus", "elm");
71            evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 1);
72      }
73    else
74      {
75            edje_object_signal_emit((Evas_Object *)wd->seg_ctrl, "elm,action,unfocus", "elm");
76            evas_object_focus_set((Evas_Object *)wd->seg_ctrl, 0);
77                 EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
78                 {
79                         if (it->segment_id == wd->cur_seg_id) {
80                                 edje_object_signal_emit(it->base, "elm,state,segment,off", "elm");
81                                 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
82                                  break;
83                         }
84                 }
85      }
86 }
87
88 static void
89 _signal_segment_on(void *data, Evas_Object *obj, const char *emission, const char *source)
90 {
91         Elm_Segment_Item *item = (Elm_Segment_Item *) data;
92         Widget_Data *wd = elm_widget_data_get(item->obj);
93
94         if (!wd)
95                 return;
96
97         edje_object_signal_emit(item->base, "elm,state,segment,on", "elm");
98         edje_object_signal_emit(item->base, "elm,state,text,change", "elm");
99         Elm_Segment_Item *it;
100         Eina_List *l;
101         if (item->segment_id == wd->cur_seg_id)
102         {
103                 wd->cur_seg_id = item->segment_id;
104                 return;
105         }
106         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
107         {
108                 if (it->segment_id == wd->cur_seg_id) {
109                         edje_object_signal_emit(it->base, "elm,state,segment,off", "elm");
110                         edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
111                          break;
112                 }
113         }
114         wd->cur_seg_id = item->segment_id;
115    evas_object_smart_callback_call(item->obj, "changed", (void*)wd->cur_seg_id);
116 }
117
118 static void
119 _theme_hook(Evas_Object *obj)
120 {
121    _elm_theme_object_set(obj, obj, "segmented-control", "base", elm_widget_style_get(obj));
122
123    return;
124 }
125
126 static void
127 _item_free(Evas_Object *obj, Elm_Segment_Item *it)
128 {
129    Widget_Data *wd = elm_widget_data_get(obj);
130    if (!wd) return;
131
132    if(wd->seg_ctrl)
133         wd->seg_ctrl = eina_list_remove(wd->seg_ctrl, it);
134
135    if(it->icon) evas_object_del(it->icon);
136    if(it->base) evas_object_del(it->base);
137    if(it->label) eina_stringshare_del(it->label);
138
139    if(it)
140         free(it);
141    it = NULL;
142         return;
143 }
144
145 static void
146 _del_hook(Evas_Object *obj)
147 {
148    Widget_Data *wd = elm_widget_data_get(obj);
149    Elm_Segment_Item *it;
150    Eina_List *l, *clear = NULL;
151
152    EINA_LIST_FOREACH(wd->seg_ctrl, l, it) clear = eina_list_append(clear, it);
153    EINA_LIST_FREE(clear, it) _item_free(obj, it);
154
155    if(wd)
156         free(wd);
157    wd = NULL;
158
159    return;
160 }
161
162
163 static void
164 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
165 {
166    Widget_Data *wd = data;
167    if (!wd) return;
168    _els_box_layout(o, priv, 1, 0); /* making box layout non homogenous */
169
170    return;
171 }
172
173 static void
174 _segment_resizing(void *data)
175 {
176         Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
177         if (!wd) return;
178         Evas_Coord w = 0, h = 0;
179
180         evas_object_geometry_get(wd->base, NULL, NULL, &w, &h);
181
182         wd->item_width = wd->width = w;
183         wd->height = h;
184
185         _state_value_set((Evas_Object *)data);
186 }
187
188 static void _object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
189 {
190         Widget_Data *wd;
191         if(!data) return;
192         wd = elm_widget_data_get((Evas_Object *)data);
193         if(!wd) return;
194
195         ecore_job_add(_segment_resizing, (Evas_Object *)data);
196 }
197
198 /**
199  * Add a new segmentcontrol to the parent
200  * @param parent The parent object
201  * @return The new object or NULL if it cannot be created
202  *
203  * @ingroup SegmentControl SegmentControl
204  */
205 EAPI Evas_Object *
206 elm_segment_control_add(Evas_Object *parent)
207 {
208         Evas_Object *obj;
209         Evas *e;
210         Widget_Data *wd;
211
212         wd = ELM_NEW(Widget_Data);
213         e = evas_object_evas_get(parent);
214         obj = elm_widget_add(e);
215         elm_widget_type_set(obj, "segmented-control");
216         elm_widget_sub_object_add(parent, obj);
217         elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
218         elm_widget_data_set(obj, wd);
219         elm_widget_del_hook_set(obj, _del_hook);
220         elm_widget_theme_hook_set(obj, _theme_hook);
221
222         wd->base = edje_object_add(e);
223         _elm_theme_object_set(obj, wd->base, "segmented-control", "base", "default");
224         elm_widget_resize_object_set(obj, wd->base);
225
226         wd->box = evas_object_box_add(e);
227         evas_object_box_layout_set(wd->box, _layout, wd, NULL);
228         elm_widget_sub_object_add(obj, wd->box);
229         edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
230         evas_object_show(wd->box);
231
232         evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _object_resize, obj);
233         wd->id = 0;
234         wd->del_index = 0;
235         wd->insert_index = 0;
236         wd->cur_seg_id = -1;
237
238         return obj;
239 }
240
241 static Elm_Segment_Item*
242 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon)
243 {
244    Widget_Data *wd = elm_widget_data_get(obj);
245    if (!wd) return NULL;
246
247    Elm_Segment_Item *it;
248    it = calloc(1, sizeof(   Elm_Segment_Item));
249    if (!it) return NULL;
250
251    Evas_Coord mw, mh;
252
253    if(obj) it->obj = obj;
254    it->delete_me = EINA_FALSE;
255    it->segment_id = wd->id;
256
257    it->base = edje_object_add(evas_object_evas_get(obj));
258    _elm_theme_object_set(obj, it->base, "segment", "base", elm_object_style_get(it->base));
259
260    if (it->label) eina_stringshare_del(it->label);
261    if (label)
262          {
263                         it->label = eina_stringshare_add(label);
264          }
265    else
266          {
267                         it->label = NULL;
268          }
269
270    if ((it->icon != icon) && (it->icon))
271          elm_widget_sub_object_del(obj, it->icon);
272    it->icon = icon;
273    if (icon)
274          {
275                 elm_widget_sub_object_add(obj, icon);
276                 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
277
278                 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
279                 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
280
281                 evas_object_size_hint_weight_set(it->base, 1.0, -1.0);
282                 evas_object_size_hint_align_set(it->base, 1.0, -1.0);
283                 evas_object_size_hint_min_set(it->base, -1, -1);
284                 evas_object_size_hint_max_set(it->base, maxw, maxh);
285          }
286
287         edje_object_size_min_restricted_calc(obj, &mw, &mh, 0, 0);
288         evas_object_size_hint_weight_set(obj, 1.0, 1.0);
289         evas_object_size_hint_align_set(obj, -1.0, -1.0);
290
291         return it;
292 }
293
294
295 static void _update_list(Evas_Object *obj)
296 {
297         Widget_Data *wd = elm_widget_data_get(obj);
298         if (!wd) return;
299
300         Elm_Segment_Item *it;
301         Eina_List *l;
302         int i = 0;
303         wd->count = eina_list_count(wd->seg_ctrl);
304
305         if(wd->count == 1)
306         {
307                 it = _item_find(obj, 0);
308                 _elm_theme_object_set(obj, it->base, "segment", "base", "single");
309                 edje_object_signal_emit(it->base, "elm,state,segment,on", "elm");
310                 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
311                 edje_object_signal_emit(it->base, "elm,state,text,change", "elm");
312                 edje_object_message_signal_process(it->base);
313
314                 edje_object_part_text_set(it->base, "elm.text", it->label);
315
316                 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
317                 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
318                 return;
319         }
320
321         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
322         {
323                 if(i==0)
324                 {
325                         _elm_theme_object_set(obj, it->base, "segment", "base", "first");
326                 }
327                 else if(i==wd->count-1)
328                 {
329                         _elm_theme_object_set(obj, it->base, "segment", "base", "last");
330                 }
331                 else
332                 {
333                         _elm_theme_object_set(obj, it->base, "segment", "base", "default");
334                 }
335
336                 edje_object_signal_emit(it->base, "elm,state,text,visible", "elm");
337                 edje_object_message_signal_process(it->base);
338
339                 edje_object_part_text_set(it->base, "elm.text", it->label);
340
341                 edje_object_part_swallow(it->base, "elm.swallow.content", it->icon);
342                 edje_object_signal_emit(it->base, "elm,state,icon,visible", "elm");
343
344                 i++;
345         }
346 }
347
348
349 static void _refresh_segment_ids(Evas_Object *obj)
350 {
351         Widget_Data *wd = elm_widget_data_get(obj);
352         if (!wd) return;
353
354         Elm_Segment_Item *it;
355         Eina_List *l;
356
357         if (wd->insert_index && wd->cur_seg_id >= wd->insert_index)
358         {
359                 ++wd->cur_seg_id;
360                 wd->insert_index = 0;
361         }
362         if (wd->del_index)
363         {
364                 if (wd->cur_seg_id >= wd->del_index)
365                         --wd->cur_seg_id;
366                 wd->del_index =0;
367         }
368
369         int i = 0;
370         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
371         {
372                 it->segment_id = i;
373                 i++;
374         }
375 }
376
377 static void _state_value_set(Evas_Object *obj)
378 {
379         Widget_Data *wd = elm_widget_data_get(obj);
380         if (!wd) return;
381
382         Elm_Segment_Item *it;
383         Eina_List *l;
384    Evas_Coord mw, mh, x, y;
385    int w1=0, w2;
386
387
388         unsigned int count = eina_list_count(wd->seg_ctrl);
389
390         if(count > 0)
391                 wd->item_width = wd->width/count;
392
393         if(wd->ani_it)
394         {
395                 evas_object_geometry_get(wd->ani_it->base, &x, &y, &w1, NULL);
396                 if(wd->ani_it->delete_me)
397                 {
398                         w1-=(wd->item_width/15);
399                         if( w1< 0) w1 = 0;
400                 }
401                 else
402                 {
403                         w1+=(wd->item_width/15);
404                         if( w1 > wd->item_width )
405                                         w1 = wd->item_width;
406                 }
407
408                         w2 = (wd->width-w1)/(count -1);
409         }
410         else
411                         w2 = wd->item_width;
412
413         int i=0;
414
415         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
416         {
417                 edje_object_size_min_restricted_calc(it->base, &mw, &mh, 0, 0);
418                 evas_object_size_hint_weight_set(it->base, 1.0, 1.0);
419                 evas_object_size_hint_align_set(it->base, -1.0, -1.0);
420
421                 if(wd->ani_it  && it == wd->ani_it)
422                 {
423                         evas_object_resize(it->base, w1, wd->height);
424                         evas_object_size_hint_min_set(it->base, w1, wd->height);
425                         evas_object_size_hint_max_set(it->base, w1, wd->height);
426                 }
427                 else
428                 {
429                         evas_object_resize(it->base, w2, wd->height);
430                         evas_object_size_hint_min_set(it->base, w2, wd->height);
431                         evas_object_size_hint_max_set(it->base, w2, wd->height);
432                 }
433
434                 ++i;
435         }
436
437         return;
438 }
439
440
441 static int *
442 _animator_animate_add_cb(Evas_Object *obj)
443 {
444         Widget_Data *wd = elm_widget_data_get(obj);
445         if (!wd) return;
446
447         int w;
448         evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
449
450         if( w <  wd->item_width )
451         {
452          _state_value_set(obj);
453          evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
454                         return ECORE_CALLBACK_RENEW;
455         }
456         else
457          {
458                  ecore_animator_del(wd->ani);
459                  wd->ani = NULL;
460                  wd->ani_it = NULL;
461                         return ECORE_CALLBACK_CANCEL;
462          }
463 }
464
465
466 static int *
467 _animator_animate_del_cb(Evas_Object *obj)
468 {
469         Widget_Data *wd = elm_widget_data_get(obj);
470         if (!wd) return;
471
472         int w;
473         evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
474         if( w >  0 )
475         {
476          _state_value_set(obj);
477          evas_object_geometry_get(wd->ani_it->base, NULL, NULL, &w, NULL);
478                         return ECORE_CALLBACK_RENEW;
479         }
480         else
481          {
482                 _item_free(obj, wd->ani_it );
483                 _refresh_segment_ids(obj);
484                  ecore_animator_del(wd->ani);
485                  wd->ani = NULL;
486                  wd->ani_it = NULL;
487                 _update_list(obj);
488                 wd->id = eina_list_count(wd->seg_ctrl);
489                         return ECORE_CALLBACK_CANCEL;
490          }
491 }
492
493 /**
494  * Add a new segment to segmentcontrol
495  * @param obj The SegmentControl object
496  * @param icon The icon object for added segment
497  * @param label The label for added segment
498  * @param animate If 1 the action be animated with sliding effects default 0.
499  * @return The new segment or NULL if it cannot be created
500  *
501  * @ingroup SegmentControl SegmentControl
502  */
503
504 EAPI Elm_Segment_Item *
505 elm_segment_control_add_segment(Evas_Object *obj, Evas_Object *icon, const char *label, Eina_Bool animate)
506 {
507    Widget_Data *wd = elm_widget_data_get(obj);
508    if(!wd) return NULL;
509
510    Evas_Object *seg;
511    Elm_Segment_Item *it;
512
513    it = _item_new(obj, label, icon);
514         if(!it)
515                 return NULL;
516
517         wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
518         wd->id = eina_list_count(wd->seg_ctrl);
519
520         _update_list(obj);
521
522           edje_object_signal_callback_add(it->base, "elm,action,segment,click", "elm", _signal_segment_on, it);
523 //              ++wd->id;
524           wd->insert_index = 0;
525           wd->del_index = 0;
526            _refresh_segment_ids(obj);
527
528         if(animate && it->segment_id && wd->ani_it == NULL)
529            {
530                                 evas_object_resize(it->base, 1, wd->height);
531                                 wd->ani_it = it;
532                                 wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
533            }
534            else
535               _state_value_set(obj);
536         evas_object_show( it->base);
537
538         evas_object_box_append(wd->box, it->base);
539         evas_object_smart_calculate(wd->box);
540
541    return it;
542 }
543
544
545 static Elm_Segment_Item *
546 _item_find(Evas_Object *obj, unsigned int index)
547 {
548         Widget_Data *wd = elm_widget_data_get(obj);
549         if (!wd)
550                 return NULL;
551
552         Elm_Segment_Item *it;
553         Eina_List *l;
554
555         int i = 0;
556         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
557         {
558                 if (i == index) {
559                         return it;
560                 }
561                 i++;
562         }
563         return NULL;
564 }
565
566
567 static Elm_Segment_Item *
568 _item_search(Evas_Object *obj, Elm_Segment_Item *item)
569 {
570         Widget_Data *wd = elm_widget_data_get(obj);
571         if (!wd)
572                 return NULL;
573
574         Elm_Segment_Item *it;
575         Eina_List *l;
576
577         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
578         {
579                 if (it == item) {
580                         return it;
581                 }
582         }
583         return NULL;
584 }
585
586 /**
587  * Insert a new segment to segmentcontrol
588  * @param obj The SegmentControl object
589  * @param icon The icon object for added segment
590  * @param label The label for added segment
591  * @param index The position at which segment to be inserted
592  * @param animate If 1 the action be animated with sliding effects default 0.
593  * @return The new segment or NULL if it cannot be created
594  *
595  * @ingroup SegmentControl SegmentControl
596  */
597 EAPI void
598 elm_segment_control_insert_segment_at(Evas_Object *obj, Evas_Object *icon, const char *label, unsigned int index, Eina_Bool animate)
599 {
600    Widget_Data *wd = elm_widget_data_get(obj);
601    if(!wd) return;
602
603    Elm_Segment_Item *it, *it_rel;
604
605    it = _item_new(obj, label, icon);
606    it_rel = _item_find(obj, index);
607    if (!it_rel)
608      {
609       wd->seg_ctrl = eina_list_append(wd->seg_ctrl, it);
610      }
611    else
612    {
613       if (!it) return;
614                 wd->seg_ctrl = eina_list_prepend_relative(wd->seg_ctrl, it, it_rel);
615    }
616         edje_object_signal_callback_add(it->base, "elm,action,segment,click", "elm", _signal_segment_on, it);
617    wd->insert_index = index;
618 //      ++wd->id;
619    wd->id = eina_list_count(wd->seg_ctrl);
620    _refresh_segment_ids(obj);
621
622         _update_list(obj);
623
624
625         if(animate && it->segment_id && wd->ani_it == NULL)
626    {
627                         wd->ani_it = it;
628                         evas_object_resize(it->base, 1, wd->height);
629                         wd->ani = ecore_animator_add( _animator_animate_add_cb, obj );
630    }
631    else
632       _state_value_set(obj);
633
634         evas_object_show( it->base);
635
636          if(index >= wd->id-1)
637            {
638                 evas_object_box_append(wd->box,  it->base);
639            }
640            else
641            {
642                 evas_object_box_insert_at(wd->box,  it->base, index);
643            }
644
645                 evas_object_smart_calculate(wd->box);
646
647    return;
648 }
649
650 /**
651  * Delete a segment to segmentcontrol
652  * @param obj The SegmentControl object
653  * @param item The Segment to be deleted
654  * @param animate If 1 the action be animated with sliding effects default 0.
655  *
656  * @ingroup SegmentControl SegmentControl
657  */
658 EAPI void
659 elm_segment_control_delete_segment(Evas_Object *obj, Elm_Segment_Item *item, Eina_Bool animate)
660 {
661    Widget_Data *wd = elm_widget_data_get(obj);
662    if(!wd) return;
663
664    if(!item) return;
665
666    Elm_Segment_Item *it;
667    it = _item_search(obj, item);
668
669    if(!it)
670         return;
671    wd->del_index = it->segment_id;
672
673         if(animate && it->segment_id && wd->ani_it == NULL)
674         {
675                         it->delete_me = EINA_TRUE;
676                         wd->ani_it = it;
677                         wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
678         }
679         else
680         {
681                 evas_object_box_remove(wd->box, it->base);
682                 evas_object_smart_calculate(wd->box);
683                 _item_free(obj, it);
684            _refresh_segment_ids(obj);
685                 _state_value_set(obj);
686                 _update_list(obj);
687         }
688 //      --wd->id;
689         wd->id = eina_list_count(wd->seg_ctrl);
690    return;
691 }
692
693 /**
694  * Delete a segment to segmentcontrol
695  * @param obj The SegmentControl object
696  * @param index The position at which segment to be deleted
697  * @param animate If 1 the action be animated with sliding effects default 0.
698  *
699  * @ingroup SegmentControl SegmentControl
700  */
701
702 EAPI void
703 elm_segment_control_delete_segment_at(Evas_Object *obj,  unsigned int index, Eina_Bool animate)
704 {
705    Widget_Data *wd = elm_widget_data_get(obj);
706    if(!wd) return;
707    Elm_Segment_Item *it, *it_rel;
708
709    it = _item_find(obj, index);
710
711    if(!it)
712         return;
713
714    wd->del_index = index;
715
716         if(animate && it->segment_id)
717                 {
718                         if(wd->ani_it == NULL)
719                         {
720                                 wd->ani_it = it;
721                                 it->delete_me = EINA_TRUE;
722                                 wd->ani = ecore_animator_add( _animator_animate_del_cb, obj );
723                         }
724                         else
725                         {
726                                 wd->queue = eina_list_append(wd->queue, it);
727                         }
728                 }
729                 else
730                 {
731                         evas_object_box_remove(wd->box, it->base);
732                         evas_object_smart_calculate(wd->box);
733                         _item_free(obj, it);
734                    _refresh_segment_ids(obj);
735                         _state_value_set(obj);
736                         _update_list(obj);
737                 }
738
739 //      --wd->id;
740         wd->id = eina_list_count(wd->seg_ctrl);
741    return;
742 }
743
744 /**
745  * Get the label of a segment of segmentcontrol
746  * @param obj The SegmentControl object
747  * @param index The index of the segment
748  * @return The label
749  *
750  * @ingroup SegmentControl SegmentControl
751  */
752
753 EAPI const char *
754 elm_segment_control_get_segment_label_at(Evas_Object *obj, unsigned int index)
755 {
756         Elm_Segment_Item *it_rel;
757    Widget_Data *wd = elm_widget_data_get(obj);
758    if(!wd) return NULL;
759
760    it_rel = _item_find(obj, index);
761
762    if(it_rel)
763       return it_rel->label;
764
765    return NULL;
766 }
767
768 /**
769  * Get the icon of a segment of segmentcontrol
770  * @param obj The SegmentControl object
771  * @param index The index of the segment
772  * @return The icon object
773  *
774  * @ingroup SegmentControl SegmentControl
775  */
776
777 EAPI Evas_Object *
778 elm_segment_control_get_segment_icon_at(Evas_Object *obj, unsigned int index)
779 {
780         Elm_Segment_Item *seg_rel;
781    Widget_Data *wd = elm_widget_data_get(obj);
782    if(!wd) return NULL;
783
784    seg_rel = _item_find(obj, index);
785
786    if(seg_rel)
787         return seg_rel->icon;
788
789    return NULL;
790 }
791
792 /**
793  * Get the currently selected segment of segmentcontrol
794  * @param obj The SegmentControl object
795  * @param value The current segment id
796  * @return The selected Segment
797  *
798  * @ingroup SegmentControl SegmentControl
799  */
800
801 EAPI Elm_Segment_Item *
802 elm_segment_control_selected_segment_get(const Evas_Object *obj, int *value)
803 {
804    Widget_Data *wd = elm_widget_data_get(obj);
805         if(!wd || !wd->seg_ctrl) return NULL;
806
807         Elm_Segment_Item *it;
808         Eina_List *l;
809
810         EINA_LIST_FOREACH(wd->seg_ctrl, l, it)
811         {
812                 if(it->segment_id == wd->cur_seg_id)
813                         {
814                                 * value = wd->cur_seg_id;
815                                 return it;
816                         }
817         }
818         return NULL;
819 }
820
821 /**
822  * Get the count of segments of segmentcontrol
823  * @param obj The SegmentControl object
824  * @return The count of Segments
825  *
826  * @ingroup SegmentControl SegmentControl
827  */
828
829 EAPI int
830 elm_segment_control_get_segment_count(Evas_Object *obj)
831 {
832    Widget_Data *wd = elm_widget_data_get(obj);
833    if(!wd) return 0;
834
835    return wd->id;
836 }
837
838 /**
839  * set the size of segmentcontrol
840  * @param obj The SegmentControl object
841  * @param width width of segment control
842  * @param height height of segment control
843  *
844  * @ingroup SegmentControl SegmentControl
845  */
846
847 EAPI void
848 elm_segment_control_set_size(Evas_Object *obj, int width, int height)
849 {
850    Widget_Data *wd = elm_widget_data_get(obj);
851    if(!wd) return 0;
852
853    wd->scale_factor = elm_scale_get();
854         if ( wd->scale_factor == 0.0 ) {
855                         wd->scale_factor = 1.0;
856         }
857
858    wd->item_width = wd->width = width*wd->scale_factor;
859    wd->height = height*wd->scale_factor;
860
861    return 0;
862 }