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 _default_display_item_num_set(Widget_Data *wd)
187 str = edje_object_data_get(wd->right_blank, "display_item_num");
188 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
189 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
193 _del_hook(Evas_Object * obj)
195 Widget_Data *wd = elm_widget_data_get(obj);
201 _del_pre_hook(Evas_Object * obj)
203 Elm_Diskselector_Item *it;
206 Widget_Data *wd = elm_widget_data_get(obj);
210 evas_object_del(wd->left_blank);
212 evas_object_del(wd->right_blank);
215 eina_stringshare_del(wd->last->label);
216 evas_object_del(wd->VIEW(last));
221 eina_stringshare_del(wd->s_last->label);
222 evas_object_del(wd->VIEW(s_last));
227 eina_stringshare_del(wd->second->label);
228 evas_object_del(wd->VIEW(second));
233 eina_stringshare_del(wd->first->label);
234 evas_object_del(wd->VIEW(first));
238 EINA_LIST_FOREACH(wd->under_items, l, it)
242 eina_stringshare_del(it->label);
243 evas_object_del(VIEW(wd->first));
248 EINA_LIST_FOREACH(wd->over_items, l, it)
252 eina_stringshare_del(it->label);
253 evas_object_del(VIEW(wd->first));
258 EINA_LIST_FREE(wd->items, it) _item_del(it);
259 eina_list_free(wd->r_items);
263 _sizing_eval(Evas_Object * obj)
265 Widget_Data *wd = elm_widget_data_get(obj);
267 _diskselector_object_resize(obj, NULL, obj, NULL);
271 _theme_hook(Evas_Object * obj)
274 Elm_Diskselector_Item *it;
275 Widget_Data *wd = elm_widget_data_get(obj);
279 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
280 "base", elm_widget_style_get(obj));
283 EINA_LIST_FOREACH(wd->r_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);
292 EINA_LIST_FOREACH(wd->items, l, it)
294 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
295 elm_widget_style_get(obj));
296 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
299 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
300 elm_widget_style_get(obj));
306 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
308 Widget_Data *wd = elm_widget_data_get(obj);
309 Evas_Object *sub = event_info;
310 Elm_Diskselector_Item *it;
315 if (sub == wd->scroller)
319 EINA_LIST_FOREACH(wd->items, l, it)
332 _select_item(Elm_Diskselector_Item *it)
335 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
336 wd->selected_item = it;
337 _selected_item_indicate(wd->selected_item);
338 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
339 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
343 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
345 Widget_Data *wd = elm_widget_data_get(obj);
349 if (elm_widget_focus_get(obj))
351 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
352 evas_object_focus_set(wd->self, EINA_TRUE);
356 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
357 evas_object_focus_set(wd->self, EINA_FALSE);
362 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
364 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
365 Evas_Event_Key_Down *ev = event_info;
366 Widget_Data *wd = elm_widget_data_get(obj);
367 if (!wd) return EINA_FALSE;
368 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
369 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
371 Elm_Diskselector_Item *it = NULL;
374 if (!wd->selected_item) {
375 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
379 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
380 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
382 l = wd->selected_item->node->prev;
383 if ((!l) && (wd->round))
384 l = eina_list_last(wd->items);
386 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
387 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
389 l = wd->selected_item->node->next;
390 if ((!l) && (wd->round))
393 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
395 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
396 l = eina_list_last(wd->items);
397 else return EINA_FALSE;
400 it = eina_list_data_get(l);
404 wd->selected_item = it;
406 wd->idler = ecore_idler_add(_move_scroller, obj);
409 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
414 _count_letter(const char *str)
419 for (chnum = 0; ; chnum++)
421 pos = evas_string_char_next_get(str, pos, &code);
422 if (code == 0) break;
428 _check_letter(const char *str, int length)
433 for (chnum = 0; ; chnum++)
435 if (chnum == length) break;
436 pos = evas_string_char_next_get(str, pos, &code);
437 if (code == 0) break;
443 _check_string(void *data)
445 int mid, steps, length, diff;
446 Elm_Diskselector_Item *it;
450 Widget_Data *wd = data;
452 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
462 EINA_LIST_FOREACH(list, l, it)
466 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
467 /* item not visible */
468 if ((x + w <= ox) || (x >= ox + ow))
471 len = _count_letter(it->label);
472 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
473 // len = eina_stringshare_strlen(it->label);
476 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
478 else if (x + w >= ox + ow - 5)
479 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
483 if ((wd->len_threshold) && (len > wd->len_threshold))
484 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
487 edje_object_signal_emit(VIEW(it), "elm,state,center",
491 // if len is les that the limit len, skip anyway
492 if (len <= wd->len_side)
495 steps = len - wd->len_side + 1;
497 if (mid <= ox + ow / 2)
498 diff = (ox + ow / 2) - mid;
500 diff = mid - (ox + ow / 2);
502 length = len - (int)(diff * steps / (ow / 3));
503 length = MAX(length, wd->len_side);
504 // limit string len to "length" ut8f chars
505 length = _check_letter(it->label, length);
506 // cut it off at byte mark returned form _check_letter
507 strncpy(buf, it->label, length);
509 edje_object_part_text_set(VIEW(it), "elm.text", buf);
513 ecore_idler_del(wd->check_idler);
514 wd->check_idler = NULL;
519 _selected_item_indicate(Elm_Diskselector_Item *it)
521 Elm_Diskselector_Item *item;
524 wd = elm_widget_data_get(WIDGET(it));
528 EINA_LIST_FOREACH(wd->r_items, l, item)
530 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
532 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
537 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
538 const char *emission __UNUSED__, const char *source __UNUSED__)
540 Elm_Diskselector_Item *it = data;
545 wd = elm_widget_data_get(WIDGET(it));
549 if (wd->selected_item != it)
551 wd->selected_item = it;
552 _selected_item_indicate(wd->selected_item);
555 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
559 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
561 Evas_Coord x, y, w, h, bw;
562 Widget_Data *wd = data;
565 elm_smart_scroller_child_pos_get(obj, &x, &y);
566 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
569 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
570 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
571 elm_smart_scroller_child_region_show(wd->scroller,
572 x - ((w / wd->display_item_num) * wd->item_count),
575 elm_smart_scroller_child_region_show(wd->scroller,
576 x + ((w / wd->display_item_num) * wd->item_count),
582 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
584 Elm_Diskselector_Item *it;
585 Widget_Data *wd = data;
597 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
598 EINA_LIST_FOREACH(list, l, it)
600 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
601 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
612 _move_scroller(void *data)
614 Evas_Object *obj = data;
617 Elm_Diskselector_Item *dit;
621 wd = elm_widget_data_get(obj);
622 if (!wd) return EINA_FALSE;
629 EINA_LIST_FOREACH(wd->items, l, dit)
631 if (wd->selected_item == dit)
638 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
642 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
643 //move scroller in two steps for getting smooth launching effect.
645 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * (i-2), y, w, h);
646 elm_smart_scroller_region_bring_in(wd->scroller, w / wd->display_item_num * i, y, w, h);
651 ecore_idler_del(wd->idler);
654 wd->init = EINA_TRUE;
661 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
664 elm_box_unpack(wd->main_box, VIEW(it));
665 wd->r_items = eina_list_remove(wd->r_items, it);
666 eina_stringshare_del(it->label);
667 evas_object_del(VIEW(it));
672 _round_items_del(Widget_Data *wd)
675 Elm_Diskselector_Item * it;
677 _round_item_del(wd, wd->last);
679 _round_item_del(wd, wd->s_last);
681 _round_item_del(wd, wd->second);
683 _round_item_del(wd, wd->first);
686 EINA_LIST_FOREACH(wd->under_items, l, it)
688 _round_item_del(wd, it);
692 EINA_LIST_FOREACH(wd->over_items, l, it)
694 _round_item_del(wd, it);
700 _round_items_add(Widget_Data *wd)
702 Elm_Diskselector_Item *dit;
703 Elm_Diskselector_Item *it;
704 Elm_Diskselector_Item *temp_it;
706 dit = it = eina_list_nth(wd->items, 0);
711 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
713 wd->first->node = it->node;
714 wd->r_items = eina_list_append(wd->r_items, wd->first);
717 it = eina_list_nth(wd->items, 1);
722 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
724 wd->second->node = it->node;
725 wd->r_items = eina_list_append(wd->r_items, wd->second);
728 // if more than 3 itmes should be displayed
729 for (i = 2; i < CEIL(wd->display_item_num); i++)
731 it = eina_list_nth(wd->items, i);
733 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
734 wd->over_items = eina_list_append(wd->over_items, temp_it);
735 wd->r_items = eina_list_append(wd->r_items, temp_it);
738 it = eina_list_nth(wd->items, wd->item_count - 1);
743 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
745 wd->last->node = it->node;
746 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
749 it = eina_list_nth(wd->items, wd->item_count - 2);
754 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
756 wd->s_last->node = it->node;
757 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
760 // if more than 3 itmes should be displayed
761 for (i = 3; i <= CEIL(wd->display_item_num); i++)
763 it = eina_list_nth(wd->items, wd->item_count - i);
765 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
766 wd->under_items = eina_list_append(wd->under_items, temp_it);
767 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
772 elm_diskselector_add(Evas_Object *parent)
778 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
780 ELM_SET_WIDTYPE(widtype, "diskselector");
781 elm_widget_type_set(obj, "diskselector");
782 elm_widget_sub_object_add(parent, obj);
783 elm_widget_data_set(obj, wd);
784 elm_widget_del_hook_set(obj, _del_hook);
785 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
786 elm_widget_theme_hook_set(obj, _theme_hook);
787 elm_widget_can_focus_set(obj, EINA_TRUE);
788 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
789 elm_widget_event_hook_set(obj, _event_hook);
793 wd->round = EINA_FALSE;
794 wd->init = EINA_FALSE;
796 wd->display_item_num_by_api = EINA_FALSE;
798 wd->scroller = elm_smart_scroller_add(e);
799 elm_smart_scroller_widget_set(wd->scroller, obj);
801 elm_widget_resize_object_set(obj, wd->scroller);
802 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
803 ELM_SMART_SCROLLER_POLICY_OFF);
804 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
805 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
807 evas_object_smart_callback_add(wd->scroller, "animate,stop",
808 _scroller_stop_cb, wd);
809 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
811 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
812 _diskselector_object_resize, obj);
814 wd->main_box = elm_box_add(parent);
815 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
816 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
817 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
819 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
821 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
823 elm_widget_sub_object_add(obj, wd->main_box);
825 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
827 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
828 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
830 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
832 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
834 elm_box_pack_end(wd->main_box, wd->left_blank);
835 evas_object_show(wd->left_blank);
837 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
838 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
840 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
842 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
844 elm_box_pack_end(wd->main_box, wd->right_blank);
845 evas_object_show(wd->right_blank);
849 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
850 evas_object_smart_callbacks_descriptions_set(obj, _signals);
856 elm_diskselector_round_get(const Evas_Object *obj)
858 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
859 Widget_Data *wd = elm_widget_data_get(obj);
860 if (!wd) return EINA_FALSE;
865 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
868 Elm_Diskselector_Item *it;
870 ELM_CHECK_WIDTYPE(obj, widtype);
871 Widget_Data *wd = elm_widget_data_get(obj);
874 if (wd->round == round)
880 wd->r_items = eina_list_clone(wd->items);
881 elm_box_unpack(wd->main_box, wd->left_blank);
882 evas_object_hide(wd->left_blank);
883 elm_box_unpack(wd->main_box, wd->right_blank);
884 evas_object_hide(wd->right_blank);
888 _round_items_add(wd);
891 elm_box_pack_start(wd->main_box, wd->VIEW(last));
893 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
895 // if more than 3 items should be displayed
896 EINA_LIST_FOREACH(wd->under_items, elist, it)
897 elm_box_pack_start(wd->main_box, VIEW(it));
900 elm_box_pack_end(wd->main_box, wd->VIEW(first));
902 elm_box_pack_end(wd->main_box, wd->VIEW(second));
904 // if more than 3 items should be displayed
905 EINA_LIST_FOREACH(wd->over_items, elist, it)
906 elm_box_pack_end(wd->main_box, VIEW(it));
910 _round_items_del(wd);
911 elm_box_pack_start(wd->main_box, wd->left_blank);
912 elm_box_pack_end(wd->main_box, wd->right_blank);
913 eina_list_free(wd->r_items);
921 elm_diskselector_side_label_length_get(const Evas_Object *obj)
923 ELM_CHECK_WIDTYPE(obj, widtype) 0;
924 Widget_Data *wd = elm_widget_data_get(obj);
930 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
932 ELM_CHECK_WIDTYPE(obj, widtype);
933 Widget_Data *wd = elm_widget_data_get(obj);
939 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
941 return elm_diskselector_side_label_length_set(obj, len);
945 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
947 return elm_diskselector_side_label_length_get(obj);
951 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
953 ELM_CHECK_WIDTYPE(obj, widtype);
954 Widget_Data *wd = elm_widget_data_get(obj);
957 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
961 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
963 ELM_CHECK_WIDTYPE(obj, widtype);
964 Widget_Data *wd = elm_widget_data_get(obj);
966 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
970 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
972 ELM_CHECK_WIDTYPE(obj, widtype);
973 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
974 Widget_Data *wd = elm_widget_data_get(obj);
975 if ((!wd) || (!wd->scroller)) return;
976 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
977 *policy_h = (Elm_Scroller_Policy) s_policy_h;
978 *policy_v = (Elm_Scroller_Policy) s_policy_v;
982 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
984 ELM_CHECK_WIDTYPE(obj, widtype);
985 Widget_Data *wd = elm_widget_data_get(obj);
987 if ((policy_h >= 3) || (policy_v >= 3)) return;
989 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
993 elm_diskselector_clear(Evas_Object *obj)
995 ELM_CHECK_WIDTYPE(obj, widtype);
996 Widget_Data *wd = elm_widget_data_get(obj);
997 Elm_Diskselector_Item *it;
1000 if (!wd->items) return;
1002 wd->selected_item = NULL;
1003 EINA_LIST_FREE(wd->items, it) _item_del(it);
1004 _round_items_del(wd);
1008 EAPI const Eina_List *
1009 elm_diskselector_items_get(const Evas_Object *obj)
1011 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1012 Widget_Data *wd = elm_widget_data_get(obj);
1013 if (!wd) return NULL;
1017 EAPI Elm_Diskselector_Item *
1018 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1020 Elm_Diskselector_Item *it;
1021 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1022 Widget_Data *wd = elm_widget_data_get(obj);
1023 if (!wd) return NULL;
1025 it = _item_new(obj, icon, label, func, data);
1026 wd->items = eina_list_append(wd->items, it);
1027 it->node = eina_list_last(wd->items);
1031 _round_items_del(wd);
1032 wd->r_items = eina_list_append(wd->r_items, it);
1033 _round_items_add(wd);
1035 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1037 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1038 elm_box_pack_end(wd->main_box, VIEW(it));
1040 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1042 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1046 elm_box_unpack(wd->main_box, wd->right_blank);
1047 elm_box_pack_end(wd->main_box, VIEW(it));
1048 elm_box_pack_end(wd->main_box, wd->right_blank);
1050 if (!wd->selected_item)
1051 wd->selected_item = it;
1053 wd->idler = ecore_idler_add(_move_scroller, obj);
1059 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1061 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1062 Elm_Diskselector_Item *dit;
1063 Elm_Diskselector_Item *item;
1066 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1069 elm_box_unpack(wd->main_box, VIEW(it));
1072 wd->r_items = eina_list_remove(wd->r_items, it);
1074 wd->items = eina_list_remove(wd->items, it);
1076 if (wd->selected_item == it)
1078 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1080 wd->selected_item = dit;
1082 wd->selected_item = eina_list_nth(wd->items, 1);
1084 _selected_item_indicate(wd->selected_item);
1088 wd->item_count -= 1;
1092 if (!wd->item_count)
1094 evas_object_hide(wd->VIEW(first));
1095 evas_object_hide(wd->VIEW(second));
1096 evas_object_hide(wd->VIEW(last));
1097 evas_object_hide(wd->VIEW(s_last));
1099 EINA_LIST_FOREACH(wd->under_items, l, item)
1100 evas_object_hide(VIEW(item));
1102 EINA_LIST_FOREACH(wd->over_items, l, item)
1103 evas_object_hide(VIEW(item));
1107 dit = eina_list_nth(wd->items, 0);
1110 eina_stringshare_replace(&wd->first->label, dit->label);
1111 edje_object_part_text_set(wd->VIEW(first), "elm.text",
1114 dit = eina_list_nth(wd->items, 1);
1117 eina_stringshare_replace(&wd->second->label, dit->label);
1118 edje_object_part_text_set(wd->VIEW(second), "elm.text",
1121 // if more than 3 itmes should be displayed
1122 for (i = 2; i < CEIL(wd->display_item_num); i++)
1124 dit = eina_list_nth(wd->items, i);
1125 item = eina_list_nth(wd->over_items, i - 2);
1126 eina_stringshare_replace(&item->label, dit->label);
1127 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1130 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1133 eina_stringshare_replace(&wd->last->label, dit->label);
1134 edje_object_part_text_set(wd->VIEW(last), "elm.text",
1137 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1140 eina_stringshare_replace(&wd->s_last->label, dit->label);
1141 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
1144 // if more than 3 itmes should be displayed
1145 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1147 dit = eina_list_nth(wd->items, wd->item_count - i);
1148 item = eina_list_nth(wd->under_items, i - 3);
1149 eina_stringshare_replace(&item->label, dit->label);
1150 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1154 wd->check_idler = ecore_idler_add(_check_string, wd);
1155 _sizing_eval(wd->self);
1159 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1161 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1166 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1168 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1169 eina_stringshare_replace(&it->label, label);
1170 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1173 EAPI Elm_Diskselector_Item *
1174 elm_diskselector_selected_item_get(const Evas_Object *obj)
1176 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1177 Widget_Data *wd = elm_widget_data_get(obj);
1178 if (!wd) return NULL;
1179 return wd->selected_item;
1183 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1185 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1187 wd = elm_widget_data_get(WIDGET(it));
1190 if ((wd->selected_item == it) && (selected))
1193 if ((wd->selected_item == it) && (!selected))
1194 wd->selected_item = eina_list_data_get(wd->items);
1197 wd->selected_item = it;
1198 _selected_item_indicate(wd->selected_item);
1202 ecore_idler_add(_move_scroller, WIDGET(it));
1206 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1208 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1211 wd = elm_widget_data_get(WIDGET(it));
1212 if (!wd) return EINA_FALSE;
1213 return (wd->selected_item == it);
1217 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1219 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1220 elm_widget_item_del_cb_set(it, func);
1224 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1226 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1227 return elm_widget_item_data_get(it);
1231 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1233 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1238 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1240 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1241 if (it->icon == icon) return;
1243 evas_object_del(it->icon);
1246 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
1249 EAPI Elm_Diskselector_Item *
1250 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1252 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1253 if (it->node->prev) return it->node->prev->data;
1257 EAPI Elm_Diskselector_Item *
1258 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1260 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1261 if (it->node->next) return it->node->next->data;
1265 EAPI Elm_Diskselector_Item *
1266 elm_diskselector_first_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(wd->items);
1278 EAPI Elm_Diskselector_Item *
1279 elm_diskselector_last_item_get(const Evas_Object *obj)
1281 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1284 wd = elm_widget_data_get(obj);
1285 if (!wd || !wd->items)
1288 return eina_list_data_get(eina_list_last(wd->items));
1292 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1294 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1295 elm_widget_item_tooltip_text_set(item, text);
1299 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)
1301 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1302 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1306 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1308 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1309 elm_widget_item_tooltip_unset(item);
1313 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1315 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1316 elm_widget_item_tooltip_style_set(item, style);
1320 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1322 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1323 return elm_widget_item_tooltip_style_get(item);
1327 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1329 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1330 elm_widget_item_cursor_set(item, cursor);
1334 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1336 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1337 return elm_widget_item_cursor_get(item);
1341 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1343 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1344 elm_widget_item_cursor_unset(item);
1348 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1350 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1351 elm_widget_item_cursor_style_set(item, style);
1355 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1357 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1358 return elm_widget_item_cursor_style_get(item);
1362 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1364 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1365 elm_widget_item_cursor_engine_only_set(item, engine_only);
1369 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1371 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1372 return elm_widget_item_cursor_engine_only_get(item);
1376 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1378 ELM_CHECK_WIDTYPE(obj, widtype);
1379 Widget_Data *wd = elm_widget_data_get(obj);
1381 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1382 wd->display_item_num = num;
1383 wd->display_item_num_by_api = EINA_TRUE;
1387 elm_diskselector_display_item_num_get(const Evas_Object *item)
1389 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1390 Widget_Data *wd = elm_widget_data_get(item);
1392 return wd->display_item_num;