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;
20 Evas_Object *scroller;
21 Evas_Object *main_box;
22 Evas_Object *left_blank;
23 Evas_Object *right_blank;
24 Elm_Diskselector_Item *selected_item;
25 Elm_Diskselector_Item *first;
26 Elm_Diskselector_Item *second;
27 Elm_Diskselector_Item *s_last;
28 Elm_Diskselector_Item *last;
31 Eina_List *over_items;
32 Eina_List *under_items;
33 int item_count, len_threshold, len_side, display_item_num;
35 Ecore_Idler *check_idler;
36 Evas_Coord minw, minh;
39 Eina_Bool display_item_num_by_api:1;
42 struct _Elm_Diskselector_Item
51 static const char *widtype = NULL;
53 #define ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, ...) \
54 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
55 ELM_CHECK_WIDTYPE(WIDGET(it), widtype) __VA_ARGS__;
57 static Eina_Bool _move_scroller(void *data);
58 static void _del_hook(Evas_Object * obj);
59 static void _del_pre_hook(Evas_Object * obj);
60 static void _sizing_eval(Evas_Object * obj);
61 static void _theme_hook(Evas_Object * obj);
62 static void _on_focus_hook(void *data, Evas_Object *obj);
63 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
64 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
65 static void _round_items_del(Widget_Data *wd);
66 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
67 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
68 const char *emission __UNUSED__,
69 const char *source __UNUSED__);
70 static void _selected_item_indicate(Elm_Diskselector_Item *it);
72 static const char SIG_SELECTED[] = "selected";
73 static const Evas_Smart_Cb_Description _signals[] = {
79 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
84 wd = elm_widget_data_get(data);
87 if (wd->minw == -1 && wd->minh == -1) elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
88 edje_object_size_min_restricted_calc(elm_smart_scroller_edje_object_get(
89 wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
90 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
91 evas_object_size_hint_max_set(obj, -1, -1);
93 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
95 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
97 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
99 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
100 (int)(w / wd->display_item_num), 0);
103 wd->idler = ecore_idler_add(_move_scroller, data);
106 static Elm_Diskselector_Item *
107 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
109 Elm_Diskselector_Item *it;
110 const char *style = elm_widget_style_get(obj);
112 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
113 if (!it) return NULL;
115 it->label = eina_stringshare_add(label);
118 it->base.data = data;
119 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
120 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
121 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
123 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
125 evas_object_show(VIEW(it));
129 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
130 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
134 evas_object_size_hint_min_set(it->icon, 24, 24);
135 evas_object_size_hint_max_set(it->icon, 40, 40);
136 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
137 evas_object_show(it->icon);
138 elm_widget_sub_object_add(obj, it->icon);
144 _item_del(Elm_Diskselector_Item *item)
147 eina_stringshare_del(item->label);
149 evas_object_del(item->icon);
150 elm_widget_item_del(item);
154 _theme_data_get(Widget_Data *wd)
158 str = edje_object_data_get(wd->right_blank, "len_threshold");
159 if (str) wd->len_threshold = MAX(0, atoi(str));
160 else wd->len_threshold = 0;
162 if (!wd->display_item_num_by_api)
164 str = edje_object_data_get(wd->right_blank, "display_item_num");
165 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
166 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
169 str = edje_object_data_get(wd->right_blank, "min_width");
170 if (str) wd->minw = MAX(-1, atoi(str));
173 parent = elm_widget_parent_widget_get(wd->self);
174 if (!parent) wd->minw = -1;
175 else evas_object_geometry_get(parent, NULL, NULL, &wd->minw, NULL);
178 str = edje_object_data_get(wd->right_blank, "min_height");
179 if (str) wd->minh = MAX(-1, atoi(str));
184 _del_hook(Evas_Object * obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
192 _del_pre_hook(Evas_Object * obj)
194 Elm_Diskselector_Item *it;
197 Widget_Data *wd = elm_widget_data_get(obj);
201 evas_object_del(wd->left_blank);
203 evas_object_del(wd->right_blank);
206 eina_stringshare_del(wd->last->label);
207 evas_object_del(wd->VIEW(last));
212 eina_stringshare_del(wd->s_last->label);
213 evas_object_del(wd->VIEW(s_last));
218 eina_stringshare_del(wd->second->label);
219 evas_object_del(wd->VIEW(second));
224 eina_stringshare_del(wd->first->label);
225 evas_object_del(wd->VIEW(first));
229 EINA_LIST_FOREACH(wd->under_items, l, it)
233 eina_stringshare_del(it->label);
234 evas_object_del(VIEW(wd->first));
239 EINA_LIST_FOREACH(wd->over_items, l, it)
243 eina_stringshare_del(it->label);
244 evas_object_del(VIEW(wd->first));
249 EINA_LIST_FREE(wd->items, it) _item_del(it);
250 eina_list_free(wd->r_items);
254 _sizing_eval(Evas_Object * obj)
256 Widget_Data *wd = elm_widget_data_get(obj);
258 _diskselector_object_resize(obj, NULL, obj, NULL);
262 _theme_hook(Evas_Object * obj)
265 Elm_Diskselector_Item *it;
266 Widget_Data *wd = elm_widget_data_get(obj);
270 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
271 "base", elm_widget_style_get(obj));
274 EINA_LIST_FOREACH(wd->r_items, l, it)
276 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
277 elm_widget_style_get(obj));
278 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
283 EINA_LIST_FOREACH(wd->items, l, it)
285 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
286 elm_widget_style_get(obj));
287 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
290 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
291 elm_widget_style_get(obj));
297 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
299 Widget_Data *wd = elm_widget_data_get(obj);
300 Evas_Object *sub = event_info;
301 Elm_Diskselector_Item *it;
306 if (sub == wd->scroller)
310 EINA_LIST_FOREACH(wd->items, l, it)
323 _select_item(Elm_Diskselector_Item *it)
326 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
327 wd->selected_item = it;
328 _selected_item_indicate(wd->selected_item);
329 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
330 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
334 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
336 Widget_Data *wd = elm_widget_data_get(obj);
340 if (elm_widget_focus_get(obj))
342 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
343 evas_object_focus_set(wd->self, EINA_TRUE);
347 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
348 evas_object_focus_set(wd->self, EINA_FALSE);
353 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
355 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
356 Evas_Event_Key_Down *ev = event_info;
357 Widget_Data *wd = elm_widget_data_get(obj);
358 if (!wd) return EINA_FALSE;
359 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
360 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
362 Elm_Diskselector_Item *it = NULL;
365 if (!wd->selected_item) {
366 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
370 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
371 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
373 l = wd->selected_item->node->prev;
374 if ((!l) && (wd->round))
375 l = eina_list_last(wd->items);
377 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
378 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
380 l = wd->selected_item->node->next;
381 if ((!l) && (wd->round))
384 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
386 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
387 l = eina_list_last(wd->items);
388 else return EINA_FALSE;
391 it = eina_list_data_get(l);
395 wd->selected_item = it;
397 wd->idler = ecore_idler_add(_move_scroller, obj);
400 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
405 _count_letter(const char *str)
410 for (chnum = 0; ; chnum++)
412 pos = evas_string_char_next_get(str, pos, &code);
413 if (code == 0) break;
419 _check_letter(const char *str, int length)
424 for (chnum = 0; ; chnum++)
426 if (chnum == length) break;
427 pos = evas_string_char_next_get(str, pos, &code);
428 if (code == 0) break;
434 _check_string(void *data)
436 int mid, steps, length, diff;
437 Elm_Diskselector_Item *it;
441 Widget_Data *wd = data;
443 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
453 EINA_LIST_FOREACH(list, l, it)
457 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
458 /* item not visible */
459 if ((x + w <= ox) || (x >= ox + ow))
462 len = _count_letter(it->label);
463 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
464 // len = eina_stringshare_strlen(it->label);
467 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
469 else if (x + w >= ox + ow - 5)
470 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
474 if ((wd->len_threshold) && (len > wd->len_threshold))
475 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
478 edje_object_signal_emit(VIEW(it), "elm,state,center",
482 // if len is les that the limit len, skip anyway
483 if (len <= wd->len_side)
486 steps = len - wd->len_side + 1;
488 if (mid <= ox + ow / 2)
489 diff = (ox + ow / 2) - mid;
491 diff = mid - (ox + ow / 2);
493 length = len - (int)(diff * steps / (ow / 3));
494 length = MAX(length, wd->len_side);
495 // limit string len to "length" ut8f chars
496 length = _check_letter(it->label, length);
497 // cut it off at byte mark returned form _check_letter
498 strncpy(buf, it->label, length);
500 edje_object_part_text_set(VIEW(it), "elm.text", buf);
504 ecore_idler_del(wd->check_idler);
505 wd->check_idler = NULL;
510 _selected_item_indicate(Elm_Diskselector_Item *it)
512 Elm_Diskselector_Item *item;
515 wd = elm_widget_data_get(WIDGET(it));
519 EINA_LIST_FOREACH(wd->r_items, l, item)
521 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
523 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
528 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
529 const char *emission __UNUSED__, const char *source __UNUSED__)
531 Elm_Diskselector_Item *it = data;
536 wd = elm_widget_data_get(WIDGET(it));
540 if (wd->selected_item != it)
542 wd->selected_item = it;
543 _selected_item_indicate(wd->selected_item);
546 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
550 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
552 Evas_Coord x, y, w, h, bw;
553 Widget_Data *wd = data;
556 elm_smart_scroller_child_pos_get(obj, &x, &y);
557 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
560 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
561 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
562 elm_smart_scroller_child_region_show(wd->scroller,
563 x - ((w / wd->display_item_num) * wd->item_count),
566 elm_smart_scroller_child_region_show(wd->scroller,
567 x + ((w / wd->display_item_num) * wd->item_count),
573 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
575 Elm_Diskselector_Item *it;
576 Widget_Data *wd = data;
588 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
589 EINA_LIST_FOREACH(list, l, it)
591 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
592 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
603 _move_scroller(void *data)
605 Evas_Object *obj = data;
608 Elm_Diskselector_Item *dit;
612 wd = elm_widget_data_get(obj);
613 if (!wd) return EINA_FALSE;
620 EINA_LIST_FOREACH(wd->items, l, dit)
622 if (wd->selected_item == dit)
629 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
633 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
634 //move scroller in two steps for getting smooth launching effect.
636 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * (i-2), y, w, h);
637 elm_smart_scroller_region_bring_in(wd->scroller, w / wd->display_item_num * i, y, w, h);
642 ecore_idler_del(wd->idler);
645 wd->init = EINA_TRUE;
652 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
655 elm_box_unpack(wd->main_box, VIEW(it));
656 wd->r_items = eina_list_remove(wd->r_items, it);
657 eina_stringshare_del(it->label);
658 evas_object_del(VIEW(it));
663 _round_items_del(Widget_Data *wd)
666 Elm_Diskselector_Item * it;
668 _round_item_del(wd, wd->last);
670 _round_item_del(wd, wd->s_last);
672 _round_item_del(wd, wd->second);
674 _round_item_del(wd, wd->first);
677 EINA_LIST_FOREACH(wd->under_items, l, it)
679 _round_item_del(wd, it);
683 EINA_LIST_FOREACH(wd->over_items, l, it)
685 _round_item_del(wd, it);
691 _round_items_add(Widget_Data *wd)
693 Elm_Diskselector_Item *dit;
694 Elm_Diskselector_Item *it;
695 Elm_Diskselector_Item *temp_it;
697 dit = it = eina_list_nth(wd->items, 0);
702 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
704 wd->first->node = it->node;
705 wd->r_items = eina_list_append(wd->r_items, wd->first);
708 it = eina_list_nth(wd->items, 1);
713 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
715 wd->second->node = it->node;
716 wd->r_items = eina_list_append(wd->r_items, wd->second);
719 // if more than 3 itmes should be displayed
720 for (i = 2; i < CEIL(wd->display_item_num); i++)
722 it = eina_list_nth(wd->items, i);
724 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
725 wd->over_items = eina_list_append(wd->over_items, temp_it);
726 wd->r_items = eina_list_append(wd->r_items, temp_it);
729 it = eina_list_nth(wd->items, wd->item_count - 1);
734 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
736 wd->last->node = it->node;
737 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
740 it = eina_list_nth(wd->items, wd->item_count - 2);
745 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
747 wd->s_last->node = it->node;
748 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
751 // if more than 3 itmes should be displayed
752 for (i = 3; i <= CEIL(wd->display_item_num); i++)
754 it = eina_list_nth(wd->items, wd->item_count - i);
756 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
757 wd->under_items = eina_list_append(wd->under_items, temp_it);
758 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
763 elm_diskselector_add(Evas_Object *parent)
769 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
771 ELM_SET_WIDTYPE(widtype, "diskselector");
772 elm_widget_type_set(obj, "diskselector");
773 elm_widget_sub_object_add(parent, obj);
774 elm_widget_data_set(obj, wd);
775 elm_widget_del_hook_set(obj, _del_hook);
776 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
777 elm_widget_theme_hook_set(obj, _theme_hook);
778 elm_widget_can_focus_set(obj, EINA_TRUE);
779 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
780 elm_widget_event_hook_set(obj, _event_hook);
784 wd->round = EINA_FALSE;
785 wd->init = EINA_FALSE;
787 wd->display_item_num_by_api = EINA_FALSE;
789 wd->scroller = elm_smart_scroller_add(e);
790 elm_smart_scroller_widget_set(wd->scroller, obj);
792 elm_widget_resize_object_set(obj, wd->scroller);
793 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
794 ELM_SMART_SCROLLER_POLICY_OFF);
795 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
796 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
798 evas_object_smart_callback_add(wd->scroller, "animate,stop",
799 _scroller_stop_cb, wd);
800 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
802 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
803 _diskselector_object_resize, obj);
805 wd->main_box = elm_box_add(parent);
806 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
807 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
808 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
810 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
812 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
814 elm_widget_sub_object_add(obj, wd->main_box);
816 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
818 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
819 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
821 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
823 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
825 elm_box_pack_end(wd->main_box, wd->left_blank);
826 evas_object_show(wd->left_blank);
828 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
829 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
831 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
833 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
835 elm_box_pack_end(wd->main_box, wd->right_blank);
836 evas_object_show(wd->right_blank);
840 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
841 evas_object_smart_callbacks_descriptions_set(obj, _signals);
847 elm_diskselector_round_get(const Evas_Object *obj)
849 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
850 Widget_Data *wd = elm_widget_data_get(obj);
851 if (!wd) return EINA_FALSE;
856 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
859 Elm_Diskselector_Item *it;
861 ELM_CHECK_WIDTYPE(obj, widtype);
862 Widget_Data *wd = elm_widget_data_get(obj);
865 if (wd->round == round)
871 wd->r_items = eina_list_clone(wd->items);
872 elm_box_unpack(wd->main_box, wd->left_blank);
873 evas_object_hide(wd->left_blank);
874 elm_box_unpack(wd->main_box, wd->right_blank);
875 evas_object_hide(wd->right_blank);
879 _round_items_add(wd);
882 elm_box_pack_start(wd->main_box, wd->VIEW(last));
884 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
886 // if more than 3 items should be displayed
887 EINA_LIST_FOREACH(wd->under_items, elist, it)
888 elm_box_pack_start(wd->main_box, VIEW(it));
891 elm_box_pack_end(wd->main_box, wd->VIEW(first));
893 elm_box_pack_end(wd->main_box, wd->VIEW(second));
895 // if more than 3 items should be displayed
896 EINA_LIST_FOREACH(wd->over_items, elist, it)
897 elm_box_pack_end(wd->main_box, VIEW(it));
901 _round_items_del(wd);
902 elm_box_pack_start(wd->main_box, wd->left_blank);
903 elm_box_pack_end(wd->main_box, wd->right_blank);
904 eina_list_free(wd->r_items);
912 elm_diskselector_side_label_length_get(const Evas_Object *obj)
914 ELM_CHECK_WIDTYPE(obj, widtype) 0;
915 Widget_Data *wd = elm_widget_data_get(obj);
921 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
923 ELM_CHECK_WIDTYPE(obj, widtype);
924 Widget_Data *wd = elm_widget_data_get(obj);
930 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
932 return elm_diskselector_side_label_length_set(obj, len);
936 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
938 return elm_diskselector_side_label_length_get(obj);
942 elm_diskselector_bounce_set(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);
948 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
952 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
954 ELM_CHECK_WIDTYPE(obj, widtype);
955 Widget_Data *wd = elm_widget_data_get(obj);
957 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
961 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
963 ELM_CHECK_WIDTYPE(obj, widtype);
964 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
965 Widget_Data *wd = elm_widget_data_get(obj);
966 if ((!wd) || (!wd->scroller)) return;
967 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
968 *policy_h = (Elm_Scroller_Policy) s_policy_h;
969 *policy_v = (Elm_Scroller_Policy) s_policy_v;
973 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
975 ELM_CHECK_WIDTYPE(obj, widtype);
976 Widget_Data *wd = elm_widget_data_get(obj);
978 if ((policy_h >= 3) || (policy_v >= 3)) return;
980 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
984 elm_diskselector_clear(Evas_Object *obj)
986 ELM_CHECK_WIDTYPE(obj, widtype);
987 Widget_Data *wd = elm_widget_data_get(obj);
988 Elm_Diskselector_Item *it;
991 if (!wd->items) return;
993 wd->selected_item = NULL;
994 EINA_LIST_FREE(wd->items, it) _item_del(it);
995 _round_items_del(wd);
999 EAPI const Eina_List *
1000 elm_diskselector_items_get(const Evas_Object *obj)
1002 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1003 Widget_Data *wd = elm_widget_data_get(obj);
1004 if (!wd) return NULL;
1008 EAPI Elm_Diskselector_Item *
1009 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1011 Elm_Diskselector_Item *it;
1012 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1013 Widget_Data *wd = elm_widget_data_get(obj);
1014 if (!wd) return NULL;
1016 it = _item_new(obj, icon, label, func, data);
1017 wd->items = eina_list_append(wd->items, it);
1018 it->node = eina_list_last(wd->items);
1022 _round_items_del(wd);
1023 wd->r_items = eina_list_append(wd->r_items, it);
1024 _round_items_add(wd);
1026 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1028 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1029 elm_box_pack_end(wd->main_box, VIEW(it));
1031 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1033 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1037 elm_box_unpack(wd->main_box, wd->right_blank);
1038 elm_box_pack_end(wd->main_box, VIEW(it));
1039 elm_box_pack_end(wd->main_box, wd->right_blank);
1041 if (!wd->selected_item)
1042 wd->selected_item = it;
1044 wd->idler = ecore_idler_add(_move_scroller, obj);
1050 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1052 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1053 Elm_Diskselector_Item *dit;
1054 Elm_Diskselector_Item *item;
1057 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1060 elm_box_unpack(wd->main_box, VIEW(it));
1063 wd->r_items = eina_list_remove(wd->r_items, it);
1065 wd->items = eina_list_remove(wd->items, it);
1067 if (wd->selected_item == it)
1069 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1071 wd->selected_item = dit;
1073 wd->selected_item = eina_list_nth(wd->items, 1);
1075 _selected_item_indicate(wd->selected_item);
1079 wd->item_count -= 1;
1083 if (!wd->item_count)
1085 evas_object_hide(wd->VIEW(first));
1086 evas_object_hide(wd->VIEW(second));
1087 evas_object_hide(wd->VIEW(last));
1088 evas_object_hide(wd->VIEW(s_last));
1090 EINA_LIST_FOREACH(wd->under_items, l, item)
1091 evas_object_hide(VIEW(item));
1093 EINA_LIST_FOREACH(wd->over_items, l, item)
1094 evas_object_hide(VIEW(item));
1098 dit = eina_list_nth(wd->items, 0);
1101 eina_stringshare_replace(&wd->first->label, dit->label);
1102 edje_object_part_text_set(wd->VIEW(first), "elm.text",
1105 dit = eina_list_nth(wd->items, 1);
1108 eina_stringshare_replace(&wd->second->label, dit->label);
1109 edje_object_part_text_set(wd->VIEW(second), "elm.text",
1112 // if more than 3 itmes should be displayed
1113 for (i = 2; i < CEIL(wd->display_item_num); i++)
1115 dit = eina_list_nth(wd->items, i);
1116 item = eina_list_nth(wd->over_items, i - 2);
1117 eina_stringshare_replace(&item->label, dit->label);
1118 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1121 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1124 eina_stringshare_replace(&wd->last->label, dit->label);
1125 edje_object_part_text_set(wd->VIEW(last), "elm.text",
1128 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1131 eina_stringshare_replace(&wd->s_last->label, dit->label);
1132 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
1135 // if more than 3 itmes should be displayed
1136 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1138 dit = eina_list_nth(wd->items, wd->item_count - i);
1139 item = eina_list_nth(wd->under_items, i - 3);
1140 eina_stringshare_replace(&item->label, dit->label);
1141 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1145 wd->check_idler = ecore_idler_add(_check_string, wd);
1146 _sizing_eval(wd->self);
1150 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1152 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1157 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1159 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1160 eina_stringshare_replace(&it->label, label);
1161 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1164 EAPI Elm_Diskselector_Item *
1165 elm_diskselector_selected_item_get(const Evas_Object *obj)
1167 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1168 Widget_Data *wd = elm_widget_data_get(obj);
1169 if (!wd) return NULL;
1170 return wd->selected_item;
1174 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1176 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1178 wd = elm_widget_data_get(WIDGET(it));
1181 if ((wd->selected_item == it) && (selected))
1184 if ((wd->selected_item == it) && (!selected))
1185 wd->selected_item = eina_list_data_get(wd->items);
1188 wd->selected_item = it;
1189 _selected_item_indicate(wd->selected_item);
1193 ecore_idler_add(_move_scroller, WIDGET(it));
1197 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1199 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1202 wd = elm_widget_data_get(WIDGET(it));
1203 if (!wd) return EINA_FALSE;
1204 return (wd->selected_item == it);
1208 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1210 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1211 elm_widget_item_del_cb_set(it, func);
1215 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1217 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1218 return elm_widget_item_data_get(it);
1222 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1224 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1229 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1231 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1232 if (it->icon == icon) return;
1234 evas_object_del(it->icon);
1237 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
1240 EAPI Elm_Diskselector_Item *
1241 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1243 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1244 if (it->node->prev) return it->node->prev->data;
1248 EAPI Elm_Diskselector_Item *
1249 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1251 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1252 if (it->node->next) return it->node->next->data;
1256 EAPI Elm_Diskselector_Item *
1257 elm_diskselector_first_item_get(const Evas_Object *obj)
1259 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1262 wd = elm_widget_data_get(obj);
1263 if (!wd || !wd->items)
1266 return eina_list_data_get(wd->items);
1269 EAPI Elm_Diskselector_Item *
1270 elm_diskselector_last_item_get(const Evas_Object *obj)
1272 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1275 wd = elm_widget_data_get(obj);
1276 if (!wd || !wd->items)
1279 return eina_list_data_get(eina_list_last(wd->items));
1283 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1285 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1286 elm_widget_item_tooltip_text_set(item, text);
1290 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)
1292 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1293 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1297 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1299 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1300 elm_widget_item_tooltip_unset(item);
1304 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1306 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1307 elm_widget_item_tooltip_style_set(item, style);
1311 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1313 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1314 return elm_widget_item_tooltip_style_get(item);
1318 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1320 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1321 elm_widget_item_cursor_set(item, cursor);
1325 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1327 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1328 return elm_widget_item_cursor_get(item);
1332 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1334 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1335 elm_widget_item_cursor_unset(item);
1339 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1341 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1342 elm_widget_item_cursor_style_set(item, style);
1346 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1348 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1349 return elm_widget_item_cursor_style_get(item);
1353 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1355 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1356 elm_widget_item_cursor_engine_only_set(item, engine_only);
1360 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1362 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1363 return elm_widget_item_cursor_engine_only_get(item);
1367 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1369 ELM_CHECK_WIDTYPE(obj, widtype);
1370 Widget_Data *wd = elm_widget_data_get(obj);
1372 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1373 wd->display_item_num = num;
1374 wd->display_item_num_by_api = EINA_TRUE;
1378 elm_diskselector_display_item_num_get(const Evas_Object *item)
1380 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1381 Widget_Data *wd = elm_widget_data_get(item);
1383 return wd->display_item_num;