1 #include <Elementary.h>
5 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
9 #define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
12 #define DISPLAY_ITEM_NUM_MIN 3
14 typedef struct _Widget_Data Widget_Data;
19 Evas_Object *scroller;
20 Evas_Object *main_box;
21 Evas_Object *left_blank;
22 Evas_Object *right_blank;
23 Elm_Diskselector_Item *selected_item;
24 Elm_Diskselector_Item *first;
25 Elm_Diskselector_Item *second;
26 Elm_Diskselector_Item *s_last;
27 Elm_Diskselector_Item *last;
30 Eina_List *over_items;
31 Eina_List *under_items;
32 int item_count, len_threshold, len_side, display_item_num;
34 Ecore_Idler *check_idler;
35 Evas_Coord minw, minh;
38 Eina_Bool display_item_num_by_api:1;
41 struct _Elm_Diskselector_Item
50 static const char *widtype = NULL;
52 #define ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, ...) \
53 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
54 ELM_CHECK_WIDTYPE(it->base.widget, widtype) __VA_ARGS__;
56 static Eina_Bool _move_scroller(void *data);
57 static void _del_hook(Evas_Object * obj);
58 static void _del_pre_hook(Evas_Object * obj);
59 static void _sizing_eval(Evas_Object * obj);
60 static void _theme_hook(Evas_Object * obj);
61 static void _on_focus_hook(void *data, Evas_Object *obj);
62 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
63 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
64 static void _round_items_del(Widget_Data *wd);
65 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
66 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
67 const char *emission __UNUSED__,
68 const char *source __UNUSED__);
69 static void _selected_item_indicate(Elm_Diskselector_Item *it);
71 static const char SIG_SELECTED[] = "selected";
72 static const Evas_Smart_Cb_Description _signals[] = {
78 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
83 wd = elm_widget_data_get(data);
86 if (wd->minw == -1 && wd->minh == -1) elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
87 edje_object_size_min_restricted_calc(elm_smart_scroller_edje_object_get(
88 wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
89 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
90 evas_object_size_hint_max_set(obj, -1, -1);
92 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
94 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
96 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
98 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
99 (int)(w / wd->display_item_num), 0);
102 wd->idler = ecore_idler_add(_move_scroller, data);
105 static Elm_Diskselector_Item *
106 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
108 Elm_Diskselector_Item *it;
109 const char *style = elm_widget_style_get(obj);
111 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
112 if (!it) return NULL;
114 it->label = eina_stringshare_add(label);
117 it->base.data = data;
118 it->base.view = edje_object_add(evas_object_evas_get(obj));
119 _elm_theme_object_set(obj, it->base.view, "diskselector", "item", style);
120 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND,
122 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL,
124 evas_object_show(it->base.view);
128 edje_object_part_text_set(it->base.view, "elm.text", it->label);
129 edje_object_signal_callback_add(it->base.view, "elm,action,click", "", _item_click_cb, it);
133 evas_object_size_hint_min_set(it->icon, 24, 24);
134 evas_object_size_hint_max_set(it->icon, 40, 40);
135 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
136 evas_object_show(it->icon);
137 elm_widget_sub_object_add(obj, it->icon);
143 _item_del(Elm_Diskselector_Item *item)
146 eina_stringshare_del(item->label);
148 evas_object_del(item->icon);
149 elm_widget_item_del(item);
153 _theme_data_get(Widget_Data *wd)
156 str = edje_object_data_get(wd->right_blank, "len_threshold");
157 if (str) wd->len_threshold = MAX(0, atoi(str));
158 else wd->len_threshold = 0;
160 if (!wd->display_item_num_by_api)
162 str = edje_object_data_get(wd->right_blank, "display_item_num");
163 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
164 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
167 str = edje_object_data_get(wd->right_blank, "min_width");
168 if (str) wd->minw = MAX(-1, atoi(str));
171 str = edje_object_data_get(wd->right_blank, "min_height");
172 if (str) wd->minh = MAX(-1, atoi(str));
177 _del_hook(Evas_Object * obj)
179 Widget_Data *wd = elm_widget_data_get(obj);
185 _del_pre_hook(Evas_Object * obj)
187 Elm_Diskselector_Item *it;
190 Widget_Data *wd = elm_widget_data_get(obj);
194 evas_object_del(wd->left_blank);
196 evas_object_del(wd->right_blank);
199 eina_stringshare_del(wd->last->label);
200 evas_object_del(wd->last->base.view);
205 eina_stringshare_del(wd->s_last->label);
206 evas_object_del(wd->s_last->base.view);
211 eina_stringshare_del(wd->second->label);
212 evas_object_del(wd->second->base.view);
217 eina_stringshare_del(wd->first->label);
218 evas_object_del(wd->first->base.view);
222 EINA_LIST_FOREACH(wd->under_items, l, it)
226 eina_stringshare_del(it->label);
227 evas_object_del(it->base.view);
232 EINA_LIST_FOREACH(wd->over_items, l, it)
236 eina_stringshare_del(it->label);
237 evas_object_del(it->base.view);
242 EINA_LIST_FREE(wd->items, it) _item_del(it);
243 eina_list_free(wd->r_items);
247 _sizing_eval(Evas_Object * obj)
249 Widget_Data *wd = elm_widget_data_get(obj);
251 _diskselector_object_resize(obj, NULL, obj, NULL);
255 _theme_hook(Evas_Object * obj)
258 Elm_Diskselector_Item *it;
259 Widget_Data *wd = elm_widget_data_get(obj);
263 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
264 "base", elm_widget_style_get(obj));
267 EINA_LIST_FOREACH(wd->r_items, l, it)
269 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
270 elm_widget_style_get(obj));
271 edje_object_part_text_set(it->base.view, "elm.text", it->label);
276 EINA_LIST_FOREACH(wd->items, l, it)
278 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
279 elm_widget_style_get(obj));
280 edje_object_part_text_set(it->base.view, "elm.text", it->label);
283 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
284 elm_widget_style_get(obj));
290 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
292 Widget_Data *wd = elm_widget_data_get(obj);
293 Evas_Object *sub = event_info;
294 Elm_Diskselector_Item *it;
299 if (sub == wd->scroller)
303 EINA_LIST_FOREACH(wd->items, l, it)
316 _select_item(Elm_Diskselector_Item *it)
319 Widget_Data *wd = elm_widget_data_get(it->base.widget);
320 wd->selected_item = it;
321 _selected_item_indicate(wd->selected_item);
322 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
323 evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
327 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
329 Widget_Data *wd = elm_widget_data_get(obj);
333 if (elm_widget_focus_get(obj))
335 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
336 evas_object_focus_set(wd->self, EINA_TRUE);
340 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
341 evas_object_focus_set(wd->self, EINA_FALSE);
346 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
348 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
349 Evas_Event_Key_Down *ev = event_info;
350 Widget_Data *wd = elm_widget_data_get(obj);
351 if (!wd) return EINA_FALSE;
352 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
353 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
355 Elm_Diskselector_Item *it = NULL;
358 if (!wd->selected_item) {
359 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
363 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
364 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
366 l = wd->selected_item->node->prev;
367 if ((!l) && (wd->round))
368 l = eina_list_last(wd->items);
370 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
371 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
373 l = wd->selected_item->node->next;
374 if ((!l) && (wd->round))
377 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
379 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
380 l = eina_list_last(wd->items);
381 else return EINA_FALSE;
384 it = eina_list_data_get(l);
388 wd->selected_item = it;
390 wd->idler = ecore_idler_add(_move_scroller, obj);
393 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
398 _count_letter(const char *str)
403 for (chnum = 0; ; chnum++)
405 pos = evas_string_char_next_get(str, pos, &code);
406 if (code == 0) break;
412 _check_letter(const char *str, int length)
417 for (chnum = 0; ; chnum++)
419 if (chnum == length) break;
420 pos = evas_string_char_next_get(str, pos, &code);
421 if (code == 0) break;
427 _check_string(void *data)
429 int mid, steps, length, diff;
430 Elm_Diskselector_Item *it;
434 Widget_Data *wd = data;
436 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
446 EINA_LIST_FOREACH(list, l, it)
450 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
451 /* item not visible */
452 if ((x + w <= ox) || (x >= ox + ow))
455 len = _count_letter(it->label);
456 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
457 // len = eina_stringshare_strlen(it->label);
460 edje_object_signal_emit(it->base.view, "elm,state,left_side",
462 else if (x + w >= ox + ow - 5)
463 edje_object_signal_emit(it->base.view, "elm,state,right_side",
467 if ((wd->len_threshold) && (len > wd->len_threshold))
468 edje_object_signal_emit(it->base.view, "elm,state,center_small",
471 edje_object_signal_emit(it->base.view, "elm,state,center",
475 // if len is les that the limit len, skip anyway
476 if (len <= wd->len_side)
479 steps = len - wd->len_side + 1;
481 if (mid <= ox + ow / 2)
482 diff = (ox + ow / 2) - mid;
484 diff = mid - (ox + ow / 2);
486 length = len - (int)(diff * steps / (ow / 3));
487 length = MAX(length, wd->len_side);
488 // limit string len to "length" ut8f chars
489 length = _check_letter(it->label, length);
490 // cut it off at byte mark returned form _check_letter
491 strncpy(buf, it->label, length);
493 edje_object_part_text_set(it->base.view, "elm.text", buf);
497 ecore_idler_del(wd->check_idler);
498 wd->check_idler = NULL;
503 _selected_item_indicate(Elm_Diskselector_Item *it)
505 Elm_Diskselector_Item *item;
508 wd = elm_widget_data_get(it->base.widget);
512 EINA_LIST_FOREACH(wd->r_items, l, item)
514 if (!strcmp(item->label, it->label)) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
516 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
521 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
522 const char *emission __UNUSED__, const char *source __UNUSED__)
524 Elm_Diskselector_Item *it = data;
529 wd = elm_widget_data_get(it->base.widget);
533 if (wd->selected_item != it)
535 wd->selected_item = it;
536 _selected_item_indicate(wd->selected_item);
539 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
543 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
545 Evas_Coord x, y, w, h, bw;
546 Widget_Data *wd = data;
549 elm_smart_scroller_child_pos_get(obj, &x, &y);
550 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
553 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
554 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
555 elm_smart_scroller_child_region_show(wd->scroller,
556 x - ((w / wd->display_item_num) * wd->item_count),
559 elm_smart_scroller_child_region_show(wd->scroller,
560 x + ((w / wd->display_item_num) * wd->item_count),
566 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
568 Elm_Diskselector_Item *it;
569 Widget_Data *wd = data;
581 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
582 EINA_LIST_FOREACH(list, l, it)
584 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
585 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
596 _move_scroller(void *data)
598 Evas_Object *obj = data;
601 Elm_Diskselector_Item *dit;
605 wd = elm_widget_data_get(obj);
606 if (!wd) return EINA_FALSE;
613 EINA_LIST_FOREACH(wd->items, l, dit)
615 if (wd->selected_item == dit)
622 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
626 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
627 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
631 ecore_idler_del(wd->idler);
634 wd->init = EINA_TRUE;
641 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
644 elm_box_unpack(wd->main_box, it->base.view);
645 wd->r_items = eina_list_remove(wd->r_items, it);
646 eina_stringshare_del(it->label);
647 evas_object_del(it->base.view);
652 _round_items_del(Widget_Data *wd)
655 Elm_Diskselector_Item * it;
657 _round_item_del(wd, wd->last);
659 _round_item_del(wd, wd->s_last);
661 _round_item_del(wd, wd->second);
663 _round_item_del(wd, wd->first);
666 EINA_LIST_FOREACH(wd->under_items, l, it)
668 _round_item_del(wd, it);
672 EINA_LIST_FOREACH(wd->over_items, l, it)
674 _round_item_del(wd, it);
680 _round_items_add(Widget_Data *wd)
682 Elm_Diskselector_Item *dit;
683 Elm_Diskselector_Item *it;
684 Elm_Diskselector_Item *temp_it;
686 dit = it = eina_list_nth(wd->items, 0);
691 wd->first = _item_new(it->base.widget, it->icon, it->label, it->func,
693 wd->first->node = it->node;
694 wd->r_items = eina_list_append(wd->r_items, wd->first);
697 it = eina_list_nth(wd->items, 1);
702 wd->second = _item_new(it->base.widget, it->icon, it->label, it->func,
704 wd->second->node = it->node;
705 wd->r_items = eina_list_append(wd->r_items, wd->second);
708 // if more than 3 itmes should be displayed
709 for (i = 2; i < CEIL(wd->display_item_num); i++)
711 it = eina_list_nth(wd->items, i);
713 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
714 wd->over_items = eina_list_append(wd->over_items, temp_it);
715 wd->r_items = eina_list_append(wd->r_items, temp_it);
718 it = eina_list_nth(wd->items, wd->item_count - 1);
723 wd->last = _item_new(it->base.widget, it->icon, it->label, it->func,
725 wd->last->node = it->node;
726 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
729 it = eina_list_nth(wd->items, wd->item_count - 2);
734 wd->s_last = _item_new(it->base.widget, it->icon, it->label, it->func,
736 wd->s_last->node = it->node;
737 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
740 // if more than 3 itmes should be displayed
741 for (i = 3; i <= CEIL(wd->display_item_num); i++)
743 it = eina_list_nth(wd->items, wd->item_count - i);
745 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
746 wd->under_items = eina_list_append(wd->under_items, temp_it);
747 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
752 elm_diskselector_add(Evas_Object *parent)
758 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
760 ELM_SET_WIDTYPE(widtype, "diskselector");
761 elm_widget_type_set(obj, "diskselector");
762 elm_widget_sub_object_add(parent, obj);
763 elm_widget_data_set(obj, wd);
764 elm_widget_del_hook_set(obj, _del_hook);
765 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
766 elm_widget_theme_hook_set(obj, _theme_hook);
767 elm_widget_can_focus_set(obj, EINA_TRUE);
768 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
769 elm_widget_event_hook_set(obj, _event_hook);
773 wd->round = EINA_FALSE;
774 wd->init = EINA_FALSE;
776 wd->display_item_num_by_api = EINA_FALSE;
778 wd->scroller = elm_smart_scroller_add(e);
779 elm_smart_scroller_widget_set(wd->scroller, obj);
781 elm_widget_resize_object_set(obj, wd->scroller);
782 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
783 ELM_SMART_SCROLLER_POLICY_OFF);
784 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
785 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
787 evas_object_smart_callback_add(wd->scroller, "animate,stop",
788 _scroller_stop_cb, wd);
789 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
791 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
792 _diskselector_object_resize, obj);
794 wd->main_box = elm_box_add(parent);
795 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
796 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
797 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
799 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
801 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
803 elm_widget_sub_object_add(obj, wd->main_box);
805 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
807 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
808 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
810 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
812 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
814 elm_box_pack_end(wd->main_box, wd->left_blank);
815 evas_object_show(wd->left_blank);
817 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
818 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
820 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
822 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
824 elm_box_pack_end(wd->main_box, wd->right_blank);
825 evas_object_show(wd->right_blank);
829 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
830 evas_object_smart_callbacks_descriptions_set(obj, _signals);
836 elm_diskselector_round_get(const Evas_Object *obj)
838 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
839 Widget_Data *wd = elm_widget_data_get(obj);
840 if (!wd) return EINA_FALSE;
845 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
848 Elm_Diskselector_Item *it;
850 ELM_CHECK_WIDTYPE(obj, widtype);
851 Widget_Data *wd = elm_widget_data_get(obj);
854 if (wd->round == round)
860 wd->r_items = eina_list_clone(wd->items);
861 elm_box_unpack(wd->main_box, wd->left_blank);
862 evas_object_hide(wd->left_blank);
863 elm_box_unpack(wd->main_box, wd->right_blank);
864 evas_object_hide(wd->right_blank);
868 _round_items_add(wd);
871 elm_box_pack_start(wd->main_box, wd->last->base.view);
873 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
875 // if more than 3 items should be displayed
876 EINA_LIST_FOREACH(wd->under_items, elist, it)
877 elm_box_pack_start(wd->main_box, it->base.view);
880 elm_box_pack_end(wd->main_box, wd->first->base.view);
882 elm_box_pack_end(wd->main_box, wd->second->base.view);
884 // if more than 3 items should be displayed
885 EINA_LIST_FOREACH(wd->over_items, elist, it)
886 elm_box_pack_end(wd->main_box, it->base.view);
890 _round_items_del(wd);
891 elm_box_pack_start(wd->main_box, wd->left_blank);
892 elm_box_pack_end(wd->main_box, wd->right_blank);
893 eina_list_free(wd->r_items);
897 _selected_item_indicate(wd->selected_item);
902 elm_diskselector_side_label_length_get(const Evas_Object *obj)
904 ELM_CHECK_WIDTYPE(obj, widtype) 0;
905 Widget_Data *wd = elm_widget_data_get(obj);
911 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
913 ELM_CHECK_WIDTYPE(obj, widtype);
914 Widget_Data *wd = elm_widget_data_get(obj);
920 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
922 return elm_diskselector_side_label_length_set(obj, len);
926 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
928 return elm_diskselector_side_label_length_get(obj);
932 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
934 ELM_CHECK_WIDTYPE(obj, widtype);
935 Widget_Data *wd = elm_widget_data_get(obj);
938 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
942 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
944 ELM_CHECK_WIDTYPE(obj, widtype);
945 Widget_Data *wd = elm_widget_data_get(obj);
947 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
951 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
953 ELM_CHECK_WIDTYPE(obj, widtype);
954 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
955 Widget_Data *wd = elm_widget_data_get(obj);
956 if ((!wd) || (!wd->scroller)) return;
957 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
958 *policy_h = (Elm_Scroller_Policy) s_policy_h;
959 *policy_v = (Elm_Scroller_Policy) s_policy_v;
963 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
965 ELM_CHECK_WIDTYPE(obj, widtype);
966 Widget_Data *wd = elm_widget_data_get(obj);
967 if ((!wd) || (!wd->scroller)) return;
968 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
969 (policy_v >= ELM_SCROLLER_POLICY_LAST))
971 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
975 elm_diskselector_clear(Evas_Object *obj)
977 ELM_CHECK_WIDTYPE(obj, widtype);
978 Widget_Data *wd = elm_widget_data_get(obj);
979 Elm_Diskselector_Item *it;
982 if (!wd->items) return;
984 wd->selected_item = NULL;
985 EINA_LIST_FREE(wd->items, it) _item_del(it);
986 _round_items_del(wd);
990 EAPI const Eina_List *
991 elm_diskselector_items_get(const Evas_Object *obj)
993 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
994 Widget_Data *wd = elm_widget_data_get(obj);
995 if (!wd) return NULL;
999 EAPI Elm_Diskselector_Item *
1000 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1002 Elm_Diskselector_Item *it;
1003 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1004 Widget_Data *wd = elm_widget_data_get(obj);
1005 if (!wd) return NULL;
1007 it = _item_new(obj, icon, label, func, data);
1008 wd->items = eina_list_append(wd->items, it);
1009 it->node = eina_list_last(wd->items);
1013 _round_items_del(wd);
1014 wd->r_items = eina_list_append(wd->r_items, it);
1015 _round_items_add(wd);
1017 elm_box_pack_start(wd->main_box, wd->last->base.view);
1019 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
1020 elm_box_pack_end(wd->main_box, it->base.view);
1022 elm_box_pack_end(wd->main_box, wd->first->base.view);
1024 elm_box_pack_end(wd->main_box, wd->second->base.view);
1028 elm_box_unpack(wd->main_box, wd->right_blank);
1029 elm_box_pack_end(wd->main_box, it->base.view);
1030 elm_box_pack_end(wd->main_box, wd->right_blank);
1032 if (!wd->selected_item)
1033 wd->selected_item = it;
1035 wd->idler = ecore_idler_add(_move_scroller, obj);
1041 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1043 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1044 Elm_Diskselector_Item *dit;
1045 Elm_Diskselector_Item *item;
1048 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1051 elm_box_unpack(wd->main_box, it->base.view);
1054 wd->r_items = eina_list_remove(wd->r_items, it);
1056 wd->items = eina_list_remove(wd->items, it);
1058 if (wd->selected_item == it)
1060 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1062 wd->selected_item = dit;
1064 wd->selected_item = eina_list_nth(wd->items, 1);
1066 _selected_item_indicate(wd->selected_item);
1070 wd->item_count -= 1;
1074 if (!wd->item_count)
1076 evas_object_hide(wd->first->base.view);
1077 evas_object_hide(wd->second->base.view);
1078 evas_object_hide(wd->last->base.view);
1079 evas_object_hide(wd->s_last->base.view);
1081 EINA_LIST_FOREACH(wd->under_items, l, item)
1082 evas_object_hide(item->base.view);
1084 EINA_LIST_FOREACH(wd->over_items, l, item)
1085 evas_object_hide(item->base.view);
1089 dit = eina_list_nth(wd->items, 0);
1092 eina_stringshare_replace(&wd->first->label, dit->label);
1093 edje_object_part_text_set(wd->first->base.view, "elm.text",
1096 dit = eina_list_nth(wd->items, 1);
1099 eina_stringshare_replace(&wd->second->label, dit->label);
1100 edje_object_part_text_set(wd->second->base.view, "elm.text",
1103 // if more than 3 itmes should be displayed
1104 for (i = 2; i < CEIL(wd->display_item_num); i++)
1106 dit = eina_list_nth(wd->items, i);
1107 item = eina_list_nth(wd->over_items, i - 2);
1108 eina_stringshare_replace(&item->label, dit->label);
1109 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1112 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1115 eina_stringshare_replace(&wd->last->label, dit->label);
1116 edje_object_part_text_set(wd->last->base.view, "elm.text",
1119 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1122 eina_stringshare_replace(&wd->s_last->label, dit->label);
1123 edje_object_part_text_set(wd->s_last->base.view, "elm.text",
1126 // if more than 3 itmes should be displayed
1127 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1129 dit = eina_list_nth(wd->items, wd->item_count - i);
1130 item = eina_list_nth(wd->under_items, i - 3);
1131 eina_stringshare_replace(&item->label, dit->label);
1132 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1136 wd->check_idler = ecore_idler_add(_check_string, wd);
1137 _sizing_eval(wd->self);
1141 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1143 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1148 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1150 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1151 eina_stringshare_replace(&it->label, label);
1152 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1155 EAPI Elm_Diskselector_Item *
1156 elm_diskselector_selected_item_get(const Evas_Object *obj)
1158 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1159 Widget_Data *wd = elm_widget_data_get(obj);
1160 if (!wd) return NULL;
1161 return wd->selected_item;
1165 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1167 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1169 wd = elm_widget_data_get(it->base.widget);
1172 if ((wd->selected_item == it) && (selected))
1175 if ((wd->selected_item == it) && (!selected))
1176 wd->selected_item = eina_list_data_get(wd->items);
1179 wd->selected_item = it;
1180 _selected_item_indicate(wd->selected_item);
1184 wd->idler = ecore_idler_add(_move_scroller, it->base.widget);
1188 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1190 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1193 wd = elm_widget_data_get(it->base.widget);
1194 if (!wd) return EINA_FALSE;
1195 return (wd->selected_item == it);
1199 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1201 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1202 elm_widget_item_del_cb_set(it, func);
1206 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1208 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1209 return elm_widget_item_data_get(it);
1213 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1215 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1220 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1222 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1223 if (it->icon == icon) return;
1225 evas_object_del(it->icon);
1228 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
1231 EAPI Elm_Diskselector_Item *
1232 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1234 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1235 if (it->node->prev) return it->node->prev->data;
1239 EAPI Elm_Diskselector_Item *
1240 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1242 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1243 if (it->node->next) return it->node->next->data;
1247 EAPI Elm_Diskselector_Item *
1248 elm_diskselector_first_item_get(const Evas_Object *obj)
1250 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1253 wd = elm_widget_data_get(obj);
1254 if (!wd || !wd->items)
1257 return eina_list_data_get(wd->items);
1260 EAPI Elm_Diskselector_Item *
1261 elm_diskselector_last_item_get(const Evas_Object *obj)
1263 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1266 wd = elm_widget_data_get(obj);
1267 if (!wd || !wd->items)
1270 return eina_list_data_get(eina_list_last(wd->items));
1274 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1276 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1277 elm_widget_item_tooltip_text_set(item, text);
1281 elm_diskselector_item_tooltip_content_cb_set(Elm_Diskselector_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1283 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1284 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1288 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1290 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1291 elm_widget_item_tooltip_unset(item);
1295 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1297 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1298 elm_widget_item_tooltip_style_set(item, style);
1302 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1304 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1305 return elm_widget_item_tooltip_style_get(item);
1309 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1311 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1312 elm_widget_item_cursor_set(item, cursor);
1316 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1318 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1319 return elm_widget_item_cursor_get(item);
1323 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1325 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1326 elm_widget_item_cursor_unset(item);
1330 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1332 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1333 elm_widget_item_cursor_style_set(item, style);
1337 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1339 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1340 return elm_widget_item_cursor_style_get(item);
1344 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1346 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1347 elm_widget_item_cursor_engine_only_set(item, engine_only);
1351 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1353 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1354 return elm_widget_item_cursor_engine_only_get(item);
1358 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1360 ELM_CHECK_WIDTYPE(obj, widtype);
1361 Widget_Data *wd = elm_widget_data_get(obj);
1363 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1364 wd->display_item_num = num;
1365 wd->display_item_num_by_api = EINA_TRUE;
1369 elm_diskselector_display_item_num_get(const Evas_Object *item)
1371 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1372 Widget_Data *wd = elm_widget_data_get(item);
1374 return wd->display_item_num;