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;
34 Ecore_Idle_Enterer *idler;
35 Ecore_Idle_Enterer *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))
88 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
89 edje_object_size_min_restricted_calc
90 (elm_smart_scroller_edje_object_get
91 (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
92 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
93 evas_object_size_hint_max_set(obj, -1, -1);
95 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
97 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
99 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
101 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
102 (int)(w / wd->display_item_num), 0);
105 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
108 static Elm_Diskselector_Item *
109 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
111 Elm_Diskselector_Item *it;
112 const char *style = elm_widget_style_get(obj);
114 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
115 if (!it) return NULL;
117 it->label = eina_stringshare_add(label);
120 it->base.data = data;
121 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
122 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
123 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
125 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
127 evas_object_show(VIEW(it));
131 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
132 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
136 evas_object_size_hint_min_set(it->icon, 24, 24);
137 evas_object_size_hint_max_set(it->icon, 40, 40);
138 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
139 evas_object_show(it->icon);
140 elm_widget_sub_object_add(obj, it->icon);
146 _item_del(Elm_Diskselector_Item *item)
149 eina_stringshare_del(item->label);
151 evas_object_del(item->icon);
152 elm_widget_item_del(item);
156 _theme_data_get(Widget_Data *wd)
159 str = edje_object_data_get(wd->right_blank, "len_threshold");
160 if (str) wd->len_threshold = MAX(0, atoi(str));
161 else wd->len_threshold = 0;
163 if (!wd->display_item_num_by_api)
165 str = edje_object_data_get(wd->right_blank, "display_item_num");
166 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
167 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
170 str = edje_object_data_get(wd->right_blank, "min_width");
171 if (str) wd->minw = MAX(-1, atoi(str));
174 str = edje_object_data_get(wd->right_blank, "min_height");
175 if (str) wd->minh = MAX(-1, atoi(str));
180 _del_hook(Evas_Object * obj)
182 Widget_Data *wd = elm_widget_data_get(obj);
188 _del_pre_hook(Evas_Object * obj)
190 Elm_Diskselector_Item *it;
193 Widget_Data *wd = elm_widget_data_get(obj);
197 evas_object_del(wd->left_blank);
199 evas_object_del(wd->right_blank);
202 eina_stringshare_del(wd->last->label);
203 evas_object_del(wd->VIEW(last));
208 eina_stringshare_del(wd->s_last->label);
209 evas_object_del(wd->VIEW(s_last));
214 eina_stringshare_del(wd->second->label);
215 evas_object_del(wd->VIEW(second));
220 eina_stringshare_del(wd->first->label);
221 evas_object_del(wd->VIEW(first));
225 EINA_LIST_FOREACH(wd->under_items, l, it)
229 eina_stringshare_del(it->label);
230 evas_object_del(VIEW(it));
235 EINA_LIST_FOREACH(wd->over_items, l, it)
239 eina_stringshare_del(it->label);
240 evas_object_del(VIEW(it));
245 EINA_LIST_FREE(wd->items, it) _item_del(it);
246 eina_list_free(wd->r_items);
250 _sizing_eval(Evas_Object * obj)
252 Widget_Data *wd = elm_widget_data_get(obj);
254 _diskselector_object_resize(obj, NULL, obj, NULL);
258 _theme_hook(Evas_Object * obj)
261 Elm_Diskselector_Item *it;
262 Widget_Data *wd = elm_widget_data_get(obj);
266 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
267 "base", elm_widget_style_get(obj));
270 EINA_LIST_FOREACH(wd->r_items, l, it)
272 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
273 elm_widget_style_get(obj));
274 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
279 EINA_LIST_FOREACH(wd->items, l, it)
281 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
282 elm_widget_style_get(obj));
283 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
286 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
287 elm_widget_style_get(obj));
293 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
295 Widget_Data *wd = elm_widget_data_get(obj);
296 Evas_Object *sub = event_info;
297 Elm_Diskselector_Item *it;
302 if (sub == wd->scroller)
306 EINA_LIST_FOREACH(wd->items, l, it)
319 _select_item(Elm_Diskselector_Item *it)
322 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
323 wd->selected_item = it;
324 _selected_item_indicate(wd->selected_item);
325 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
326 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
330 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
332 Widget_Data *wd = elm_widget_data_get(obj);
336 if (elm_widget_focus_get(obj))
338 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
339 evas_object_focus_set(wd->self, EINA_TRUE);
343 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
344 evas_object_focus_set(wd->self, EINA_FALSE);
349 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
351 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
352 Evas_Event_Key_Down *ev = event_info;
353 Widget_Data *wd = elm_widget_data_get(obj);
354 if (!wd) return EINA_FALSE;
355 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
356 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
358 Elm_Diskselector_Item *it = NULL;
361 if (!wd->selected_item) {
362 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
366 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
367 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
369 l = wd->selected_item->node->prev;
370 if ((!l) && (wd->round))
371 l = eina_list_last(wd->items);
373 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
374 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
376 l = wd->selected_item->node->next;
377 if ((!l) && (wd->round))
380 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
382 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
383 l = eina_list_last(wd->items);
384 else return EINA_FALSE;
387 it = eina_list_data_get(l);
391 wd->selected_item = it;
393 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
396 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
401 _count_letter(const char *str)
406 for (chnum = 0; ; chnum++)
408 pos = evas_string_char_next_get(str, pos, &code);
409 if (code == 0) break;
415 _check_letter(const char *str, int length)
420 for (chnum = 0; ; chnum++)
422 if (chnum == length) break;
423 pos = evas_string_char_next_get(str, pos, &code);
424 if (code == 0) break;
430 _check_string(void *data)
432 int mid, steps, length, diff;
433 Elm_Diskselector_Item *it;
437 Widget_Data *wd = data;
439 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
449 EINA_LIST_FOREACH(list, l, it)
453 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
454 /* item not visible */
455 if ((x + w <= ox) || (x >= ox + ow))
458 len = _count_letter(it->label);
459 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
460 // len = eina_stringshare_strlen(it->label);
463 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
465 else if (x + w >= ox + ow - 5)
466 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
470 if ((wd->len_threshold) && (len > wd->len_threshold))
471 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
474 edje_object_signal_emit(VIEW(it), "elm,state,center",
478 // if len is les that the limit len, skip anyway
479 if (len <= wd->len_side)
482 steps = len - wd->len_side + 1;
484 if (mid <= ox + ow / 2)
485 diff = (ox + ow / 2) - mid;
487 diff = mid - (ox + ow / 2);
489 length = len - (int)(diff * steps / (ow / 3));
490 length = MAX(length, wd->len_side);
491 // limit string len to "length" ut8f chars
492 length = _check_letter(it->label, length);
493 // cut it off at byte mark returned form _check_letter
494 strncpy(buf, it->label, length);
496 edje_object_part_text_set(VIEW(it), "elm.text", buf);
500 ecore_idle_enterer_del(wd->check_idler);
501 wd->check_idler = NULL;
506 _selected_item_indicate(Elm_Diskselector_Item *it)
508 Elm_Diskselector_Item *item;
511 wd = elm_widget_data_get(WIDGET(it));
515 EINA_LIST_FOREACH(wd->r_items, l, item)
517 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
519 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
524 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
525 const char *emission __UNUSED__, const char *source __UNUSED__)
527 Elm_Diskselector_Item *it = data;
532 wd = elm_widget_data_get(WIDGET(it));
536 if (wd->selected_item != it)
538 wd->selected_item = it;
539 _selected_item_indicate(wd->selected_item);
542 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
546 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
548 Evas_Coord x, y, w, h, bw;
549 Widget_Data *wd = data;
552 elm_smart_scroller_child_pos_get(obj, &x, &y);
553 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
556 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
557 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
558 elm_smart_scroller_child_region_show(wd->scroller,
559 x - ((w / wd->display_item_num) * wd->item_count),
562 elm_smart_scroller_child_region_show(wd->scroller,
563 x + ((w / wd->display_item_num) * wd->item_count),
569 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
571 Elm_Diskselector_Item *it;
572 Widget_Data *wd = data;
584 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
585 EINA_LIST_FOREACH(list, l, it)
587 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
588 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
599 _move_scroller(void *data)
601 Evas_Object *obj = data;
604 Elm_Diskselector_Item *dit;
608 wd = elm_widget_data_get(obj);
609 if (!wd) return EINA_FALSE;
622 EINA_LIST_FOREACH(list, l, dit)
624 if (wd->selected_item == dit)
629 if (wd->round) i -= CEIL(wd->display_item_num);
634 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
638 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
639 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
643 ecore_idle_enterer_del(wd->idler);
646 wd->init = EINA_TRUE;
653 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
656 elm_box_unpack(wd->main_box, VIEW(it));
657 wd->r_items = eina_list_remove(wd->r_items, it);
658 eina_stringshare_del(it->label);
659 evas_object_del(VIEW(it));
664 _round_items_del(Widget_Data *wd)
667 Elm_Diskselector_Item * it;
669 _round_item_del(wd, wd->last);
671 _round_item_del(wd, wd->s_last);
673 _round_item_del(wd, wd->second);
675 _round_item_del(wd, wd->first);
678 EINA_LIST_FOREACH(wd->under_items, l, it)
680 _round_item_del(wd, it);
682 wd->under_items = eina_list_free(wd->under_items);
684 EINA_LIST_FOREACH(wd->over_items, l, it)
686 _round_item_del(wd, it);
688 wd->over_items = eina_list_free(wd->over_items);
692 _round_items_add(Widget_Data *wd)
694 Elm_Diskselector_Item *dit;
695 Elm_Diskselector_Item *it;
696 Elm_Diskselector_Item *temp_it;
698 dit = it = eina_list_nth(wd->items, 0);
703 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
705 wd->first->node = it->node;
706 wd->r_items = eina_list_append(wd->r_items, wd->first);
709 it = eina_list_nth(wd->items, 1);
714 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
716 wd->second->node = it->node;
717 wd->r_items = eina_list_append(wd->r_items, wd->second);
720 // if more than 3 itmes should be displayed
721 for (i = 2; i < CEIL(wd->display_item_num); i++)
723 it = eina_list_nth(wd->items, i);
725 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
726 wd->over_items = eina_list_append(wd->over_items, temp_it);
727 wd->r_items = eina_list_append(wd->r_items, temp_it);
730 it = eina_list_nth(wd->items, wd->item_count - 1);
735 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
737 wd->last->node = it->node;
738 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
741 it = eina_list_nth(wd->items, wd->item_count - 2);
746 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
748 wd->s_last->node = it->node;
749 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
752 // if more than 3 itmes should be displayed
753 for (i = 3; i <= CEIL(wd->display_item_num); i++)
755 it = eina_list_nth(wd->items, wd->item_count - i);
757 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
758 wd->under_items = eina_list_append(wd->under_items, temp_it);
759 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
764 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
766 if (it->icon == icon) return;
768 evas_object_del(it->icon);
772 evas_object_size_hint_min_set(it->icon, 24, 24);
773 evas_object_size_hint_max_set(it->icon, 40, 40);
774 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
775 evas_object_show(it->icon);
776 elm_widget_sub_object_add(WIDGET(it), it->icon);
781 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
784 Elm_Diskselector_Item *dit;
790 wd = elm_widget_data_get(WIDGET(it));
795 // Get index from indentical item from round items
796 EINA_LIST_FOREACH(wd->r_items, l, dit)
798 if (it == dit) break;
803 ic = eina_list_count(wd->r_items);
804 if (idx >= ic) return;
807 // Number of added items: CEIL(wd->display_item_num)
808 ac = CEIL(wd->display_item_num);
810 if (((idx >= 0) && (idx < ac)) ||
811 ((idx >= ac) && (idx < (2 * ac))))
813 // Selected item: under, low region
814 dit = eina_list_nth(wd->r_items,
815 idx + ic - (2 * ac));
817 else if (((idx >= (ic - ac)) && (idx < ic)) ||
818 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
820 // Selected item: over, high region
821 dit = eina_list_nth(wd->r_items,
822 idx - ic + (2 * ac));
825 if(dit) _item_icon_set(dit, icon);
826 _sizing_eval(wd->self);
831 elm_diskselector_add(Evas_Object *parent)
837 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
839 ELM_SET_WIDTYPE(widtype, "diskselector");
840 elm_widget_type_set(obj, "diskselector");
841 elm_widget_sub_object_add(parent, obj);
842 elm_widget_data_set(obj, wd);
843 elm_widget_del_hook_set(obj, _del_hook);
844 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
845 elm_widget_theme_hook_set(obj, _theme_hook);
846 elm_widget_can_focus_set(obj, EINA_TRUE);
847 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
848 elm_widget_event_hook_set(obj, _event_hook);
852 wd->round = EINA_FALSE;
853 wd->init = EINA_FALSE;
855 wd->display_item_num_by_api = EINA_FALSE;
857 wd->scroller = elm_smart_scroller_add(e);
858 elm_smart_scroller_widget_set(wd->scroller, obj);
860 elm_widget_resize_object_set(obj, wd->scroller);
861 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
862 ELM_SMART_SCROLLER_POLICY_OFF);
863 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
864 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
866 evas_object_smart_callback_add(wd->scroller, "animate,stop",
867 _scroller_stop_cb, wd);
868 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
870 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
871 _diskselector_object_resize, obj);
873 wd->main_box = elm_box_add(parent);
874 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
875 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
876 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
878 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
880 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
882 elm_widget_sub_object_add(obj, wd->main_box);
884 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
886 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
887 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
889 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
891 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
893 elm_box_pack_end(wd->main_box, wd->left_blank);
894 evas_object_show(wd->left_blank);
896 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
897 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
899 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
901 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
903 elm_box_pack_end(wd->main_box, wd->right_blank);
904 evas_object_show(wd->right_blank);
908 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
909 evas_object_smart_callbacks_descriptions_set(obj, _signals);
915 elm_diskselector_round_get(const Evas_Object *obj)
917 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
918 Widget_Data *wd = elm_widget_data_get(obj);
919 if (!wd) return EINA_FALSE;
924 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
927 Elm_Diskselector_Item *it;
929 ELM_CHECK_WIDTYPE(obj, widtype);
930 Widget_Data *wd = elm_widget_data_get(obj);
933 if (wd->round == round)
939 wd->r_items = eina_list_clone(wd->items);
940 elm_box_unpack(wd->main_box, wd->left_blank);
941 evas_object_hide(wd->left_blank);
942 elm_box_unpack(wd->main_box, wd->right_blank);
943 evas_object_hide(wd->right_blank);
947 _round_items_add(wd);
950 elm_box_pack_start(wd->main_box, wd->VIEW(last));
952 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
954 // if more than 3 items should be displayed
955 EINA_LIST_FOREACH(wd->under_items, elist, it)
956 elm_box_pack_start(wd->main_box, VIEW(it));
959 elm_box_pack_end(wd->main_box, wd->VIEW(first));
961 elm_box_pack_end(wd->main_box, wd->VIEW(second));
963 // if more than 3 items should be displayed
964 EINA_LIST_FOREACH(wd->over_items, elist, it)
965 elm_box_pack_end(wd->main_box, VIEW(it));
969 _round_items_del(wd);
970 elm_box_pack_start(wd->main_box, wd->left_blank);
971 elm_box_pack_end(wd->main_box, wd->right_blank);
972 eina_list_free(wd->r_items);
976 _selected_item_indicate(wd->selected_item);
981 elm_diskselector_side_label_length_get(const Evas_Object *obj)
983 ELM_CHECK_WIDTYPE(obj, widtype) 0;
984 Widget_Data *wd = elm_widget_data_get(obj);
990 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
992 ELM_CHECK_WIDTYPE(obj, widtype);
993 Widget_Data *wd = elm_widget_data_get(obj);
999 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
1001 return elm_diskselector_side_label_length_set(obj, len);
1005 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1007 return elm_diskselector_side_label_length_get(obj);
1011 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1013 ELM_CHECK_WIDTYPE(obj, widtype);
1014 Widget_Data *wd = elm_widget_data_get(obj);
1017 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1021 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1023 ELM_CHECK_WIDTYPE(obj, widtype);
1024 Widget_Data *wd = elm_widget_data_get(obj);
1026 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1030 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1032 ELM_CHECK_WIDTYPE(obj, widtype);
1033 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1034 Widget_Data *wd = elm_widget_data_get(obj);
1035 if ((!wd) || (!wd->scroller)) return;
1036 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1037 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1038 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1042 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1044 ELM_CHECK_WIDTYPE(obj, widtype);
1045 Widget_Data *wd = elm_widget_data_get(obj);
1046 if ((!wd) || (!wd->scroller)) return;
1047 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1048 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1050 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1054 elm_diskselector_clear(Evas_Object *obj)
1056 ELM_CHECK_WIDTYPE(obj, widtype);
1057 Widget_Data *wd = elm_widget_data_get(obj);
1058 Elm_Diskselector_Item *it;
1061 if (!wd->items) return;
1063 wd->selected_item = NULL;
1064 EINA_LIST_FREE(wd->items, it) _item_del(it);
1065 _round_items_del(wd);
1069 EAPI const Eina_List *
1070 elm_diskselector_items_get(const Evas_Object *obj)
1072 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1073 Widget_Data *wd = elm_widget_data_get(obj);
1074 if (!wd) return NULL;
1078 EAPI Elm_Diskselector_Item *
1079 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1081 Elm_Diskselector_Item *it;
1082 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1083 Widget_Data *wd = elm_widget_data_get(obj);
1084 if (!wd) return NULL;
1086 it = _item_new(obj, icon, label, func, data);
1087 wd->items = eina_list_append(wd->items, it);
1088 it->node = eina_list_last(wd->items);
1092 _round_items_del(wd);
1093 wd->r_items = eina_list_append(wd->r_items, it);
1094 _round_items_add(wd);
1096 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1098 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1099 elm_box_pack_end(wd->main_box, VIEW(it));
1101 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1103 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1107 elm_box_unpack(wd->main_box, wd->right_blank);
1108 elm_box_pack_end(wd->main_box, VIEW(it));
1109 elm_box_pack_end(wd->main_box, wd->right_blank);
1111 if (!wd->selected_item)
1112 wd->selected_item = it;
1114 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1120 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1122 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1123 Elm_Diskselector_Item *dit;
1124 Elm_Diskselector_Item *item;
1127 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1130 elm_box_unpack(wd->main_box, VIEW(it));
1133 wd->r_items = eina_list_remove(wd->r_items, it);
1135 wd->items = eina_list_remove(wd->items, it);
1137 if (wd->selected_item == it)
1139 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1141 wd->selected_item = dit;
1143 wd->selected_item = eina_list_nth(wd->items, 1);
1145 _selected_item_indicate(wd->selected_item);
1149 wd->item_count -= 1;
1153 if (!wd->item_count)
1155 evas_object_hide(wd->VIEW(first));
1156 evas_object_hide(wd->VIEW(second));
1157 evas_object_hide(wd->VIEW(last));
1158 evas_object_hide(wd->VIEW(s_last));
1160 EINA_LIST_FOREACH(wd->under_items, l, item)
1161 evas_object_hide(VIEW(item));
1163 EINA_LIST_FOREACH(wd->over_items, l, item)
1164 evas_object_hide(VIEW(item));
1168 dit = eina_list_nth(wd->items, 0);
1171 eina_stringshare_replace(&wd->first->label, dit->label);
1172 edje_object_part_text_set(wd->VIEW(first), "elm.text",
1175 dit = eina_list_nth(wd->items, 1);
1178 eina_stringshare_replace(&wd->second->label, dit->label);
1179 edje_object_part_text_set(wd->VIEW(second), "elm.text",
1182 // if more than 3 itmes should be displayed
1183 for (i = 2; i < CEIL(wd->display_item_num); i++)
1185 dit = eina_list_nth(wd->items, i);
1186 item = eina_list_nth(wd->over_items, i - 2);
1187 eina_stringshare_replace(&item->label, dit->label);
1188 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1191 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1194 eina_stringshare_replace(&wd->last->label, dit->label);
1195 edje_object_part_text_set(wd->VIEW(last), "elm.text",
1198 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1201 eina_stringshare_replace(&wd->s_last->label, dit->label);
1202 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
1205 // if more than 3 itmes should be displayed
1206 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1208 dit = eina_list_nth(wd->items, wd->item_count - i);
1209 item = eina_list_nth(wd->under_items, i - 3);
1210 eina_stringshare_replace(&item->label, dit->label);
1211 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1215 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
1216 _sizing_eval(wd->self);
1220 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1222 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1227 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1229 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1230 eina_stringshare_replace(&it->label, label);
1231 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1234 EAPI Elm_Diskselector_Item *
1235 elm_diskselector_selected_item_get(const Evas_Object *obj)
1237 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1238 Widget_Data *wd = elm_widget_data_get(obj);
1239 if (!wd) return NULL;
1240 return wd->selected_item;
1244 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1246 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1248 wd = elm_widget_data_get(WIDGET(it));
1251 if ((wd->selected_item == it) && (selected))
1254 if ((wd->selected_item == it) && (!selected))
1255 wd->selected_item = eina_list_data_get(wd->items);
1258 wd->selected_item = it;
1259 _selected_item_indicate(wd->selected_item);
1263 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(it));
1267 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1269 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1272 wd = elm_widget_data_get(WIDGET(it));
1273 if (!wd) return EINA_FALSE;
1274 return (wd->selected_item == it);
1278 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1280 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1281 elm_widget_item_del_cb_set(it, func);
1285 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1287 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1288 return elm_widget_item_data_get(it);
1292 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1294 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1299 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1301 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1302 _item_icon_set(it, icon);
1303 _check_identical_item(it, icon);
1306 EAPI Elm_Diskselector_Item *
1307 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1309 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1310 if (it->node->prev) return it->node->prev->data;
1314 EAPI Elm_Diskselector_Item *
1315 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1317 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1318 if (it->node->next) return it->node->next->data;
1322 EAPI Elm_Diskselector_Item *
1323 elm_diskselector_first_item_get(const Evas_Object *obj)
1325 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1328 wd = elm_widget_data_get(obj);
1329 if (!wd || !wd->items)
1332 return eina_list_data_get(wd->items);
1335 EAPI Elm_Diskselector_Item *
1336 elm_diskselector_last_item_get(const Evas_Object *obj)
1338 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1341 wd = elm_widget_data_get(obj);
1342 if (!wd || !wd->items)
1345 return eina_list_data_get(eina_list_last(wd->items));
1349 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1351 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1352 elm_widget_item_tooltip_text_set(item, text);
1356 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)
1358 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1359 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1363 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1365 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1366 elm_widget_item_tooltip_unset(item);
1370 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1372 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1373 elm_widget_item_tooltip_style_set(item, style);
1377 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1379 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1380 return elm_widget_item_tooltip_style_get(item);
1384 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1386 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1387 elm_widget_item_cursor_set(item, cursor);
1391 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1393 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1394 return elm_widget_item_cursor_get(item);
1398 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1400 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1401 elm_widget_item_cursor_unset(item);
1405 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1407 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1408 elm_widget_item_cursor_style_set(item, style);
1412 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1414 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1415 return elm_widget_item_cursor_style_get(item);
1419 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1421 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1422 elm_widget_item_cursor_engine_only_set(item, engine_only);
1426 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1428 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1429 return elm_widget_item_cursor_engine_only_get(item);
1433 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1435 ELM_CHECK_WIDTYPE(obj, widtype);
1436 Widget_Data *wd = elm_widget_data_get(obj);
1438 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1439 wd->display_item_num = num;
1440 wd->display_item_num_by_api = EINA_TRUE;
1444 elm_diskselector_display_item_num_get(const Evas_Object *item)
1446 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1447 Widget_Data *wd = elm_widget_data_get(item);
1449 return wd->display_item_num;