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);
68 static void _item_text_set_hook(Elm_Object_Item *it,
71 static const char * _item_text_get_hook(const Elm_Object_Item *it,
73 static void _item_content_set_hook(Elm_Object_Item *it,
75 Evas_Object *content);
76 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
79 static const char SIG_SELECTED[] = "selected";
80 static const Evas_Smart_Cb_Description _signals[] = {
86 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
91 wd = elm_widget_data_get(data);
94 if ((wd->minw == -1) && (wd->minh == -1))
95 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
96 edje_object_size_min_restricted_calc
97 (elm_smart_scroller_edje_object_get
98 (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
99 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
100 evas_object_size_hint_max_set(obj, -1, -1);
102 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
104 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
106 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
108 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
109 (int)(w / wd->display_item_num), 0);
112 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
116 _item_del(Elm_Diskselector_Item *item)
119 eina_stringshare_del(item->label);
121 evas_object_del(item->icon);
125 _count_letter(const char *str)
130 for (chnum = 0; ; chnum++)
132 pos = evas_string_char_next_get(str, pos, &code);
133 if (code == 0) break;
139 _check_letter(const char *str, int length)
144 for (chnum = 0; ; chnum++)
146 if (chnum == length) break;
147 pos = evas_string_char_next_get(str, pos, &code);
148 if (code == 0) break;
154 _check_string(void *data)
156 int mid, steps, length, diff;
157 Elm_Diskselector_Item *it;
161 Widget_Data *wd = data;
163 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
173 EINA_LIST_FOREACH(list, l, it)
177 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
178 /* item not visible */
179 if ((x + w <= ox) || (x >= ox + ow))
182 len = _count_letter(it->label);
183 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
184 // len = eina_stringshare_strlen(it->label);
187 edje_object_signal_emit(VIEW(it), "elm,state,left_side",
189 else if (x + w >= ox + ow - 5)
190 edje_object_signal_emit(VIEW(it), "elm,state,right_side",
194 if ((wd->len_threshold) && (len > wd->len_threshold))
195 edje_object_signal_emit(VIEW(it), "elm,state,center_small",
198 edje_object_signal_emit(VIEW(it), "elm,state,center",
202 // if len is les that the limit len, skip anyway
203 if (len <= wd->len_side)
206 steps = len - wd->len_side + 1;
208 if (mid <= ox + ow / 2)
209 diff = (ox + ow / 2) - mid;
211 diff = mid - (ox + ow / 2);
213 length = len - (int)(diff * steps / (ow / 3));
214 length = MAX(length, wd->len_side);
215 // limit string len to "length" ut8f chars
216 length = _check_letter(it->label, length);
217 // cut it off at byte mark returned form _check_letter
218 strncpy(buf, it->label, length);
220 edje_object_part_text_set(VIEW(it), "elm.text", buf);
224 ecore_idle_enterer_del(wd->check_idler);
225 wd->check_idler = NULL;
230 _item_del_pre_hook(Elm_Object_Item *it)
232 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
233 Elm_Diskselector_Item *item, *item2, *dit;
237 item = (Elm_Diskselector_Item *) it;
238 wd = elm_widget_data_get(WIDGET(item));
241 elm_box_unpack(wd->main_box, VIEW(item));
244 wd->r_items = eina_list_remove(wd->r_items, item);
246 wd->items = eina_list_remove(wd->items, item);
248 if (wd->selected_item == item)
250 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
252 wd->selected_item = dit;
254 wd->selected_item = eina_list_nth(wd->items, 1);
256 _selected_item_indicate(wd->selected_item);
266 evas_object_hide(wd->VIEW(first));
267 evas_object_hide(wd->VIEW(second));
268 evas_object_hide(wd->VIEW(last));
269 evas_object_hide(wd->VIEW(s_last));
271 EINA_LIST_FOREACH(wd->under_items, l, item2)
272 evas_object_hide(VIEW(item2));
274 EINA_LIST_FOREACH(wd->over_items, l, item2)
275 evas_object_hide(VIEW(item2));
279 dit = eina_list_nth(wd->items, 0);
282 eina_stringshare_replace(&wd->first->label, dit->label);
283 edje_object_part_text_set(wd->VIEW(first), "elm.text",
286 dit = eina_list_nth(wd->items, 1);
289 eina_stringshare_replace(&wd->second->label, dit->label);
290 edje_object_part_text_set(wd->VIEW(second), "elm.text",
293 // if more than 3 itmes should be displayed
294 for (i = 2; i < CEIL(wd->display_item_num); i++)
296 dit = eina_list_nth(wd->items, i);
297 item2 = eina_list_nth(wd->over_items, i - 2);
298 eina_stringshare_replace(&item2->label, dit->label);
299 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
302 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
305 eina_stringshare_replace(&wd->last->label, dit->label);
306 edje_object_part_text_set(wd->VIEW(last), "elm.text",
309 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
312 eina_stringshare_replace(&wd->s_last->label, dit->label);
313 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
316 // if more than 3 itmes should be displayed
317 for (i = 3; i <= CEIL(wd->display_item_num); i++)
319 dit = eina_list_nth(wd->items, wd->item_count - i);
320 item2 = eina_list_nth(wd->under_items, i - 3);
321 eina_stringshare_replace(&item2->label, dit->label);
322 edje_object_part_text_set(VIEW(item2), "elm.text",
327 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
328 _sizing_eval(wd->self);
332 static Elm_Diskselector_Item *
333 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
335 Elm_Diskselector_Item *it;
336 const char *style = elm_widget_style_get(obj);
338 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
339 if (!it) return NULL;
341 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
342 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
343 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
344 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
345 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
347 it->label = eina_stringshare_add(label);
350 it->base.data = data;
351 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
352 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
353 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
355 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
357 evas_object_show(VIEW(it));
361 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
362 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
366 evas_object_size_hint_min_set(it->icon, 24, 24);
367 evas_object_size_hint_max_set(it->icon, 40, 40);
368 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
369 evas_object_show(it->icon);
370 elm_widget_sub_object_add(obj, it->icon);
376 _theme_data_get(Widget_Data *wd)
379 str = edje_object_data_get(wd->right_blank, "len_threshold");
380 if (str) wd->len_threshold = MAX(0, atoi(str));
381 else wd->len_threshold = 0;
383 if (!wd->display_item_num_by_api)
385 str = edje_object_data_get(wd->right_blank, "display_item_num");
386 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
387 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
390 str = edje_object_data_get(wd->right_blank, "min_width");
391 if (str) wd->minw = MAX(-1, atoi(str));
394 str = edje_object_data_get(wd->right_blank, "min_height");
395 if (str) wd->minh = MAX(-1, atoi(str));
400 _del_hook(Evas_Object * obj)
402 Widget_Data *wd = elm_widget_data_get(obj);
408 _del_pre_hook(Evas_Object * obj)
410 Elm_Diskselector_Item *it;
413 Widget_Data *wd = elm_widget_data_get(obj);
417 evas_object_del(wd->left_blank);
419 evas_object_del(wd->right_blank);
422 eina_stringshare_del(wd->last->label);
423 evas_object_del(wd->VIEW(last));
428 eina_stringshare_del(wd->s_last->label);
429 evas_object_del(wd->VIEW(s_last));
434 eina_stringshare_del(wd->second->label);
435 evas_object_del(wd->VIEW(second));
440 eina_stringshare_del(wd->first->label);
441 evas_object_del(wd->VIEW(first));
445 EINA_LIST_FOREACH(wd->under_items, l, it)
449 eina_stringshare_del(it->label);
450 evas_object_del(VIEW(it));
455 EINA_LIST_FOREACH(wd->over_items, l, it)
459 eina_stringshare_del(it->label);
460 evas_object_del(VIEW(it));
465 EINA_LIST_FREE(wd->items, it)
468 elm_widget_item_free(it);
470 eina_list_free(wd->r_items);
474 _sizing_eval(Evas_Object * obj)
476 Widget_Data *wd = elm_widget_data_get(obj);
478 _diskselector_object_resize(obj, NULL, obj, NULL);
482 _theme_hook(Evas_Object * obj)
485 Elm_Diskselector_Item *it;
486 Widget_Data *wd = elm_widget_data_get(obj);
490 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
491 "base", elm_widget_style_get(obj));
494 EINA_LIST_FOREACH(wd->r_items, l, it)
496 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
497 elm_widget_style_get(obj));
498 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
503 EINA_LIST_FOREACH(wd->items, l, it)
505 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
506 elm_widget_style_get(obj));
507 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
510 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
511 elm_widget_style_get(obj));
517 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
519 Widget_Data *wd = elm_widget_data_get(obj);
520 Evas_Object *sub = event_info;
521 Elm_Diskselector_Item *it;
526 if (sub == wd->scroller)
530 EINA_LIST_FOREACH(wd->items, l, it)
543 _select_item(Elm_Diskselector_Item *it)
546 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
547 wd->selected_item = it;
548 _selected_item_indicate(wd->selected_item);
549 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
550 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
554 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
556 Widget_Data *wd = elm_widget_data_get(obj);
560 if (elm_widget_focus_get(obj))
562 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
563 evas_object_focus_set(wd->self, EINA_TRUE);
567 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
568 evas_object_focus_set(wd->self, EINA_FALSE);
573 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
575 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
576 Evas_Event_Key_Down *ev = event_info;
577 Widget_Data *wd = elm_widget_data_get(obj);
578 if (!wd) return EINA_FALSE;
579 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
580 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
582 Elm_Diskselector_Item *it = NULL;
585 if (!wd->selected_item) {
586 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
590 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
591 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
593 l = wd->selected_item->node->prev;
594 if ((!l) && (wd->round))
595 l = eina_list_last(wd->items);
597 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
598 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
600 l = wd->selected_item->node->next;
601 if ((!l) && (wd->round))
604 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
606 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
607 l = eina_list_last(wd->items);
608 else return EINA_FALSE;
611 it = eina_list_data_get(l);
615 wd->selected_item = it;
617 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
620 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
625 _selected_item_indicate(Elm_Diskselector_Item *it)
627 Elm_Diskselector_Item *item;
630 wd = elm_widget_data_get(WIDGET(it));
634 EINA_LIST_FOREACH(wd->r_items, l, item)
636 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
638 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
643 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
644 const char *emission __UNUSED__, const char *source __UNUSED__)
646 Elm_Diskselector_Item *it = data;
651 wd = elm_widget_data_get(WIDGET(it));
655 if (wd->selected_item != it)
657 wd->selected_item = it;
658 _selected_item_indicate(wd->selected_item);
661 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
665 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
667 Evas_Coord x, y, w, h, bw;
668 Widget_Data *wd = data;
671 elm_smart_scroller_child_pos_get(obj, &x, &y);
672 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
675 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
676 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
677 elm_smart_scroller_child_region_show(wd->scroller,
678 x - ((w / wd->display_item_num) * wd->item_count),
681 elm_smart_scroller_child_region_show(wd->scroller,
682 x + ((w / wd->display_item_num) * wd->item_count),
688 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
690 Elm_Diskselector_Item *it;
691 Widget_Data *wd = data;
695 if (wd->idler) return;
702 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
703 EINA_LIST_FOREACH(list, l, it)
705 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
706 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
714 _move_scroller(void *data)
716 Evas_Object *obj = data;
719 Elm_Diskselector_Item *dit;
723 wd = elm_widget_data_get(obj);
724 if (!wd) return EINA_FALSE;
737 EINA_LIST_FOREACH(list, l, dit)
739 if (wd->selected_item == dit)
744 if (wd->round) i -= CEIL(wd->display_item_num);
749 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
753 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
754 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
758 ecore_idle_enterer_del(wd->idler);
761 wd->init = EINA_TRUE;
768 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
771 elm_box_unpack(wd->main_box, VIEW(it));
772 wd->r_items = eina_list_remove(wd->r_items, it);
773 eina_stringshare_del(it->label);
774 elm_widget_item_free(it);
778 _round_items_del(Widget_Data *wd)
781 Elm_Diskselector_Item * it;
783 _round_item_del(wd, wd->last);
785 _round_item_del(wd, wd->s_last);
787 _round_item_del(wd, wd->second);
789 _round_item_del(wd, wd->first);
792 EINA_LIST_FOREACH(wd->under_items, l, it)
794 _round_item_del(wd, it);
796 wd->under_items = eina_list_free(wd->under_items);
798 EINA_LIST_FOREACH(wd->over_items, l, it)
800 _round_item_del(wd, it);
802 wd->over_items = eina_list_free(wd->over_items);
806 _round_items_add(Widget_Data *wd)
808 Elm_Diskselector_Item *dit;
809 Elm_Diskselector_Item *it;
810 Elm_Diskselector_Item *temp_it;
812 dit = it = eina_list_nth(wd->items, 0);
817 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
819 wd->first->node = it->node;
820 wd->r_items = eina_list_append(wd->r_items, wd->first);
823 it = eina_list_nth(wd->items, 1);
828 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
830 wd->second->node = it->node;
831 wd->r_items = eina_list_append(wd->r_items, wd->second);
834 // if more than 3 itmes should be displayed
835 for (i = 2; i < CEIL(wd->display_item_num); i++)
837 it = eina_list_nth(wd->items, i);
839 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
840 wd->over_items = eina_list_append(wd->over_items, temp_it);
841 wd->r_items = eina_list_append(wd->r_items, temp_it);
844 it = eina_list_nth(wd->items, wd->item_count - 1);
849 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
851 wd->last->node = it->node;
852 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
855 it = eina_list_nth(wd->items, wd->item_count - 2);
860 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
862 wd->s_last->node = it->node;
863 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
866 // if more than 3 itmes should be displayed
867 for (i = 3; i <= CEIL(wd->display_item_num); i++)
869 it = eina_list_nth(wd->items, wd->item_count - i);
871 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
872 wd->under_items = eina_list_append(wd->under_items, temp_it);
873 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
878 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
880 if (it->icon == icon) return;
882 evas_object_del(it->icon);
886 evas_object_size_hint_min_set(it->icon, 24, 24);
887 evas_object_size_hint_max_set(it->icon, 40, 40);
888 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
889 evas_object_show(it->icon);
890 elm_widget_sub_object_add(WIDGET(it), it->icon);
895 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
898 Elm_Diskselector_Item *dit;
904 wd = elm_widget_data_get(WIDGET(it));
909 // Get index from indentical item from round items
910 EINA_LIST_FOREACH(wd->r_items, l, dit)
912 if (it == dit) break;
917 ic = eina_list_count(wd->r_items);
918 if (idx >= ic) return;
921 // Number of added items: CEIL(wd->display_item_num)
922 ac = CEIL(wd->display_item_num);
924 if (((idx >= 0) && (idx < ac)) ||
925 ((idx >= ac) && (idx < (2 * ac))))
927 // Selected item: under, low region
928 dit = eina_list_nth(wd->r_items,
929 idx + ic - (2 * ac));
931 else if (((idx >= (ic - ac)) && (idx < ic)) ||
932 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
934 // Selected item: over, high region
935 dit = eina_list_nth(wd->r_items,
936 idx - ic + (2 * ac));
939 if(dit) _item_icon_set(dit, icon);
940 _sizing_eval(wd->self);
945 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
947 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
948 Elm_Diskselector_Item *item;
949 if (part && strcmp(part, "default")) return;
950 item = (Elm_Diskselector_Item *) it;
951 eina_stringshare_replace(&item->label, label);
952 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
956 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
958 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
959 if (part && strcmp(part, "default")) return NULL;
960 return ((Elm_Diskselector_Item *) it)->label;
964 _item_content_set_hook(Elm_Object_Item *it,
966 Evas_Object *content)
968 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
969 if (part && strcmp(part, "icon")) return;
970 _item_icon_set((Elm_Diskselector_Item *) it, content);
971 _check_identical_item((Elm_Diskselector_Item *) it, content);
975 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
977 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
978 if (part && strcmp(part, "icon")) return NULL;
979 return ((Elm_Diskselector_Item *) it)->icon;
984 elm_diskselector_add(Evas_Object *parent)
990 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
992 ELM_SET_WIDTYPE(widtype, "diskselector");
993 elm_widget_type_set(obj, "diskselector");
994 elm_widget_sub_object_add(parent, obj);
995 elm_widget_data_set(obj, wd);
996 elm_widget_del_hook_set(obj, _del_hook);
997 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
998 elm_widget_theme_hook_set(obj, _theme_hook);
999 elm_widget_can_focus_set(obj, EINA_TRUE);
1000 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1001 elm_widget_event_hook_set(obj, _event_hook);
1005 wd->round = EINA_FALSE;
1006 wd->init = EINA_FALSE;
1008 wd->display_item_num_by_api = EINA_FALSE;
1010 wd->scroller = elm_smart_scroller_add(e);
1011 elm_smart_scroller_widget_set(wd->scroller, obj);
1013 elm_widget_resize_object_set(obj, wd->scroller);
1014 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1015 ELM_SMART_SCROLLER_POLICY_OFF);
1016 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1017 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1019 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1020 _scroller_stop_cb, wd);
1021 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1023 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1024 _diskselector_object_resize, obj);
1026 wd->main_box = elm_box_add(parent);
1027 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1028 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1029 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1031 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1033 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1035 elm_widget_sub_object_add(obj, wd->main_box);
1037 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1039 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1040 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1042 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1044 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1046 elm_box_pack_end(wd->main_box, wd->left_blank);
1047 evas_object_show(wd->left_blank);
1049 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1050 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1052 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1054 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1056 elm_box_pack_end(wd->main_box, wd->right_blank);
1057 evas_object_show(wd->right_blank);
1059 _theme_data_get(wd);
1061 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1062 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1068 elm_diskselector_round_get(const Evas_Object *obj)
1070 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1071 Widget_Data *wd = elm_widget_data_get(obj);
1072 if (!wd) return EINA_FALSE;
1077 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
1080 Elm_Diskselector_Item *it;
1082 ELM_CHECK_WIDTYPE(obj, widtype);
1083 Widget_Data *wd = elm_widget_data_get(obj);
1086 if (wd->round == round)
1092 wd->r_items = eina_list_clone(wd->items);
1093 elm_box_unpack(wd->main_box, wd->left_blank);
1094 evas_object_hide(wd->left_blank);
1095 elm_box_unpack(wd->main_box, wd->right_blank);
1096 evas_object_hide(wd->right_blank);
1100 _round_items_add(wd);
1103 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1105 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1107 // if more than 3 items should be displayed
1108 EINA_LIST_FOREACH(wd->under_items, elist, it)
1109 elm_box_pack_start(wd->main_box, VIEW(it));
1112 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1114 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1116 // if more than 3 items should be displayed
1117 EINA_LIST_FOREACH(wd->over_items, elist, it)
1118 elm_box_pack_end(wd->main_box, VIEW(it));
1122 _round_items_del(wd);
1123 elm_box_pack_start(wd->main_box, wd->left_blank);
1124 elm_box_pack_end(wd->main_box, wd->right_blank);
1125 eina_list_free(wd->r_items);
1129 _selected_item_indicate(wd->selected_item);
1134 elm_diskselector_side_label_length_get(const Evas_Object *obj)
1136 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1137 Widget_Data *wd = elm_widget_data_get(obj);
1139 return wd->len_side;
1143 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
1145 ELM_CHECK_WIDTYPE(obj, widtype);
1146 Widget_Data *wd = elm_widget_data_get(obj);
1152 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
1154 return elm_diskselector_side_label_length_set(obj, len);
1158 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1160 return elm_diskselector_side_label_length_get(obj);
1164 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1166 ELM_CHECK_WIDTYPE(obj, widtype);
1167 Widget_Data *wd = elm_widget_data_get(obj);
1170 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1174 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1176 ELM_CHECK_WIDTYPE(obj, widtype);
1177 Widget_Data *wd = elm_widget_data_get(obj);
1179 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1183 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1185 ELM_CHECK_WIDTYPE(obj, widtype);
1186 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1187 Widget_Data *wd = elm_widget_data_get(obj);
1188 if ((!wd) || (!wd->scroller)) return;
1189 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1190 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1191 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1195 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1197 ELM_CHECK_WIDTYPE(obj, widtype);
1198 Widget_Data *wd = elm_widget_data_get(obj);
1199 if ((!wd) || (!wd->scroller)) return;
1200 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1201 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1203 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1207 elm_diskselector_clear(Evas_Object *obj)
1209 ELM_CHECK_WIDTYPE(obj, widtype);
1210 Widget_Data *wd = elm_widget_data_get(obj);
1211 Elm_Diskselector_Item *it;
1214 if (!wd->items) return;
1216 wd->selected_item = NULL;
1217 EINA_LIST_FREE(wd->items, it)
1220 elm_widget_item_free(it);
1222 _round_items_del(wd);
1226 EAPI const Eina_List *
1227 elm_diskselector_items_get(const Evas_Object *obj)
1229 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1230 Widget_Data *wd = elm_widget_data_get(obj);
1231 if (!wd) return NULL;
1235 EAPI Elm_Object_Item *
1236 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1238 Elm_Diskselector_Item *it;
1239 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1240 Widget_Data *wd = elm_widget_data_get(obj);
1241 if (!wd) return NULL;
1243 it = _item_new(obj, icon, label, func, data);
1244 wd->items = eina_list_append(wd->items, it);
1245 it->node = eina_list_last(wd->items);
1249 _round_items_del(wd);
1250 wd->r_items = eina_list_append(wd->r_items, it);
1251 _round_items_add(wd);
1253 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1255 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1256 elm_box_pack_end(wd->main_box, VIEW(it));
1258 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1260 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1264 elm_box_unpack(wd->main_box, wd->right_blank);
1265 elm_box_pack_end(wd->main_box, VIEW(it));
1266 elm_box_pack_end(wd->main_box, wd->right_blank);
1268 if (!wd->selected_item)
1269 wd->selected_item = it;
1271 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1273 return (Elm_Object_Item *) it;
1277 elm_diskselector_item_del(Elm_Object_Item * it)
1279 elm_object_item_del(it);
1283 elm_diskselector_item_label_get(const Elm_Object_Item * it)
1285 return _item_text_get_hook(it, NULL);
1289 elm_diskselector_item_label_set(Elm_Object_Item * it, const char *label)
1291 _item_text_set_hook(it, NULL, label);
1294 EAPI Elm_Object_Item *
1295 elm_diskselector_selected_item_get(const Evas_Object *obj)
1297 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1298 Widget_Data *wd = elm_widget_data_get(obj);
1299 if (!wd) return NULL;
1300 return (Elm_Object_Item *) wd->selected_item;
1304 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1306 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1308 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1309 wd = elm_widget_data_get(WIDGET(item));
1312 if ((wd->selected_item == item) && (selected))
1315 if ((wd->selected_item == item) && (!selected))
1316 wd->selected_item = eina_list_data_get(wd->items);
1319 wd->selected_item = item;
1320 _selected_item_indicate(wd->selected_item);
1324 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1328 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1330 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1331 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1332 if (!wd) return EINA_FALSE;
1333 return (wd->selected_item == ((Elm_Diskselector_Item *) it));
1337 elm_diskselector_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1339 elm_object_item_del_cb_set(it, func);
1343 elm_diskselector_item_data_get(const Elm_Object_Item *it)
1345 return elm_object_item_data_get(it);
1349 elm_diskselector_item_icon_get(const Elm_Object_Item *it)
1351 return _item_content_get_hook(it, NULL);
1355 elm_diskselector_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1357 _item_content_set_hook(it, NULL, icon);
1360 EAPI Elm_Object_Item *
1361 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1363 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1364 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1365 if (item->node->prev) return item->node->prev->data;
1369 EAPI Elm_Object_Item *
1370 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1372 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1373 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1374 if (item->node->next) return item->node->next->data;
1378 EAPI Elm_Object_Item *
1379 elm_diskselector_first_item_get(const Evas_Object *obj)
1381 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1382 Widget_Data *wd = elm_widget_data_get(obj);
1383 if (!wd || !wd->items) return NULL;
1384 return eina_list_data_get(wd->items);
1387 EAPI Elm_Object_Item *
1388 elm_diskselector_last_item_get(const Evas_Object *obj)
1390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1391 Widget_Data *wd = elm_widget_data_get(obj);
1392 if (!wd || !wd->items) return NULL;
1393 return eina_list_data_get(eina_list_last(wd->items));
1397 elm_diskselector_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1399 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1400 elm_widget_item_tooltip_text_set(it, text);
1404 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)
1406 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1407 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1411 elm_diskselector_item_tooltip_unset(Elm_Object_Item *it)
1413 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1414 elm_widget_item_tooltip_unset(it);
1418 elm_diskselector_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1420 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1421 elm_widget_item_tooltip_style_set(it, style);
1425 elm_diskselector_item_tooltip_style_get(const Elm_Object_Item *it)
1427 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1428 return elm_widget_item_tooltip_style_get(it);
1432 elm_diskselector_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1434 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1435 elm_widget_item_cursor_set(it, cursor);
1439 elm_diskselector_item_cursor_get(const Elm_Object_Item *it)
1441 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1442 return elm_widget_item_cursor_get(it);
1446 elm_diskselector_item_cursor_unset(Elm_Object_Item *it)
1448 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1449 elm_widget_item_cursor_unset(it);
1453 elm_diskselector_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1455 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1456 elm_widget_item_cursor_style_set(it, style);
1460 elm_diskselector_item_cursor_style_get(const Elm_Object_Item *it)
1462 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1463 return elm_widget_item_cursor_style_get(it);
1467 elm_diskselector_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1469 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1470 elm_widget_item_cursor_engine_only_set(it, engine_only);
1474 elm_diskselector_item_cursor_engine_only_get(const Elm_Object_Item *it)
1476 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1477 return elm_widget_item_cursor_engine_only_get(it);
1481 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1483 ELM_CHECK_WIDTYPE(obj, widtype);
1484 Widget_Data *wd = elm_widget_data_get(obj);
1486 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1487 wd->display_item_num = num;
1488 wd->display_item_num_by_api = EINA_TRUE;
1492 elm_diskselector_display_item_num_get(const Evas_Object *item)
1494 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1495 Widget_Data *wd = elm_widget_data_get(item);
1497 return wd->display_item_num;