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)
157 str = edje_object_data_get(wd->right_blank, "len_threshold");
158 if (str) wd->len_threshold = MAX(0, atoi(str));
159 else wd->len_threshold = 0;
161 if (!wd->display_item_num_by_api)
163 str = edje_object_data_get(wd->right_blank, "display_item_num");
164 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
165 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
168 str = edje_object_data_get(wd->right_blank, "min_width");
169 if (str) wd->minw = MAX(-1, atoi(str));
172 parent = elm_widget_parent_widget_get(wd->self);
173 if (!parent) wd->minw = -1;
174 else evas_object_geometry_get(parent, NULL, NULL, &wd->minw, NULL);
177 str = edje_object_data_get(wd->right_blank, "min_height");
178 if (str) wd->minh = MAX(-1, atoi(str));
183 _del_hook(Evas_Object * obj)
185 Widget_Data *wd = elm_widget_data_get(obj);
191 _del_pre_hook(Evas_Object * obj)
193 Elm_Diskselector_Item *it;
196 Widget_Data *wd = elm_widget_data_get(obj);
200 evas_object_del(wd->left_blank);
202 evas_object_del(wd->right_blank);
205 eina_stringshare_del(wd->last->label);
206 evas_object_del(wd->last->base.view);
211 eina_stringshare_del(wd->s_last->label);
212 evas_object_del(wd->s_last->base.view);
217 eina_stringshare_del(wd->second->label);
218 evas_object_del(wd->second->base.view);
223 eina_stringshare_del(wd->first->label);
224 evas_object_del(wd->first->base.view);
228 EINA_LIST_FOREACH(wd->under_items, l, it)
232 eina_stringshare_del(it->label);
233 evas_object_del(wd->first->base.view);
238 EINA_LIST_FOREACH(wd->over_items, l, it)
242 eina_stringshare_del(it->label);
243 evas_object_del(wd->first->base.view);
248 EINA_LIST_FREE(wd->items, it) _item_del(it);
249 eina_list_free(wd->r_items);
253 _sizing_eval(Evas_Object * obj)
255 Widget_Data *wd = elm_widget_data_get(obj);
257 _diskselector_object_resize(obj, NULL, obj, NULL);
261 _theme_hook(Evas_Object * obj)
264 Elm_Diskselector_Item *it;
265 Widget_Data *wd = elm_widget_data_get(obj);
269 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
270 "base", elm_widget_style_get(obj));
273 EINA_LIST_FOREACH(wd->r_items, l, it)
275 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
276 elm_widget_style_get(obj));
277 edje_object_part_text_set(it->base.view, "elm.text", it->label);
282 EINA_LIST_FOREACH(wd->items, l, it)
284 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
285 elm_widget_style_get(obj));
286 edje_object_part_text_set(it->base.view, "elm.text", it->label);
289 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
290 elm_widget_style_get(obj));
296 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
298 Widget_Data *wd = elm_widget_data_get(obj);
299 Evas_Object *sub = event_info;
300 Elm_Diskselector_Item *it;
305 if (sub == wd->scroller)
309 EINA_LIST_FOREACH(wd->items, l, it)
322 _select_item(Elm_Diskselector_Item *it)
325 Widget_Data *wd = elm_widget_data_get(it->base.widget);
326 wd->selected_item = it;
327 _selected_item_indicate(wd->selected_item);
328 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
329 evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
333 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
335 Widget_Data *wd = elm_widget_data_get(obj);
339 if (elm_widget_focus_get(obj))
341 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
342 evas_object_focus_set(wd->self, EINA_TRUE);
346 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
347 evas_object_focus_set(wd->self, EINA_FALSE);
352 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
354 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
355 Evas_Event_Key_Down *ev = event_info;
356 Widget_Data *wd = elm_widget_data_get(obj);
357 if (!wd) return EINA_FALSE;
358 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
359 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
361 Elm_Diskselector_Item *it = NULL;
364 if (!wd->selected_item) {
365 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
369 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
370 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
372 l = wd->selected_item->node->prev;
373 if ((!l) && (wd->round))
374 l = eina_list_last(wd->items);
376 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
377 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
379 l = wd->selected_item->node->next;
380 if ((!l) && (wd->round))
383 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
385 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
386 l = eina_list_last(wd->items);
387 else return EINA_FALSE;
390 it = eina_list_data_get(l);
394 wd->selected_item = it;
396 wd->idler = ecore_idler_add(_move_scroller, obj);
399 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
404 _count_letter(const char *str)
409 for (chnum = 0; ; chnum++)
411 pos = evas_string_char_next_get(str, pos, &code);
412 if (code == 0) break;
418 _check_letter(const char *str, int length)
423 for (chnum = 0; ; chnum++)
425 if (chnum == length) break;
426 pos = evas_string_char_next_get(str, pos, &code);
427 if (code == 0) break;
433 _check_string(void *data)
435 int mid, steps, length, diff;
436 Elm_Diskselector_Item *it;
440 Widget_Data *wd = data;
442 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
452 EINA_LIST_FOREACH(list, l, it)
456 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
457 /* item not visible */
458 if ((x + w <= ox) || (x >= ox + ow))
461 len = _count_letter(it->label);
462 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
463 // len = eina_stringshare_strlen(it->label);
466 edje_object_signal_emit(it->base.view, "elm,state,left_side",
468 else if (x + w >= ox + ow - 5)
469 edje_object_signal_emit(it->base.view, "elm,state,right_side",
473 if ((wd->len_threshold) && (len > wd->len_threshold))
474 edje_object_signal_emit(it->base.view, "elm,state,center_small",
477 edje_object_signal_emit(it->base.view, "elm,state,center",
481 // if len is les that the limit len, skip anyway
482 if (len <= wd->len_side)
485 steps = len - wd->len_side + 1;
487 if (mid <= ox + ow / 2)
488 diff = (ox + ow / 2) - mid;
490 diff = mid - (ox + ow / 2);
492 length = len - (int)(diff * steps / (ow / 3));
493 length = MAX(length, wd->len_side);
494 // limit string len to "length" ut8f chars
495 length = _check_letter(it->label, length);
496 // cut it off at byte mark returned form _check_letter
497 strncpy(buf, it->label, length);
499 edje_object_part_text_set(it->base.view, "elm.text", buf);
503 ecore_idler_del(wd->check_idler);
504 wd->check_idler = NULL;
509 _selected_item_indicate(Elm_Diskselector_Item *it)
511 Elm_Diskselector_Item *item;
514 wd = elm_widget_data_get(it->base.widget);
518 EINA_LIST_FOREACH(wd->r_items, l, item)
520 if (!strcmp(item->label, it->label)) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
522 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
527 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
528 const char *emission __UNUSED__, const char *source __UNUSED__)
530 Elm_Diskselector_Item *it = data;
535 wd = elm_widget_data_get(it->base.widget);
539 if (wd->selected_item != it)
541 wd->selected_item = it;
542 _selected_item_indicate(wd->selected_item);
545 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
549 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
551 Evas_Coord x, y, w, h, bw;
552 Widget_Data *wd = data;
555 elm_smart_scroller_child_pos_get(obj, &x, &y);
556 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
559 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
560 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
561 elm_smart_scroller_child_region_show(wd->scroller,
562 x - ((w / wd->display_item_num) * wd->item_count),
565 elm_smart_scroller_child_region_show(wd->scroller,
566 x + ((w / wd->display_item_num) * wd->item_count),
572 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
574 Elm_Diskselector_Item *it;
575 Widget_Data *wd = data;
587 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
588 EINA_LIST_FOREACH(list, l, it)
590 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
591 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
602 _move_scroller(void *data)
604 Evas_Object *obj = data;
607 Elm_Diskselector_Item *dit;
611 wd = elm_widget_data_get(obj);
612 if (!wd) return EINA_FALSE;
619 EINA_LIST_FOREACH(wd->items, l, dit)
621 if (wd->selected_item == dit)
628 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
632 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
633 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
637 ecore_idler_del(wd->idler);
640 wd->init = EINA_TRUE;
647 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
650 elm_box_unpack(wd->main_box, it->base.view);
651 wd->r_items = eina_list_remove(wd->r_items, it);
652 eina_stringshare_del(it->label);
653 evas_object_del(it->base.view);
658 _round_items_del(Widget_Data *wd)
661 Elm_Diskselector_Item * it;
663 _round_item_del(wd, wd->last);
665 _round_item_del(wd, wd->s_last);
667 _round_item_del(wd, wd->second);
669 _round_item_del(wd, wd->first);
672 EINA_LIST_FOREACH(wd->under_items, l, it)
674 _round_item_del(wd, it);
678 EINA_LIST_FOREACH(wd->over_items, l, it)
680 _round_item_del(wd, it);
686 _round_items_add(Widget_Data *wd)
688 Elm_Diskselector_Item *dit;
689 Elm_Diskselector_Item *it;
690 Elm_Diskselector_Item *temp_it;
692 dit = it = eina_list_nth(wd->items, 0);
697 wd->first = _item_new(it->base.widget, it->icon, it->label, it->func,
699 wd->first->node = it->node;
700 wd->r_items = eina_list_append(wd->r_items, wd->first);
703 it = eina_list_nth(wd->items, 1);
708 wd->second = _item_new(it->base.widget, it->icon, it->label, it->func,
710 wd->second->node = it->node;
711 wd->r_items = eina_list_append(wd->r_items, wd->second);
714 // if more than 3 itmes should be displayed
715 for (i = 2; i < CEIL(wd->display_item_num); i++)
717 it = eina_list_nth(wd->items, i);
719 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
720 wd->over_items = eina_list_append(wd->over_items, temp_it);
721 wd->r_items = eina_list_append(wd->r_items, temp_it);
724 it = eina_list_nth(wd->items, wd->item_count - 1);
729 wd->last = _item_new(it->base.widget, it->icon, it->label, it->func,
731 wd->last->node = it->node;
732 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
735 it = eina_list_nth(wd->items, wd->item_count - 2);
740 wd->s_last = _item_new(it->base.widget, it->icon, it->label, it->func,
742 wd->s_last->node = it->node;
743 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
746 // if more than 3 itmes should be displayed
747 for (i = 3; i <= CEIL(wd->display_item_num); i++)
749 it = eina_list_nth(wd->items, wd->item_count - i);
751 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
752 wd->under_items = eina_list_append(wd->under_items, temp_it);
753 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
758 elm_diskselector_add(Evas_Object *parent)
764 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
766 ELM_SET_WIDTYPE(widtype, "diskselector");
767 elm_widget_type_set(obj, "diskselector");
768 elm_widget_sub_object_add(parent, obj);
769 elm_widget_data_set(obj, wd);
770 elm_widget_del_hook_set(obj, _del_hook);
771 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
772 elm_widget_theme_hook_set(obj, _theme_hook);
773 elm_widget_can_focus_set(obj, EINA_TRUE);
774 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
775 elm_widget_event_hook_set(obj, _event_hook);
779 wd->round = EINA_FALSE;
780 wd->init = EINA_FALSE;
782 wd->display_item_num_by_api = EINA_FALSE;
784 wd->scroller = elm_smart_scroller_add(e);
785 elm_smart_scroller_widget_set(wd->scroller, obj);
787 elm_widget_resize_object_set(obj, wd->scroller);
788 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
789 ELM_SMART_SCROLLER_POLICY_OFF);
790 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
791 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
793 evas_object_smart_callback_add(wd->scroller, "animate,stop",
794 _scroller_stop_cb, wd);
795 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
797 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
798 _diskselector_object_resize, obj);
800 wd->main_box = elm_box_add(parent);
801 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
802 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
803 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
805 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
807 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
809 elm_widget_sub_object_add(obj, wd->main_box);
811 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
813 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
814 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
816 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
818 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
820 elm_box_pack_end(wd->main_box, wd->left_blank);
821 evas_object_show(wd->left_blank);
823 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
824 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
826 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
828 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
830 elm_box_pack_end(wd->main_box, wd->right_blank);
831 evas_object_show(wd->right_blank);
835 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
836 evas_object_smart_callbacks_descriptions_set(obj, _signals);
842 elm_diskselector_round_get(const Evas_Object *obj)
844 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
845 Widget_Data *wd = elm_widget_data_get(obj);
846 if (!wd) return EINA_FALSE;
851 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
854 Elm_Diskselector_Item *it;
856 ELM_CHECK_WIDTYPE(obj, widtype);
857 Widget_Data *wd = elm_widget_data_get(obj);
860 if (wd->round == round)
866 wd->r_items = eina_list_clone(wd->items);
867 elm_box_unpack(wd->main_box, wd->left_blank);
868 evas_object_hide(wd->left_blank);
869 elm_box_unpack(wd->main_box, wd->right_blank);
870 evas_object_hide(wd->right_blank);
874 _round_items_add(wd);
877 elm_box_pack_start(wd->main_box, wd->last->base.view);
879 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
881 // if more than 3 items should be displayed
882 EINA_LIST_FOREACH(wd->under_items, elist, it)
883 elm_box_pack_start(wd->main_box, it->base.view);
886 elm_box_pack_end(wd->main_box, wd->first->base.view);
888 elm_box_pack_end(wd->main_box, wd->second->base.view);
890 // if more than 3 items should be displayed
891 EINA_LIST_FOREACH(wd->over_items, elist, it)
892 elm_box_pack_end(wd->main_box, it->base.view);
896 _round_items_del(wd);
897 elm_box_pack_start(wd->main_box, wd->left_blank);
898 elm_box_pack_end(wd->main_box, wd->right_blank);
899 eina_list_free(wd->r_items);
903 _selected_item_indicate(wd->selected_item);
908 elm_diskselector_side_label_length_get(const Evas_Object *obj)
910 ELM_CHECK_WIDTYPE(obj, widtype) 0;
911 Widget_Data *wd = elm_widget_data_get(obj);
917 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
919 ELM_CHECK_WIDTYPE(obj, widtype);
920 Widget_Data *wd = elm_widget_data_get(obj);
926 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
928 return elm_diskselector_side_label_length_set(obj, len);
932 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
934 return elm_diskselector_side_label_length_get(obj);
938 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
940 ELM_CHECK_WIDTYPE(obj, widtype);
941 Widget_Data *wd = elm_widget_data_get(obj);
944 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
948 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
950 ELM_CHECK_WIDTYPE(obj, widtype);
951 Widget_Data *wd = elm_widget_data_get(obj);
953 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
957 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
959 ELM_CHECK_WIDTYPE(obj, widtype);
960 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
961 Widget_Data *wd = elm_widget_data_get(obj);
962 if ((!wd) || (!wd->scroller)) return;
963 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
964 *policy_h = (Elm_Scroller_Policy) s_policy_h;
965 *policy_v = (Elm_Scroller_Policy) s_policy_v;
969 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
971 ELM_CHECK_WIDTYPE(obj, widtype);
972 Widget_Data *wd = elm_widget_data_get(obj);
974 if ((policy_h >= 3) || (policy_v >= 3)) return;
976 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
980 elm_diskselector_clear(Evas_Object *obj)
982 ELM_CHECK_WIDTYPE(obj, widtype);
983 Widget_Data *wd = elm_widget_data_get(obj);
984 Elm_Diskselector_Item *it;
987 if (!wd->items) return;
989 wd->selected_item = NULL;
990 EINA_LIST_FREE(wd->items, it) _item_del(it);
991 _round_items_del(wd);
995 EAPI const Eina_List *
996 elm_diskselector_items_get(const Evas_Object *obj)
998 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
999 Widget_Data *wd = elm_widget_data_get(obj);
1000 if (!wd) return NULL;
1004 EAPI Elm_Diskselector_Item *
1005 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1007 Elm_Diskselector_Item *it;
1008 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1009 Widget_Data *wd = elm_widget_data_get(obj);
1010 if (!wd) return NULL;
1012 it = _item_new(obj, icon, label, func, data);
1013 wd->items = eina_list_append(wd->items, it);
1014 it->node = eina_list_last(wd->items);
1018 _round_items_del(wd);
1019 wd->r_items = eina_list_append(wd->r_items, it);
1020 _round_items_add(wd);
1022 elm_box_pack_start(wd->main_box, wd->last->base.view);
1024 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
1025 elm_box_pack_end(wd->main_box, it->base.view);
1027 elm_box_pack_end(wd->main_box, wd->first->base.view);
1029 elm_box_pack_end(wd->main_box, wd->second->base.view);
1033 elm_box_unpack(wd->main_box, wd->right_blank);
1034 elm_box_pack_end(wd->main_box, it->base.view);
1035 elm_box_pack_end(wd->main_box, wd->right_blank);
1037 if (!wd->selected_item)
1038 wd->selected_item = it;
1040 wd->idler = ecore_idler_add(_move_scroller, obj);
1046 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1048 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1049 Elm_Diskselector_Item *dit;
1050 Elm_Diskselector_Item *item;
1053 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1056 elm_box_unpack(wd->main_box, it->base.view);
1059 wd->r_items = eina_list_remove(wd->r_items, it);
1061 wd->items = eina_list_remove(wd->items, it);
1063 if (wd->selected_item == it)
1065 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1067 wd->selected_item = dit;
1069 wd->selected_item = eina_list_nth(wd->items, 1);
1071 _selected_item_indicate(wd->selected_item);
1075 wd->item_count -= 1;
1079 if (!wd->item_count)
1081 evas_object_hide(wd->first->base.view);
1082 evas_object_hide(wd->second->base.view);
1083 evas_object_hide(wd->last->base.view);
1084 evas_object_hide(wd->s_last->base.view);
1086 EINA_LIST_FOREACH(wd->under_items, l, item)
1087 evas_object_hide(item->base.view);
1089 EINA_LIST_FOREACH(wd->over_items, l, item)
1090 evas_object_hide(item->base.view);
1094 dit = eina_list_nth(wd->items, 0);
1097 eina_stringshare_replace(&wd->first->label, dit->label);
1098 edje_object_part_text_set(wd->first->base.view, "elm.text",
1101 dit = eina_list_nth(wd->items, 1);
1104 eina_stringshare_replace(&wd->second->label, dit->label);
1105 edje_object_part_text_set(wd->second->base.view, "elm.text",
1108 // if more than 3 itmes should be displayed
1109 for (i = 2; i < CEIL(wd->display_item_num); i++)
1111 dit = eina_list_nth(wd->items, i);
1112 item = eina_list_nth(wd->over_items, i - 2);
1113 eina_stringshare_replace(&item->label, dit->label);
1114 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1117 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1120 eina_stringshare_replace(&wd->last->label, dit->label);
1121 edje_object_part_text_set(wd->last->base.view, "elm.text",
1124 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1127 eina_stringshare_replace(&wd->s_last->label, dit->label);
1128 edje_object_part_text_set(wd->s_last->base.view, "elm.text",
1131 // if more than 3 itmes should be displayed
1132 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1134 dit = eina_list_nth(wd->items, wd->item_count - i);
1135 item = eina_list_nth(wd->under_items, i - 3);
1136 eina_stringshare_replace(&item->label, dit->label);
1137 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1141 wd->check_idler = ecore_idler_add(_check_string, wd);
1142 _sizing_eval(wd->self);
1146 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1148 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1153 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1155 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1156 eina_stringshare_replace(&it->label, label);
1157 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1160 EAPI Elm_Diskselector_Item *
1161 elm_diskselector_selected_item_get(const Evas_Object *obj)
1163 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1164 Widget_Data *wd = elm_widget_data_get(obj);
1165 if (!wd) return NULL;
1166 return wd->selected_item;
1170 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1172 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1174 wd = elm_widget_data_get(it->base.widget);
1177 if ((wd->selected_item == it) && (selected))
1180 if ((wd->selected_item == it) && (!selected))
1181 wd->selected_item = eina_list_data_get(wd->items);
1184 wd->selected_item = it;
1185 _selected_item_indicate(wd->selected_item);
1189 ecore_idler_add(_move_scroller, it->base.widget);
1193 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1195 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1198 wd = elm_widget_data_get(it->base.widget);
1199 if (!wd) return EINA_FALSE;
1200 return (wd->selected_item == it);
1204 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1206 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1207 elm_widget_item_del_cb_set(it, func);
1211 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1213 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1214 return elm_widget_item_data_get(it);
1218 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1220 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1225 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1227 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1228 if (it->icon == icon) return;
1230 evas_object_del(it->icon);
1233 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
1236 EAPI Elm_Diskselector_Item *
1237 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1239 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1240 if (it->node->prev) return it->node->prev->data;
1244 EAPI Elm_Diskselector_Item *
1245 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1247 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1248 if (it->node->next) return it->node->next->data;
1252 EAPI Elm_Diskselector_Item *
1253 elm_diskselector_first_item_get(const Evas_Object *obj)
1255 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1258 wd = elm_widget_data_get(obj);
1259 if (!wd || !wd->items)
1262 return eina_list_data_get(wd->items);
1265 EAPI Elm_Diskselector_Item *
1266 elm_diskselector_last_item_get(const Evas_Object *obj)
1268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1271 wd = elm_widget_data_get(obj);
1272 if (!wd || !wd->items)
1275 return eina_list_data_get(eina_list_last(wd->items));
1279 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1281 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1282 elm_widget_item_tooltip_text_set(item, text);
1286 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)
1288 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1289 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1293 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1295 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1296 elm_widget_item_tooltip_unset(item);
1300 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1302 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1303 elm_widget_item_tooltip_style_set(item, style);
1307 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1309 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1310 return elm_widget_item_tooltip_style_get(item);
1314 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1316 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1317 elm_widget_item_cursor_set(item, cursor);
1321 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1323 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1324 return elm_widget_item_cursor_get(item);
1328 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1330 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1331 elm_widget_item_cursor_unset(item);
1335 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1337 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1338 elm_widget_item_cursor_style_set(item, style);
1342 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1344 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1345 return elm_widget_item_cursor_style_get(item);
1349 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1351 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1352 elm_widget_item_cursor_engine_only_set(item, engine_only);
1356 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1358 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1359 return elm_widget_item_cursor_engine_only_get(item);
1363 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1365 ELM_CHECK_WIDTYPE(obj, widtype);
1366 Widget_Data *wd = elm_widget_data_get(obj);
1368 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1369 wd->display_item_num = num;
1370 wd->display_item_num_by_api = EINA_TRUE;