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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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_escaped_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)
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;
393 if (!wd->display_item_num_by_api)
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;
400 str = edje_object_data_get(wd->right_blank, "min_width");
401 if (str) wd->minw = MAX(-1, atoi(str)) * elm_scale_get();
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);
409 str = edje_object_data_get(wd->right_blank, "min_height");
410 if (str) wd->minh = MAX(-1, atoi(str)) * elm_scale_get();
415 _del_hook(Evas_Object * obj)
417 Widget_Data *wd = elm_widget_data_get(obj);
423 _del_pre_hook(Evas_Object * obj)
425 Elm_Diskselector_Item *it;
428 Widget_Data *wd = elm_widget_data_get(obj);
432 evas_object_del(wd->left_blank);
434 evas_object_del(wd->right_blank);
437 eina_stringshare_del(wd->last->label);
438 evas_object_del(wd->VIEW(last));
443 eina_stringshare_del(wd->s_last->label);
444 evas_object_del(wd->VIEW(s_last));
449 eina_stringshare_del(wd->second->label);
450 evas_object_del(wd->VIEW(second));
455 eina_stringshare_del(wd->first->label);
456 evas_object_del(wd->VIEW(first));
460 EINA_LIST_FOREACH(wd->under_items, l, it)
464 eina_stringshare_del(it->label);
465 evas_object_del(VIEW(it));
470 EINA_LIST_FOREACH(wd->over_items, l, it)
474 eina_stringshare_del(it->label);
475 evas_object_del(VIEW(it));
480 EINA_LIST_FREE(wd->items, it)
483 elm_widget_item_free(it);
485 eina_list_free(wd->r_items);
489 _sizing_eval(Evas_Object * obj)
491 Widget_Data *wd = elm_widget_data_get(obj);
493 _diskselector_object_resize(obj, NULL, obj, NULL);
497 _theme_hook(Evas_Object * obj)
500 Elm_Diskselector_Item *it;
501 Widget_Data *wd = elm_widget_data_get(obj);
505 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
506 "base", elm_widget_style_get(obj));
509 EINA_LIST_FOREACH(wd->r_items, l, it)
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);
518 EINA_LIST_FOREACH(wd->items, l, it)
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);
525 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
526 elm_widget_style_get(obj));
532 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
534 Widget_Data *wd = elm_widget_data_get(obj);
535 Evas_Object *sub = event_info;
536 Elm_Diskselector_Item *it;
541 if (sub == wd->scroller)
545 EINA_LIST_FOREACH(wd->items, l, it)
558 _select_item(Elm_Diskselector_Item *it)
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);
569 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
571 Widget_Data *wd = elm_widget_data_get(obj);
575 if (elm_widget_focus_get(obj))
577 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
578 evas_object_focus_set(wd->self, EINA_TRUE);
582 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
583 evas_object_focus_set(wd->self, EINA_FALSE);
588 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
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;
597 Elm_Diskselector_Item *it = NULL;
600 if (!wd->selected_item) {
601 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
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)))
610 l = wd->selected_item->node->prev;
611 if ((!l) && (wd->round))
612 l = eina_list_last(wd->items);
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)))
619 l = wd->selected_item->node->next;
620 if ((!l) && (wd->round))
623 else if ((!strcmp(ev->keyname, "Home")) ||
624 ((!strcmp(ev->keyname, "KP_Home")) && (!ev->string)))
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;
632 it = eina_list_data_get(l);
636 wd->selected_item = it;
638 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
641 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
646 _selected_item_indicate(Elm_Diskselector_Item *it)
648 Elm_Diskselector_Item *item;
651 wd = elm_widget_data_get(WIDGET(it));
654 if (!it->label) return;
656 EINA_LIST_FOREACH(wd->r_items, l, item)
658 if (item->label && !strcmp(item->label, it->label))
659 edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
661 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
666 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
667 const char *emission __UNUSED__, const char *source __UNUSED__)
669 Elm_Diskselector_Item *it = data;
674 wd = elm_widget_data_get(WIDGET(it));
678 if (wd->selected_item != it)
680 wd->selected_item = it;
681 _selected_item_indicate(wd->selected_item);
684 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
688 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
690 Evas_Coord x, y, w, h, bw;
691 Widget_Data *wd = data;
694 elm_smart_scroller_child_pos_get(obj, &x, &y);
695 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
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),
704 elm_smart_scroller_child_region_show(wd->scroller,
705 x + ((w / wd->display_item_num) * wd->item_count),
711 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
713 Elm_Diskselector_Item *it;
714 Widget_Data *wd = elm_widget_data_get(data);
718 if (wd->idler) return;
725 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
726 EINA_LIST_FOREACH(list, l, it)
728 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
729 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
734 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, it);
738 _scroller_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
740 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START,
741 elm_diskselector_selected_item_get(data));
745 _drag_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
747 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START,
748 elm_diskselector_selected_item_get(data));
752 _drag_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
754 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP,
755 elm_diskselector_selected_item_get(data));
759 _move_scroller(void *data)
761 Evas_Object *obj = data;
764 Elm_Diskselector_Item *dit;
768 wd = elm_widget_data_get(obj);
769 if (!wd) return EINA_FALSE;
782 EINA_LIST_FOREACH(list, l, dit)
784 if (wd->selected_item == dit)
789 if (wd->round) i -= CEIL(wd->display_item_num);
794 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
798 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
799 //move scroller in two steps for getting smooth launching effect.
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);
807 ecore_idle_enterer_del(wd->idler);
810 wd->init = EINA_TRUE;
817 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
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);
827 _round_items_del(Widget_Data *wd)
830 Elm_Diskselector_Item * it;
832 _round_item_del(wd, wd->last);
834 _round_item_del(wd, wd->s_last);
836 _round_item_del(wd, wd->second);
838 _round_item_del(wd, wd->first);
841 EINA_LIST_FOREACH(wd->under_items, l, it)
843 _round_item_del(wd, it);
845 wd->under_items = eina_list_free(wd->under_items);
847 EINA_LIST_FOREACH(wd->over_items, l, it)
849 _round_item_del(wd, it);
851 wd->over_items = eina_list_free(wd->over_items);
855 _round_items_add(Widget_Data *wd)
857 Elm_Diskselector_Item *dit;
858 Elm_Diskselector_Item *it;
859 Elm_Diskselector_Item *temp_it;
861 dit = it = eina_list_nth(wd->items, 0);
866 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
868 wd->first->node = it->node;
869 wd->r_items = eina_list_append(wd->r_items, wd->first);
872 it = eina_list_nth(wd->items, 1);
877 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
879 wd->second->node = it->node;
880 wd->r_items = eina_list_append(wd->r_items, wd->second);
883 // if more than 3 itmes should be displayed
884 for (i = 2; i < CEIL(wd->display_item_num); i++)
886 it = eina_list_nth(wd->items, i);
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);
893 it = eina_list_nth(wd->items, wd->item_count - 1);
898 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
900 wd->last->node = it->node;
901 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
904 it = eina_list_nth(wd->items, wd->item_count - 2);
909 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
911 wd->s_last->node = it->node;
912 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
915 // if more than 3 itmes should be displayed
916 for (i = 3; i <= CEIL(wd->display_item_num); i++)
918 it = eina_list_nth(wd->items, wd->item_count - i);
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);
927 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
929 if (it->icon == icon) return;
930 if (it->icon) evas_object_del(it->icon);
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);
943 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
946 Elm_Diskselector_Item *dit;
952 wd = elm_widget_data_get(WIDGET(it));
957 // Get index from indentical item from round items
958 EINA_LIST_FOREACH(wd->r_items, l, dit)
960 if (it == dit) break;
965 ic = eina_list_count(wd->r_items);
966 if (idx >= ic) return;
969 // Number of added items: CEIL(wd->display_item_num)
970 ac = CEIL(wd->display_item_num);
972 if (((idx >= 0) && (idx < ac)) ||
973 ((idx >= ac) && (idx < (2 * ac))))
975 // Selected item: under, low region
976 dit = eina_list_nth(wd->r_items,
977 idx + ic - (2 * ac));
979 else if (((idx >= (ic - ac)) && (idx < ic)) ||
980 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
982 // Selected item: over, high region
983 dit = eina_list_nth(wd->r_items,
984 idx - ic + (2 * ac));
987 if (dit) _item_icon_set(dit, icon);
988 _sizing_eval(wd->self);
993 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
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);
1003 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1005 if (part && strcmp(part, "default")) return NULL;
1006 return ((Elm_Diskselector_Item *)it)->label;
1010 _item_content_set_hook(Elm_Object_Item *it,
1012 Evas_Object *content)
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);
1019 static Evas_Object *
1020 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1022 if (part && strcmp(part, "icon")) return NULL;
1023 return ((Elm_Diskselector_Item *)it)->icon;
1027 elm_diskselector_add(Evas_Object *parent)
1033 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
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);
1048 wd->round = EINA_FALSE;
1049 wd->init = EINA_FALSE;
1051 wd->display_item_num_by_api = EINA_FALSE;
1053 wd->scroller = elm_smart_scroller_add(e);
1054 elm_smart_scroller_widget_set(wd->scroller, 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,
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);
1071 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1073 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1074 _diskselector_object_resize, obj);
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,
1081 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1083 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1085 elm_widget_sub_object_add(obj, wd->main_box);
1087 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1089 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1090 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1092 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1094 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1096 elm_box_pack_end(wd->main_box, wd->left_blank);
1097 evas_object_show(wd->left_blank);
1099 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1100 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1102 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1104 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1106 elm_box_pack_end(wd->main_box, wd->right_blank);
1107 evas_object_show(wd->right_blank);
1109 _theme_data_get(wd);
1111 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1112 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1118 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1120 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1121 Widget_Data *wd = elm_widget_data_get(obj);
1122 if (!wd) return EINA_FALSE;
1127 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1130 Elm_Diskselector_Item *it;
1132 ELM_CHECK_WIDTYPE(obj, widtype);
1133 Widget_Data *wd = elm_widget_data_get(obj);
1136 if (wd->round == enabled)
1139 wd->round = !!enabled;
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);
1150 _round_items_add(wd);
1153 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1155 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
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));
1162 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1164 elm_box_pack_end(wd->main_box, wd->VIEW(second));
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));
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);
1179 _selected_item_indicate(wd->selected_item);
1184 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1186 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1187 Widget_Data *wd = elm_widget_data_get(obj);
1189 return wd->len_side;
1193 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1195 ELM_CHECK_WIDTYPE(obj, widtype);
1196 Widget_Data *wd = elm_widget_data_get(obj);
1202 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1204 ELM_CHECK_WIDTYPE(obj, widtype);
1205 Widget_Data *wd = elm_widget_data_get(obj);
1208 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1212 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1214 ELM_CHECK_WIDTYPE(obj, widtype);
1215 Widget_Data *wd = elm_widget_data_get(obj);
1217 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1221 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
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;
1233 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
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))
1241 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1245 elm_diskselector_clear(Evas_Object *obj)
1247 ELM_CHECK_WIDTYPE(obj, widtype);
1248 Widget_Data *wd = elm_widget_data_get(obj);
1249 Elm_Diskselector_Item *it;
1252 if (!wd->items) return;
1254 wd->selected_item = NULL;
1255 EINA_LIST_FREE(wd->items, it)
1258 elm_widget_item_free(it);
1260 _round_items_del(wd);
1264 EAPI const Eina_List *
1265 elm_diskselector_items_get(const Evas_Object *obj)
1267 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1268 Widget_Data *wd = elm_widget_data_get(obj);
1269 if (!wd) return NULL;
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)
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;
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);
1287 _round_items_del(wd);
1288 wd->r_items = eina_list_append(wd->r_items, it);
1289 _round_items_add(wd);
1291 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1293 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1294 elm_box_pack_end(wd->main_box, VIEW(it));
1296 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1298 elm_box_pack_end(wd->main_box, wd->VIEW(second));
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);
1306 if (!wd->selected_item)
1307 wd->selected_item = it;
1309 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1311 return (Elm_Object_Item *)it;
1314 EAPI Elm_Object_Item *
1315 elm_diskselector_selected_item_get(const Evas_Object *obj)
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;
1324 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1326 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1328 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1329 wd = elm_widget_data_get(WIDGET(item));
1332 if ((wd->selected_item == item) && (selected))
1335 if ((wd->selected_item == item) && (!selected))
1336 wd->selected_item = eina_list_data_get(wd->items);
1339 wd->selected_item = item;
1340 _selected_item_indicate(wd->selected_item);
1344 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1348 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
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));
1356 EAPI Elm_Object_Item *
1357 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
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;
1365 EAPI Elm_Object_Item *
1366 elm_diskselector_item_next_get(const Elm_Object_Item *it)
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;
1374 EAPI Elm_Object_Item *
1375 elm_diskselector_first_item_get(const Evas_Object *obj)
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);
1383 EAPI Elm_Object_Item *
1384 elm_diskselector_last_item_get(const Evas_Object *obj)
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));
1393 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1395 ELM_CHECK_WIDTYPE(obj, widtype);
1396 Widget_Data *wd = elm_widget_data_get(obj);
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;
1404 elm_diskselector_display_item_num_get(const Evas_Object *item)
1406 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1407 Widget_Data *wd = elm_widget_data_get(item);
1409 return wd->display_item_num;