1 #include <Elementary.h>
5 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
9 #define CEIL(a) (((a) % 2 != 0) ? ((a) / 2 + 1) : ((a) / 2))
12 #define DISPLAY_ITEM_NUM_MIN 3
14 typedef struct _Widget_Data Widget_Data;
19 Evas_Object *scroller;
20 Evas_Object *main_box;
21 Evas_Object *left_blank;
22 Evas_Object *right_blank;
23 Elm_Diskselector_Item *selected_item;
24 Elm_Diskselector_Item *first;
25 Elm_Diskselector_Item *second;
26 Elm_Diskselector_Item *s_last;
27 Elm_Diskselector_Item *last;
30 Eina_List *over_items;
31 Eina_List *under_items;
32 int item_count, len_threshold, len_side, display_item_num;
34 Ecore_Idler *check_idler;
35 Evas_Coord minw, minh;
38 Eina_Bool display_item_num_by_api:1;
41 struct _Elm_Diskselector_Item
50 static const char *widtype = NULL;
52 #define ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, ...) \
53 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
54 ELM_CHECK_WIDTYPE(it->base.widget, widtype) __VA_ARGS__;
56 static Eina_Bool _move_scroller(void *data);
57 static void _del_hook(Evas_Object * obj);
58 static void _del_pre_hook(Evas_Object * obj);
59 static void _sizing_eval(Evas_Object * obj);
60 static void _theme_hook(Evas_Object * obj);
61 static void _on_focus_hook(void *data, Evas_Object *obj);
62 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
63 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
64 static void _round_items_del(Widget_Data *wd);
65 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
66 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
67 const char *emission __UNUSED__,
68 const char *source __UNUSED__);
69 static void _selected_item_indicate(Elm_Diskselector_Item *it);
71 static const char SIG_SELECTED[] = "selected";
72 static const Evas_Smart_Cb_Description _signals[] = {
78 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
83 wd = elm_widget_data_get(data);
86 if (wd->minw == -1 && wd->minh == -1) elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
87 edje_object_size_min_restricted_calc(elm_smart_scroller_edje_object_get(
88 wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
89 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
90 evas_object_size_hint_max_set(obj, -1, -1);
92 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
94 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
96 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
98 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
99 (int)(w / wd->display_item_num), 0);
102 wd->idler = ecore_idler_add(_move_scroller, data);
105 static Elm_Diskselector_Item *
106 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
108 Elm_Diskselector_Item *it;
109 const char *style = elm_widget_style_get(obj);
111 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
112 if (!it) return NULL;
114 it->label = eina_stringshare_add(label);
117 it->base.data = data;
118 it->base.view = edje_object_add(evas_object_evas_get(obj));
119 _elm_theme_object_set(obj, it->base.view, "diskselector", "item", style);
120 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND,
122 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL,
124 evas_object_show(it->base.view);
128 edje_object_part_text_set(it->base.view, "elm.text", it->label);
129 edje_object_signal_callback_add(it->base.view, "elm,action,click", "", _item_click_cb, it);
133 evas_object_size_hint_min_set(it->icon, 24, 24);
134 evas_object_size_hint_max_set(it->icon, 40, 40);
135 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
136 evas_object_show(it->icon);
137 elm_widget_sub_object_add(obj, it->icon);
143 _item_del(Elm_Diskselector_Item *item)
146 eina_stringshare_del(item->label);
148 evas_object_del(item->icon);
149 elm_widget_item_del(item);
153 _theme_data_get(Widget_Data *wd)
157 str = edje_object_data_get(wd->right_blank, "len_threshold");
158 if (str) wd->len_threshold = MAX(0, atoi(str));
159 else wd->len_threshold = 0;
161 if (!wd->display_item_num_by_api)
163 str = edje_object_data_get(wd->right_blank, "display_item_num");
164 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
165 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
168 str = edje_object_data_get(wd->right_blank, "min_width");
169 if (str) wd->minw = MAX(-1, atoi(str));
172 parent = elm_widget_parent_widget_get(wd->self);
173 if (!parent) wd->minw = -1;
174 else evas_object_geometry_get(parent, NULL, NULL, &wd->minw, NULL);
177 str = edje_object_data_get(wd->right_blank, "min_height");
178 if (str) wd->minh = MAX(-1, atoi(str));
183 _default_display_item_num_set(Widget_Data *wd)
186 str = edje_object_data_get(wd->right_blank, "display_item_num");
187 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
188 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
192 _del_hook(Evas_Object * obj)
194 Widget_Data *wd = elm_widget_data_get(obj);
200 _del_pre_hook(Evas_Object * obj)
202 Elm_Diskselector_Item *it;
205 Widget_Data *wd = elm_widget_data_get(obj);
209 evas_object_del(wd->left_blank);
211 evas_object_del(wd->right_blank);
214 eina_stringshare_del(wd->last->label);
215 evas_object_del(wd->last->base.view);
220 eina_stringshare_del(wd->s_last->label);
221 evas_object_del(wd->s_last->base.view);
226 eina_stringshare_del(wd->second->label);
227 evas_object_del(wd->second->base.view);
232 eina_stringshare_del(wd->first->label);
233 evas_object_del(wd->first->base.view);
237 EINA_LIST_FOREACH(wd->under_items, l, it)
241 eina_stringshare_del(it->label);
242 evas_object_del(wd->first->base.view);
247 EINA_LIST_FOREACH(wd->over_items, l, it)
251 eina_stringshare_del(it->label);
252 evas_object_del(wd->first->base.view);
257 EINA_LIST_FREE(wd->items, it) _item_del(it);
258 eina_list_free(wd->r_items);
262 _sizing_eval(Evas_Object * obj)
264 Widget_Data *wd = elm_widget_data_get(obj);
266 _diskselector_object_resize(obj, NULL, obj, NULL);
270 _theme_hook(Evas_Object * obj)
273 Elm_Diskselector_Item *it;
274 Widget_Data *wd = elm_widget_data_get(obj);
278 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
279 "base", elm_widget_style_get(obj));
282 EINA_LIST_FOREACH(wd->r_items, l, it)
284 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
285 elm_widget_style_get(obj));
286 edje_object_part_text_set(it->base.view, "elm.text", it->label);
291 EINA_LIST_FOREACH(wd->items, l, it)
293 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
294 elm_widget_style_get(obj));
295 edje_object_part_text_set(it->base.view, "elm.text", it->label);
298 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
299 elm_widget_style_get(obj));
305 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
307 Widget_Data *wd = elm_widget_data_get(obj);
308 Evas_Object *sub = event_info;
309 Elm_Diskselector_Item *it;
314 if (sub == wd->scroller)
318 EINA_LIST_FOREACH(wd->items, l, it)
331 _select_item(Elm_Diskselector_Item *it)
334 Widget_Data *wd = elm_widget_data_get(it->base.widget);
335 wd->selected_item = it;
336 _selected_item_indicate(wd->selected_item);
337 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
338 evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
342 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
344 Widget_Data *wd = elm_widget_data_get(obj);
348 if (elm_widget_focus_get(obj))
350 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
351 evas_object_focus_set(wd->self, EINA_TRUE);
355 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
356 evas_object_focus_set(wd->self, EINA_FALSE);
361 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
363 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
364 Evas_Event_Key_Down *ev = event_info;
365 Widget_Data *wd = elm_widget_data_get(obj);
366 if (!wd) return EINA_FALSE;
367 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
368 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
370 Elm_Diskselector_Item *it = NULL;
373 if (!wd->selected_item) {
374 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
378 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
379 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
381 l = wd->selected_item->node->prev;
382 if ((!l) && (wd->round))
383 l = eina_list_last(wd->items);
385 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
386 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
388 l = wd->selected_item->node->next;
389 if ((!l) && (wd->round))
392 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
394 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
395 l = eina_list_last(wd->items);
396 else return EINA_FALSE;
399 it = eina_list_data_get(l);
403 wd->selected_item = it;
405 wd->idler = ecore_idler_add(_move_scroller, obj);
408 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
413 _count_letter(const char *str)
418 for (chnum = 0; ; chnum++)
420 pos = evas_string_char_next_get(str, pos, &code);
421 if (code == 0) break;
427 _check_letter(const char *str, int length)
432 for (chnum = 0; ; chnum++)
434 if (chnum == length) break;
435 pos = evas_string_char_next_get(str, pos, &code);
436 if (code == 0) break;
442 _check_string(void *data)
444 int mid, steps, length, diff;
445 Elm_Diskselector_Item *it;
449 Widget_Data *wd = data;
451 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
461 EINA_LIST_FOREACH(list, l, it)
465 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
466 /* item not visible */
467 if ((x + w <= ox) || (x >= ox + ow))
470 len = _count_letter(it->label);
471 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
472 // len = eina_stringshare_strlen(it->label);
475 edje_object_signal_emit(it->base.view, "elm,state,left_side",
477 else if (x + w >= ox + ow - 5)
478 edje_object_signal_emit(it->base.view, "elm,state,right_side",
482 if ((wd->len_threshold) && (len > wd->len_threshold))
483 edje_object_signal_emit(it->base.view, "elm,state,center_small",
486 edje_object_signal_emit(it->base.view, "elm,state,center",
490 // if len is les that the limit len, skip anyway
491 if (len <= wd->len_side)
494 steps = len - wd->len_side + 1;
496 if (mid <= ox + ow / 2)
497 diff = (ox + ow / 2) - mid;
499 diff = mid - (ox + ow / 2);
501 length = len - (int)(diff * steps / (ow / 3));
502 length = MAX(length, wd->len_side);
503 // limit string len to "length" ut8f chars
504 length = _check_letter(it->label, length);
505 // cut it off at byte mark returned form _check_letter
506 strncpy(buf, it->label, length);
508 edje_object_part_text_set(it->base.view, "elm.text", buf);
512 ecore_idler_del(wd->check_idler);
513 wd->check_idler = NULL;
518 _selected_item_indicate(Elm_Diskselector_Item *it)
520 Elm_Diskselector_Item *item;
523 wd = elm_widget_data_get(it->base.widget);
527 EINA_LIST_FOREACH(wd->r_items, l, item)
529 if (!strcmp(item->label, it->label)) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
531 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
536 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
537 const char *emission __UNUSED__, const char *source __UNUSED__)
539 Elm_Diskselector_Item *it = data;
544 wd = elm_widget_data_get(it->base.widget);
548 if (wd->selected_item != it)
550 wd->selected_item = it;
551 _selected_item_indicate(wd->selected_item);
554 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
558 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
560 Evas_Coord x, y, w, h, bw;
561 Widget_Data *wd = data;
564 elm_smart_scroller_child_pos_get(obj, &x, &y);
565 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
568 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
569 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
570 elm_smart_scroller_child_region_show(wd->scroller,
571 x - ((w / wd->display_item_num) * wd->item_count),
574 elm_smart_scroller_child_region_show(wd->scroller,
575 x + ((w / wd->display_item_num) * wd->item_count),
581 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
583 Elm_Diskselector_Item *it;
584 Widget_Data *wd = data;
596 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
597 EINA_LIST_FOREACH(list, l, it)
599 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
600 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
611 _move_scroller(void *data)
613 Evas_Object *obj = data;
616 Elm_Diskselector_Item *dit;
620 wd = elm_widget_data_get(obj);
621 if (!wd) return EINA_FALSE;
628 EINA_LIST_FOREACH(wd->items, l, dit)
630 if (wd->selected_item == dit)
637 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
641 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
642 //move scroller in two steps for getting smooth launching effect.
644 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * (i-2), y, w, h);
645 elm_smart_scroller_region_bring_in(wd->scroller, w / wd->display_item_num * i, y, w, h);
650 ecore_idler_del(wd->idler);
653 wd->init = EINA_TRUE;
660 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
663 elm_box_unpack(wd->main_box, it->base.view);
664 wd->r_items = eina_list_remove(wd->r_items, it);
665 eina_stringshare_del(it->label);
666 evas_object_del(it->base.view);
671 _round_items_del(Widget_Data *wd)
674 Elm_Diskselector_Item * it;
676 _round_item_del(wd, wd->last);
678 _round_item_del(wd, wd->s_last);
680 _round_item_del(wd, wd->second);
682 _round_item_del(wd, wd->first);
685 EINA_LIST_FOREACH(wd->under_items, l, it)
687 _round_item_del(wd, it);
691 EINA_LIST_FOREACH(wd->over_items, l, it)
693 _round_item_del(wd, it);
699 _round_items_add(Widget_Data *wd)
701 Elm_Diskselector_Item *dit;
702 Elm_Diskselector_Item *it;
703 Elm_Diskselector_Item *temp_it;
705 dit = it = eina_list_nth(wd->items, 0);
710 wd->first = _item_new(it->base.widget, it->icon, it->label, it->func,
712 wd->first->node = it->node;
713 wd->r_items = eina_list_append(wd->r_items, wd->first);
716 it = eina_list_nth(wd->items, 1);
721 wd->second = _item_new(it->base.widget, it->icon, it->label, it->func,
723 wd->second->node = it->node;
724 wd->r_items = eina_list_append(wd->r_items, wd->second);
727 // if more than 3 itmes should be displayed
728 for (i = 2; i < CEIL(wd->display_item_num); i++)
730 it = eina_list_nth(wd->items, i);
732 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
733 wd->over_items = eina_list_append(wd->over_items, temp_it);
734 wd->r_items = eina_list_append(wd->r_items, temp_it);
737 it = eina_list_nth(wd->items, wd->item_count - 1);
742 wd->last = _item_new(it->base.widget, it->icon, it->label, it->func,
744 wd->last->node = it->node;
745 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
748 it = eina_list_nth(wd->items, wd->item_count - 2);
753 wd->s_last = _item_new(it->base.widget, it->icon, it->label, it->func,
755 wd->s_last->node = it->node;
756 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
759 // if more than 3 itmes should be displayed
760 for (i = 3; i <= CEIL(wd->display_item_num); i++)
762 it = eina_list_nth(wd->items, wd->item_count - i);
764 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
765 wd->under_items = eina_list_append(wd->under_items, temp_it);
766 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
771 elm_diskselector_add(Evas_Object *parent)
777 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
779 ELM_SET_WIDTYPE(widtype, "diskselector");
780 elm_widget_type_set(obj, "diskselector");
781 elm_widget_sub_object_add(parent, obj);
782 elm_widget_data_set(obj, wd);
783 elm_widget_del_hook_set(obj, _del_hook);
784 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
785 elm_widget_theme_hook_set(obj, _theme_hook);
786 elm_widget_can_focus_set(obj, EINA_TRUE);
787 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
788 elm_widget_event_hook_set(obj, _event_hook);
792 wd->round = EINA_FALSE;
793 wd->init = EINA_FALSE;
795 wd->display_item_num_by_api = EINA_FALSE;
797 wd->scroller = elm_smart_scroller_add(e);
798 elm_smart_scroller_widget_set(wd->scroller, obj);
800 elm_widget_resize_object_set(obj, wd->scroller);
801 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
802 ELM_SMART_SCROLLER_POLICY_OFF);
803 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
804 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
806 evas_object_smart_callback_add(wd->scroller, "animate,stop",
807 _scroller_stop_cb, wd);
808 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
810 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
811 _diskselector_object_resize, obj);
813 wd->main_box = elm_box_add(parent);
814 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
815 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
816 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
818 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
820 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
822 elm_widget_sub_object_add(obj, wd->main_box);
824 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
826 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
827 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
829 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
831 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
833 elm_box_pack_end(wd->main_box, wd->left_blank);
834 evas_object_show(wd->left_blank);
836 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
837 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
839 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
841 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
843 elm_box_pack_end(wd->main_box, wd->right_blank);
844 evas_object_show(wd->right_blank);
848 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
849 evas_object_smart_callbacks_descriptions_set(obj, _signals);
855 elm_diskselector_round_get(const Evas_Object *obj)
857 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
858 Widget_Data *wd = elm_widget_data_get(obj);
859 if (!wd) return EINA_FALSE;
864 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
867 Elm_Diskselector_Item *it;
869 ELM_CHECK_WIDTYPE(obj, widtype);
870 Widget_Data *wd = elm_widget_data_get(obj);
873 if (wd->round == round)
879 wd->r_items = eina_list_clone(wd->items);
880 elm_box_unpack(wd->main_box, wd->left_blank);
881 evas_object_hide(wd->left_blank);
882 elm_box_unpack(wd->main_box, wd->right_blank);
883 evas_object_hide(wd->right_blank);
887 _round_items_add(wd);
890 elm_box_pack_start(wd->main_box, wd->last->base.view);
892 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
894 // if more than 3 items should be displayed
895 EINA_LIST_FOREACH(wd->under_items, elist, it)
896 elm_box_pack_start(wd->main_box, it->base.view);
899 elm_box_pack_end(wd->main_box, wd->first->base.view);
901 elm_box_pack_end(wd->main_box, wd->second->base.view);
903 // if more than 3 items should be displayed
904 EINA_LIST_FOREACH(wd->over_items, elist, it)
905 elm_box_pack_end(wd->main_box, it->base.view);
909 _round_items_del(wd);
910 elm_box_pack_start(wd->main_box, wd->left_blank);
911 elm_box_pack_end(wd->main_box, wd->right_blank);
912 eina_list_free(wd->r_items);
920 elm_diskselector_side_label_length_get(const Evas_Object *obj)
922 ELM_CHECK_WIDTYPE(obj, widtype) 0;
923 Widget_Data *wd = elm_widget_data_get(obj);
929 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
931 ELM_CHECK_WIDTYPE(obj, widtype);
932 Widget_Data *wd = elm_widget_data_get(obj);
938 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
940 return elm_diskselector_side_label_length_set(obj, len);
944 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
946 return elm_diskselector_side_label_length_get(obj);
950 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
952 ELM_CHECK_WIDTYPE(obj, widtype);
953 Widget_Data *wd = elm_widget_data_get(obj);
956 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
960 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
962 ELM_CHECK_WIDTYPE(obj, widtype);
963 Widget_Data *wd = elm_widget_data_get(obj);
965 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
969 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
971 ELM_CHECK_WIDTYPE(obj, widtype);
972 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
973 Widget_Data *wd = elm_widget_data_get(obj);
974 if ((!wd) || (!wd->scroller)) return;
975 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
976 *policy_h = (Elm_Scroller_Policy) s_policy_h;
977 *policy_v = (Elm_Scroller_Policy) s_policy_v;
981 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
983 ELM_CHECK_WIDTYPE(obj, widtype);
984 Widget_Data *wd = elm_widget_data_get(obj);
986 if ((policy_h >= 3) || (policy_v >= 3)) return;
988 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
992 elm_diskselector_clear(Evas_Object *obj)
994 ELM_CHECK_WIDTYPE(obj, widtype);
995 Widget_Data *wd = elm_widget_data_get(obj);
996 Elm_Diskselector_Item *it;
999 if (!wd->items) return;
1001 wd->selected_item = NULL;
1002 EINA_LIST_FREE(wd->items, it) _item_del(it);
1003 _round_items_del(wd);
1007 EAPI const Eina_List *
1008 elm_diskselector_items_get(const Evas_Object *obj)
1010 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1011 Widget_Data *wd = elm_widget_data_get(obj);
1012 if (!wd) return NULL;
1016 EAPI Elm_Diskselector_Item *
1017 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1019 Elm_Diskselector_Item *it;
1020 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1021 Widget_Data *wd = elm_widget_data_get(obj);
1022 if (!wd) return NULL;
1024 it = _item_new(obj, icon, label, func, data);
1025 wd->items = eina_list_append(wd->items, it);
1026 it->node = eina_list_last(wd->items);
1030 _round_items_del(wd);
1031 wd->r_items = eina_list_append(wd->r_items, it);
1032 _round_items_add(wd);
1034 elm_box_pack_start(wd->main_box, wd->last->base.view);
1036 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
1037 elm_box_pack_end(wd->main_box, it->base.view);
1039 elm_box_pack_end(wd->main_box, wd->first->base.view);
1041 elm_box_pack_end(wd->main_box, wd->second->base.view);
1045 elm_box_unpack(wd->main_box, wd->right_blank);
1046 elm_box_pack_end(wd->main_box, it->base.view);
1047 elm_box_pack_end(wd->main_box, wd->right_blank);
1049 if (!wd->selected_item)
1050 wd->selected_item = it;
1052 wd->idler = ecore_idler_add(_move_scroller, obj);
1058 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1060 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1061 Elm_Diskselector_Item *dit;
1062 Elm_Diskselector_Item *item;
1065 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1068 elm_box_unpack(wd->main_box, it->base.view);
1071 wd->r_items = eina_list_remove(wd->r_items, it);
1073 wd->items = eina_list_remove(wd->items, it);
1075 if (wd->selected_item == it)
1077 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1079 wd->selected_item = dit;
1081 wd->selected_item = eina_list_nth(wd->items, 1);
1083 _selected_item_indicate(wd->selected_item);
1087 wd->item_count -= 1;
1091 if (!wd->item_count)
1093 evas_object_hide(wd->first->base.view);
1094 evas_object_hide(wd->second->base.view);
1095 evas_object_hide(wd->last->base.view);
1096 evas_object_hide(wd->s_last->base.view);
1098 EINA_LIST_FOREACH(wd->under_items, l, item)
1099 evas_object_hide(item->base.view);
1101 EINA_LIST_FOREACH(wd->over_items, l, item)
1102 evas_object_hide(item->base.view);
1106 dit = eina_list_nth(wd->items, 0);
1109 eina_stringshare_replace(&wd->first->label, dit->label);
1110 edje_object_part_text_set(wd->first->base.view, "elm.text",
1113 dit = eina_list_nth(wd->items, 1);
1116 eina_stringshare_replace(&wd->second->label, dit->label);
1117 edje_object_part_text_set(wd->second->base.view, "elm.text",
1120 // if more than 3 itmes should be displayed
1121 for (i = 2; i < CEIL(wd->display_item_num); i++)
1123 dit = eina_list_nth(wd->items, i);
1124 item = eina_list_nth(wd->over_items, i - 2);
1125 eina_stringshare_replace(&item->label, dit->label);
1126 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1129 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1132 eina_stringshare_replace(&wd->last->label, dit->label);
1133 edje_object_part_text_set(wd->last->base.view, "elm.text",
1136 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1139 eina_stringshare_replace(&wd->s_last->label, dit->label);
1140 edje_object_part_text_set(wd->s_last->base.view, "elm.text",
1143 // if more than 3 itmes should be displayed
1144 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1146 dit = eina_list_nth(wd->items, wd->item_count - i);
1147 item = eina_list_nth(wd->under_items, i - 3);
1148 eina_stringshare_replace(&item->label, dit->label);
1149 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1153 wd->check_idler = ecore_idler_add(_check_string, wd);
1154 _sizing_eval(wd->self);
1158 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1160 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1165 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1167 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1168 eina_stringshare_replace(&it->label, label);
1169 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1172 EAPI Elm_Diskselector_Item *
1173 elm_diskselector_selected_item_get(const Evas_Object *obj)
1175 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1176 Widget_Data *wd = elm_widget_data_get(obj);
1177 if (!wd) return NULL;
1178 return wd->selected_item;
1182 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1184 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1186 wd = elm_widget_data_get(it->base.widget);
1189 if ((wd->selected_item == it) && (selected))
1192 if ((wd->selected_item == it) && (!selected))
1193 wd->selected_item = eina_list_data_get(wd->items);
1196 wd->selected_item = it;
1197 _selected_item_indicate(wd->selected_item);
1201 ecore_idler_add(_move_scroller, it->base.widget);
1205 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1207 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1210 wd = elm_widget_data_get(it->base.widget);
1211 if (!wd) return EINA_FALSE;
1212 return (wd->selected_item == it);
1216 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1218 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1219 elm_widget_item_del_cb_set(it, func);
1223 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1225 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1226 return elm_widget_item_data_get(it);
1230 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1232 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1237 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1239 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1240 if (it->icon == icon) return;
1242 evas_object_del(it->icon);
1245 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
1248 EAPI Elm_Diskselector_Item *
1249 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1251 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1252 if (it->node->prev) return it->node->prev->data;
1256 EAPI Elm_Diskselector_Item *
1257 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1259 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1260 if (it->node->next) return it->node->next->data;
1264 EAPI Elm_Diskselector_Item *
1265 elm_diskselector_first_item_get(const Evas_Object *obj)
1267 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1270 wd = elm_widget_data_get(obj);
1271 if (!wd || !wd->items)
1274 return eina_list_data_get(wd->items);
1277 EAPI Elm_Diskselector_Item *
1278 elm_diskselector_last_item_get(const Evas_Object *obj)
1280 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1283 wd = elm_widget_data_get(obj);
1284 if (!wd || !wd->items)
1287 return eina_list_data_get(eina_list_last(wd->items));
1291 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1293 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1294 elm_widget_item_tooltip_text_set(item, text);
1298 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)
1300 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1301 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1305 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1307 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1308 elm_widget_item_tooltip_unset(item);
1312 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1314 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1315 elm_widget_item_tooltip_style_set(item, style);
1319 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1321 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1322 return elm_widget_item_tooltip_style_get(item);
1326 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1328 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1329 elm_widget_item_cursor_set(item, cursor);
1333 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1335 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1336 return elm_widget_item_cursor_get(item);
1340 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1342 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1343 elm_widget_item_cursor_unset(item);
1347 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1349 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1350 elm_widget_item_cursor_style_set(item, style);
1354 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1356 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1357 return elm_widget_item_cursor_style_get(item);
1361 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1363 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1364 elm_widget_item_cursor_engine_only_set(item, engine_only);
1368 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1370 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1371 return elm_widget_item_cursor_engine_only_get(item);
1375 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1377 ELM_CHECK_WIDTYPE(obj, widtype);
1378 Widget_Data *wd = elm_widget_data_get(obj);
1380 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1381 wd->display_item_num = num;
1382 wd->display_item_num_by_api = EINA_TRUE;