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;
16 typedef struct _Elm_Diskselector_Item Elm_Diskselector_Item;
21 Evas_Object *scroller;
22 Evas_Object *main_box;
23 Evas_Object *left_blank;
24 Evas_Object *right_blank;
25 Elm_Diskselector_Item *selected_item;
26 Elm_Diskselector_Item *first;
27 Elm_Diskselector_Item *second;
28 Elm_Diskselector_Item *s_last;
29 Elm_Diskselector_Item *last;
32 Eina_List *over_items;
33 Eina_List *under_items;
34 int item_count, len_threshold, len_side, display_item_num;
35 Ecore_Idle_Enterer *idler;
36 Ecore_Idle_Enterer *check_idler;
37 Evas_Coord minw, minh;
40 Eina_Bool display_item_num_by_api:1;
43 struct _Elm_Diskselector_Item
52 static const char *widtype = NULL;
54 static Eina_Bool _move_scroller(void *data);
55 static void _del_hook(Evas_Object * obj);
56 static void _del_pre_hook(Evas_Object * obj);
57 static void _sizing_eval(Evas_Object * obj);
58 static void _theme_hook(Evas_Object * obj);
59 static void _on_focus_hook(void *data, Evas_Object *obj);
60 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
61 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
62 static void _round_items_del(Widget_Data *wd);
63 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
64 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
65 const char *emission __UNUSED__,
66 const char *source __UNUSED__);
67 static void _selected_item_indicate(Elm_Diskselector_Item *it);
69 static const char SIG_SELECTED[] = "selected";
70 static const Evas_Smart_Cb_Description _signals[] = {
76 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
81 wd = elm_widget_data_get(data);
84 if ((wd->minw == -1) && (wd->minh == -1))
85 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
86 edje_object_size_min_restricted_calc
87 (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_idle_enterer_before_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 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
119 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
120 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
122 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
124 evas_object_show(VIEW(it));
128 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
129 edje_object_signal_callback_add(VIEW(it), "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(VIEW(it), "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)
156 str = edje_object_data_get(wd->right_blank, "len_threshold");
157 if (str) wd->len_threshold = MAX(0, atoi(str));
158 else wd->len_threshold = 0;
160 if (!wd->display_item_num_by_api)
162 str = edje_object_data_get(wd->right_blank, "display_item_num");
163 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
164 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
167 str = edje_object_data_get(wd->right_blank, "min_width");
168 if (str) wd->minw = MAX(-1, atoi(str));
171 str = edje_object_data_get(wd->right_blank, "min_height");
172 if (str) wd->minh = MAX(-1, atoi(str));
177 _del_hook(Evas_Object * obj)
179 Widget_Data *wd = elm_widget_data_get(obj);
185 _del_pre_hook(Evas_Object * obj)
187 Elm_Diskselector_Item *it;
190 Widget_Data *wd = elm_widget_data_get(obj);
194 evas_object_del(wd->left_blank);
196 evas_object_del(wd->right_blank);
199 eina_stringshare_del(wd->last->label);
200 evas_object_del(wd->VIEW(last));
205 eina_stringshare_del(wd->s_last->label);
206 evas_object_del(wd->VIEW(s_last));
211 eina_stringshare_del(wd->second->label);
212 evas_object_del(wd->VIEW(second));
217 eina_stringshare_del(wd->first->label);
218 evas_object_del(wd->VIEW(first));
222 EINA_LIST_FOREACH(wd->under_items, l, it)
226 eina_stringshare_del(it->label);
227 evas_object_del(VIEW(it));
232 EINA_LIST_FOREACH(wd->over_items, l, it)
236 eina_stringshare_del(it->label);
237 evas_object_del(VIEW(it));
242 EINA_LIST_FREE(wd->items, it) _item_del(it);
243 eina_list_free(wd->r_items);
247 _sizing_eval(Evas_Object * obj)
249 Widget_Data *wd = elm_widget_data_get(obj);
251 _diskselector_object_resize(obj, NULL, obj, NULL);
255 _theme_hook(Evas_Object * obj)
258 Elm_Diskselector_Item *it;
259 Widget_Data *wd = elm_widget_data_get(obj);
263 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
264 "base", elm_widget_style_get(obj));
267 EINA_LIST_FOREACH(wd->r_items, l, it)
269 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
270 elm_widget_style_get(obj));
271 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
276 EINA_LIST_FOREACH(wd->items, l, it)
278 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
279 elm_widget_style_get(obj));
280 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
283 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
284 elm_widget_style_get(obj));
290 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
292 Widget_Data *wd = elm_widget_data_get(obj);
293 Evas_Object *sub = event_info;
294 Elm_Diskselector_Item *it;
299 if (sub == wd->scroller)
303 EINA_LIST_FOREACH(wd->items, l, it)
316 _select_item(Elm_Diskselector_Item *it)
319 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
320 wd->selected_item = it;
321 _selected_item_indicate(wd->selected_item);
322 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
323 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
327 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
329 Widget_Data *wd = elm_widget_data_get(obj);
333 if (elm_widget_focus_get(obj))
335 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
336 evas_object_focus_set(wd->self, EINA_TRUE);
340 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
341 evas_object_focus_set(wd->self, EINA_FALSE);
346 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
348 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
349 Evas_Event_Key_Down *ev = event_info;
350 Widget_Data *wd = elm_widget_data_get(obj);
351 if (!wd) return EINA_FALSE;
352 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
353 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
355 Elm_Diskselector_Item *it = NULL;
358 if (!wd->selected_item) {
359 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
363 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
364 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
366 l = wd->selected_item->node->prev;
367 if ((!l) && (wd->round))
368 l = eina_list_last(wd->items);
370 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
371 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
373 l = wd->selected_item->node->next;
374 if ((!l) && (wd->round))
377 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
379 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
380 l = eina_list_last(wd->items);
381 else return EINA_FALSE;
384 it = eina_list_data_get(l);
388 wd->selected_item = it;
390 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
393 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
398 _count_letter(const char *str)
403 for (chnum = 0; ; chnum++)
405 pos = evas_string_char_next_get(str, pos, &code);
406 if (code == 0) break;
412 _check_letter(const char *str, int length)
417 for (chnum = 0; ; chnum++)
419 if (chnum == length) break;
420 pos = evas_string_char_next_get(str, pos, &code);
421 if (code == 0) break;
427 _check_string(void *data)
429 int mid, steps, length, diff;
430 Elm_Diskselector_Item *it;
434 Widget_Data *wd = data;
436 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
446 EINA_LIST_FOREACH(list, l, it)
450 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
451 /* item not visible */
452 if ((x + w <= ox) || (x >= ox + ow))
455 len = _count_letter(it->label);
456 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
457 // len = eina_stringshare_strlen(it->label);
460 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
462 else if (x + w >= ox + ow - 5)
463 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
467 if ((wd->len_threshold) && (len > wd->len_threshold))
468 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
471 edje_object_signal_emit(VIEW(it), "elm,state,center",
475 // if len is les that the limit len, skip anyway
476 if (len <= wd->len_side)
479 steps = len - wd->len_side + 1;
481 if (mid <= ox + ow / 2)
482 diff = (ox + ow / 2) - mid;
484 diff = mid - (ox + ow / 2);
486 length = len - (int)(diff * steps / (ow / 3));
487 length = MAX(length, wd->len_side);
488 // limit string len to "length" ut8f chars
489 length = _check_letter(it->label, length);
490 // cut it off at byte mark returned form _check_letter
491 strncpy(buf, it->label, length);
493 edje_object_part_text_set(VIEW(it), "elm.text", buf);
497 ecore_idle_enterer_del(wd->check_idler);
498 wd->check_idler = NULL;
503 _selected_item_indicate(Elm_Diskselector_Item *it)
505 Elm_Diskselector_Item *item;
508 wd = elm_widget_data_get(WIDGET(it));
512 EINA_LIST_FOREACH(wd->r_items, l, item)
514 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
516 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
521 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
522 const char *emission __UNUSED__, const char *source __UNUSED__)
524 Elm_Diskselector_Item *it = data;
529 wd = elm_widget_data_get(WIDGET(it));
533 if (wd->selected_item != it)
535 wd->selected_item = it;
536 _selected_item_indicate(wd->selected_item);
539 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
543 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
545 Evas_Coord x, y, w, h, bw;
546 Widget_Data *wd = data;
549 elm_smart_scroller_child_pos_get(obj, &x, &y);
550 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
553 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
554 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
555 elm_smart_scroller_child_region_show(wd->scroller,
556 x - ((w / wd->display_item_num) * wd->item_count),
559 elm_smart_scroller_child_region_show(wd->scroller,
560 x + ((w / wd->display_item_num) * wd->item_count),
566 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
568 Elm_Diskselector_Item *it;
569 Widget_Data *wd = data;
581 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
582 EINA_LIST_FOREACH(list, l, it)
584 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
585 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
596 _move_scroller(void *data)
598 Evas_Object *obj = data;
601 Elm_Diskselector_Item *dit;
605 wd = elm_widget_data_get(obj);
606 if (!wd) return EINA_FALSE;
619 EINA_LIST_FOREACH(list, l, dit)
621 if (wd->selected_item == dit)
626 if (wd->round) i -= CEIL(wd->display_item_num);
631 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
635 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
636 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
640 ecore_idle_enterer_del(wd->idler);
643 wd->init = EINA_TRUE;
650 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
653 elm_box_unpack(wd->main_box, VIEW(it));
654 wd->r_items = eina_list_remove(wd->r_items, it);
655 eina_stringshare_del(it->label);
656 evas_object_del(VIEW(it));
661 _round_items_del(Widget_Data *wd)
664 Elm_Diskselector_Item * it;
666 _round_item_del(wd, wd->last);
668 _round_item_del(wd, wd->s_last);
670 _round_item_del(wd, wd->second);
672 _round_item_del(wd, wd->first);
675 EINA_LIST_FOREACH(wd->under_items, l, it)
677 _round_item_del(wd, it);
679 wd->under_items = eina_list_free(wd->under_items);
681 EINA_LIST_FOREACH(wd->over_items, l, it)
683 _round_item_del(wd, it);
685 wd->over_items = eina_list_free(wd->over_items);
689 _round_items_add(Widget_Data *wd)
691 Elm_Diskselector_Item *dit;
692 Elm_Diskselector_Item *it;
693 Elm_Diskselector_Item *temp_it;
695 dit = it = eina_list_nth(wd->items, 0);
700 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
702 wd->first->node = it->node;
703 wd->r_items = eina_list_append(wd->r_items, wd->first);
706 it = eina_list_nth(wd->items, 1);
711 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
713 wd->second->node = it->node;
714 wd->r_items = eina_list_append(wd->r_items, wd->second);
717 // if more than 3 itmes should be displayed
718 for (i = 2; i < CEIL(wd->display_item_num); i++)
720 it = eina_list_nth(wd->items, i);
722 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
723 wd->over_items = eina_list_append(wd->over_items, temp_it);
724 wd->r_items = eina_list_append(wd->r_items, temp_it);
727 it = eina_list_nth(wd->items, wd->item_count - 1);
732 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
734 wd->last->node = it->node;
735 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
738 it = eina_list_nth(wd->items, wd->item_count - 2);
743 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
745 wd->s_last->node = it->node;
746 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
749 // if more than 3 itmes should be displayed
750 for (i = 3; i <= CEIL(wd->display_item_num); i++)
752 it = eina_list_nth(wd->items, wd->item_count - i);
754 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
755 wd->under_items = eina_list_append(wd->under_items, temp_it);
756 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
761 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
763 if (it->icon == icon) return;
765 evas_object_del(it->icon);
769 evas_object_size_hint_min_set(it->icon, 24, 24);
770 evas_object_size_hint_max_set(it->icon, 40, 40);
771 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
772 evas_object_show(it->icon);
773 elm_widget_sub_object_add(WIDGET(it), it->icon);
778 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
781 Elm_Diskselector_Item *dit;
787 wd = elm_widget_data_get(WIDGET(it));
792 // Get index from indentical item from round items
793 EINA_LIST_FOREACH(wd->r_items, l, dit)
795 if (it == dit) break;
800 ic = eina_list_count(wd->r_items);
801 if (idx >= ic) return;
804 // Number of added items: CEIL(wd->display_item_num)
805 ac = CEIL(wd->display_item_num);
807 if (((idx >= 0) && (idx < ac)) ||
808 ((idx >= ac) && (idx < (2 * ac))))
810 // Selected item: under, low region
811 dit = eina_list_nth(wd->r_items,
812 idx + ic - (2 * ac));
814 else if (((idx >= (ic - ac)) && (idx < ic)) ||
815 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
817 // Selected item: over, high region
818 dit = eina_list_nth(wd->r_items,
819 idx - ic + (2 * ac));
822 if(dit) _item_icon_set(dit, icon);
823 _sizing_eval(wd->self);
828 elm_diskselector_add(Evas_Object *parent)
834 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
836 ELM_SET_WIDTYPE(widtype, "diskselector");
837 elm_widget_type_set(obj, "diskselector");
838 elm_widget_sub_object_add(parent, obj);
839 elm_widget_data_set(obj, wd);
840 elm_widget_del_hook_set(obj, _del_hook);
841 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
842 elm_widget_theme_hook_set(obj, _theme_hook);
843 elm_widget_can_focus_set(obj, EINA_TRUE);
844 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
845 elm_widget_event_hook_set(obj, _event_hook);
849 wd->round = EINA_FALSE;
850 wd->init = EINA_FALSE;
852 wd->display_item_num_by_api = EINA_FALSE;
854 wd->scroller = elm_smart_scroller_add(e);
855 elm_smart_scroller_widget_set(wd->scroller, obj);
857 elm_widget_resize_object_set(obj, wd->scroller);
858 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
859 ELM_SMART_SCROLLER_POLICY_OFF);
860 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
861 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
863 evas_object_smart_callback_add(wd->scroller, "animate,stop",
864 _scroller_stop_cb, wd);
865 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
867 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
868 _diskselector_object_resize, obj);
870 wd->main_box = elm_box_add(parent);
871 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
872 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
873 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
875 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
877 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
879 elm_widget_sub_object_add(obj, wd->main_box);
881 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
883 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
884 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
886 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
888 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
890 elm_box_pack_end(wd->main_box, wd->left_blank);
891 evas_object_show(wd->left_blank);
893 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
894 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
896 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
898 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
900 elm_box_pack_end(wd->main_box, wd->right_blank);
901 evas_object_show(wd->right_blank);
905 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
906 evas_object_smart_callbacks_descriptions_set(obj, _signals);
912 elm_diskselector_round_get(const Evas_Object *obj)
914 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
915 Widget_Data *wd = elm_widget_data_get(obj);
916 if (!wd) return EINA_FALSE;
921 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
924 Elm_Diskselector_Item *it;
926 ELM_CHECK_WIDTYPE(obj, widtype);
927 Widget_Data *wd = elm_widget_data_get(obj);
930 if (wd->round == round)
936 wd->r_items = eina_list_clone(wd->items);
937 elm_box_unpack(wd->main_box, wd->left_blank);
938 evas_object_hide(wd->left_blank);
939 elm_box_unpack(wd->main_box, wd->right_blank);
940 evas_object_hide(wd->right_blank);
944 _round_items_add(wd);
947 elm_box_pack_start(wd->main_box, wd->VIEW(last));
949 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
951 // if more than 3 items should be displayed
952 EINA_LIST_FOREACH(wd->under_items, elist, it)
953 elm_box_pack_start(wd->main_box, VIEW(it));
956 elm_box_pack_end(wd->main_box, wd->VIEW(first));
958 elm_box_pack_end(wd->main_box, wd->VIEW(second));
960 // if more than 3 items should be displayed
961 EINA_LIST_FOREACH(wd->over_items, elist, it)
962 elm_box_pack_end(wd->main_box, VIEW(it));
966 _round_items_del(wd);
967 elm_box_pack_start(wd->main_box, wd->left_blank);
968 elm_box_pack_end(wd->main_box, wd->right_blank);
969 eina_list_free(wd->r_items);
973 _selected_item_indicate(wd->selected_item);
978 elm_diskselector_side_label_length_get(const Evas_Object *obj)
980 ELM_CHECK_WIDTYPE(obj, widtype) 0;
981 Widget_Data *wd = elm_widget_data_get(obj);
987 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
989 ELM_CHECK_WIDTYPE(obj, widtype);
990 Widget_Data *wd = elm_widget_data_get(obj);
996 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
998 return elm_diskselector_side_label_length_set(obj, len);
1002 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1004 return elm_diskselector_side_label_length_get(obj);
1008 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1010 ELM_CHECK_WIDTYPE(obj, widtype);
1011 Widget_Data *wd = elm_widget_data_get(obj);
1014 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1018 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1020 ELM_CHECK_WIDTYPE(obj, widtype);
1021 Widget_Data *wd = elm_widget_data_get(obj);
1023 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1027 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1029 ELM_CHECK_WIDTYPE(obj, widtype);
1030 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1031 Widget_Data *wd = elm_widget_data_get(obj);
1032 if ((!wd) || (!wd->scroller)) return;
1033 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1034 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1035 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1039 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1041 ELM_CHECK_WIDTYPE(obj, widtype);
1042 Widget_Data *wd = elm_widget_data_get(obj);
1043 if ((!wd) || (!wd->scroller)) return;
1044 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1045 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1047 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1051 elm_diskselector_clear(Evas_Object *obj)
1053 ELM_CHECK_WIDTYPE(obj, widtype);
1054 Widget_Data *wd = elm_widget_data_get(obj);
1055 Elm_Diskselector_Item *it;
1058 if (!wd->items) return;
1060 wd->selected_item = NULL;
1061 EINA_LIST_FREE(wd->items, it) _item_del(it);
1062 _round_items_del(wd);
1066 EAPI const Eina_List *
1067 elm_diskselector_items_get(const Evas_Object *obj)
1069 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1070 Widget_Data *wd = elm_widget_data_get(obj);
1071 if (!wd) return NULL;
1075 EAPI Elm_Object_Item *
1076 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1078 Elm_Diskselector_Item *it;
1079 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1080 Widget_Data *wd = elm_widget_data_get(obj);
1081 if (!wd) return NULL;
1083 it = _item_new(obj, icon, label, func, data);
1084 wd->items = eina_list_append(wd->items, it);
1085 it->node = eina_list_last(wd->items);
1089 _round_items_del(wd);
1090 wd->r_items = eina_list_append(wd->r_items, it);
1091 _round_items_add(wd);
1093 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1095 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1096 elm_box_pack_end(wd->main_box, VIEW(it));
1098 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1100 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1104 elm_box_unpack(wd->main_box, wd->right_blank);
1105 elm_box_pack_end(wd->main_box, VIEW(it));
1106 elm_box_pack_end(wd->main_box, wd->right_blank);
1108 if (!wd->selected_item)
1109 wd->selected_item = it;
1111 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1113 return (Elm_Object_Item *) it;
1117 elm_diskselector_item_del(Elm_Object_Item * it)
1119 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1120 Elm_Diskselector_Item *item, *item2, *dit;
1124 item = (Elm_Diskselector_Item *) it;
1125 wd = elm_widget_data_get(WIDGET(item));
1128 elm_box_unpack(wd->main_box, VIEW(item));
1131 wd->r_items = eina_list_remove(wd->r_items, item);
1133 wd->items = eina_list_remove(wd->items, item);
1135 if (wd->selected_item == item)
1137 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1139 wd->selected_item = dit;
1141 wd->selected_item = eina_list_nth(wd->items, 1);
1143 _selected_item_indicate(wd->selected_item);
1147 wd->item_count -= 1;
1151 if (!wd->item_count)
1153 evas_object_hide(wd->VIEW(first));
1154 evas_object_hide(wd->VIEW(second));
1155 evas_object_hide(wd->VIEW(last));
1156 evas_object_hide(wd->VIEW(s_last));
1158 EINA_LIST_FOREACH(wd->under_items, l, item2)
1159 evas_object_hide(VIEW(item2));
1161 EINA_LIST_FOREACH(wd->over_items, l, item2)
1162 evas_object_hide(VIEW(item2));
1166 dit = eina_list_nth(wd->items, 0);
1169 eina_stringshare_replace(&wd->first->label, dit->label);
1170 edje_object_part_text_set(wd->VIEW(first), "elm.text",
1173 dit = eina_list_nth(wd->items, 1);
1176 eina_stringshare_replace(&wd->second->label, dit->label);
1177 edje_object_part_text_set(wd->VIEW(second), "elm.text",
1180 // if more than 3 itmes should be displayed
1181 for (i = 2; i < CEIL(wd->display_item_num); i++)
1183 dit = eina_list_nth(wd->items, i);
1184 item2 = eina_list_nth(wd->over_items, i - 2);
1185 eina_stringshare_replace(&item2->label, dit->label);
1186 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
1189 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1192 eina_stringshare_replace(&wd->last->label, dit->label);
1193 edje_object_part_text_set(wd->VIEW(last), "elm.text",
1196 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1199 eina_stringshare_replace(&wd->s_last->label, dit->label);
1200 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
1203 // if more than 3 itmes should be displayed
1204 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1206 dit = eina_list_nth(wd->items, wd->item_count - i);
1207 item2 = eina_list_nth(wd->under_items, i - 3);
1208 eina_stringshare_replace(&item2->label, dit->label);
1209 edje_object_part_text_set(VIEW(item2), "elm.text",
1214 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
1215 _sizing_eval(wd->self);
1219 elm_diskselector_item_label_get(const Elm_Object_Item * it)
1221 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1222 return ((Elm_Diskselector_Item *) it)->label;
1226 elm_diskselector_item_label_set(Elm_Object_Item * it, const char *label)
1228 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1229 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1230 eina_stringshare_replace(&item->label, label);
1231 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1234 EAPI Elm_Object_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 (Elm_Object_Item *) wd->selected_item;
1244 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1246 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1248 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1249 wd = elm_widget_data_get(WIDGET(item));
1252 if ((wd->selected_item == item) && (selected))
1255 if ((wd->selected_item == item) && (!selected))
1256 wd->selected_item = eina_list_data_get(wd->items);
1259 wd->selected_item = item;
1260 _selected_item_indicate(wd->selected_item);
1264 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1268 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1270 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1271 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1272 if (!wd) return EINA_FALSE;
1273 return (wd->selected_item == ((Elm_Diskselector_Item *) it));
1277 elm_diskselector_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1279 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1280 elm_widget_item_del_cb_set(it, func);
1284 elm_diskselector_item_data_get(const Elm_Object_Item *it)
1286 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1287 return elm_widget_item_data_get(it);
1291 elm_diskselector_item_icon_get(const Elm_Object_Item *it)
1293 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1294 return ((Elm_Diskselector_Item *) it)->icon;
1298 elm_diskselector_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1300 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1301 _item_icon_set((Elm_Diskselector_Item *) it, icon);
1302 _check_identical_item((Elm_Diskselector_Item *) it, icon);
1305 EAPI Elm_Object_Item *
1306 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1308 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1309 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1310 if (item->node->prev) return item->node->prev->data;
1314 EAPI Elm_Object_Item *
1315 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1317 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1318 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1319 if (item->node->next) return item->node->next->data;
1323 EAPI Elm_Object_Item *
1324 elm_diskselector_first_item_get(const Evas_Object *obj)
1326 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1327 Widget_Data *wd = elm_widget_data_get(obj);
1328 if (!wd || !wd->items) return NULL;
1329 return eina_list_data_get(wd->items);
1332 EAPI Elm_Object_Item *
1333 elm_diskselector_last_item_get(const Evas_Object *obj)
1335 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1336 Widget_Data *wd = elm_widget_data_get(obj);
1337 if (!wd || !wd->items) return NULL;
1338 return eina_list_data_get(eina_list_last(wd->items));
1342 elm_diskselector_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1344 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1345 elm_widget_item_tooltip_text_set(it, text);
1349 elm_diskselector_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1351 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1352 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1356 elm_diskselector_item_tooltip_unset(Elm_Object_Item *it)
1358 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1359 elm_widget_item_tooltip_unset(it);
1363 elm_diskselector_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1365 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1366 elm_widget_item_tooltip_style_set(it, style);
1370 elm_diskselector_item_tooltip_style_get(const Elm_Object_Item *it)
1372 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1373 return elm_widget_item_tooltip_style_get(it);
1377 elm_diskselector_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1379 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1380 elm_widget_item_cursor_set(it, cursor);
1384 elm_diskselector_item_cursor_get(const Elm_Object_Item *it)
1386 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1387 return elm_widget_item_cursor_get(it);
1391 elm_diskselector_item_cursor_unset(Elm_Object_Item *it)
1393 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1394 elm_widget_item_cursor_unset(it);
1398 elm_diskselector_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1400 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1401 elm_widget_item_cursor_style_set(it, style);
1405 elm_diskselector_item_cursor_style_get(const Elm_Object_Item *it)
1407 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1408 return elm_widget_item_cursor_style_get(it);
1412 elm_diskselector_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1414 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1415 elm_widget_item_cursor_engine_only_set(it, engine_only);
1419 elm_diskselector_item_cursor_engine_only_get(const Elm_Object_Item *it)
1421 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1422 return elm_widget_item_cursor_engine_only_get(it);
1426 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1428 ELM_CHECK_WIDTYPE(obj, widtype);
1429 Widget_Data *wd = elm_widget_data_get(obj);
1431 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1432 wd->display_item_num = num;
1433 wd->display_item_num_by_api = EINA_TRUE;
1437 elm_diskselector_display_item_num_get(const Evas_Object *item)
1439 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1440 Widget_Data *wd = elm_widget_data_get(item);
1442 return wd->display_item_num;