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