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 Evas_Smart_Cb_Description _signals[] = {
86 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
91 wd = elm_widget_data_get(data);
94 if ((wd->minw == -1) && (wd->minh == -1))
95 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
96 edje_object_size_min_restricted_calc
97 (elm_smart_scroller_edje_object_get
98 (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
99 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
100 evas_object_size_hint_max_set(obj, -1, -1);
102 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
104 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
106 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
108 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
109 (int)(w / wd->display_item_num), 0);
112 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
115 static Elm_Diskselector_Item *
116 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
118 Elm_Diskselector_Item *it;
119 const char *style = elm_widget_style_get(obj);
121 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
122 if (!it) return NULL;
124 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
125 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
126 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
127 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
129 it->label = eina_stringshare_add(label);
132 it->base.data = data;
133 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
134 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
135 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
137 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
139 evas_object_show(VIEW(it));
143 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
144 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
148 evas_object_size_hint_min_set(it->icon, 24, 24);
149 evas_object_size_hint_max_set(it->icon, 40, 40);
150 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
151 evas_object_show(it->icon);
152 elm_widget_sub_object_add(obj, it->icon);
158 _item_del(Elm_Diskselector_Item *item)
161 eina_stringshare_del(item->label);
163 evas_object_del(item->icon);
164 elm_widget_item_del(item);
168 _theme_data_get(Widget_Data *wd)
171 str = edje_object_data_get(wd->right_blank, "len_threshold");
172 if (str) wd->len_threshold = MAX(0, atoi(str));
173 else wd->len_threshold = 0;
175 if (!wd->display_item_num_by_api)
177 str = edje_object_data_get(wd->right_blank, "display_item_num");
178 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
179 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
182 str = edje_object_data_get(wd->right_blank, "min_width");
183 if (str) wd->minw = MAX(-1, atoi(str));
186 str = edje_object_data_get(wd->right_blank, "min_height");
187 if (str) wd->minh = MAX(-1, atoi(str));
192 _del_hook(Evas_Object * obj)
194 Widget_Data *wd = elm_widget_data_get(obj);
200 _del_pre_hook(Evas_Object * obj)
202 Elm_Diskselector_Item *it;
205 Widget_Data *wd = elm_widget_data_get(obj);
209 evas_object_del(wd->left_blank);
211 evas_object_del(wd->right_blank);
214 eina_stringshare_del(wd->last->label);
215 evas_object_del(wd->VIEW(last));
220 eina_stringshare_del(wd->s_last->label);
221 evas_object_del(wd->VIEW(s_last));
226 eina_stringshare_del(wd->second->label);
227 evas_object_del(wd->VIEW(second));
232 eina_stringshare_del(wd->first->label);
233 evas_object_del(wd->VIEW(first));
237 EINA_LIST_FOREACH(wd->under_items, l, it)
241 eina_stringshare_del(it->label);
242 evas_object_del(VIEW(it));
247 EINA_LIST_FOREACH(wd->over_items, l, it)
251 eina_stringshare_del(it->label);
252 evas_object_del(VIEW(it));
257 EINA_LIST_FREE(wd->items, it) _item_del(it);
258 eina_list_free(wd->r_items);
262 _sizing_eval(Evas_Object * obj)
264 Widget_Data *wd = elm_widget_data_get(obj);
266 _diskselector_object_resize(obj, NULL, obj, NULL);
270 _theme_hook(Evas_Object * obj)
273 Elm_Diskselector_Item *it;
274 Widget_Data *wd = elm_widget_data_get(obj);
278 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
279 "base", elm_widget_style_get(obj));
282 EINA_LIST_FOREACH(wd->r_items, l, it)
284 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
285 elm_widget_style_get(obj));
286 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
291 EINA_LIST_FOREACH(wd->items, l, it)
293 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
294 elm_widget_style_get(obj));
295 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
298 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
299 elm_widget_style_get(obj));
305 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
307 Widget_Data *wd = elm_widget_data_get(obj);
308 Evas_Object *sub = event_info;
309 Elm_Diskselector_Item *it;
314 if (sub == wd->scroller)
318 EINA_LIST_FOREACH(wd->items, l, it)
331 _select_item(Elm_Diskselector_Item *it)
334 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
335 wd->selected_item = it;
336 _selected_item_indicate(wd->selected_item);
337 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
338 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
342 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
344 Widget_Data *wd = elm_widget_data_get(obj);
348 if (elm_widget_focus_get(obj))
350 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
351 evas_object_focus_set(wd->self, EINA_TRUE);
355 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
356 evas_object_focus_set(wd->self, EINA_FALSE);
361 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
363 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
364 Evas_Event_Key_Down *ev = event_info;
365 Widget_Data *wd = elm_widget_data_get(obj);
366 if (!wd) return EINA_FALSE;
367 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
368 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
370 Elm_Diskselector_Item *it = NULL;
373 if (!wd->selected_item) {
374 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
378 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
379 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
381 l = wd->selected_item->node->prev;
382 if ((!l) && (wd->round))
383 l = eina_list_last(wd->items);
385 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
386 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
388 l = wd->selected_item->node->next;
389 if ((!l) && (wd->round))
392 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
394 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
395 l = eina_list_last(wd->items);
396 else return EINA_FALSE;
399 it = eina_list_data_get(l);
403 wd->selected_item = it;
405 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
408 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
413 _count_letter(const char *str)
418 for (chnum = 0; ; chnum++)
420 pos = evas_string_char_next_get(str, pos, &code);
421 if (code == 0) break;
427 _check_letter(const char *str, int length)
432 for (chnum = 0; ; chnum++)
434 if (chnum == length) break;
435 pos = evas_string_char_next_get(str, pos, &code);
436 if (code == 0) break;
442 _check_string(void *data)
444 int mid, steps, length, diff;
445 Elm_Diskselector_Item *it;
449 Widget_Data *wd = data;
451 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
461 EINA_LIST_FOREACH(list, l, it)
465 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
466 /* item not visible */
467 if ((x + w <= ox) || (x >= ox + ow))
470 len = _count_letter(it->label);
471 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
472 // len = eina_stringshare_strlen(it->label);
475 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
477 else if (x + w >= ox + ow - 5)
478 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
482 if ((wd->len_threshold) && (len > wd->len_threshold))
483 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
486 edje_object_signal_emit(VIEW(it), "elm,state,center",
490 // if len is les that the limit len, skip anyway
491 if (len <= wd->len_side)
494 steps = len - wd->len_side + 1;
496 if (mid <= ox + ow / 2)
497 diff = (ox + ow / 2) - mid;
499 diff = mid - (ox + ow / 2);
501 length = len - (int)(diff * steps / (ow / 3));
502 length = MAX(length, wd->len_side);
503 // limit string len to "length" ut8f chars
504 length = _check_letter(it->label, length);
505 // cut it off at byte mark returned form _check_letter
506 strncpy(buf, it->label, length);
508 edje_object_part_text_set(VIEW(it), "elm.text", buf);
512 ecore_idle_enterer_del(wd->check_idler);
513 wd->check_idler = NULL;
518 _selected_item_indicate(Elm_Diskselector_Item *it)
520 Elm_Diskselector_Item *item;
523 wd = elm_widget_data_get(WIDGET(it));
527 EINA_LIST_FOREACH(wd->r_items, l, item)
529 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
531 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
536 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
537 const char *emission __UNUSED__, const char *source __UNUSED__)
539 Elm_Diskselector_Item *it = data;
544 wd = elm_widget_data_get(WIDGET(it));
548 if (wd->selected_item != it)
550 wd->selected_item = it;
551 _selected_item_indicate(wd->selected_item);
554 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
558 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
560 Evas_Coord x, y, w, h, bw;
561 Widget_Data *wd = data;
564 elm_smart_scroller_child_pos_get(obj, &x, &y);
565 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
568 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
569 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
570 elm_smart_scroller_child_region_show(wd->scroller,
571 x - ((w / wd->display_item_num) * wd->item_count),
574 elm_smart_scroller_child_region_show(wd->scroller,
575 x + ((w / wd->display_item_num) * wd->item_count),
581 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
583 Elm_Diskselector_Item *it;
584 Widget_Data *wd = data;
588 if (wd->idler) return;
595 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
596 EINA_LIST_FOREACH(list, l, it)
598 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
599 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
607 _move_scroller(void *data)
609 Evas_Object *obj = data;
612 Elm_Diskselector_Item *dit;
616 wd = elm_widget_data_get(obj);
617 if (!wd) return EINA_FALSE;
630 EINA_LIST_FOREACH(list, l, dit)
632 if (wd->selected_item == dit)
637 if (wd->round) i -= CEIL(wd->display_item_num);
642 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
646 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
647 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
651 ecore_idle_enterer_del(wd->idler);
654 wd->init = EINA_TRUE;
661 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
664 elm_box_unpack(wd->main_box, VIEW(it));
665 wd->r_items = eina_list_remove(wd->r_items, it);
666 eina_stringshare_del(it->label);
667 evas_object_del(VIEW(it));
672 _round_items_del(Widget_Data *wd)
675 Elm_Diskselector_Item * it;
677 _round_item_del(wd, wd->last);
679 _round_item_del(wd, wd->s_last);
681 _round_item_del(wd, wd->second);
683 _round_item_del(wd, wd->first);
686 EINA_LIST_FOREACH(wd->under_items, l, it)
688 _round_item_del(wd, it);
690 wd->under_items = eina_list_free(wd->under_items);
692 EINA_LIST_FOREACH(wd->over_items, l, it)
694 _round_item_del(wd, it);
696 wd->over_items = eina_list_free(wd->over_items);
700 _round_items_add(Widget_Data *wd)
702 Elm_Diskselector_Item *dit;
703 Elm_Diskselector_Item *it;
704 Elm_Diskselector_Item *temp_it;
706 dit = it = eina_list_nth(wd->items, 0);
711 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
713 wd->first->node = it->node;
714 wd->r_items = eina_list_append(wd->r_items, wd->first);
717 it = eina_list_nth(wd->items, 1);
722 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
724 wd->second->node = it->node;
725 wd->r_items = eina_list_append(wd->r_items, wd->second);
728 // if more than 3 itmes should be displayed
729 for (i = 2; i < CEIL(wd->display_item_num); i++)
731 it = eina_list_nth(wd->items, i);
733 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
734 wd->over_items = eina_list_append(wd->over_items, temp_it);
735 wd->r_items = eina_list_append(wd->r_items, temp_it);
738 it = eina_list_nth(wd->items, wd->item_count - 1);
743 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
745 wd->last->node = it->node;
746 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
749 it = eina_list_nth(wd->items, wd->item_count - 2);
754 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
756 wd->s_last->node = it->node;
757 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
760 // if more than 3 itmes should be displayed
761 for (i = 3; i <= CEIL(wd->display_item_num); i++)
763 it = eina_list_nth(wd->items, wd->item_count - i);
765 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
766 wd->under_items = eina_list_append(wd->under_items, temp_it);
767 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
772 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
774 if (it->icon == icon) return;
776 evas_object_del(it->icon);
780 evas_object_size_hint_min_set(it->icon, 24, 24);
781 evas_object_size_hint_max_set(it->icon, 40, 40);
782 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
783 evas_object_show(it->icon);
784 elm_widget_sub_object_add(WIDGET(it), it->icon);
789 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
792 Elm_Diskselector_Item *dit;
798 wd = elm_widget_data_get(WIDGET(it));
803 // Get index from indentical item from round items
804 EINA_LIST_FOREACH(wd->r_items, l, dit)
806 if (it == dit) break;
811 ic = eina_list_count(wd->r_items);
812 if (idx >= ic) return;
815 // Number of added items: CEIL(wd->display_item_num)
816 ac = CEIL(wd->display_item_num);
818 if (((idx >= 0) && (idx < ac)) ||
819 ((idx >= ac) && (idx < (2 * ac))))
821 // Selected item: under, low region
822 dit = eina_list_nth(wd->r_items,
823 idx + ic - (2 * ac));
825 else if (((idx >= (ic - ac)) && (idx < ic)) ||
826 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
828 // Selected item: over, high region
829 dit = eina_list_nth(wd->r_items,
830 idx - ic + (2 * ac));
833 if(dit) _item_icon_set(dit, icon);
834 _sizing_eval(wd->self);
839 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
841 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
842 Elm_Diskselector_Item *item;
843 if (part && strcmp(part, "default")) return;
844 item = (Elm_Diskselector_Item *) it;
845 eina_stringshare_replace(&item->label, label);
846 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
850 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
852 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
853 if (part && strcmp(part, "default")) return NULL;
854 return ((Elm_Diskselector_Item *) it)->label;
858 _item_content_set_hook(Elm_Object_Item *it,
860 Evas_Object *content)
862 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
863 if (part && strcmp(part, "icon")) return;
864 _item_icon_set((Elm_Diskselector_Item *) it, content);
865 _check_identical_item((Elm_Diskselector_Item *) it, content);
869 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
871 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
872 if (part && strcmp(part, "icon")) return NULL;
873 return ((Elm_Diskselector_Item *) it)->icon;
877 elm_diskselector_add(Evas_Object *parent)
883 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
885 ELM_SET_WIDTYPE(widtype, "diskselector");
886 elm_widget_type_set(obj, "diskselector");
887 elm_widget_sub_object_add(parent, obj);
888 elm_widget_data_set(obj, wd);
889 elm_widget_del_hook_set(obj, _del_hook);
890 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
891 elm_widget_theme_hook_set(obj, _theme_hook);
892 elm_widget_can_focus_set(obj, EINA_TRUE);
893 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
894 elm_widget_event_hook_set(obj, _event_hook);
898 wd->round = EINA_FALSE;
899 wd->init = EINA_FALSE;
901 wd->display_item_num_by_api = EINA_FALSE;
903 wd->scroller = elm_smart_scroller_add(e);
904 elm_smart_scroller_widget_set(wd->scroller, obj);
906 elm_widget_resize_object_set(obj, wd->scroller);
907 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
908 ELM_SMART_SCROLLER_POLICY_OFF);
909 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
910 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
912 evas_object_smart_callback_add(wd->scroller, "animate,stop",
913 _scroller_stop_cb, wd);
914 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
916 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
917 _diskselector_object_resize, obj);
919 wd->main_box = elm_box_add(parent);
920 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
921 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
922 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
924 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
926 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
928 elm_widget_sub_object_add(obj, wd->main_box);
930 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
932 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
933 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
935 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
937 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
939 elm_box_pack_end(wd->main_box, wd->left_blank);
940 evas_object_show(wd->left_blank);
942 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
943 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
945 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
947 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
949 elm_box_pack_end(wd->main_box, wd->right_blank);
950 evas_object_show(wd->right_blank);
954 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
955 evas_object_smart_callbacks_descriptions_set(obj, _signals);
961 elm_diskselector_round_get(const Evas_Object *obj)
963 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
964 Widget_Data *wd = elm_widget_data_get(obj);
965 if (!wd) return EINA_FALSE;
970 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
973 Elm_Diskselector_Item *it;
975 ELM_CHECK_WIDTYPE(obj, widtype);
976 Widget_Data *wd = elm_widget_data_get(obj);
979 if (wd->round == round)
985 wd->r_items = eina_list_clone(wd->items);
986 elm_box_unpack(wd->main_box, wd->left_blank);
987 evas_object_hide(wd->left_blank);
988 elm_box_unpack(wd->main_box, wd->right_blank);
989 evas_object_hide(wd->right_blank);
993 _round_items_add(wd);
996 elm_box_pack_start(wd->main_box, wd->VIEW(last));
998 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1000 // if more than 3 items should be displayed
1001 EINA_LIST_FOREACH(wd->under_items, elist, it)
1002 elm_box_pack_start(wd->main_box, VIEW(it));
1005 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1007 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1009 // if more than 3 items should be displayed
1010 EINA_LIST_FOREACH(wd->over_items, elist, it)
1011 elm_box_pack_end(wd->main_box, VIEW(it));
1015 _round_items_del(wd);
1016 elm_box_pack_start(wd->main_box, wd->left_blank);
1017 elm_box_pack_end(wd->main_box, wd->right_blank);
1018 eina_list_free(wd->r_items);
1022 _selected_item_indicate(wd->selected_item);
1027 elm_diskselector_side_label_length_get(const Evas_Object *obj)
1029 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1030 Widget_Data *wd = elm_widget_data_get(obj);
1032 return wd->len_side;
1036 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
1038 ELM_CHECK_WIDTYPE(obj, widtype);
1039 Widget_Data *wd = elm_widget_data_get(obj);
1045 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
1047 return elm_diskselector_side_label_length_set(obj, len);
1051 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1053 return elm_diskselector_side_label_length_get(obj);
1057 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1059 ELM_CHECK_WIDTYPE(obj, widtype);
1060 Widget_Data *wd = elm_widget_data_get(obj);
1063 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1067 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1069 ELM_CHECK_WIDTYPE(obj, widtype);
1070 Widget_Data *wd = elm_widget_data_get(obj);
1072 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1076 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1078 ELM_CHECK_WIDTYPE(obj, widtype);
1079 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1080 Widget_Data *wd = elm_widget_data_get(obj);
1081 if ((!wd) || (!wd->scroller)) return;
1082 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1083 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1084 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1088 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1090 ELM_CHECK_WIDTYPE(obj, widtype);
1091 Widget_Data *wd = elm_widget_data_get(obj);
1092 if ((!wd) || (!wd->scroller)) return;
1093 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1094 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1096 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1100 elm_diskselector_clear(Evas_Object *obj)
1102 ELM_CHECK_WIDTYPE(obj, widtype);
1103 Widget_Data *wd = elm_widget_data_get(obj);
1104 Elm_Diskselector_Item *it;
1107 if (!wd->items) return;
1109 wd->selected_item = NULL;
1110 EINA_LIST_FREE(wd->items, it) _item_del(it);
1111 _round_items_del(wd);
1115 EAPI const Eina_List *
1116 elm_diskselector_items_get(const Evas_Object *obj)
1118 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1119 Widget_Data *wd = elm_widget_data_get(obj);
1120 if (!wd) return NULL;
1124 EAPI Elm_Object_Item *
1125 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1127 Elm_Diskselector_Item *it;
1128 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1129 Widget_Data *wd = elm_widget_data_get(obj);
1130 if (!wd) return NULL;
1132 it = _item_new(obj, icon, label, func, data);
1133 wd->items = eina_list_append(wd->items, it);
1134 it->node = eina_list_last(wd->items);
1138 _round_items_del(wd);
1139 wd->r_items = eina_list_append(wd->r_items, it);
1140 _round_items_add(wd);
1142 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1144 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1145 elm_box_pack_end(wd->main_box, VIEW(it));
1147 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1149 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1153 elm_box_unpack(wd->main_box, wd->right_blank);
1154 elm_box_pack_end(wd->main_box, VIEW(it));
1155 elm_box_pack_end(wd->main_box, wd->right_blank);
1157 if (!wd->selected_item)
1158 wd->selected_item = it;
1160 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1162 return (Elm_Object_Item *) it;
1166 elm_diskselector_item_del(Elm_Object_Item * it)
1168 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1169 Elm_Diskselector_Item *item, *item2, *dit;
1173 item = (Elm_Diskselector_Item *) it;
1174 wd = elm_widget_data_get(WIDGET(item));
1177 elm_box_unpack(wd->main_box, VIEW(item));
1180 wd->r_items = eina_list_remove(wd->r_items, item);
1182 wd->items = eina_list_remove(wd->items, item);
1184 if (wd->selected_item == item)
1186 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1188 wd->selected_item = dit;
1190 wd->selected_item = eina_list_nth(wd->items, 1);
1192 _selected_item_indicate(wd->selected_item);
1196 wd->item_count -= 1;
1200 if (!wd->item_count)
1202 evas_object_hide(wd->VIEW(first));
1203 evas_object_hide(wd->VIEW(second));
1204 evas_object_hide(wd->VIEW(last));
1205 evas_object_hide(wd->VIEW(s_last));
1207 EINA_LIST_FOREACH(wd->under_items, l, item2)
1208 evas_object_hide(VIEW(item2));
1210 EINA_LIST_FOREACH(wd->over_items, l, item2)
1211 evas_object_hide(VIEW(item2));
1215 dit = eina_list_nth(wd->items, 0);
1218 eina_stringshare_replace(&wd->first->label, dit->label);
1219 edje_object_part_text_set(wd->VIEW(first), "elm.text",
1222 dit = eina_list_nth(wd->items, 1);
1225 eina_stringshare_replace(&wd->second->label, dit->label);
1226 edje_object_part_text_set(wd->VIEW(second), "elm.text",
1229 // if more than 3 itmes should be displayed
1230 for (i = 2; i < CEIL(wd->display_item_num); i++)
1232 dit = eina_list_nth(wd->items, i);
1233 item2 = eina_list_nth(wd->over_items, i - 2);
1234 eina_stringshare_replace(&item2->label, dit->label);
1235 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
1238 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1241 eina_stringshare_replace(&wd->last->label, dit->label);
1242 edje_object_part_text_set(wd->VIEW(last), "elm.text",
1245 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1248 eina_stringshare_replace(&wd->s_last->label, dit->label);
1249 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
1252 // if more than 3 itmes should be displayed
1253 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1255 dit = eina_list_nth(wd->items, wd->item_count - i);
1256 item2 = eina_list_nth(wd->under_items, i - 3);
1257 eina_stringshare_replace(&item2->label, dit->label);
1258 edje_object_part_text_set(VIEW(item2), "elm.text",
1263 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
1264 _sizing_eval(wd->self);
1268 elm_diskselector_item_label_get(const Elm_Object_Item * it)
1270 return _item_text_get_hook(it, NULL);
1274 elm_diskselector_item_label_set(Elm_Object_Item * it, const char *label)
1276 _item_text_set_hook(it, NULL, label);
1279 EAPI Elm_Object_Item *
1280 elm_diskselector_selected_item_get(const Evas_Object *obj)
1282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1283 Widget_Data *wd = elm_widget_data_get(obj);
1284 if (!wd) return NULL;
1285 return (Elm_Object_Item *) wd->selected_item;
1289 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1291 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1293 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1294 wd = elm_widget_data_get(WIDGET(item));
1297 if ((wd->selected_item == item) && (selected))
1300 if ((wd->selected_item == item) && (!selected))
1301 wd->selected_item = eina_list_data_get(wd->items);
1304 wd->selected_item = item;
1305 _selected_item_indicate(wd->selected_item);
1309 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1313 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1315 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1316 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1317 if (!wd) return EINA_FALSE;
1318 return (wd->selected_item == ((Elm_Diskselector_Item *) it));
1322 elm_diskselector_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1324 elm_object_item_del_cb_set(it, func);
1328 elm_diskselector_item_data_get(const Elm_Object_Item *it)
1330 return elm_object_item_data_get(it);
1334 elm_diskselector_item_icon_get(const Elm_Object_Item *it)
1336 return _item_content_get_hook(it, NULL);
1340 elm_diskselector_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1342 _item_content_set_hook(it, NULL, icon);
1345 EAPI Elm_Object_Item *
1346 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1348 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1349 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1350 if (item->node->prev) return item->node->prev->data;
1354 EAPI Elm_Object_Item *
1355 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1357 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1358 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1359 if (item->node->next) return item->node->next->data;
1363 EAPI Elm_Object_Item *
1364 elm_diskselector_first_item_get(const Evas_Object *obj)
1366 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1367 Widget_Data *wd = elm_widget_data_get(obj);
1368 if (!wd || !wd->items) return NULL;
1369 return eina_list_data_get(wd->items);
1372 EAPI Elm_Object_Item *
1373 elm_diskselector_last_item_get(const Evas_Object *obj)
1375 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1376 Widget_Data *wd = elm_widget_data_get(obj);
1377 if (!wd || !wd->items) return NULL;
1378 return eina_list_data_get(eina_list_last(wd->items));
1382 elm_diskselector_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1384 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1385 elm_widget_item_tooltip_text_set(it, text);
1389 elm_diskselector_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1391 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1392 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1396 elm_diskselector_item_tooltip_unset(Elm_Object_Item *it)
1398 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1399 elm_widget_item_tooltip_unset(it);
1403 elm_diskselector_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1405 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1406 elm_widget_item_tooltip_style_set(it, style);
1410 elm_diskselector_item_tooltip_style_get(const Elm_Object_Item *it)
1412 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1413 return elm_widget_item_tooltip_style_get(it);
1417 elm_diskselector_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1419 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1420 elm_widget_item_cursor_set(it, cursor);
1424 elm_diskselector_item_cursor_get(const Elm_Object_Item *it)
1426 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1427 return elm_widget_item_cursor_get(it);
1431 elm_diskselector_item_cursor_unset(Elm_Object_Item *it)
1433 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1434 elm_widget_item_cursor_unset(it);
1438 elm_diskselector_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1440 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1441 elm_widget_item_cursor_style_set(it, style);
1445 elm_diskselector_item_cursor_style_get(const Elm_Object_Item *it)
1447 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1448 return elm_widget_item_cursor_style_get(it);
1452 elm_diskselector_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1454 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1455 elm_widget_item_cursor_engine_only_set(it, engine_only);
1459 elm_diskselector_item_cursor_engine_only_get(const Elm_Object_Item *it)
1461 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1462 return elm_widget_item_cursor_engine_only_get(it);
1466 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1468 ELM_CHECK_WIDTYPE(obj, widtype);
1469 Widget_Data *wd = elm_widget_data_get(obj);
1471 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1472 wd->display_item_num = num;
1473 wd->display_item_num_by_api = EINA_TRUE;
1477 elm_diskselector_display_item_num_get(const Evas_Object *item)
1479 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1480 Widget_Data *wd = elm_widget_data_get(item);
1482 return wd->display_item_num;