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;
33 Ecore_Idle_Enterer *idler;
34 Ecore_Idle_Enterer *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))
87 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
88 edje_object_size_min_restricted_calc
89 (elm_smart_scroller_edje_object_get
90 (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
91 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
92 evas_object_size_hint_max_set(obj, -1, -1);
94 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
96 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
98 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
100 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
101 (int)(w / wd->display_item_num), 0);
104 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
107 static Elm_Diskselector_Item *
108 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
110 Elm_Diskselector_Item *it;
111 const char *style = elm_widget_style_get(obj);
113 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
114 if (!it) return NULL;
116 it->label = eina_stringshare_add(label);
119 it->base.data = data;
120 it->base.view = edje_object_add(evas_object_evas_get(obj));
121 _elm_theme_object_set(obj, it->base.view, "diskselector", "item", style);
122 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND,
124 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL,
126 evas_object_show(it->base.view);
130 edje_object_part_text_set(it->base.view, "elm.text", it->label);
131 edje_object_signal_callback_add(it->base.view, "elm,action,click", "", _item_click_cb, it);
135 evas_object_size_hint_min_set(it->icon, 24, 24);
136 evas_object_size_hint_max_set(it->icon, 40, 40);
137 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
138 evas_object_show(it->icon);
139 elm_widget_sub_object_add(obj, it->icon);
145 _item_del(Elm_Diskselector_Item *item)
148 eina_stringshare_del(item->label);
150 evas_object_del(item->icon);
151 elm_widget_item_del(item);
155 _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 str = edje_object_data_get(wd->right_blank, "min_height");
174 if (str) wd->minh = MAX(-1, atoi(str));
179 _del_hook(Evas_Object * obj)
181 Widget_Data *wd = elm_widget_data_get(obj);
187 _del_pre_hook(Evas_Object * obj)
189 Elm_Diskselector_Item *it;
192 Widget_Data *wd = elm_widget_data_get(obj);
196 evas_object_del(wd->left_blank);
198 evas_object_del(wd->right_blank);
201 eina_stringshare_del(wd->last->label);
202 evas_object_del(wd->last->base.view);
207 eina_stringshare_del(wd->s_last->label);
208 evas_object_del(wd->s_last->base.view);
213 eina_stringshare_del(wd->second->label);
214 evas_object_del(wd->second->base.view);
219 eina_stringshare_del(wd->first->label);
220 evas_object_del(wd->first->base.view);
224 EINA_LIST_FOREACH(wd->under_items, l, it)
228 eina_stringshare_del(it->label);
229 evas_object_del(it->base.view);
234 EINA_LIST_FOREACH(wd->over_items, l, it)
238 eina_stringshare_del(it->label);
239 evas_object_del(it->base.view);
244 EINA_LIST_FREE(wd->items, it) _item_del(it);
245 eina_list_free(wd->r_items);
249 _sizing_eval(Evas_Object * obj)
251 Widget_Data *wd = elm_widget_data_get(obj);
253 _diskselector_object_resize(obj, NULL, obj, NULL);
257 _theme_hook(Evas_Object * obj)
260 Elm_Diskselector_Item *it;
261 Widget_Data *wd = elm_widget_data_get(obj);
265 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
266 "base", elm_widget_style_get(obj));
269 EINA_LIST_FOREACH(wd->r_items, l, it)
271 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
272 elm_widget_style_get(obj));
273 edje_object_part_text_set(it->base.view, "elm.text", it->label);
278 EINA_LIST_FOREACH(wd->items, l, it)
280 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
281 elm_widget_style_get(obj));
282 edje_object_part_text_set(it->base.view, "elm.text", it->label);
285 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
286 elm_widget_style_get(obj));
292 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
294 Widget_Data *wd = elm_widget_data_get(obj);
295 Evas_Object *sub = event_info;
296 Elm_Diskselector_Item *it;
301 if (sub == wd->scroller)
305 EINA_LIST_FOREACH(wd->items, l, it)
318 _select_item(Elm_Diskselector_Item *it)
321 Widget_Data *wd = elm_widget_data_get(it->base.widget);
322 wd->selected_item = it;
323 _selected_item_indicate(wd->selected_item);
324 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
325 evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
329 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
331 Widget_Data *wd = elm_widget_data_get(obj);
335 if (elm_widget_focus_get(obj))
337 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
338 evas_object_focus_set(wd->self, EINA_TRUE);
342 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
343 evas_object_focus_set(wd->self, EINA_FALSE);
348 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
350 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
351 Evas_Event_Key_Down *ev = event_info;
352 Widget_Data *wd = elm_widget_data_get(obj);
353 if (!wd) return EINA_FALSE;
354 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
355 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
357 Elm_Diskselector_Item *it = NULL;
360 if (!wd->selected_item) {
361 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
365 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
366 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
368 l = wd->selected_item->node->prev;
369 if ((!l) && (wd->round))
370 l = eina_list_last(wd->items);
372 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
373 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
375 l = wd->selected_item->node->next;
376 if ((!l) && (wd->round))
379 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
381 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
382 l = eina_list_last(wd->items);
383 else return EINA_FALSE;
386 it = eina_list_data_get(l);
390 wd->selected_item = it;
392 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
395 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
400 _count_letter(const char *str)
405 for (chnum = 0; ; chnum++)
407 pos = evas_string_char_next_get(str, pos, &code);
408 if (code == 0) break;
414 _check_letter(const char *str, int length)
419 for (chnum = 0; ; chnum++)
421 if (chnum == length) break;
422 pos = evas_string_char_next_get(str, pos, &code);
423 if (code == 0) break;
429 _check_string(void *data)
431 int mid, steps, length, diff;
432 Elm_Diskselector_Item *it;
436 Widget_Data *wd = data;
438 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
448 EINA_LIST_FOREACH(list, l, it)
452 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
453 /* item not visible */
454 if ((x + w <= ox) || (x >= ox + ow))
457 len = _count_letter(it->label);
458 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
459 // len = eina_stringshare_strlen(it->label);
462 edje_object_signal_emit(it->base.view, "elm,state,left_side",
464 else if (x + w >= ox + ow - 5)
465 edje_object_signal_emit(it->base.view, "elm,state,right_side",
469 if ((wd->len_threshold) && (len > wd->len_threshold))
470 edje_object_signal_emit(it->base.view, "elm,state,center_small",
473 edje_object_signal_emit(it->base.view, "elm,state,center",
477 // if len is les that the limit len, skip anyway
478 if (len <= wd->len_side)
481 steps = len - wd->len_side + 1;
483 if (mid <= ox + ow / 2)
484 diff = (ox + ow / 2) - mid;
486 diff = mid - (ox + ow / 2);
488 length = len - (int)(diff * steps / (ow / 3));
489 length = MAX(length, wd->len_side);
490 // limit string len to "length" ut8f chars
491 length = _check_letter(it->label, length);
492 // cut it off at byte mark returned form _check_letter
493 strncpy(buf, it->label, length);
495 edje_object_part_text_set(it->base.view, "elm.text", buf);
499 ecore_idle_enterer_del(wd->check_idler);
500 wd->check_idler = NULL;
505 _selected_item_indicate(Elm_Diskselector_Item *it)
507 Elm_Diskselector_Item *item;
510 wd = elm_widget_data_get(it->base.widget);
514 EINA_LIST_FOREACH(wd->r_items, l, item)
516 if (!strcmp(item->label, it->label)) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
518 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
523 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
524 const char *emission __UNUSED__, const char *source __UNUSED__)
526 Elm_Diskselector_Item *it = data;
531 wd = elm_widget_data_get(it->base.widget);
535 if (wd->selected_item != it)
537 wd->selected_item = it;
538 _selected_item_indicate(wd->selected_item);
541 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
545 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
547 Evas_Coord x, y, w, h, bw;
548 Widget_Data *wd = data;
551 elm_smart_scroller_child_pos_get(obj, &x, &y);
552 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
555 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
556 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
557 elm_smart_scroller_child_region_show(wd->scroller,
558 x - ((w / wd->display_item_num) * wd->item_count),
561 elm_smart_scroller_child_region_show(wd->scroller,
562 x + ((w / wd->display_item_num) * wd->item_count),
568 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
570 Elm_Diskselector_Item *it;
571 Widget_Data *wd = data;
583 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
584 EINA_LIST_FOREACH(list, l, it)
586 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
587 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
598 _move_scroller(void *data)
600 Evas_Object *obj = data;
603 Elm_Diskselector_Item *dit;
607 wd = elm_widget_data_get(obj);
608 if (!wd) return EINA_FALSE;
615 EINA_LIST_FOREACH(wd->items, l, dit)
617 if (wd->selected_item == dit)
624 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
628 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
629 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
633 ecore_idle_enterer_del(wd->idler);
636 wd->init = EINA_TRUE;
643 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
646 elm_box_unpack(wd->main_box, it->base.view);
647 wd->r_items = eina_list_remove(wd->r_items, it);
648 eina_stringshare_del(it->label);
649 evas_object_del(it->base.view);
654 _round_items_del(Widget_Data *wd)
657 Elm_Diskselector_Item * it;
659 _round_item_del(wd, wd->last);
661 _round_item_del(wd, wd->s_last);
663 _round_item_del(wd, wd->second);
665 _round_item_del(wd, wd->first);
668 EINA_LIST_FOREACH(wd->under_items, l, it)
670 _round_item_del(wd, it);
674 EINA_LIST_FOREACH(wd->over_items, l, it)
676 _round_item_del(wd, it);
682 _round_items_add(Widget_Data *wd)
684 Elm_Diskselector_Item *dit;
685 Elm_Diskselector_Item *it;
686 Elm_Diskselector_Item *temp_it;
688 dit = it = eina_list_nth(wd->items, 0);
693 wd->first = _item_new(it->base.widget, it->icon, it->label, it->func,
695 wd->first->node = it->node;
696 wd->r_items = eina_list_append(wd->r_items, wd->first);
699 it = eina_list_nth(wd->items, 1);
704 wd->second = _item_new(it->base.widget, it->icon, it->label, it->func,
706 wd->second->node = it->node;
707 wd->r_items = eina_list_append(wd->r_items, wd->second);
710 // if more than 3 itmes should be displayed
711 for (i = 2; i < CEIL(wd->display_item_num); i++)
713 it = eina_list_nth(wd->items, i);
715 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
716 wd->over_items = eina_list_append(wd->over_items, temp_it);
717 wd->r_items = eina_list_append(wd->r_items, temp_it);
720 it = eina_list_nth(wd->items, wd->item_count - 1);
725 wd->last = _item_new(it->base.widget, it->icon, it->label, it->func,
727 wd->last->node = it->node;
728 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
731 it = eina_list_nth(wd->items, wd->item_count - 2);
736 wd->s_last = _item_new(it->base.widget, it->icon, it->label, it->func,
738 wd->s_last->node = it->node;
739 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
742 // if more than 3 itmes should be displayed
743 for (i = 3; i <= CEIL(wd->display_item_num); i++)
745 it = eina_list_nth(wd->items, wd->item_count - i);
747 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
748 wd->under_items = eina_list_append(wd->under_items, temp_it);
749 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
754 elm_diskselector_add(Evas_Object *parent)
760 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
762 ELM_SET_WIDTYPE(widtype, "diskselector");
763 elm_widget_type_set(obj, "diskselector");
764 elm_widget_sub_object_add(parent, obj);
765 elm_widget_data_set(obj, wd);
766 elm_widget_del_hook_set(obj, _del_hook);
767 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
768 elm_widget_theme_hook_set(obj, _theme_hook);
769 elm_widget_can_focus_set(obj, EINA_TRUE);
770 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
771 elm_widget_event_hook_set(obj, _event_hook);
775 wd->round = EINA_FALSE;
776 wd->init = EINA_FALSE;
778 wd->display_item_num_by_api = EINA_FALSE;
780 wd->scroller = elm_smart_scroller_add(e);
781 elm_smart_scroller_widget_set(wd->scroller, obj);
783 elm_widget_resize_object_set(obj, wd->scroller);
784 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
785 ELM_SMART_SCROLLER_POLICY_OFF);
786 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
787 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
789 evas_object_smart_callback_add(wd->scroller, "animate,stop",
790 _scroller_stop_cb, wd);
791 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
793 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
794 _diskselector_object_resize, obj);
796 wd->main_box = elm_box_add(parent);
797 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
798 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
799 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
801 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
803 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
805 elm_widget_sub_object_add(obj, wd->main_box);
807 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
809 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
810 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
812 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
814 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
816 elm_box_pack_end(wd->main_box, wd->left_blank);
817 evas_object_show(wd->left_blank);
819 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
820 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
822 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
824 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
826 elm_box_pack_end(wd->main_box, wd->right_blank);
827 evas_object_show(wd->right_blank);
831 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
832 evas_object_smart_callbacks_descriptions_set(obj, _signals);
838 elm_diskselector_round_get(const Evas_Object *obj)
840 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
841 Widget_Data *wd = elm_widget_data_get(obj);
842 if (!wd) return EINA_FALSE;
847 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
850 Elm_Diskselector_Item *it;
852 ELM_CHECK_WIDTYPE(obj, widtype);
853 Widget_Data *wd = elm_widget_data_get(obj);
856 if (wd->round == round)
862 wd->r_items = eina_list_clone(wd->items);
863 elm_box_unpack(wd->main_box, wd->left_blank);
864 evas_object_hide(wd->left_blank);
865 elm_box_unpack(wd->main_box, wd->right_blank);
866 evas_object_hide(wd->right_blank);
870 _round_items_add(wd);
873 elm_box_pack_start(wd->main_box, wd->last->base.view);
875 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
877 // if more than 3 items should be displayed
878 EINA_LIST_FOREACH(wd->under_items, elist, it)
879 elm_box_pack_start(wd->main_box, it->base.view);
882 elm_box_pack_end(wd->main_box, wd->first->base.view);
884 elm_box_pack_end(wd->main_box, wd->second->base.view);
886 // if more than 3 items should be displayed
887 EINA_LIST_FOREACH(wd->over_items, elist, it)
888 elm_box_pack_end(wd->main_box, it->base.view);
892 _round_items_del(wd);
893 elm_box_pack_start(wd->main_box, wd->left_blank);
894 elm_box_pack_end(wd->main_box, wd->right_blank);
895 eina_list_free(wd->r_items);
899 _selected_item_indicate(wd->selected_item);
904 elm_diskselector_side_label_length_get(const Evas_Object *obj)
906 ELM_CHECK_WIDTYPE(obj, widtype) 0;
907 Widget_Data *wd = elm_widget_data_get(obj);
913 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
915 ELM_CHECK_WIDTYPE(obj, widtype);
916 Widget_Data *wd = elm_widget_data_get(obj);
922 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
924 return elm_diskselector_side_label_length_set(obj, len);
928 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
930 return elm_diskselector_side_label_length_get(obj);
934 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
936 ELM_CHECK_WIDTYPE(obj, widtype);
937 Widget_Data *wd = elm_widget_data_get(obj);
940 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
944 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
946 ELM_CHECK_WIDTYPE(obj, widtype);
947 Widget_Data *wd = elm_widget_data_get(obj);
949 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
953 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
955 ELM_CHECK_WIDTYPE(obj, widtype);
956 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
957 Widget_Data *wd = elm_widget_data_get(obj);
958 if ((!wd) || (!wd->scroller)) return;
959 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
960 *policy_h = (Elm_Scroller_Policy) s_policy_h;
961 *policy_v = (Elm_Scroller_Policy) s_policy_v;
965 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
967 ELM_CHECK_WIDTYPE(obj, widtype);
968 Widget_Data *wd = elm_widget_data_get(obj);
969 if ((!wd) || (!wd->scroller)) return;
970 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
971 (policy_v >= ELM_SCROLLER_POLICY_LAST))
973 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
977 elm_diskselector_clear(Evas_Object *obj)
979 ELM_CHECK_WIDTYPE(obj, widtype);
980 Widget_Data *wd = elm_widget_data_get(obj);
981 Elm_Diskselector_Item *it;
984 if (!wd->items) return;
986 wd->selected_item = NULL;
987 EINA_LIST_FREE(wd->items, it) _item_del(it);
988 _round_items_del(wd);
992 EAPI const Eina_List *
993 elm_diskselector_items_get(const Evas_Object *obj)
995 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
996 Widget_Data *wd = elm_widget_data_get(obj);
997 if (!wd) return NULL;
1001 EAPI Elm_Diskselector_Item *
1002 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1004 Elm_Diskselector_Item *it;
1005 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1006 Widget_Data *wd = elm_widget_data_get(obj);
1007 if (!wd) return NULL;
1009 it = _item_new(obj, icon, label, func, data);
1010 wd->items = eina_list_append(wd->items, it);
1011 it->node = eina_list_last(wd->items);
1015 _round_items_del(wd);
1016 wd->r_items = eina_list_append(wd->r_items, it);
1017 _round_items_add(wd);
1019 elm_box_pack_start(wd->main_box, wd->last->base.view);
1021 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
1022 elm_box_pack_end(wd->main_box, it->base.view);
1024 elm_box_pack_end(wd->main_box, wd->first->base.view);
1026 elm_box_pack_end(wd->main_box, wd->second->base.view);
1030 elm_box_unpack(wd->main_box, wd->right_blank);
1031 elm_box_pack_end(wd->main_box, it->base.view);
1032 elm_box_pack_end(wd->main_box, wd->right_blank);
1034 if (!wd->selected_item)
1035 wd->selected_item = it;
1037 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1043 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1045 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1046 Elm_Diskselector_Item *dit;
1047 Elm_Diskselector_Item *item;
1050 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1053 elm_box_unpack(wd->main_box, it->base.view);
1056 wd->r_items = eina_list_remove(wd->r_items, it);
1058 wd->items = eina_list_remove(wd->items, it);
1060 if (wd->selected_item == it)
1062 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1064 wd->selected_item = dit;
1066 wd->selected_item = eina_list_nth(wd->items, 1);
1068 _selected_item_indicate(wd->selected_item);
1072 wd->item_count -= 1;
1076 if (!wd->item_count)
1078 evas_object_hide(wd->first->base.view);
1079 evas_object_hide(wd->second->base.view);
1080 evas_object_hide(wd->last->base.view);
1081 evas_object_hide(wd->s_last->base.view);
1083 EINA_LIST_FOREACH(wd->under_items, l, item)
1084 evas_object_hide(item->base.view);
1086 EINA_LIST_FOREACH(wd->over_items, l, item)
1087 evas_object_hide(item->base.view);
1091 dit = eina_list_nth(wd->items, 0);
1094 eina_stringshare_replace(&wd->first->label, dit->label);
1095 edje_object_part_text_set(wd->first->base.view, "elm.text",
1098 dit = eina_list_nth(wd->items, 1);
1101 eina_stringshare_replace(&wd->second->label, dit->label);
1102 edje_object_part_text_set(wd->second->base.view, "elm.text",
1105 // if more than 3 itmes should be displayed
1106 for (i = 2; i < CEIL(wd->display_item_num); i++)
1108 dit = eina_list_nth(wd->items, i);
1109 item = eina_list_nth(wd->over_items, i - 2);
1110 eina_stringshare_replace(&item->label, dit->label);
1111 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1114 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1117 eina_stringshare_replace(&wd->last->label, dit->label);
1118 edje_object_part_text_set(wd->last->base.view, "elm.text",
1121 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1124 eina_stringshare_replace(&wd->s_last->label, dit->label);
1125 edje_object_part_text_set(wd->s_last->base.view, "elm.text",
1128 // if more than 3 itmes should be displayed
1129 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1131 dit = eina_list_nth(wd->items, wd->item_count - i);
1132 item = eina_list_nth(wd->under_items, i - 3);
1133 eina_stringshare_replace(&item->label, dit->label);
1134 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1138 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
1139 _sizing_eval(wd->self);
1143 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1145 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1150 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1152 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1153 eina_stringshare_replace(&it->label, label);
1154 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1157 EAPI Elm_Diskselector_Item *
1158 elm_diskselector_selected_item_get(const Evas_Object *obj)
1160 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1161 Widget_Data *wd = elm_widget_data_get(obj);
1162 if (!wd) return NULL;
1163 return wd->selected_item;
1167 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1169 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1171 wd = elm_widget_data_get(it->base.widget);
1174 if ((wd->selected_item == it) && (selected))
1177 if ((wd->selected_item == it) && (!selected))
1178 wd->selected_item = eina_list_data_get(wd->items);
1181 wd->selected_item = it;
1182 _selected_item_indicate(wd->selected_item);
1186 wd->idler = ecore_idle_enterer_before_add(_move_scroller, it->base.widget);
1190 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1192 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1195 wd = elm_widget_data_get(it->base.widget);
1196 if (!wd) return EINA_FALSE;
1197 return (wd->selected_item == it);
1201 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1203 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1204 elm_widget_item_del_cb_set(it, func);
1208 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1210 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1211 return elm_widget_item_data_get(it);
1215 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1217 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1222 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1224 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1225 if (it->icon == icon) return;
1227 evas_object_del(it->icon);
1231 evas_object_size_hint_min_set(it->icon, 24, 24);
1232 evas_object_size_hint_max_set(it->icon, 40, 40);
1233 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
1234 evas_object_show(it->icon);
1235 elm_widget_sub_object_add(it->base.widget, it->icon);
1239 EAPI Elm_Diskselector_Item *
1240 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1242 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1243 if (it->node->prev) return it->node->prev->data;
1247 EAPI Elm_Diskselector_Item *
1248 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1250 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1251 if (it->node->next) return it->node->next->data;
1255 EAPI Elm_Diskselector_Item *
1256 elm_diskselector_first_item_get(const Evas_Object *obj)
1258 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1261 wd = elm_widget_data_get(obj);
1262 if (!wd || !wd->items)
1265 return eina_list_data_get(wd->items);
1268 EAPI Elm_Diskselector_Item *
1269 elm_diskselector_last_item_get(const Evas_Object *obj)
1271 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1274 wd = elm_widget_data_get(obj);
1275 if (!wd || !wd->items)
1278 return eina_list_data_get(eina_list_last(wd->items));
1282 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1284 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1285 elm_widget_item_tooltip_text_set(item, text);
1289 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)
1291 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1292 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1296 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1298 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1299 elm_widget_item_tooltip_unset(item);
1303 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1305 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1306 elm_widget_item_tooltip_style_set(item, style);
1310 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1312 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1313 return elm_widget_item_tooltip_style_get(item);
1317 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1319 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1320 elm_widget_item_cursor_set(item, cursor);
1324 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1326 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1327 return elm_widget_item_cursor_get(item);
1331 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1333 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1334 elm_widget_item_cursor_unset(item);
1338 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1340 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1341 elm_widget_item_cursor_style_set(item, style);
1345 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1347 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1348 return elm_widget_item_cursor_style_get(item);
1352 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1354 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1355 elm_widget_item_cursor_engine_only_set(item, engine_only);
1359 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1361 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1362 return elm_widget_item_cursor_engine_only_get(item);
1366 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1368 ELM_CHECK_WIDTYPE(obj, widtype);
1369 Widget_Data *wd = elm_widget_data_get(obj);
1371 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1372 wd->display_item_num = num;
1373 wd->display_item_num_by_api = EINA_TRUE;
1377 elm_diskselector_display_item_num_get(const Evas_Object *item)
1379 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1380 Widget_Data *wd = elm_widget_data_get(item);
1382 return wd->display_item_num;