Elementary migration revision 70375
[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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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    Evas_Object *parent;
389    str = edje_object_data_get(wd->right_blank, "len_threshold");
390    if (str) wd->len_threshold = MAX(0, atoi(str));
391    else wd->len_threshold = 0;
392
393    if (!wd->display_item_num_by_api)
394      {
395         str = edje_object_data_get(wd->right_blank, "display_item_num");
396         if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
397         else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
398      }
399
400    str = edje_object_data_get(wd->right_blank, "min_width");
401    if (str) wd->minw = MAX(-1, atoi(str)) * elm_scale_get();
402    else
403      {
404         parent = elm_widget_parent_widget_get(wd->self);
405         if (!parent) wd->minw = -1;
406         else evas_object_geometry_get(parent, NULL, NULL, &wd->minw, NULL);
407      }
408
409    str = edje_object_data_get(wd->right_blank, "min_height");
410    if (str) wd->minh = MAX(-1, atoi(str)) * elm_scale_get();
411    else wd->minh = -1;
412 }
413
414 static void
415 _del_hook(Evas_Object * obj)
416 {
417    Widget_Data *wd = elm_widget_data_get(obj);
418    if (!wd) return;
419    free(wd);
420 }
421
422 static void
423 _del_pre_hook(Evas_Object * obj)
424 {
425    Elm_Diskselector_Item *it;
426    Eina_List *l;
427
428    Widget_Data *wd = elm_widget_data_get(obj);
429    if (!wd) return;
430
431    if (wd->left_blank)
432      evas_object_del(wd->left_blank);
433    if (wd->right_blank)
434      evas_object_del(wd->right_blank);
435    if (wd->last)
436      {
437         eina_stringshare_del(wd->last->label);
438         evas_object_del(wd->VIEW(last));
439         free(wd->last);
440      }
441    if (wd->s_last)
442      {
443         eina_stringshare_del(wd->s_last->label);
444         evas_object_del(wd->VIEW(s_last));
445         free(wd->s_last);
446      }
447    if (wd->second)
448      {
449         eina_stringshare_del(wd->second->label);
450         evas_object_del(wd->VIEW(second));
451         free(wd->second);
452      }
453    if (wd->first)
454      {
455         eina_stringshare_del(wd->first->label);
456         evas_object_del(wd->VIEW(first));
457         free(wd->first);
458      }
459
460    EINA_LIST_FOREACH(wd->under_items, l, it)
461      {
462         if (it)
463           {
464              eina_stringshare_del(it->label);
465              evas_object_del(VIEW(it));
466              free(it);
467           }
468      }
469
470    EINA_LIST_FOREACH(wd->over_items, l, it)
471    {
472      if (it)
473         {
474            eina_stringshare_del(it->label);
475            evas_object_del(VIEW(it));
476            free(it);
477         }
478    }
479
480    EINA_LIST_FREE(wd->items, it)
481      {
482         _item_del(it);
483         elm_widget_item_free(it);
484      }
485    eina_list_free(wd->r_items);
486 }
487
488 static void
489 _sizing_eval(Evas_Object * obj)
490 {
491    Widget_Data *wd = elm_widget_data_get(obj);
492    if (!wd) return;
493    _diskselector_object_resize(obj, NULL, obj, NULL);
494 }
495
496 static void
497 _theme_hook(Evas_Object * obj)
498 {
499    Eina_List *l;
500    Elm_Diskselector_Item *it;
501    Widget_Data *wd = elm_widget_data_get(obj);
502    if (!wd) return;
503
504    if (wd->scroller)
505      elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
506                                          "base", elm_widget_style_get(obj));
507    if (wd->round)
508      {
509         EINA_LIST_FOREACH(wd->r_items, l, it)
510           {
511              _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
512                                    elm_widget_style_get(obj));
513              edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
514           }
515      }
516    else
517      {
518         EINA_LIST_FOREACH(wd->items, l, it)
519           {
520              _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
521                                    elm_widget_style_get(obj));
522              edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
523           }
524      }
525    _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
526                                    elm_widget_style_get(obj));
527    _theme_data_get(wd);
528    _sizing_eval(obj);
529 }
530
531 static void
532 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
533 {
534    Widget_Data *wd = elm_widget_data_get(obj);
535    Evas_Object *sub = event_info;
536    Elm_Diskselector_Item *it;
537    const Eina_List *l;
538
539    if (!wd) return;
540    if (!sub) abort();
541    if (sub == wd->scroller)
542      wd->scroller = NULL;
543    else
544      {
545         EINA_LIST_FOREACH(wd->items, l, it)
546           {
547              if (sub == it->icon)
548                {
549                   it->icon = NULL;
550                   _sizing_eval(obj);
551                   break;
552                }
553           }
554      }
555 }
556
557 static void
558 _select_item(Elm_Diskselector_Item *it)
559 {
560    if (!it) return;
561    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
562    wd->selected_item = it;
563    _selected_item_indicate(wd->selected_item);
564    if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
565    evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
566 }
567
568 static void
569 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
570 {
571    Widget_Data *wd = elm_widget_data_get(obj);
572    if (!wd)
573      return;
574
575    if (elm_widget_focus_get(obj))
576      {
577         edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
578         evas_object_focus_set(wd->self, EINA_TRUE);
579      }
580    else
581      {
582         edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
583         evas_object_focus_set(wd->self, EINA_FALSE);
584      }
585 }
586
587 static Eina_Bool
588 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
589 {
590    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
591    Evas_Event_Key_Down *ev = event_info;
592    Widget_Data *wd = elm_widget_data_get(obj);
593    if (!wd) return EINA_FALSE;
594    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
595    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
596
597    Elm_Diskselector_Item *it = NULL;
598    Eina_List *l;
599
600    if (!wd->selected_item) {
601         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
602         return EINA_TRUE;
603    }
604
605    if ((!strcmp(ev->keyname, "Left")) ||
606        ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)) ||
607        (!strcmp(ev->keyname, "Up"))  ||
608        ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
609      {
610         l = wd->selected_item->node->prev;
611         if ((!l) && (wd->round))
612           l = eina_list_last(wd->items);
613      }
614    else if ((!strcmp(ev->keyname, "Right")) ||
615             ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)) ||
616             (!strcmp(ev->keyname, "Down")) ||
617             ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
618      {
619         l = wd->selected_item->node->next;
620         if ((!l) && (wd->round))
621           l = wd->items;
622      }
623    else if ((!strcmp(ev->keyname, "Home")) ||
624             ((!strcmp(ev->keyname, "KP_Home")) && (!ev->string)))
625      l = wd->items;
626    else if ((!strcmp(ev->keyname, "End")) ||
627             ((!strcmp(ev->keyname, "KP_End")) && (!ev->string)))
628      l = eina_list_last(wd->items);
629    else return EINA_FALSE;
630
631    if (l)
632      it = eina_list_data_get(l);
633
634    if (it)
635      {
636         wd->selected_item = it;
637         if (!wd->idler)
638           wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
639      }
640
641    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
642    return EINA_TRUE;
643 }
644
645 static void
646 _selected_item_indicate(Elm_Diskselector_Item *it)
647 {
648    Elm_Diskselector_Item *item;
649    Eina_List *l;
650    Widget_Data *wd;
651    wd = elm_widget_data_get(WIDGET(it));
652
653    if (!wd) return;
654    if (!it->label) return;
655
656    EINA_LIST_FOREACH(wd->r_items, l, item)
657      {
658         if (item->label && !strcmp(item->label, it->label))
659            edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
660         else
661            edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
662      }
663 }
664
665 static void
666 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
667                const char *emission __UNUSED__, const char *source __UNUSED__)
668 {
669    Elm_Diskselector_Item *it = data;
670
671    if (!it) return;
672
673    Widget_Data *wd;
674    wd = elm_widget_data_get(WIDGET(it));
675
676    if (!wd) return;
677
678    if (wd->selected_item != it)
679      {
680         wd->selected_item = it;
681         _selected_item_indicate(wd->selected_item);
682      }
683
684    if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
685 }
686
687 static void
688 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
689 {
690    Evas_Coord x, y, w, h, bw;
691    Widget_Data *wd = data;
692
693    _check_string(wd);
694    elm_smart_scroller_child_pos_get(obj, &x, &y);
695    elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
696    if (wd->round)
697      {
698         evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
699         if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
700            elm_smart_scroller_child_region_show(wd->scroller,
701                                                x - ((w / wd->display_item_num) * wd->item_count),
702                                                y, w, h);
703         else if (x < 0)
704            elm_smart_scroller_child_region_show(wd->scroller,
705                                                x + ((w / wd->display_item_num) * wd->item_count),
706                                                y, w, h);
707      }
708 }
709
710 static void
711 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
712 {
713    Elm_Diskselector_Item *it;
714    Widget_Data *wd = elm_widget_data_get(data);
715    Evas_Coord x, w, ow;
716    Eina_List *l, *list;
717
718    if (wd->idler) return;
719
720    if (!wd->round)
721      list = wd->items;
722    else
723      list = wd->r_items;
724
725    evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
726    EINA_LIST_FOREACH(list, l, it)
727      {
728         evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
729         if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
730      }
731
732    if (!it) return;
733    _select_item(it);
734    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, it);
735 }
736
737 static void
738 _scroller_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
739 {
740    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START,
741                                    elm_diskselector_selected_item_get(data));
742 }
743
744 static void
745 _drag_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
746 {
747    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START,
748                                    elm_diskselector_selected_item_get(data));
749 }
750
751 static void
752 _drag_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
753 {
754    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP,
755                                    elm_diskselector_selected_item_get(data));
756 }
757
758 static Eina_Bool
759 _move_scroller(void *data)
760 {
761    Evas_Object *obj = data;
762    Widget_Data *wd;
763    Eina_List *list, *l;
764    Elm_Diskselector_Item *dit;
765    Evas_Coord y, w, h;
766    int i;
767
768    wd = elm_widget_data_get(obj);
769    if (!wd) return EINA_FALSE;
770
771    if (!wd->round)
772      {
773         i = 0;
774         list = wd->items;
775      }
776    else
777      {
778         i = 1;
779         list = wd->r_items;
780      }
781
782    EINA_LIST_FOREACH(list, l, dit)
783      {
784         if (wd->selected_item == dit)
785            break;
786         i++;
787      }
788
789    if (wd->round) i -= CEIL(wd->display_item_num);
790
791    if (!dit)
792      {
793         wd->selected_item =
794            (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
795         return EINA_FALSE;
796      }
797
798    evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
799    //move scroller in two steps for getting smooth launching effect.
800    if (i > 2)
801      elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * (i-2), y, w, h);
802    elm_smart_scroller_region_bring_in(wd->scroller, w / wd->display_item_num * i, y, w, h);
803
804    _select_item(dit);
805    if (wd->idler)
806      {
807         ecore_idle_enterer_del(wd->idler);
808         wd->idler = NULL;
809      }
810    wd->init = EINA_TRUE;
811    _check_string(wd);
812
813    return EINA_TRUE;
814 }
815
816 static void
817 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
818 {
819    if (!it) return;
820    elm_box_unpack(wd->main_box, VIEW(it));
821    wd->r_items = eina_list_remove(wd->r_items, it);
822    eina_stringshare_del(it->label);
823    elm_widget_item_free(it);
824 }
825
826 static void
827 _round_items_del(Widget_Data *wd)
828 {
829    Eina_List *l;
830    Elm_Diskselector_Item * it;
831
832    _round_item_del(wd, wd->last);
833    wd->last = NULL;
834    _round_item_del(wd, wd->s_last);
835    wd->s_last = NULL;
836    _round_item_del(wd, wd->second);
837    wd->second = NULL;
838    _round_item_del(wd, wd->first);
839    wd->first = NULL;
840
841    EINA_LIST_FOREACH(wd->under_items, l, it)
842      {
843         _round_item_del(wd, it);
844      }
845    wd->under_items = eina_list_free(wd->under_items);
846
847    EINA_LIST_FOREACH(wd->over_items, l, it)
848      {
849         _round_item_del(wd, it);
850      }
851    wd->over_items = eina_list_free(wd->over_items);
852 }
853
854 static void
855 _round_items_add(Widget_Data *wd)
856 {
857    Elm_Diskselector_Item *dit;
858    Elm_Diskselector_Item *it;
859    Elm_Diskselector_Item *temp_it;
860    int i = 0;
861    dit = it = eina_list_nth(wd->items, 0);
862    if (!dit) return;
863
864    if (!wd->first)
865      {
866         wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
867                               it->base.data);
868         wd->first->node = it->node;
869         wd->r_items = eina_list_append(wd->r_items, wd->first);
870      }
871
872    it = eina_list_nth(wd->items, 1);
873    if (!it)
874      it = dit;
875    if (!wd->second)
876      {
877         wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
878                                it->base.data);
879         wd->second->node = it->node;
880         wd->r_items = eina_list_append(wd->r_items, wd->second);
881      }
882
883    // if more than 3 itmes should be displayed
884    for (i = 2; i < CEIL(wd->display_item_num); i++)
885      {
886         it = eina_list_nth(wd->items, i);
887         if (!it) it = dit;
888         temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
889         wd->over_items = eina_list_append(wd->over_items, temp_it);
890         wd->r_items = eina_list_append(wd->r_items, temp_it);
891      }
892
893    it = eina_list_nth(wd->items, wd->item_count - 1);
894    if (!it)
895      it = dit;
896    if (!wd->last)
897      {
898         wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
899                              it->base.data);
900         wd->last->node = it->node;
901         wd->r_items = eina_list_prepend(wd->r_items, wd->last);
902      }
903
904    it = eina_list_nth(wd->items, wd->item_count - 2);
905    if (!it)
906      it = dit;
907    if (!wd->s_last)
908      {
909         wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
910                                it->base.data);
911         wd->s_last->node = it->node;
912         wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
913      }
914
915    // if more than 3 itmes should be displayed
916    for (i = 3; i <= CEIL(wd->display_item_num); i++)
917      {
918         it = eina_list_nth(wd->items, wd->item_count - i);
919         if (!it) it = dit;
920         temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
921         wd->under_items = eina_list_append(wd->under_items, temp_it);
922         wd->r_items = eina_list_prepend(wd->r_items, temp_it);
923      }
924 }
925
926 static void
927 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
928 {
929    if (it->icon == icon) return;
930    if (it->icon) evas_object_del(it->icon);
931    it->icon = icon;
932    if (VIEW(it))
933      {
934         evas_object_size_hint_min_set(it->icon, 24, 24);
935         evas_object_size_hint_max_set(it->icon, 40, 40);
936         edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
937         evas_object_show(it->icon);
938         elm_widget_sub_object_add(WIDGET(it), it->icon);
939      }
940 }
941
942 static void
943 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
944 {
945    Widget_Data *wd;
946    Elm_Diskselector_Item *dit;
947    Eina_List *l;
948    int idx = 0;
949    int ic = 0;
950    int ac = 0;
951
952    wd = elm_widget_data_get(WIDGET(it));
953    if (!wd) return;
954
955    if (wd->round)
956      {
957         // Get index from indentical item from round items
958         EINA_LIST_FOREACH(wd->r_items, l, dit)
959           {
960              if (it == dit) break;
961              idx++;
962           }
963
964         // No item to match
965         ic = eina_list_count(wd->r_items);
966         if (idx >= ic) return;
967         dit = NULL;
968
969         // Number of added items: CEIL(wd->display_item_num)
970         ac = CEIL(wd->display_item_num);
971
972         if (((idx >= 0) && (idx < ac)) ||
973             ((idx >= ac) && (idx < (2 * ac))))
974           {
975               // Selected item: under, low region
976              dit = eina_list_nth(wd->r_items,
977                                  idx + ic - (2 * ac));
978           }
979         else if (((idx >= (ic - ac)) && (idx < ic)) ||
980                  ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
981           {
982               // Selected item: over, high region
983               dit = eina_list_nth(wd->r_items,
984                                   idx - ic + (2 * ac));
985           }
986
987         if (dit) _item_icon_set(dit, icon);
988         _sizing_eval(wd->self);
989      }
990 }
991
992 static void
993 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
994 {
995    Elm_Diskselector_Item *item;
996    if (part && strcmp(part, "default")) return;
997    item = (Elm_Diskselector_Item *)it;
998    eina_stringshare_replace(&item->label, label);
999    edje_object_part_text_escaped_set(VIEW(item), "elm.text", item->label);
1000 }
1001
1002 static const char *
1003 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1004 {
1005    if (part && strcmp(part, "default")) return NULL;
1006    return ((Elm_Diskselector_Item *)it)->label;
1007 }
1008
1009 static void
1010 _item_content_set_hook(Elm_Object_Item *it,
1011                        const char *part,
1012                        Evas_Object *content)
1013 {
1014    if (part && strcmp(part, "icon")) return;
1015    _item_icon_set((Elm_Diskselector_Item *)it, content);
1016    _check_identical_item((Elm_Diskselector_Item *)it, content);
1017 }
1018
1019 static Evas_Object *
1020 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1021 {
1022    if (part && strcmp(part, "icon")) return NULL;
1023    return ((Elm_Diskselector_Item *)it)->icon;
1024 }
1025
1026 EAPI Evas_Object *
1027 elm_diskselector_add(Evas_Object *parent)
1028 {
1029    Evas *e;
1030    Evas_Object *obj;
1031    Widget_Data *wd;
1032
1033    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1034
1035    ELM_SET_WIDTYPE(widtype, "diskselector");
1036    elm_widget_type_set(obj, "diskselector");
1037    elm_widget_sub_object_add(parent, obj);
1038    elm_widget_data_set(obj, wd);
1039    elm_widget_del_hook_set(obj, _del_hook);
1040    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1041    elm_widget_theme_hook_set(obj, _theme_hook);
1042    elm_widget_can_focus_set(obj, EINA_TRUE);
1043    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1044    elm_widget_event_hook_set(obj, _event_hook);
1045
1046    wd->self = obj;
1047    wd->item_count = 0;
1048    wd->round = EINA_FALSE;
1049    wd->init = EINA_FALSE;
1050    wd->len_side = 3;
1051    wd->display_item_num_by_api = EINA_FALSE;
1052
1053    wd->scroller = elm_smart_scroller_add(e);
1054    elm_smart_scroller_widget_set(wd->scroller, obj);
1055    _theme_hook(obj);
1056    elm_widget_resize_object_set(obj, wd->scroller);
1057    elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1058                                  ELM_SMART_SCROLLER_POLICY_OFF);
1059    elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1060    evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1061                                   wd);
1062    evas_object_smart_callback_add(wd->scroller, "animate,stop",
1063                                   _scroller_stop_cb, obj);
1064    evas_object_smart_callback_add(wd->scroller, "animate,start",
1065                                   _scroller_start_cb, obj);
1066    evas_object_smart_callback_add(wd->scroller, "drag,stop",
1067                                   _drag_stop_cb, obj);
1068    evas_object_smart_callback_add(wd->scroller, "drag,start",
1069                                   _drag_start_cb, obj);
1070
1071    _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1072                          "default");
1073    evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1074                                   _diskselector_object_resize, obj);
1075
1076    wd->main_box = elm_box_add(parent);
1077    elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1078    elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1079    evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1080                                     EVAS_HINT_EXPAND);
1081    evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1082                                    EVAS_HINT_FILL);
1083    _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1084                          "default");
1085    elm_widget_sub_object_add(obj, wd->main_box);
1086
1087    elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1088
1089    wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1090    _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1091                          "default");
1092    evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1093                                     EVAS_HINT_EXPAND);
1094    evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1095                                    EVAS_HINT_FILL);
1096    elm_box_pack_end(wd->main_box, wd->left_blank);
1097    evas_object_show(wd->left_blank);
1098
1099    wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1100    _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1101                          "default");
1102    evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1103                                     EVAS_HINT_EXPAND);
1104    evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1105                                    EVAS_HINT_FILL);
1106    elm_box_pack_end(wd->main_box, wd->right_blank);
1107    evas_object_show(wd->right_blank);
1108
1109    _theme_data_get(wd);
1110
1111    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1112    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1113    _sizing_eval(obj);
1114    return obj;
1115 }
1116
1117 EAPI Eina_Bool
1118 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1119 {
1120    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1121    Widget_Data *wd = elm_widget_data_get(obj);
1122    if (!wd) return EINA_FALSE;
1123    return wd->round;
1124 }
1125
1126 EAPI void
1127 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1128 {
1129    Eina_List *elist;
1130    Elm_Diskselector_Item *it;
1131
1132    ELM_CHECK_WIDTYPE(obj, widtype);
1133    Widget_Data *wd = elm_widget_data_get(obj);
1134    if (!wd) return;
1135
1136    if (wd->round == enabled)
1137      return;
1138
1139    wd->round = !!enabled;
1140    if (enabled)
1141      {
1142         wd->r_items = eina_list_clone(wd->items);
1143         elm_box_unpack(wd->main_box, wd->left_blank);
1144         evas_object_hide(wd->left_blank);
1145         elm_box_unpack(wd->main_box, wd->right_blank);
1146         evas_object_hide(wd->right_blank);
1147         if (!wd->items)
1148           return;
1149
1150         _round_items_add(wd);
1151
1152         if (wd->last)
1153           elm_box_pack_start(wd->main_box, wd->VIEW(last));
1154         if (wd->s_last)
1155           elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1156
1157         // if more than 3 items should be displayed
1158         EINA_LIST_FOREACH(wd->under_items, elist, it)
1159            elm_box_pack_start(wd->main_box, VIEW(it));
1160
1161         if (wd->first)
1162           elm_box_pack_end(wd->main_box, wd->VIEW(first));
1163         if (wd->second)
1164           elm_box_pack_end(wd->main_box, wd->VIEW(second));
1165
1166         // if more than 3 items should be displayed
1167         EINA_LIST_FOREACH(wd->over_items, elist, it)
1168            elm_box_pack_end(wd->main_box, VIEW(it));
1169      }
1170    else
1171      {
1172         _round_items_del(wd);
1173         elm_box_pack_start(wd->main_box, wd->left_blank);
1174         elm_box_pack_end(wd->main_box, wd->right_blank);
1175         eina_list_free(wd->r_items);
1176         wd->r_items = NULL;
1177      }
1178
1179    _selected_item_indicate(wd->selected_item);
1180    _sizing_eval(obj);
1181 }
1182
1183 EAPI int
1184 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1185 {
1186    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1187    Widget_Data *wd = elm_widget_data_get(obj);
1188    if (!wd) return 0;
1189    return wd->len_side;
1190 }
1191
1192 EAPI void
1193 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1194 {
1195    ELM_CHECK_WIDTYPE(obj, widtype);
1196    Widget_Data *wd = elm_widget_data_get(obj);
1197    if (!wd) return;
1198    wd->len_side = len;
1199 }
1200
1201 EAPI void
1202 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1203 {
1204    ELM_CHECK_WIDTYPE(obj, widtype);
1205    Widget_Data *wd = elm_widget_data_get(obj);
1206    if (!wd) return;
1207    if (wd->scroller)
1208      elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1209 }
1210
1211 EAPI void
1212 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1213 {
1214    ELM_CHECK_WIDTYPE(obj, widtype);
1215    Widget_Data *wd = elm_widget_data_get(obj);
1216    if (!wd) return;
1217    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1218 }
1219
1220 EAPI void
1221 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1222 {
1223    ELM_CHECK_WIDTYPE(obj, widtype);
1224    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1225    Widget_Data *wd = elm_widget_data_get(obj);
1226    if ((!wd) || (!wd->scroller)) return;
1227    elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1228    *policy_h = (Elm_Scroller_Policy) s_policy_h;
1229    *policy_v = (Elm_Scroller_Policy) s_policy_v;
1230 }
1231
1232 EAPI void
1233 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1234 {
1235    ELM_CHECK_WIDTYPE(obj, widtype);
1236    Widget_Data *wd = elm_widget_data_get(obj);
1237    if ((!wd) || (!wd->scroller)) return;
1238    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1239        (policy_v >= ELM_SCROLLER_POLICY_LAST))
1240      return;
1241    elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1242 }
1243
1244 EAPI void
1245 elm_diskselector_clear(Evas_Object *obj)
1246 {
1247    ELM_CHECK_WIDTYPE(obj, widtype);
1248    Widget_Data *wd = elm_widget_data_get(obj);
1249    Elm_Diskselector_Item *it;
1250
1251    if (!wd) return;
1252    if (!wd->items) return;
1253
1254    wd->selected_item = NULL;
1255    EINA_LIST_FREE(wd->items, it)
1256      {
1257         _item_del(it);
1258         elm_widget_item_free(it);
1259      }
1260    _round_items_del(wd);
1261    _sizing_eval(obj);
1262 }
1263
1264 EAPI const Eina_List *
1265 elm_diskselector_items_get(const Evas_Object *obj)
1266 {
1267    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1268    Widget_Data *wd = elm_widget_data_get(obj);
1269    if (!wd) return NULL;
1270    return wd->items;
1271 }
1272
1273 EAPI Elm_Object_Item *
1274 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1275 {
1276    Elm_Diskselector_Item *it;
1277    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1278    Widget_Data *wd = elm_widget_data_get(obj);
1279    if (!wd) return NULL;
1280
1281    it = _item_new(obj, icon, label, func, data);
1282    wd->items = eina_list_append(wd->items, it);
1283    it->node = eina_list_last(wd->items);
1284    wd->item_count++;
1285    if (wd->round)
1286      {
1287         _round_items_del(wd);
1288         wd->r_items = eina_list_append(wd->r_items, it);
1289         _round_items_add(wd);
1290         if (wd->last)
1291           elm_box_pack_start(wd->main_box, wd->VIEW(last));
1292         if (wd->s_last)
1293           elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1294         elm_box_pack_end(wd->main_box, VIEW(it));
1295         if (wd->first)
1296           elm_box_pack_end(wd->main_box, wd->VIEW(first));
1297         if (wd->second)
1298           elm_box_pack_end(wd->main_box, wd->VIEW(second));
1299      }
1300    else
1301      {
1302         elm_box_unpack(wd->main_box, wd->right_blank);
1303         elm_box_pack_end(wd->main_box, VIEW(it));
1304         elm_box_pack_end(wd->main_box, wd->right_blank);
1305      }
1306    if (!wd->selected_item)
1307      wd->selected_item = it;
1308    if (!wd->idler)
1309      wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1310    _sizing_eval(obj);
1311    return (Elm_Object_Item *)it;
1312 }
1313
1314 EAPI Elm_Object_Item *
1315 elm_diskselector_selected_item_get(const Evas_Object *obj)
1316 {
1317    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1318    Widget_Data *wd = elm_widget_data_get(obj);
1319    if (!wd) return NULL;
1320    return (Elm_Object_Item *) wd->selected_item;
1321 }
1322
1323 EAPI void
1324 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1325 {
1326    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1327    Widget_Data *wd;
1328    Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1329    wd = elm_widget_data_get(WIDGET(item));
1330    if (!wd) return;
1331
1332    if ((wd->selected_item == item) && (selected))
1333      return;
1334
1335    if ((wd->selected_item == item) && (!selected))
1336      wd->selected_item = eina_list_data_get(wd->items);
1337    else
1338      {
1339         wd->selected_item = item;
1340         _selected_item_indicate(wd->selected_item);
1341      }
1342
1343    if (!wd->idler)
1344      wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1345 }
1346
1347 EAPI Eina_Bool
1348 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1349 {
1350    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1351    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1352    if (!wd) return EINA_FALSE;
1353    return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1354 }
1355
1356 EAPI Elm_Object_Item *
1357 elm_diskselector_item_prev_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->prev) return item->node->prev->data;
1362    else return NULL;
1363 }
1364
1365 EAPI Elm_Object_Item *
1366 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1367 {
1368    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1369    Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1370    if (item->node->next) return item->node->next->data;
1371    else return NULL;
1372 }
1373
1374 EAPI Elm_Object_Item *
1375 elm_diskselector_first_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(wd->items);
1381 }
1382
1383 EAPI Elm_Object_Item *
1384 elm_diskselector_last_item_get(const Evas_Object *obj)
1385 {
1386    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1387    Widget_Data *wd = elm_widget_data_get(obj);
1388    if (!wd || !wd->items) return NULL;
1389    return eina_list_data_get(eina_list_last(wd->items));
1390 }
1391
1392 EAPI void
1393 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1394 {
1395    ELM_CHECK_WIDTYPE(obj, widtype);
1396    Widget_Data *wd = elm_widget_data_get(obj);
1397    if (!wd) return;
1398    if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1399    wd->display_item_num = num;
1400    wd->display_item_num_by_api = EINA_TRUE;
1401 }
1402
1403 EAPI int
1404 elm_diskselector_display_item_num_get(const Evas_Object *item)
1405 {
1406    ELM_CHECK_WIDTYPE(item, widtype) (-1);
1407    Widget_Data *wd = elm_widget_data_get(item);
1408    if (!wd) return -1;
1409    return wd->display_item_num;
1410 }