Diskselector segfault issue fix.
[framework/uifw/elementary.git] / src / lib / elm_diskselector.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_scroller.h"
4
5 #ifndef MAX
6 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
7 #endif
8
9 #ifndef CEIL
10 #define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
11 #endif
12
13 #define DISPLAY_ITEM_NUM_MIN 3
14
15 typedef struct _Widget_Data Widget_Data;
16 typedef struct _Elm_Diskselector_Item Elm_Diskselector_Item;
17
18 struct _Widget_Data
19 {
20    Evas_Object *self;
21    Evas_Object *scroller;
22    Evas_Object *main_box;
23    Evas_Object *left_blank;
24    Evas_Object *right_blank;
25    Elm_Diskselector_Item *selected_item;
26    Elm_Diskselector_Item *first;
27    Elm_Diskselector_Item *second;
28    Elm_Diskselector_Item *s_last;
29    Elm_Diskselector_Item *last;
30    Eina_List *items;
31    Eina_List *r_items;
32    Eina_List *over_items;
33    Eina_List *under_items;
34    int item_count, len_threshold, len_side, display_item_num;
35    Ecore_Idle_Enterer *idler;
36    Ecore_Idle_Enterer *check_idler;
37    Evas_Coord minw, minh;
38    Eina_Bool init:1;
39    Eina_Bool round:1;
40    Eina_Bool display_item_num_by_api:1;
41 };
42
43 struct _Elm_Diskselector_Item
44 {
45    ELM_WIDGET_ITEM;
46    Eina_List *node;
47    Evas_Object *icon;
48    const char *label;
49    Evas_Smart_Cb func;
50 };
51
52 static const char *widtype = NULL;
53
54 static Eina_Bool _move_scroller(void *data);
55 static void _del_hook(Evas_Object * obj);
56 static void _del_pre_hook(Evas_Object * obj);
57 static void _sizing_eval(Evas_Object * obj);
58 static void _theme_hook(Evas_Object * obj);
59 static void _on_focus_hook(void *data, Evas_Object *obj);
60 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
61 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
62 static void _round_items_del(Widget_Data *wd);
63 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
64 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
65                            const char *emission __UNUSED__,
66                            const char *source __UNUSED__);
67 static void _selected_item_indicate(Elm_Diskselector_Item *it);
68 static void _item_text_set_hook(Elm_Object_Item *it,
69                                 const char *part,
70                                 const char *label);
71 static const char * _item_text_get_hook(const Elm_Object_Item *it,
72                                         const char *part);
73 static void _item_content_set_hook(Elm_Object_Item *it,
74                                    const char *part,
75                                    Evas_Object *content);
76 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
77                                             const char *part);
78
79 static const char SIG_SELECTED[] = "selected";
80 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
81 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
82 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
83 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
84
85 static const Evas_Smart_Cb_Description _signals[] = {
86        {SIG_SELECTED, ""},
87        {SIG_SCROLL_ANIM_START, ""},
88        {SIG_SCROLL_ANIM_STOP, ""},
89        {SIG_SCROLL_DRAG_START, ""},
90        {SIG_SCROLL_DRAG_STOP, ""},
91        {NULL, NULL}
92 };
93
94 static void
95 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
96 {
97    Widget_Data *wd;
98    Evas_Coord w, h;
99
100    wd = elm_widget_data_get(data);
101    if (!wd) return;
102
103    if ((wd->minw == -1) && (wd->minh == -1))
104       elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
105    edje_object_size_min_restricted_calc
106       (elm_smart_scroller_edje_object_get
107           (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
108    evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
109    evas_object_size_hint_max_set(obj, -1, -1);
110
111    evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
112    if (wd->round)
113      evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
114    else
115      evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
116
117    elm_smart_scroller_paging_set(wd->scroller, 0, 0,
118                                  (int)(w / wd->display_item_num), 0);
119
120    if (!wd->idler)
121      wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
122 }
123
124 static void
125 _item_del(Elm_Diskselector_Item *item)
126 {
127    if (!item) return;
128    eina_stringshare_del(item->label);
129    if (item->icon)
130      evas_object_del(item->icon);
131 }
132
133 static int
134 _count_letter(const char *str)
135 {
136    int pos = 0;
137    int code = 0, chnum;
138
139    for (chnum = 0; ; chnum++)
140      {
141         pos = evas_string_char_next_get(str, pos, &code);
142         if (code == 0) break;
143      }
144    return chnum;
145 }
146
147 static int
148 _check_letter(const char *str, int length)
149 {
150    int pos = 0;
151    int code = 0, chnum;
152
153    for (chnum = 0; ; chnum++)
154      {
155         if (chnum == length) break;
156         pos = evas_string_char_next_get(str, pos, &code);
157         if (code == 0) break;
158      }
159    return pos;
160 }
161
162 static Eina_Bool
163 _check_string(void *data)
164 {
165    int mid, steps, length, diff;
166    Elm_Diskselector_Item *it;
167    Eina_List *list, *l;
168    Evas_Coord ox, ow;
169    char buf[1024];
170    Widget_Data *wd = data;
171
172    evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
173    if (ow <= 0)
174      return EINA_FALSE;
175    if (!wd->init)
176      return EINA_FALSE;
177    if (!wd->round)
178      list = wd->items;
179    else
180      list = wd->r_items;
181
182    EINA_LIST_FOREACH(list, l, it)
183      {
184         Evas_Coord x, w;
185         int len;
186         evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
187         /* item not visible */
188         if ((x + w <= ox) || (x >= ox + ow))
189           continue;
190
191         len = _count_letter(it->label);
192 //        // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
193 //        len = eina_stringshare_strlen(it->label);
194
195         if (x <= ox + 5)
196           edje_object_signal_emit(VIEW(it), "elm,state,left_side",
197                                   "elm");
198         else if (x + w >= ox + ow - 5)
199           edje_object_signal_emit(VIEW(it), "elm,state,right_side",
200                                   "elm");
201         else
202           {
203              if ((wd->len_threshold) && (len > wd->len_threshold))
204                edje_object_signal_emit(VIEW(it), "elm,state,center_small",
205                                        "elm");
206              else
207                edje_object_signal_emit(VIEW(it), "elm,state,center",
208                                        "elm");
209           }
210
211         // if len is les that the limit len, skip anyway
212         if (len <= wd->len_side)
213           continue;
214
215         steps = len - wd->len_side + 1;
216         mid = x + w / 2;
217         if (mid <= ox + ow / 2)
218           diff = (ox + ow / 2) - mid;
219         else
220           diff = mid - (ox + ow / 2);
221
222         length = len - (int)(diff * steps / (ow / 3));
223         length = MAX(length, wd->len_side);
224         // limit string len to "length" ut8f chars
225         length = _check_letter(it->label, length);
226         // cut it off at byte mark returned form _check_letter
227         strncpy(buf, it->label, length);
228         buf[length] = '\0';
229         edje_object_part_text_set(VIEW(it), "elm.text", buf);
230      }
231
232    if (wd->check_idler)
233      ecore_idle_enterer_del(wd->check_idler);
234    wd->check_idler = NULL;
235    return EINA_FALSE;
236 }
237
238 static Eina_Bool
239 _item_del_pre_hook(Elm_Object_Item *it)
240 {
241    Elm_Diskselector_Item *item, *item2, *dit;
242    Eina_List *l;
243    int i = 0;
244    Widget_Data *wd;
245    item = (Elm_Diskselector_Item *)it;
246    wd = elm_widget_data_get(WIDGET(item));
247    if (!wd) return EINA_FALSE;
248
249    elm_box_unpack(wd->main_box, VIEW(item));
250
251    if (wd->round)
252      wd->r_items = eina_list_remove(wd->r_items, item);
253
254    wd->items = eina_list_remove(wd->items, item);
255
256    if (wd->selected_item == item)
257      {
258         dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
259         if (dit != item)
260           wd->selected_item = dit;
261         else
262           wd->selected_item = eina_list_nth(wd->items, 1);
263
264         _selected_item_indicate(wd->selected_item);
265      }
266
267    _item_del(item);
268    wd->item_count -= 1;
269
270    if (wd->round)
271      {
272         if (!wd->item_count)
273           {
274              evas_object_hide(wd->VIEW(first));
275              evas_object_hide(wd->VIEW(second));
276              evas_object_hide(wd->VIEW(last));
277              evas_object_hide(wd->VIEW(s_last));
278
279              EINA_LIST_FOREACH(wd->under_items, l, item2)
280                evas_object_hide(VIEW(item2));
281
282              EINA_LIST_FOREACH(wd->over_items, l, item2)
283                evas_object_hide(VIEW(item2));
284           }
285         else
286           {
287              dit = eina_list_nth(wd->items, 0);
288              if (dit)
289                {
290                   eina_stringshare_replace(&wd->first->label, dit->label);
291                   edje_object_part_text_set(wd->VIEW(first), "elm.text",
292                                             wd->first->label);
293                }
294              dit = eina_list_nth(wd->items, 1);
295              if (dit)
296                {
297                   eina_stringshare_replace(&wd->second->label, dit->label);
298                   edje_object_part_text_set(wd->VIEW(second), "elm.text",
299                                             wd->second->label);
300                }
301              // if more than 3 itmes should be displayed
302              for (i = 2; i < CEIL(wd->display_item_num); i++)
303                {
304                   dit = eina_list_nth(wd->items, i);
305                   item2 = eina_list_nth(wd->over_items, i - 2);
306                   eina_stringshare_replace(&item2->label, dit->label);
307                   edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
308                }
309
310              dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
311              if (dit)
312                {
313                   eina_stringshare_replace(&wd->last->label, dit->label);
314                   edje_object_part_text_set(wd->VIEW(last), "elm.text",
315                                             wd->last->label);
316                }
317              dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
318              if (dit)
319                {
320                   eina_stringshare_replace(&wd->s_last->label, dit->label);
321                   edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
322                                             wd->s_last->label);
323                }
324              // if more than 3 itmes should be displayed
325              for (i = 3; i <= CEIL(wd->display_item_num); i++)
326                {
327                   dit = eina_list_nth(wd->items, wd->item_count - i);
328                   item2 = eina_list_nth(wd->under_items, i - 3);
329                   eina_stringshare_replace(&item2->label, dit->label);
330                   edje_object_part_text_set(VIEW(item2), "elm.text",
331                                             item2->label);
332                }
333           }
334      }
335    wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
336    _sizing_eval(wd->self);
337
338    return EINA_TRUE;
339 }
340
341 static Elm_Diskselector_Item *
342 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
343 {
344    Elm_Diskselector_Item *it;
345    const char *style = elm_widget_style_get(obj);
346
347    it = elm_widget_item_new(obj, Elm_Diskselector_Item);
348    if (!it) return NULL;
349
350    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
351    elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
352    elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
353    elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
354    elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
355
356    it->label = eina_stringshare_add(label);
357    it->icon = icon;
358    it->func = func;
359    it->base.data = data;
360    VIEW(it) = edje_object_add(evas_object_evas_get(obj));
361    _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
362    evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
363                                     EVAS_HINT_EXPAND);
364    evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
365                                    EVAS_HINT_FILL);
366    evas_object_show(VIEW(it));
367
368    if (it->label)
369      {
370         edje_object_part_text_set(VIEW(it), "elm.text", it->label);
371         edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
372      }
373    if (it->icon)
374      {
375         evas_object_size_hint_min_set(it->icon, 24, 24);
376         evas_object_size_hint_max_set(it->icon, 40, 40);
377         edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
378         evas_object_show(it->icon);
379         elm_widget_sub_object_add(obj, it->icon);
380      }
381    return it;
382 }
383
384 static void
385 _theme_data_get(Widget_Data *wd)
386 {
387    const char* str;
388    str = edje_object_data_get(wd->right_blank, "len_threshold");
389    if (str) wd->len_threshold = MAX(0, atoi(str));
390    else wd->len_threshold = 0;
391
392    if (!wd->display_item_num_by_api)
393      {
394         str = edje_object_data_get(wd->right_blank, "display_item_num");
395         if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
396         else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
397      }
398
399    str = edje_object_data_get(wd->right_blank, "min_width");
400    if (str) wd->minw = MAX(-1, atoi(str));
401    else wd->minw = -1;
402
403    str = edje_object_data_get(wd->right_blank, "min_height");
404    if (str) wd->minh = MAX(-1, atoi(str));
405    else wd->minh = -1;
406 }
407
408 static void
409 _del_hook(Evas_Object * obj)
410 {
411    Widget_Data *wd = elm_widget_data_get(obj);
412    if (!wd) return;
413    free(wd);
414 }
415
416 static void
417 _del_pre_hook(Evas_Object * obj)
418 {
419    Elm_Diskselector_Item *it;
420    Eina_List *l;
421
422    Widget_Data *wd = elm_widget_data_get(obj);
423    if (!wd) return;
424
425    if (wd->left_blank)
426      evas_object_del(wd->left_blank);
427    if (wd->right_blank)
428      evas_object_del(wd->right_blank);
429    if (wd->last)
430      {
431         eina_stringshare_del(wd->last->label);
432         evas_object_del(wd->VIEW(last));
433         free(wd->last);
434      }
435    if (wd->s_last)
436      {
437         eina_stringshare_del(wd->s_last->label);
438         evas_object_del(wd->VIEW(s_last));
439         free(wd->s_last);
440      }
441    if (wd->second)
442      {
443         eina_stringshare_del(wd->second->label);
444         evas_object_del(wd->VIEW(second));
445         free(wd->second);
446      }
447    if (wd->first)
448      {
449         eina_stringshare_del(wd->first->label);
450         evas_object_del(wd->VIEW(first));
451         free(wd->first);
452      }
453
454    EINA_LIST_FOREACH(wd->under_items, l, it)
455      {
456         if (it)
457           {
458              eina_stringshare_del(it->label);
459              evas_object_del(VIEW(it));
460              free(it);
461           }
462      }
463
464    EINA_LIST_FOREACH(wd->over_items, l, it)
465    {
466      if (it)
467         {
468            eina_stringshare_del(it->label);
469            evas_object_del(VIEW(it));
470            free(it);
471         }
472    }
473
474    EINA_LIST_FREE(wd->items, it)
475      {
476         _item_del(it);
477         elm_widget_item_free(it);
478      }
479    eina_list_free(wd->r_items);
480 }
481
482 static void
483 _sizing_eval(Evas_Object * obj)
484 {
485    Widget_Data *wd = elm_widget_data_get(obj);
486    if (!wd) return;
487    _diskselector_object_resize(obj, NULL, obj, NULL);
488 }
489
490 static void
491 _theme_hook(Evas_Object * obj)
492 {
493    Eina_List *l;
494    Elm_Diskselector_Item *it;
495    Widget_Data *wd = elm_widget_data_get(obj);
496    if (!wd) return;
497
498    if (wd->scroller)
499      elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
500                                          "base", elm_widget_style_get(obj));
501    if (wd->round)
502      {
503         EINA_LIST_FOREACH(wd->r_items, l, it)
504           {
505              _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
506                                    elm_widget_style_get(obj));
507              edje_object_part_text_set(VIEW(it), "elm.text", it->label);
508           }
509      }
510    else
511      {
512         EINA_LIST_FOREACH(wd->items, l, it)
513           {
514              _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
515                                    elm_widget_style_get(obj));
516              edje_object_part_text_set(VIEW(it), "elm.text", it->label);
517           }
518      }
519    _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
520                                    elm_widget_style_get(obj));
521    _theme_data_get(wd);
522    _sizing_eval(obj);
523 }
524
525 static void
526 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
527 {
528    Widget_Data *wd = elm_widget_data_get(obj);
529    Evas_Object *sub = event_info;
530    Elm_Diskselector_Item *it;
531    const Eina_List *l;
532
533    if (!wd) return;
534    if (!sub) abort();
535    if (sub == wd->scroller)
536      wd->scroller = NULL;
537    else
538      {
539         EINA_LIST_FOREACH(wd->items, l, it)
540           {
541              if (sub == it->icon)
542                {
543                   it->icon = NULL;
544                   _sizing_eval(obj);
545                   break;
546                }
547           }
548      }
549 }
550
551 static void
552 _select_item(Elm_Diskselector_Item *it)
553 {
554    if (!it) return;
555    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
556    wd->selected_item = it;
557    _selected_item_indicate(wd->selected_item);
558    if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
559    evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
560 }
561
562 static void
563 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
564 {
565    Widget_Data *wd = elm_widget_data_get(obj);
566    if (!wd)
567      return;
568
569    if (elm_widget_focus_get(obj))
570      {
571         edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
572         evas_object_focus_set(wd->self, EINA_TRUE);
573      }
574    else
575      {
576         edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
577         evas_object_focus_set(wd->self, EINA_FALSE);
578      }
579 }
580
581 static Eina_Bool
582 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
583 {
584    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
585    Evas_Event_Key_Down *ev = event_info;
586    Widget_Data *wd = elm_widget_data_get(obj);
587    if (!wd) return EINA_FALSE;
588    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
589    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
590
591    Elm_Diskselector_Item *it = NULL;
592    Eina_List *l;
593
594    if (!wd->selected_item) {
595         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
596         return EINA_TRUE;
597    }
598
599    if ((!strcmp(ev->keyname, "Left")) ||
600        ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)) ||
601        (!strcmp(ev->keyname, "Up"))  ||
602        ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
603      {
604         l = wd->selected_item->node->prev;
605         if ((!l) && (wd->round))
606           l = eina_list_last(wd->items);
607      }
608    else if ((!strcmp(ev->keyname, "Right")) ||
609             ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)) ||
610             (!strcmp(ev->keyname, "Down")) ||
611             ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
612      {
613         l = wd->selected_item->node->next;
614         if ((!l) && (wd->round))
615           l = wd->items;
616      }
617    else if ((!strcmp(ev->keyname, "Home")) ||
618             ((!strcmp(ev->keyname, "KP_Home")) && (!ev->string)))
619      l = wd->items;
620    else if ((!strcmp(ev->keyname, "End")) ||
621             ((!strcmp(ev->keyname, "KP_End")) && (!ev->string)))
622      l = eina_list_last(wd->items);
623    else return EINA_FALSE;
624
625    if (l)
626      it = eina_list_data_get(l);
627
628    if (it)
629      {
630         wd->selected_item = it;
631         if (!wd->idler)
632           wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
633      }
634
635    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
636    return EINA_TRUE;
637 }
638
639 static void
640 _selected_item_indicate(Elm_Diskselector_Item *it)
641 {
642    Elm_Diskselector_Item *item;
643    Eina_List *l;
644    Widget_Data *wd;
645    wd = elm_widget_data_get(WIDGET(it));
646
647    if (!wd) return;
648    if (!it->label) return;
649
650    EINA_LIST_FOREACH(wd->r_items, l, item)
651      {
652         if (item->label && !strcmp(item->label, it->label))
653            edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
654         else
655            edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
656      }
657 }
658
659 static void
660 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
661                const char *emission __UNUSED__, const char *source __UNUSED__)
662 {
663    Elm_Diskselector_Item *it = data;
664
665    if (!it) return;
666
667    Widget_Data *wd;
668    wd = elm_widget_data_get(WIDGET(it));
669
670    if (!wd) return;
671
672    if (wd->selected_item != it)
673      {
674         wd->selected_item = it;
675         _selected_item_indicate(wd->selected_item);
676      }
677
678    if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
679 }
680
681 static void
682 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
683 {
684    Evas_Coord x, y, w, h, bw;
685    Widget_Data *wd = data;
686
687    _check_string(wd);
688    elm_smart_scroller_child_pos_get(obj, &x, &y);
689    elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
690    if (wd->round)
691      {
692         evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
693         if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
694            elm_smart_scroller_child_region_show(wd->scroller,
695                                                x - ((w / wd->display_item_num) * wd->item_count),
696                                                y, w, h);
697         else if (x < 0)
698            elm_smart_scroller_child_region_show(wd->scroller,
699                                                x + ((w / wd->display_item_num) * wd->item_count),
700                                                y, w, h);
701      }
702 }
703
704 static void
705 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
706 {
707    Elm_Diskselector_Item *it;
708    Widget_Data *wd = elm_widget_data_get(data);
709    Evas_Coord x, w, ow;
710    Eina_List *l, *list;
711
712    if (wd->idler) return;
713
714    if (!wd->round)
715      list = wd->items;
716    else
717      list = wd->r_items;
718
719    evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
720    EINA_LIST_FOREACH(list, l, it)
721      {
722         evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
723         if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
724      }
725
726    if (!it) return;
727    _select_item(it);
728    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, it);
729 }
730
731 static void
732 _scroller_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
733 {
734    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START,
735                                    elm_diskselector_selected_item_get(data));
736 }
737
738 static void
739 _drag_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
740 {
741    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START,
742                                    elm_diskselector_selected_item_get(data));
743 }
744
745 static void
746 _drag_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
747 {
748    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP,
749                                    elm_diskselector_selected_item_get(data));
750 }
751
752 static Eina_Bool
753 _move_scroller(void *data)
754 {
755    Evas_Object *obj = data;
756    Widget_Data *wd;
757    Eina_List *list, *l;
758    Elm_Diskselector_Item *dit;
759    Evas_Coord y, w, h;
760    int i;
761
762    wd = elm_widget_data_get(obj);
763    if (!wd) return EINA_FALSE;
764
765    if (!wd->round)
766      {
767         i = 0;
768         list = wd->items;
769      }
770    else
771      {
772         i = 1;
773         list = wd->r_items;
774      }
775
776    EINA_LIST_FOREACH(list, l, dit)
777      {
778         if (wd->selected_item == dit)
779            break;
780         i++;
781      }
782
783    if (wd->round) i -= CEIL(wd->display_item_num);
784
785    if (!dit)
786      {
787         wd->selected_item =
788            (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
789         return EINA_FALSE;
790      }
791
792    evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
793    elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
794    _select_item(dit);
795    if (wd->idler)
796      {
797         ecore_idle_enterer_del(wd->idler);
798         wd->idler = NULL;
799      }
800    wd->init = EINA_TRUE;
801    _check_string(wd);
802
803    return EINA_TRUE;
804 }
805
806 static void
807 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
808 {
809    if (!it) return;
810    elm_box_unpack(wd->main_box, VIEW(it));
811    wd->r_items = eina_list_remove(wd->r_items, it);
812    eina_stringshare_del(it->label);
813    elm_widget_item_free(it);
814 }
815
816 static void
817 _round_items_del(Widget_Data *wd)
818 {
819    Eina_List *l;
820    Elm_Diskselector_Item * it;
821
822    _round_item_del(wd, wd->last);
823    wd->last = NULL;
824    _round_item_del(wd, wd->s_last);
825    wd->s_last = NULL;
826    _round_item_del(wd, wd->second);
827    wd->second = NULL;
828    _round_item_del(wd, wd->first);
829    wd->first = NULL;
830
831    EINA_LIST_FOREACH(wd->under_items, l, it)
832      {
833         _round_item_del(wd, it);
834      }
835    wd->under_items = eina_list_free(wd->under_items);
836
837    EINA_LIST_FOREACH(wd->over_items, l, it)
838      {
839         _round_item_del(wd, it);
840      }
841    wd->over_items = eina_list_free(wd->over_items);
842 }
843
844 static void
845 _round_items_add(Widget_Data *wd)
846 {
847    Elm_Diskselector_Item *dit;
848    Elm_Diskselector_Item *it;
849    Elm_Diskselector_Item *temp_it;
850    int i = 0;
851    dit = it = eina_list_nth(wd->items, 0);
852    if (!dit) return;
853
854    if (!wd->first)
855      {
856         wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
857                               it->base.data);
858         wd->first->node = it->node;
859         wd->r_items = eina_list_append(wd->r_items, wd->first);
860      }
861
862    it = eina_list_nth(wd->items, 1);
863    if (!it)
864      it = dit;
865    if (!wd->second)
866      {
867         wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
868                                it->base.data);
869         wd->second->node = it->node;
870         wd->r_items = eina_list_append(wd->r_items, wd->second);
871      }
872
873    // if more than 3 itmes should be displayed
874    for (i = 2; i < CEIL(wd->display_item_num); i++)
875      {
876         it = eina_list_nth(wd->items, i);
877         if (!it) it = dit;
878         temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
879         wd->over_items = eina_list_append(wd->over_items, temp_it);
880         wd->r_items = eina_list_append(wd->r_items, temp_it);
881      }
882
883    it = eina_list_nth(wd->items, wd->item_count - 1);
884    if (!it)
885      it = dit;
886    if (!wd->last)
887      {
888         wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
889                              it->base.data);
890         wd->last->node = it->node;
891         wd->r_items = eina_list_prepend(wd->r_items, wd->last);
892      }
893
894    it = eina_list_nth(wd->items, wd->item_count - 2);
895    if (!it)
896      it = dit;
897    if (!wd->s_last)
898      {
899         wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
900                                it->base.data);
901         wd->s_last->node = it->node;
902         wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
903      }
904
905    // if more than 3 itmes should be displayed
906    for (i = 3; i <= CEIL(wd->display_item_num); i++)
907      {
908         it = eina_list_nth(wd->items, wd->item_count - i);
909         if (!it) it = dit;
910         temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
911         wd->under_items = eina_list_append(wd->under_items, temp_it);
912         wd->r_items = eina_list_prepend(wd->r_items, temp_it);
913      }
914 }
915
916 static void
917 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
918 {
919    if (it->icon == icon) return;
920    if (it->icon) evas_object_del(it->icon);
921    it->icon = icon;
922    if (VIEW(it))
923      {
924         evas_object_size_hint_min_set(it->icon, 24, 24);
925         evas_object_size_hint_max_set(it->icon, 40, 40);
926         edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
927         evas_object_show(it->icon);
928         elm_widget_sub_object_add(WIDGET(it), it->icon);
929      }
930 }
931
932 static void
933 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
934 {
935    Widget_Data *wd;
936    Elm_Diskselector_Item *dit;
937    Eina_List *l;
938    int idx = 0;
939    int ic = 0;
940    int ac = 0;
941
942    wd = elm_widget_data_get(WIDGET(it));
943    if (!wd) return;
944
945    if (wd->round)
946      {
947         // Get index from indentical item from round items
948         EINA_LIST_FOREACH(wd->r_items, l, dit)
949           {
950              if (it == dit) break;
951              idx++;
952           }
953
954         // No item to match
955         ic = eina_list_count(wd->r_items);
956         if (idx >= ic) return;
957         dit = NULL;
958
959         // Number of added items: CEIL(wd->display_item_num)
960         ac = CEIL(wd->display_item_num);
961
962         if (((idx >= 0) && (idx < ac)) ||
963             ((idx >= ac) && (idx < (2 * ac))))
964           {
965               // Selected item: under, low region
966              dit = eina_list_nth(wd->r_items,
967                                  idx + ic - (2 * ac));
968           }
969         else if (((idx >= (ic - ac)) && (idx < ic)) ||
970                  ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
971           {
972               // Selected item: over, high region
973               dit = eina_list_nth(wd->r_items,
974                                   idx - ic + (2 * ac));
975           }
976
977         if (dit) _item_icon_set(dit, icon);
978         _sizing_eval(wd->self);
979      }
980 }
981
982 static void
983 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
984 {
985    Elm_Diskselector_Item *item;
986    if (part && strcmp(part, "default")) return;
987    item = (Elm_Diskselector_Item *)it;
988    eina_stringshare_replace(&item->label, label);
989    edje_object_part_text_set(VIEW(item), "elm.text", item->label);
990 }
991
992 static const char *
993 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
994 {
995    if (part && strcmp(part, "default")) return NULL;
996    return ((Elm_Diskselector_Item *)it)->label;
997 }
998
999 static void
1000 _item_content_set_hook(Elm_Object_Item *it,
1001                        const char *part,
1002                        Evas_Object *content)
1003 {
1004    if (part && strcmp(part, "icon")) return;
1005    _item_icon_set((Elm_Diskselector_Item *)it, content);
1006    _check_identical_item((Elm_Diskselector_Item *)it, content);
1007 }
1008
1009 static Evas_Object *
1010 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1011 {
1012    if (part && strcmp(part, "icon")) return NULL;
1013    return ((Elm_Diskselector_Item *)it)->icon;
1014 }
1015
1016
1017 EAPI Evas_Object *
1018 elm_diskselector_add(Evas_Object *parent)
1019 {
1020    Evas *e;
1021    Evas_Object *obj;
1022    Widget_Data *wd;
1023
1024    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1025
1026    ELM_SET_WIDTYPE(widtype, "diskselector");
1027    elm_widget_type_set(obj, "diskselector");
1028    elm_widget_sub_object_add(parent, obj);
1029    elm_widget_data_set(obj, wd);
1030    elm_widget_del_hook_set(obj, _del_hook);
1031    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1032    elm_widget_theme_hook_set(obj, _theme_hook);
1033    elm_widget_can_focus_set(obj, EINA_TRUE);
1034    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1035    elm_widget_event_hook_set(obj, _event_hook);
1036
1037    wd->self = obj;
1038    wd->item_count = 0;
1039    wd->round = EINA_FALSE;
1040    wd->init = EINA_FALSE;
1041    wd->len_side = 3;
1042    wd->display_item_num_by_api = EINA_FALSE;
1043
1044    wd->scroller = elm_smart_scroller_add(e);
1045    elm_smart_scroller_widget_set(wd->scroller, obj);
1046    _theme_hook(obj);
1047    elm_widget_resize_object_set(obj, wd->scroller);
1048    elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1049                                  ELM_SMART_SCROLLER_POLICY_OFF);
1050    elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1051    evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1052                                   wd);
1053    evas_object_smart_callback_add(wd->scroller, "animate,stop",
1054                                   _scroller_stop_cb, obj);
1055    evas_object_smart_callback_add(wd->scroller, "animate,start",
1056                                   _scroller_start_cb, obj);
1057    evas_object_smart_callback_add(wd->scroller, "drag,stop",
1058                                   _drag_stop_cb, obj);
1059    evas_object_smart_callback_add(wd->scroller, "drag,start",
1060                                   _drag_start_cb, obj);
1061
1062    _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1063                          "default");
1064    evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1065                                   _diskselector_object_resize, obj);
1066
1067    wd->main_box = elm_box_add(parent);
1068    elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1069    elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1070    evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1071                                     EVAS_HINT_EXPAND);
1072    evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1073                                    EVAS_HINT_FILL);
1074    _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1075                          "default");
1076    elm_widget_sub_object_add(obj, wd->main_box);
1077
1078    elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1079
1080    wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1081    _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1082                          "default");
1083    evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1084                                     EVAS_HINT_EXPAND);
1085    evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1086                                    EVAS_HINT_FILL);
1087    elm_box_pack_end(wd->main_box, wd->left_blank);
1088    evas_object_show(wd->left_blank);
1089
1090    wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1091    _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1092                          "default");
1093    evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1094                                     EVAS_HINT_EXPAND);
1095    evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1096                                    EVAS_HINT_FILL);
1097    elm_box_pack_end(wd->main_box, wd->right_blank);
1098    evas_object_show(wd->right_blank);
1099
1100    _theme_data_get(wd);
1101
1102    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1103    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1104    _sizing_eval(obj);
1105    return obj;
1106 }
1107
1108 EAPI Eina_Bool
1109 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1110 {
1111    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1112    Widget_Data *wd = elm_widget_data_get(obj);
1113    if (!wd) return EINA_FALSE;
1114    return wd->round;
1115 }
1116
1117 EAPI void
1118 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1119 {
1120    Eina_List *elist;
1121    Elm_Diskselector_Item *it;
1122
1123    ELM_CHECK_WIDTYPE(obj, widtype);
1124    Widget_Data *wd = elm_widget_data_get(obj);
1125    if (!wd) return;
1126
1127    if (wd->round == enabled)
1128      return;
1129
1130    wd->round = !!enabled;
1131    if (enabled)
1132      {
1133         wd->r_items = eina_list_clone(wd->items);
1134         elm_box_unpack(wd->main_box, wd->left_blank);
1135         evas_object_hide(wd->left_blank);
1136         elm_box_unpack(wd->main_box, wd->right_blank);
1137         evas_object_hide(wd->right_blank);
1138         if (!wd->items)
1139           return;
1140
1141         _round_items_add(wd);
1142
1143         if (wd->last)
1144           elm_box_pack_start(wd->main_box, wd->VIEW(last));
1145         if (wd->s_last)
1146           elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1147
1148         // if more than 3 items should be displayed
1149         EINA_LIST_FOREACH(wd->under_items, elist, it)
1150            elm_box_pack_start(wd->main_box, VIEW(it));
1151
1152         if (wd->first)
1153           elm_box_pack_end(wd->main_box, wd->VIEW(first));
1154         if (wd->second)
1155           elm_box_pack_end(wd->main_box, wd->VIEW(second));
1156
1157         // if more than 3 items should be displayed
1158         EINA_LIST_FOREACH(wd->over_items, elist, it)
1159            elm_box_pack_end(wd->main_box, VIEW(it));
1160      }
1161    else
1162      {
1163         _round_items_del(wd);
1164         elm_box_pack_start(wd->main_box, wd->left_blank);
1165         elm_box_pack_end(wd->main_box, wd->right_blank);
1166         eina_list_free(wd->r_items);
1167         wd->r_items = NULL;
1168      }
1169
1170    _selected_item_indicate(wd->selected_item);
1171    _sizing_eval(obj);
1172 }
1173
1174 EAPI int
1175 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1176 {
1177    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1178    Widget_Data *wd = elm_widget_data_get(obj);
1179    if (!wd) return 0;
1180    return wd->len_side;
1181 }
1182
1183 EAPI void
1184 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1185 {
1186    ELM_CHECK_WIDTYPE(obj, widtype);
1187    Widget_Data *wd = elm_widget_data_get(obj);
1188    if (!wd) return;
1189    wd->len_side = len;
1190 }
1191
1192 EAPI void
1193 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1194 {
1195    ELM_CHECK_WIDTYPE(obj, widtype);
1196    Widget_Data *wd = elm_widget_data_get(obj);
1197    if (!wd) return;
1198    if (wd->scroller)
1199      elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1200 }
1201
1202 EAPI void
1203 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1204 {
1205    ELM_CHECK_WIDTYPE(obj, widtype);
1206    Widget_Data *wd = elm_widget_data_get(obj);
1207    if (!wd) return;
1208    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1209 }
1210
1211 EAPI void
1212 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1213 {
1214    ELM_CHECK_WIDTYPE(obj, widtype);
1215    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1216    Widget_Data *wd = elm_widget_data_get(obj);
1217    if ((!wd) || (!wd->scroller)) return;
1218    elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1219    *policy_h = (Elm_Scroller_Policy) s_policy_h;
1220    *policy_v = (Elm_Scroller_Policy) s_policy_v;
1221 }
1222
1223 EAPI void
1224 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1225 {
1226    ELM_CHECK_WIDTYPE(obj, widtype);
1227    Widget_Data *wd = elm_widget_data_get(obj);
1228    if ((!wd) || (!wd->scroller)) return;
1229    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1230        (policy_v >= ELM_SCROLLER_POLICY_LAST))
1231      return;
1232    elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1233 }
1234
1235 EAPI void
1236 elm_diskselector_clear(Evas_Object *obj)
1237 {
1238    ELM_CHECK_WIDTYPE(obj, widtype);
1239    Widget_Data *wd = elm_widget_data_get(obj);
1240    Elm_Diskselector_Item *it;
1241
1242    if (!wd) return;
1243    if (!wd->items) return;
1244
1245    wd->selected_item = NULL;
1246    EINA_LIST_FREE(wd->items, it)
1247      {
1248         _item_del(it);
1249         elm_widget_item_free(it);
1250      }
1251    _round_items_del(wd);
1252    _sizing_eval(obj);
1253 }
1254
1255 EAPI const Eina_List *
1256 elm_diskselector_items_get(const Evas_Object *obj)
1257 {
1258    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1259    Widget_Data *wd = elm_widget_data_get(obj);
1260    if (!wd) return NULL;
1261    return wd->items;
1262 }
1263
1264 EAPI Elm_Object_Item *
1265 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1266 {
1267    Elm_Diskselector_Item *it;
1268    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269    Widget_Data *wd = elm_widget_data_get(obj);
1270    if (!wd) return NULL;
1271
1272    it = _item_new(obj, icon, label, func, data);
1273    wd->items = eina_list_append(wd->items, it);
1274    it->node = eina_list_last(wd->items);
1275    wd->item_count++;
1276    if (wd->round)
1277      {
1278         _round_items_del(wd);
1279         wd->r_items = eina_list_append(wd->r_items, it);
1280         _round_items_add(wd);
1281         if (wd->last)
1282           elm_box_pack_start(wd->main_box, wd->VIEW(last));
1283         if (wd->s_last)
1284           elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1285         elm_box_pack_end(wd->main_box, VIEW(it));
1286         if (wd->first)
1287           elm_box_pack_end(wd->main_box, wd->VIEW(first));
1288         if (wd->second)
1289           elm_box_pack_end(wd->main_box, wd->VIEW(second));
1290      }
1291    else
1292      {
1293         elm_box_unpack(wd->main_box, wd->right_blank);
1294         elm_box_pack_end(wd->main_box, VIEW(it));
1295         elm_box_pack_end(wd->main_box, wd->right_blank);
1296      }
1297    if (!wd->selected_item)
1298      wd->selected_item = it;
1299    if (!wd->idler)
1300      wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1301    _sizing_eval(obj);
1302    return (Elm_Object_Item *)it;
1303 }
1304
1305 EAPI Elm_Object_Item *
1306 elm_diskselector_selected_item_get(const Evas_Object *obj)
1307 {
1308    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1309    Widget_Data *wd = elm_widget_data_get(obj);
1310    if (!wd) return NULL;
1311    return (Elm_Object_Item *) wd->selected_item;
1312 }
1313
1314 EAPI void
1315 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1316 {
1317    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1318    Widget_Data *wd;
1319    Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1320    wd = elm_widget_data_get(WIDGET(item));
1321    if (!wd) return;
1322
1323    if ((wd->selected_item == item) && (selected))
1324      return;
1325
1326    if ((wd->selected_item == item) && (!selected))
1327      wd->selected_item = eina_list_data_get(wd->items);
1328    else
1329      {
1330         wd->selected_item = item;
1331         _selected_item_indicate(wd->selected_item);
1332      }
1333
1334    if (!wd->idler)
1335      wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1336 }
1337
1338 EAPI Eina_Bool
1339 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1340 {
1341    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1342    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1343    if (!wd) return EINA_FALSE;
1344    return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1345 }
1346
1347 EAPI Elm_Object_Item *
1348 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1349 {
1350    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1351    Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1352    if (item->node->prev) return item->node->prev->data;
1353    else return NULL;
1354 }
1355
1356 EAPI Elm_Object_Item *
1357 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1358 {
1359    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1360    Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1361    if (item->node->next) return item->node->next->data;
1362    else return NULL;
1363 }
1364
1365 EAPI Elm_Object_Item *
1366 elm_diskselector_first_item_get(const Evas_Object *obj)
1367 {
1368    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1369    Widget_Data *wd = elm_widget_data_get(obj);
1370    if (!wd || !wd->items) return NULL;
1371    return eina_list_data_get(wd->items);
1372 }
1373
1374 EAPI Elm_Object_Item *
1375 elm_diskselector_last_item_get(const Evas_Object *obj)
1376 {
1377    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1378    Widget_Data *wd = elm_widget_data_get(obj);
1379    if (!wd || !wd->items) return NULL;
1380    return eina_list_data_get(eina_list_last(wd->items));
1381 }
1382
1383 EAPI void
1384 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1385 {
1386    ELM_CHECK_WIDTYPE(obj, widtype);
1387    Widget_Data *wd = elm_widget_data_get(obj);
1388    if (!wd) return;
1389    if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1390    wd->display_item_num = num;
1391    wd->display_item_num_by_api = EINA_TRUE;
1392 }
1393
1394 EAPI int
1395 elm_diskselector_display_item_num_get(const Evas_Object *item)
1396 {
1397    ELM_CHECK_WIDTYPE(item, widtype) (-1);
1398    Widget_Data *wd = elm_widget_data_get(item);
1399    if (!wd) return -1;
1400    return wd->display_item_num;
1401 }