1 #include <Elementary.h>
3 #include "els_scroller.h"
6 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
10 #define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
13 #define DISPLAY_ITEM_NUM_MIN 3
15 typedef struct _Widget_Data Widget_Data;
16 typedef struct _Elm_Diskselector_Item Elm_Diskselector_Item;
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;
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;
40 Eina_Bool display_item_num_by_api:1;
43 struct _Elm_Diskselector_Item
52 static const char *widtype = NULL;
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,
71 static const char * _item_text_get_hook(const Elm_Object_Item *it,
73 static void _item_content_set_hook(Elm_Object_Item *it,
75 Evas_Object *content);
76 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
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";
85 static const Evas_Smart_Cb_Description _signals[] = {
87 {SIG_SCROLL_ANIM_START, ""},
88 {SIG_SCROLL_ANIM_STOP, ""},
89 {SIG_SCROLL_DRAG_START, ""},
90 {SIG_SCROLL_DRAG_STOP, ""},
95 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
100 wd = elm_widget_data_get(data);
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);
111 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
113 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
115 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
117 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
118 (int)(w / wd->display_item_num), 0);
121 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
125 _item_del(Elm_Diskselector_Item *item)
128 eina_stringshare_del(item->label);
130 evas_object_del(item->icon);
134 _count_letter(const char *str)
139 for (chnum = 0; ; chnum++)
141 pos = evas_string_char_next_get(str, pos, &code);
142 if (code == 0) break;
148 _check_letter(const char *str, int length)
153 for (chnum = 0; ; chnum++)
155 if (chnum == length) break;
156 pos = evas_string_char_next_get(str, pos, &code);
157 if (code == 0) break;
163 _check_string(void *data)
165 int mid, steps, length, diff;
166 Elm_Diskselector_Item *it;
170 Widget_Data *wd = data;
172 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
182 EINA_LIST_FOREACH(list, l, it)
186 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
187 /* item not visible */
188 if ((x + w <= ox) || (x >= ox + ow))
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);
196 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
198 else if (x + w >= ox + ow - 5)
199 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
203 if ((wd->len_threshold) && (len > wd->len_threshold))
204 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
207 edje_object_signal_emit(VIEW(it), "elm,state,center",
211 // if len is les that the limit len, skip anyway
212 if (len <= wd->len_side)
215 steps = len - wd->len_side + 1;
217 if (mid <= ox + ow / 2)
218 diff = (ox + ow / 2) - mid;
220 diff = mid - (ox + ow / 2);
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);
229 edje_object_part_text_set(VIEW(it), "elm.text", buf);
233 ecore_idle_enterer_del(wd->check_idler);
234 wd->check_idler = NULL;
239 _item_del_pre_hook(Elm_Object_Item *it)
241 Elm_Diskselector_Item *item, *item2, *dit;
245 item = (Elm_Diskselector_Item *)it;
246 wd = elm_widget_data_get(WIDGET(item));
247 if (!wd) return EINA_FALSE;
249 elm_box_unpack(wd->main_box, VIEW(item));
252 wd->r_items = eina_list_remove(wd->r_items, item);
254 wd->items = eina_list_remove(wd->items, item);
256 if (wd->selected_item == item)
258 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
260 wd->selected_item = dit;
262 wd->selected_item = eina_list_nth(wd->items, 1);
264 _selected_item_indicate(wd->selected_item);
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));
279 EINA_LIST_FOREACH(wd->under_items, l, item2)
280 evas_object_hide(VIEW(item2));
282 EINA_LIST_FOREACH(wd->over_items, l, item2)
283 evas_object_hide(VIEW(item2));
287 dit = eina_list_nth(wd->items, 0);
290 eina_stringshare_replace(&wd->first->label, dit->label);
291 edje_object_part_text_set(wd->VIEW(first), "elm.text",
294 dit = eina_list_nth(wd->items, 1);
297 eina_stringshare_replace(&wd->second->label, dit->label);
298 edje_object_part_text_set(wd->VIEW(second), "elm.text",
301 // if more than 3 itmes should be displayed
302 for (i = 2; i < CEIL(wd->display_item_num); i++)
304 dit = eina_list_nth(wd->items, i);
305 item2 = eina_list_nth(wd->over_items, i - 2);
306 eina_stringshare_replace(&item2->label, dit->label);
307 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
310 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
313 eina_stringshare_replace(&wd->last->label, dit->label);
314 edje_object_part_text_set(wd->VIEW(last), "elm.text",
317 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
320 eina_stringshare_replace(&wd->s_last->label, dit->label);
321 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
324 // if more than 3 itmes should be displayed
325 for (i = 3; i <= CEIL(wd->display_item_num); i++)
327 dit = eina_list_nth(wd->items, wd->item_count - i);
328 item2 = eina_list_nth(wd->under_items, i - 3);
329 eina_stringshare_replace(&item2->label, dit->label);
330 edje_object_part_text_set(VIEW(item2), "elm.text",
335 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
336 _sizing_eval(wd->self);
341 static Elm_Diskselector_Item *
342 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
344 Elm_Diskselector_Item *it;
345 const char *style = elm_widget_style_get(obj);
347 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
348 if (!it) return NULL;
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);
356 it->label = eina_stringshare_add(label);
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,
364 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
366 evas_object_show(VIEW(it));
370 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
371 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
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);
385 _theme_data_get(Widget_Data *wd)
388 str = edje_object_data_get(wd->right_blank, "len_threshold");
389 if (str) wd->len_threshold = MAX(0, atoi(str));
390 else wd->len_threshold = 0;
392 if (!wd->display_item_num_by_api)
394 str = edje_object_data_get(wd->right_blank, "display_item_num");
395 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
396 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
399 str = edje_object_data_get(wd->right_blank, "min_width");
400 if (str) wd->minw = MAX(-1, atoi(str));
403 str = edje_object_data_get(wd->right_blank, "min_height");
404 if (str) wd->minh = MAX(-1, atoi(str));
409 _del_hook(Evas_Object * obj)
411 Widget_Data *wd = elm_widget_data_get(obj);
417 _del_pre_hook(Evas_Object * obj)
419 Elm_Diskselector_Item *it;
422 Widget_Data *wd = elm_widget_data_get(obj);
426 evas_object_del(wd->left_blank);
428 evas_object_del(wd->right_blank);
431 eina_stringshare_del(wd->last->label);
432 evas_object_del(wd->VIEW(last));
437 eina_stringshare_del(wd->s_last->label);
438 evas_object_del(wd->VIEW(s_last));
443 eina_stringshare_del(wd->second->label);
444 evas_object_del(wd->VIEW(second));
449 eina_stringshare_del(wd->first->label);
450 evas_object_del(wd->VIEW(first));
454 EINA_LIST_FOREACH(wd->under_items, l, it)
458 eina_stringshare_del(it->label);
459 evas_object_del(VIEW(it));
464 EINA_LIST_FOREACH(wd->over_items, l, it)
468 eina_stringshare_del(it->label);
469 evas_object_del(VIEW(it));
474 EINA_LIST_FREE(wd->items, it)
477 elm_widget_item_free(it);
479 eina_list_free(wd->r_items);
483 _sizing_eval(Evas_Object * obj)
485 Widget_Data *wd = elm_widget_data_get(obj);
487 _diskselector_object_resize(obj, NULL, obj, NULL);
491 _theme_hook(Evas_Object * obj)
494 Elm_Diskselector_Item *it;
495 Widget_Data *wd = elm_widget_data_get(obj);
499 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
500 "base", elm_widget_style_get(obj));
503 EINA_LIST_FOREACH(wd->r_items, l, it)
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);
512 EINA_LIST_FOREACH(wd->items, l, it)
514 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
515 elm_widget_style_get(obj));
516 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
519 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
520 elm_widget_style_get(obj));
526 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
528 Widget_Data *wd = elm_widget_data_get(obj);
529 Evas_Object *sub = event_info;
530 Elm_Diskselector_Item *it;
535 if (sub == wd->scroller)
539 EINA_LIST_FOREACH(wd->items, l, it)
552 _select_item(Elm_Diskselector_Item *it)
555 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
556 wd->selected_item = it;
557 _selected_item_indicate(wd->selected_item);
558 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
559 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
563 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
565 Widget_Data *wd = elm_widget_data_get(obj);
569 if (elm_widget_focus_get(obj))
571 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
572 evas_object_focus_set(wd->self, EINA_TRUE);
576 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
577 evas_object_focus_set(wd->self, EINA_FALSE);
582 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
584 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
585 Evas_Event_Key_Down *ev = event_info;
586 Widget_Data *wd = elm_widget_data_get(obj);
587 if (!wd) return EINA_FALSE;
588 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
589 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
591 Elm_Diskselector_Item *it = NULL;
594 if (!wd->selected_item) {
595 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
599 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
600 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
602 l = wd->selected_item->node->prev;
603 if ((!l) && (wd->round))
604 l = eina_list_last(wd->items);
606 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
607 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
609 l = wd->selected_item->node->next;
610 if ((!l) && (wd->round))
613 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
615 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
616 l = eina_list_last(wd->items);
617 else return EINA_FALSE;
620 it = eina_list_data_get(l);
624 wd->selected_item = it;
626 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
629 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
634 _selected_item_indicate(Elm_Diskselector_Item *it)
636 Elm_Diskselector_Item *item;
639 wd = elm_widget_data_get(WIDGET(it));
643 EINA_LIST_FOREACH(wd->r_items, l, item)
645 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
647 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
652 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
653 const char *emission __UNUSED__, const char *source __UNUSED__)
655 Elm_Diskselector_Item *it = data;
660 wd = elm_widget_data_get(WIDGET(it));
664 if (wd->selected_item != it)
666 wd->selected_item = it;
667 _selected_item_indicate(wd->selected_item);
670 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
674 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
676 Evas_Coord x, y, w, h, bw;
677 Widget_Data *wd = data;
680 elm_smart_scroller_child_pos_get(obj, &x, &y);
681 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
684 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
685 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
686 elm_smart_scroller_child_region_show(wd->scroller,
687 x - ((w / wd->display_item_num) * wd->item_count),
690 elm_smart_scroller_child_region_show(wd->scroller,
691 x + ((w / wd->display_item_num) * wd->item_count),
697 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
699 Elm_Diskselector_Item *it;
700 Widget_Data *wd = elm_widget_data_get(data);
704 if (wd->idler) return;
711 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
712 EINA_LIST_FOREACH(list, l, it)
714 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
715 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
720 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, it);
724 _scroller_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
726 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START,
727 elm_diskselector_selected_item_get(data));
731 _drag_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
733 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START,
734 elm_diskselector_selected_item_get(data));
738 _drag_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
740 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP,
741 elm_diskselector_selected_item_get(data));
745 _move_scroller(void *data)
747 Evas_Object *obj = data;
750 Elm_Diskselector_Item *dit;
754 wd = elm_widget_data_get(obj);
755 if (!wd) return EINA_FALSE;
768 EINA_LIST_FOREACH(list, l, dit)
770 if (wd->selected_item == dit)
775 if (wd->round) i -= CEIL(wd->display_item_num);
780 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
784 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
785 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
789 ecore_idle_enterer_del(wd->idler);
792 wd->init = EINA_TRUE;
799 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
802 elm_box_unpack(wd->main_box, VIEW(it));
803 wd->r_items = eina_list_remove(wd->r_items, it);
804 eina_stringshare_del(it->label);
805 elm_widget_item_free(it);
809 _round_items_del(Widget_Data *wd)
812 Elm_Diskselector_Item * it;
814 _round_item_del(wd, wd->last);
816 _round_item_del(wd, wd->s_last);
818 _round_item_del(wd, wd->second);
820 _round_item_del(wd, wd->first);
823 EINA_LIST_FOREACH(wd->under_items, l, it)
825 _round_item_del(wd, it);
827 wd->under_items = eina_list_free(wd->under_items);
829 EINA_LIST_FOREACH(wd->over_items, l, it)
831 _round_item_del(wd, it);
833 wd->over_items = eina_list_free(wd->over_items);
837 _round_items_add(Widget_Data *wd)
839 Elm_Diskselector_Item *dit;
840 Elm_Diskselector_Item *it;
841 Elm_Diskselector_Item *temp_it;
843 dit = it = eina_list_nth(wd->items, 0);
848 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
850 wd->first->node = it->node;
851 wd->r_items = eina_list_append(wd->r_items, wd->first);
854 it = eina_list_nth(wd->items, 1);
859 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
861 wd->second->node = it->node;
862 wd->r_items = eina_list_append(wd->r_items, wd->second);
865 // if more than 3 itmes should be displayed
866 for (i = 2; i < CEIL(wd->display_item_num); i++)
868 it = eina_list_nth(wd->items, i);
870 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
871 wd->over_items = eina_list_append(wd->over_items, temp_it);
872 wd->r_items = eina_list_append(wd->r_items, temp_it);
875 it = eina_list_nth(wd->items, wd->item_count - 1);
880 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
882 wd->last->node = it->node;
883 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
886 it = eina_list_nth(wd->items, wd->item_count - 2);
891 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
893 wd->s_last->node = it->node;
894 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
897 // if more than 3 itmes should be displayed
898 for (i = 3; i <= CEIL(wd->display_item_num); i++)
900 it = eina_list_nth(wd->items, wd->item_count - i);
902 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
903 wd->under_items = eina_list_append(wd->under_items, temp_it);
904 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
909 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
911 if (it->icon == icon) return;
912 if (it->icon) evas_object_del(it->icon);
916 evas_object_size_hint_min_set(it->icon, 24, 24);
917 evas_object_size_hint_max_set(it->icon, 40, 40);
918 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
919 evas_object_show(it->icon);
920 elm_widget_sub_object_add(WIDGET(it), it->icon);
925 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
928 Elm_Diskselector_Item *dit;
934 wd = elm_widget_data_get(WIDGET(it));
939 // Get index from indentical item from round items
940 EINA_LIST_FOREACH(wd->r_items, l, dit)
942 if (it == dit) break;
947 ic = eina_list_count(wd->r_items);
948 if (idx >= ic) return;
951 // Number of added items: CEIL(wd->display_item_num)
952 ac = CEIL(wd->display_item_num);
954 if (((idx >= 0) && (idx < ac)) ||
955 ((idx >= ac) && (idx < (2 * ac))))
957 // Selected item: under, low region
958 dit = eina_list_nth(wd->r_items,
959 idx + ic - (2 * ac));
961 else if (((idx >= (ic - ac)) && (idx < ic)) ||
962 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
964 // Selected item: over, high region
965 dit = eina_list_nth(wd->r_items,
966 idx - ic + (2 * ac));
969 if (dit) _item_icon_set(dit, icon);
970 _sizing_eval(wd->self);
975 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
977 Elm_Diskselector_Item *item;
978 if (part && strcmp(part, "default")) return;
979 item = (Elm_Diskselector_Item *)it;
980 eina_stringshare_replace(&item->label, label);
981 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
985 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
987 if (part && strcmp(part, "default")) return NULL;
988 return ((Elm_Diskselector_Item *)it)->label;
992 _item_content_set_hook(Elm_Object_Item *it,
994 Evas_Object *content)
996 if (part && strcmp(part, "icon")) return;
997 _item_icon_set((Elm_Diskselector_Item *)it, content);
998 _check_identical_item((Elm_Diskselector_Item *)it, content);
1001 static Evas_Object *
1002 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1004 if (part && strcmp(part, "icon")) return NULL;
1005 return ((Elm_Diskselector_Item *)it)->icon;
1010 elm_diskselector_add(Evas_Object *parent)
1016 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1018 ELM_SET_WIDTYPE(widtype, "diskselector");
1019 elm_widget_type_set(obj, "diskselector");
1020 elm_widget_sub_object_add(parent, obj);
1021 elm_widget_data_set(obj, wd);
1022 elm_widget_del_hook_set(obj, _del_hook);
1023 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1024 elm_widget_theme_hook_set(obj, _theme_hook);
1025 elm_widget_can_focus_set(obj, EINA_TRUE);
1026 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1027 elm_widget_event_hook_set(obj, _event_hook);
1031 wd->round = EINA_FALSE;
1032 wd->init = EINA_FALSE;
1034 wd->display_item_num_by_api = EINA_FALSE;
1036 wd->scroller = elm_smart_scroller_add(e);
1037 elm_smart_scroller_widget_set(wd->scroller, obj);
1039 elm_widget_resize_object_set(obj, wd->scroller);
1040 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1041 ELM_SMART_SCROLLER_POLICY_OFF);
1042 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1043 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1045 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1046 _scroller_stop_cb, obj);
1047 evas_object_smart_callback_add(wd->scroller, "animate,start",
1048 _scroller_start_cb, obj);
1049 evas_object_smart_callback_add(wd->scroller, "drag,stop",
1050 _drag_stop_cb, obj);
1051 evas_object_smart_callback_add(wd->scroller, "drag,start",
1052 _drag_start_cb, obj);
1054 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1056 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1057 _diskselector_object_resize, obj);
1059 wd->main_box = elm_box_add(parent);
1060 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1061 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1062 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1064 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1066 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1068 elm_widget_sub_object_add(obj, wd->main_box);
1070 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1072 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1073 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1075 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1077 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1079 elm_box_pack_end(wd->main_box, wd->left_blank);
1080 evas_object_show(wd->left_blank);
1082 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1083 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1085 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1087 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1089 elm_box_pack_end(wd->main_box, wd->right_blank);
1090 evas_object_show(wd->right_blank);
1092 _theme_data_get(wd);
1094 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1095 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1101 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1103 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1104 Widget_Data *wd = elm_widget_data_get(obj);
1105 if (!wd) return EINA_FALSE;
1110 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1113 Elm_Diskselector_Item *it;
1115 ELM_CHECK_WIDTYPE(obj, widtype);
1116 Widget_Data *wd = elm_widget_data_get(obj);
1119 if (wd->round == enabled)
1122 wd->round = !!enabled;
1125 wd->r_items = eina_list_clone(wd->items);
1126 elm_box_unpack(wd->main_box, wd->left_blank);
1127 evas_object_hide(wd->left_blank);
1128 elm_box_unpack(wd->main_box, wd->right_blank);
1129 evas_object_hide(wd->right_blank);
1133 _round_items_add(wd);
1136 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1138 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1140 // if more than 3 items should be displayed
1141 EINA_LIST_FOREACH(wd->under_items, elist, it)
1142 elm_box_pack_start(wd->main_box, VIEW(it));
1145 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1147 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1149 // if more than 3 items should be displayed
1150 EINA_LIST_FOREACH(wd->over_items, elist, it)
1151 elm_box_pack_end(wd->main_box, VIEW(it));
1155 _round_items_del(wd);
1156 elm_box_pack_start(wd->main_box, wd->left_blank);
1157 elm_box_pack_end(wd->main_box, wd->right_blank);
1158 eina_list_free(wd->r_items);
1162 _selected_item_indicate(wd->selected_item);
1167 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1169 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1170 Widget_Data *wd = elm_widget_data_get(obj);
1172 return wd->len_side;
1176 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1178 ELM_CHECK_WIDTYPE(obj, widtype);
1179 Widget_Data *wd = elm_widget_data_get(obj);
1185 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1187 ELM_CHECK_WIDTYPE(obj, widtype);
1188 Widget_Data *wd = elm_widget_data_get(obj);
1191 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1195 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1197 ELM_CHECK_WIDTYPE(obj, widtype);
1198 Widget_Data *wd = elm_widget_data_get(obj);
1200 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1204 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1206 ELM_CHECK_WIDTYPE(obj, widtype);
1207 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1208 Widget_Data *wd = elm_widget_data_get(obj);
1209 if ((!wd) || (!wd->scroller)) return;
1210 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1211 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1212 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1216 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1218 ELM_CHECK_WIDTYPE(obj, widtype);
1219 Widget_Data *wd = elm_widget_data_get(obj);
1220 if ((!wd) || (!wd->scroller)) return;
1221 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1222 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1224 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1228 elm_diskselector_clear(Evas_Object *obj)
1230 ELM_CHECK_WIDTYPE(obj, widtype);
1231 Widget_Data *wd = elm_widget_data_get(obj);
1232 Elm_Diskselector_Item *it;
1235 if (!wd->items) return;
1237 wd->selected_item = NULL;
1238 EINA_LIST_FREE(wd->items, it)
1241 elm_widget_item_free(it);
1243 _round_items_del(wd);
1247 EAPI const Eina_List *
1248 elm_diskselector_items_get(const Evas_Object *obj)
1250 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1251 Widget_Data *wd = elm_widget_data_get(obj);
1252 if (!wd) return NULL;
1256 EAPI Elm_Object_Item *
1257 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1259 Elm_Diskselector_Item *it;
1260 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1261 Widget_Data *wd = elm_widget_data_get(obj);
1262 if (!wd) return NULL;
1264 it = _item_new(obj, icon, label, func, data);
1265 wd->items = eina_list_append(wd->items, it);
1266 it->node = eina_list_last(wd->items);
1270 _round_items_del(wd);
1271 wd->r_items = eina_list_append(wd->r_items, it);
1272 _round_items_add(wd);
1274 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1276 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1277 elm_box_pack_end(wd->main_box, VIEW(it));
1279 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1281 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1285 elm_box_unpack(wd->main_box, wd->right_blank);
1286 elm_box_pack_end(wd->main_box, VIEW(it));
1287 elm_box_pack_end(wd->main_box, wd->right_blank);
1289 if (!wd->selected_item)
1290 wd->selected_item = it;
1292 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1294 return (Elm_Object_Item *)it;
1297 EAPI Elm_Object_Item *
1298 elm_diskselector_selected_item_get(const Evas_Object *obj)
1300 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1301 Widget_Data *wd = elm_widget_data_get(obj);
1302 if (!wd) return NULL;
1303 return (Elm_Object_Item *) wd->selected_item;
1307 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1309 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1311 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1312 wd = elm_widget_data_get(WIDGET(item));
1315 if ((wd->selected_item == item) && (selected))
1318 if ((wd->selected_item == item) && (!selected))
1319 wd->selected_item = eina_list_data_get(wd->items);
1322 wd->selected_item = item;
1323 _selected_item_indicate(wd->selected_item);
1327 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1331 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1333 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1334 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1335 if (!wd) return EINA_FALSE;
1336 return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1339 EAPI Elm_Object_Item *
1340 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1342 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1343 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1344 if (item->node->prev) return item->node->prev->data;
1348 EAPI Elm_Object_Item *
1349 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1351 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1352 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1353 if (item->node->next) return item->node->next->data;
1357 EAPI Elm_Object_Item *
1358 elm_diskselector_first_item_get(const Evas_Object *obj)
1360 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1361 Widget_Data *wd = elm_widget_data_get(obj);
1362 if (!wd || !wd->items) return NULL;
1363 return eina_list_data_get(wd->items);
1366 EAPI Elm_Object_Item *
1367 elm_diskselector_last_item_get(const Evas_Object *obj)
1369 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1370 Widget_Data *wd = elm_widget_data_get(obj);
1371 if (!wd || !wd->items) return NULL;
1372 return eina_list_data_get(eina_list_last(wd->items));
1376 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1378 ELM_CHECK_WIDTYPE(obj, widtype);
1379 Widget_Data *wd = elm_widget_data_get(obj);
1381 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1382 wd->display_item_num = num;
1383 wd->display_item_num_by_api = EINA_TRUE;
1387 elm_diskselector_display_item_num_get(const Evas_Object *item)
1389 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1390 Widget_Data *wd = elm_widget_data_get(item);
1392 return wd->display_item_num;