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")) ||
600 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)) ||
601 (!strcmp(ev->keyname, "Up")) ||
602 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
604 l = wd->selected_item->node->prev;
605 if ((!l) && (wd->round))
606 l = eina_list_last(wd->items);
608 else if ((!strcmp(ev->keyname, "Right")) ||
609 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)) ||
610 (!strcmp(ev->keyname, "Down")) ||
611 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
613 l = wd->selected_item->node->next;
614 if ((!l) && (wd->round))
617 else if ((!strcmp(ev->keyname, "Home")) ||
618 ((!strcmp(ev->keyname, "KP_Home")) && (!ev->string)))
620 else if ((!strcmp(ev->keyname, "End")) ||
621 ((!strcmp(ev->keyname, "KP_End")) && (!ev->string)))
622 l = eina_list_last(wd->items);
623 else return EINA_FALSE;
626 it = eina_list_data_get(l);
630 wd->selected_item = it;
632 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
635 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
640 _selected_item_indicate(Elm_Diskselector_Item *it)
642 Elm_Diskselector_Item *item;
645 wd = elm_widget_data_get(WIDGET(it));
648 if (!it->label) return;
650 EINA_LIST_FOREACH(wd->r_items, l, item)
652 if (item->label && !strcmp(item->label, it->label))
653 edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
655 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
660 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
661 const char *emission __UNUSED__, const char *source __UNUSED__)
663 Elm_Diskselector_Item *it = data;
668 wd = elm_widget_data_get(WIDGET(it));
672 if (wd->selected_item != it)
674 wd->selected_item = it;
675 _selected_item_indicate(wd->selected_item);
678 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
682 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
684 Evas_Coord x, y, w, h, bw;
685 Widget_Data *wd = data;
688 elm_smart_scroller_child_pos_get(obj, &x, &y);
689 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
692 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
693 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
694 elm_smart_scroller_child_region_show(wd->scroller,
695 x - ((w / wd->display_item_num) * wd->item_count),
698 elm_smart_scroller_child_region_show(wd->scroller,
699 x + ((w / wd->display_item_num) * wd->item_count),
705 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
707 Elm_Diskselector_Item *it;
708 Widget_Data *wd = elm_widget_data_get(data);
712 if (wd->idler) return;
719 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
720 EINA_LIST_FOREACH(list, l, it)
722 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
723 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
728 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, it);
732 _scroller_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
734 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START,
735 elm_diskselector_selected_item_get(data));
739 _drag_start_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
741 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START,
742 elm_diskselector_selected_item_get(data));
746 _drag_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
748 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP,
749 elm_diskselector_selected_item_get(data));
753 _move_scroller(void *data)
755 Evas_Object *obj = data;
758 Elm_Diskselector_Item *dit;
762 wd = elm_widget_data_get(obj);
763 if (!wd) return EINA_FALSE;
776 EINA_LIST_FOREACH(list, l, dit)
778 if (wd->selected_item == dit)
783 if (wd->round) i -= CEIL(wd->display_item_num);
788 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
792 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
793 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
797 ecore_idle_enterer_del(wd->idler);
800 wd->init = EINA_TRUE;
807 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
810 elm_box_unpack(wd->main_box, VIEW(it));
811 wd->r_items = eina_list_remove(wd->r_items, it);
812 eina_stringshare_del(it->label);
813 elm_widget_item_free(it);
817 _round_items_del(Widget_Data *wd)
820 Elm_Diskselector_Item * it;
822 _round_item_del(wd, wd->last);
824 _round_item_del(wd, wd->s_last);
826 _round_item_del(wd, wd->second);
828 _round_item_del(wd, wd->first);
831 EINA_LIST_FOREACH(wd->under_items, l, it)
833 _round_item_del(wd, it);
835 wd->under_items = eina_list_free(wd->under_items);
837 EINA_LIST_FOREACH(wd->over_items, l, it)
839 _round_item_del(wd, it);
841 wd->over_items = eina_list_free(wd->over_items);
845 _round_items_add(Widget_Data *wd)
847 Elm_Diskselector_Item *dit;
848 Elm_Diskselector_Item *it;
849 Elm_Diskselector_Item *temp_it;
851 dit = it = eina_list_nth(wd->items, 0);
856 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
858 wd->first->node = it->node;
859 wd->r_items = eina_list_append(wd->r_items, wd->first);
862 it = eina_list_nth(wd->items, 1);
867 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
869 wd->second->node = it->node;
870 wd->r_items = eina_list_append(wd->r_items, wd->second);
873 // if more than 3 itmes should be displayed
874 for (i = 2; i < CEIL(wd->display_item_num); i++)
876 it = eina_list_nth(wd->items, i);
878 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
879 wd->over_items = eina_list_append(wd->over_items, temp_it);
880 wd->r_items = eina_list_append(wd->r_items, temp_it);
883 it = eina_list_nth(wd->items, wd->item_count - 1);
888 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
890 wd->last->node = it->node;
891 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
894 it = eina_list_nth(wd->items, wd->item_count - 2);
899 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
901 wd->s_last->node = it->node;
902 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
905 // if more than 3 itmes should be displayed
906 for (i = 3; i <= CEIL(wd->display_item_num); i++)
908 it = eina_list_nth(wd->items, wd->item_count - i);
910 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
911 wd->under_items = eina_list_append(wd->under_items, temp_it);
912 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
917 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
919 if (it->icon == icon) return;
920 if (it->icon) evas_object_del(it->icon);
924 evas_object_size_hint_min_set(it->icon, 24, 24);
925 evas_object_size_hint_max_set(it->icon, 40, 40);
926 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
927 evas_object_show(it->icon);
928 elm_widget_sub_object_add(WIDGET(it), it->icon);
933 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
936 Elm_Diskselector_Item *dit;
942 wd = elm_widget_data_get(WIDGET(it));
947 // Get index from indentical item from round items
948 EINA_LIST_FOREACH(wd->r_items, l, dit)
950 if (it == dit) break;
955 ic = eina_list_count(wd->r_items);
956 if (idx >= ic) return;
959 // Number of added items: CEIL(wd->display_item_num)
960 ac = CEIL(wd->display_item_num);
962 if (((idx >= 0) && (idx < ac)) ||
963 ((idx >= ac) && (idx < (2 * ac))))
965 // Selected item: under, low region
966 dit = eina_list_nth(wd->r_items,
967 idx + ic - (2 * ac));
969 else if (((idx >= (ic - ac)) && (idx < ic)) ||
970 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
972 // Selected item: over, high region
973 dit = eina_list_nth(wd->r_items,
974 idx - ic + (2 * ac));
977 if (dit) _item_icon_set(dit, icon);
978 _sizing_eval(wd->self);
983 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
985 Elm_Diskselector_Item *item;
986 if (part && strcmp(part, "default")) return;
987 item = (Elm_Diskselector_Item *)it;
988 eina_stringshare_replace(&item->label, label);
989 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
993 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
995 if (part && strcmp(part, "default")) return NULL;
996 return ((Elm_Diskselector_Item *)it)->label;
1000 _item_content_set_hook(Elm_Object_Item *it,
1002 Evas_Object *content)
1004 if (part && strcmp(part, "icon")) return;
1005 _item_icon_set((Elm_Diskselector_Item *)it, content);
1006 _check_identical_item((Elm_Diskselector_Item *)it, content);
1009 static Evas_Object *
1010 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1012 if (part && strcmp(part, "icon")) return NULL;
1013 return ((Elm_Diskselector_Item *)it)->icon;
1018 elm_diskselector_add(Evas_Object *parent)
1024 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1026 ELM_SET_WIDTYPE(widtype, "diskselector");
1027 elm_widget_type_set(obj, "diskselector");
1028 elm_widget_sub_object_add(parent, obj);
1029 elm_widget_data_set(obj, wd);
1030 elm_widget_del_hook_set(obj, _del_hook);
1031 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1032 elm_widget_theme_hook_set(obj, _theme_hook);
1033 elm_widget_can_focus_set(obj, EINA_TRUE);
1034 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1035 elm_widget_event_hook_set(obj, _event_hook);
1039 wd->round = EINA_FALSE;
1040 wd->init = EINA_FALSE;
1042 wd->display_item_num_by_api = EINA_FALSE;
1044 wd->scroller = elm_smart_scroller_add(e);
1045 elm_smart_scroller_widget_set(wd->scroller, obj);
1047 elm_widget_resize_object_set(obj, wd->scroller);
1048 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1049 ELM_SMART_SCROLLER_POLICY_OFF);
1050 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1051 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1053 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1054 _scroller_stop_cb, obj);
1055 evas_object_smart_callback_add(wd->scroller, "animate,start",
1056 _scroller_start_cb, obj);
1057 evas_object_smart_callback_add(wd->scroller, "drag,stop",
1058 _drag_stop_cb, obj);
1059 evas_object_smart_callback_add(wd->scroller, "drag,start",
1060 _drag_start_cb, obj);
1062 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1064 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1065 _diskselector_object_resize, obj);
1067 wd->main_box = elm_box_add(parent);
1068 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1069 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1070 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1072 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1074 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1076 elm_widget_sub_object_add(obj, wd->main_box);
1078 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1080 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1081 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1083 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1085 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1087 elm_box_pack_end(wd->main_box, wd->left_blank);
1088 evas_object_show(wd->left_blank);
1090 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1091 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1093 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1095 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1097 elm_box_pack_end(wd->main_box, wd->right_blank);
1098 evas_object_show(wd->right_blank);
1100 _theme_data_get(wd);
1102 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1103 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1109 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1111 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1112 Widget_Data *wd = elm_widget_data_get(obj);
1113 if (!wd) return EINA_FALSE;
1118 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1121 Elm_Diskselector_Item *it;
1123 ELM_CHECK_WIDTYPE(obj, widtype);
1124 Widget_Data *wd = elm_widget_data_get(obj);
1127 if (wd->round == enabled)
1130 wd->round = !!enabled;
1133 wd->r_items = eina_list_clone(wd->items);
1134 elm_box_unpack(wd->main_box, wd->left_blank);
1135 evas_object_hide(wd->left_blank);
1136 elm_box_unpack(wd->main_box, wd->right_blank);
1137 evas_object_hide(wd->right_blank);
1141 _round_items_add(wd);
1144 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1146 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1148 // if more than 3 items should be displayed
1149 EINA_LIST_FOREACH(wd->under_items, elist, it)
1150 elm_box_pack_start(wd->main_box, VIEW(it));
1153 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1155 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1157 // if more than 3 items should be displayed
1158 EINA_LIST_FOREACH(wd->over_items, elist, it)
1159 elm_box_pack_end(wd->main_box, VIEW(it));
1163 _round_items_del(wd);
1164 elm_box_pack_start(wd->main_box, wd->left_blank);
1165 elm_box_pack_end(wd->main_box, wd->right_blank);
1166 eina_list_free(wd->r_items);
1170 _selected_item_indicate(wd->selected_item);
1175 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1177 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1178 Widget_Data *wd = elm_widget_data_get(obj);
1180 return wd->len_side;
1184 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1186 ELM_CHECK_WIDTYPE(obj, widtype);
1187 Widget_Data *wd = elm_widget_data_get(obj);
1193 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1195 ELM_CHECK_WIDTYPE(obj, widtype);
1196 Widget_Data *wd = elm_widget_data_get(obj);
1199 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1203 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1205 ELM_CHECK_WIDTYPE(obj, widtype);
1206 Widget_Data *wd = elm_widget_data_get(obj);
1208 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1212 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1214 ELM_CHECK_WIDTYPE(obj, widtype);
1215 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1216 Widget_Data *wd = elm_widget_data_get(obj);
1217 if ((!wd) || (!wd->scroller)) return;
1218 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1219 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1220 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1224 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1226 ELM_CHECK_WIDTYPE(obj, widtype);
1227 Widget_Data *wd = elm_widget_data_get(obj);
1228 if ((!wd) || (!wd->scroller)) return;
1229 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1230 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1232 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1236 elm_diskselector_clear(Evas_Object *obj)
1238 ELM_CHECK_WIDTYPE(obj, widtype);
1239 Widget_Data *wd = elm_widget_data_get(obj);
1240 Elm_Diskselector_Item *it;
1243 if (!wd->items) return;
1245 wd->selected_item = NULL;
1246 EINA_LIST_FREE(wd->items, it)
1249 elm_widget_item_free(it);
1251 _round_items_del(wd);
1255 EAPI const Eina_List *
1256 elm_diskselector_items_get(const Evas_Object *obj)
1258 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1259 Widget_Data *wd = elm_widget_data_get(obj);
1260 if (!wd) return NULL;
1264 EAPI Elm_Object_Item *
1265 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1267 Elm_Diskselector_Item *it;
1268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269 Widget_Data *wd = elm_widget_data_get(obj);
1270 if (!wd) return NULL;
1272 it = _item_new(obj, icon, label, func, data);
1273 wd->items = eina_list_append(wd->items, it);
1274 it->node = eina_list_last(wd->items);
1278 _round_items_del(wd);
1279 wd->r_items = eina_list_append(wd->r_items, it);
1280 _round_items_add(wd);
1282 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1284 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1285 elm_box_pack_end(wd->main_box, VIEW(it));
1287 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1289 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1293 elm_box_unpack(wd->main_box, wd->right_blank);
1294 elm_box_pack_end(wd->main_box, VIEW(it));
1295 elm_box_pack_end(wd->main_box, wd->right_blank);
1297 if (!wd->selected_item)
1298 wd->selected_item = it;
1300 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1302 return (Elm_Object_Item *)it;
1305 EAPI Elm_Object_Item *
1306 elm_diskselector_selected_item_get(const Evas_Object *obj)
1308 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1309 Widget_Data *wd = elm_widget_data_get(obj);
1310 if (!wd) return NULL;
1311 return (Elm_Object_Item *) wd->selected_item;
1315 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1317 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1319 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1320 wd = elm_widget_data_get(WIDGET(item));
1323 if ((wd->selected_item == item) && (selected))
1326 if ((wd->selected_item == item) && (!selected))
1327 wd->selected_item = eina_list_data_get(wd->items);
1330 wd->selected_item = item;
1331 _selected_item_indicate(wd->selected_item);
1335 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1339 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1341 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1342 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1343 if (!wd) return EINA_FALSE;
1344 return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1347 EAPI Elm_Object_Item *
1348 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1350 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1351 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1352 if (item->node->prev) return item->node->prev->data;
1356 EAPI Elm_Object_Item *
1357 elm_diskselector_item_next_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->next) return item->node->next->data;
1365 EAPI Elm_Object_Item *
1366 elm_diskselector_first_item_get(const Evas_Object *obj)
1368 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1369 Widget_Data *wd = elm_widget_data_get(obj);
1370 if (!wd || !wd->items) return NULL;
1371 return eina_list_data_get(wd->items);
1374 EAPI Elm_Object_Item *
1375 elm_diskselector_last_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(eina_list_last(wd->items));
1384 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1386 ELM_CHECK_WIDTYPE(obj, widtype);
1387 Widget_Data *wd = elm_widget_data_get(obj);
1389 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1390 wd->display_item_num = num;
1391 wd->display_item_num_by_api = EINA_TRUE;
1395 elm_diskselector_display_item_num_get(const Evas_Object *item)
1397 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1398 Widget_Data *wd = elm_widget_data_get(item);
1400 return wd->display_item_num;