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_Diskselector_Item *item, *item2, *dit;
236 item = (Elm_Diskselector_Item *)it;
237 wd = elm_widget_data_get(WIDGET(item));
238 if (!wd) return EINA_FALSE;
240 elm_box_unpack(wd->main_box, VIEW(item));
243 wd->r_items = eina_list_remove(wd->r_items, item);
245 wd->items = eina_list_remove(wd->items, item);
247 if (wd->selected_item == item)
249 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
251 wd->selected_item = dit;
253 wd->selected_item = eina_list_nth(wd->items, 1);
255 _selected_item_indicate(wd->selected_item);
265 evas_object_hide(wd->VIEW(first));
266 evas_object_hide(wd->VIEW(second));
267 evas_object_hide(wd->VIEW(last));
268 evas_object_hide(wd->VIEW(s_last));
270 EINA_LIST_FOREACH(wd->under_items, l, item2)
271 evas_object_hide(VIEW(item2));
273 EINA_LIST_FOREACH(wd->over_items, l, item2)
274 evas_object_hide(VIEW(item2));
278 dit = eina_list_nth(wd->items, 0);
281 eina_stringshare_replace(&wd->first->label, dit->label);
282 edje_object_part_text_set(wd->VIEW(first), "elm.text",
285 dit = eina_list_nth(wd->items, 1);
288 eina_stringshare_replace(&wd->second->label, dit->label);
289 edje_object_part_text_set(wd->VIEW(second), "elm.text",
292 // if more than 3 itmes should be displayed
293 for (i = 2; i < CEIL(wd->display_item_num); i++)
295 dit = eina_list_nth(wd->items, i);
296 item2 = eina_list_nth(wd->over_items, i - 2);
297 eina_stringshare_replace(&item2->label, dit->label);
298 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
301 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
304 eina_stringshare_replace(&wd->last->label, dit->label);
305 edje_object_part_text_set(wd->VIEW(last), "elm.text",
308 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
311 eina_stringshare_replace(&wd->s_last->label, dit->label);
312 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
315 // if more than 3 itmes should be displayed
316 for (i = 3; i <= CEIL(wd->display_item_num); i++)
318 dit = eina_list_nth(wd->items, wd->item_count - i);
319 item2 = eina_list_nth(wd->under_items, i - 3);
320 eina_stringshare_replace(&item2->label, dit->label);
321 edje_object_part_text_set(VIEW(item2), "elm.text",
326 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
327 _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_Diskselector_Item *item;
948 if (part && strcmp(part, "default")) return;
949 item = (Elm_Diskselector_Item *)it;
950 eina_stringshare_replace(&item->label, label);
951 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
955 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
957 if (part && strcmp(part, "default")) return NULL;
958 return ((Elm_Diskselector_Item *)it)->label;
962 _item_content_set_hook(Elm_Object_Item *it,
964 Evas_Object *content)
966 if (part && strcmp(part, "icon")) return;
967 _item_icon_set((Elm_Diskselector_Item *)it, content);
968 _check_identical_item((Elm_Diskselector_Item *)it, content);
972 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
974 if (part && strcmp(part, "icon")) return NULL;
975 return ((Elm_Diskselector_Item *)it)->icon;
980 elm_diskselector_add(Evas_Object *parent)
986 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
988 ELM_SET_WIDTYPE(widtype, "diskselector");
989 elm_widget_type_set(obj, "diskselector");
990 elm_widget_sub_object_add(parent, obj);
991 elm_widget_data_set(obj, wd);
992 elm_widget_del_hook_set(obj, _del_hook);
993 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
994 elm_widget_theme_hook_set(obj, _theme_hook);
995 elm_widget_can_focus_set(obj, EINA_TRUE);
996 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
997 elm_widget_event_hook_set(obj, _event_hook);
1001 wd->round = EINA_FALSE;
1002 wd->init = EINA_FALSE;
1004 wd->display_item_num_by_api = EINA_FALSE;
1006 wd->scroller = elm_smart_scroller_add(e);
1007 elm_smart_scroller_widget_set(wd->scroller, obj);
1009 elm_widget_resize_object_set(obj, wd->scroller);
1010 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1011 ELM_SMART_SCROLLER_POLICY_OFF);
1012 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1013 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1015 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1016 _scroller_stop_cb, wd);
1017 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1019 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1020 _diskselector_object_resize, obj);
1022 wd->main_box = elm_box_add(parent);
1023 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1024 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1025 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1027 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1029 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1031 elm_widget_sub_object_add(obj, wd->main_box);
1033 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1035 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1036 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1038 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1040 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1042 elm_box_pack_end(wd->main_box, wd->left_blank);
1043 evas_object_show(wd->left_blank);
1045 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1046 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1048 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1050 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1052 elm_box_pack_end(wd->main_box, wd->right_blank);
1053 evas_object_show(wd->right_blank);
1055 _theme_data_get(wd);
1057 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1058 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1064 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1066 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1067 Widget_Data *wd = elm_widget_data_get(obj);
1068 if (!wd) return EINA_FALSE;
1073 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1076 Elm_Diskselector_Item *it;
1078 ELM_CHECK_WIDTYPE(obj, widtype);
1079 Widget_Data *wd = elm_widget_data_get(obj);
1082 if (wd->round == enabled)
1085 wd->round = !!enabled;
1088 wd->r_items = eina_list_clone(wd->items);
1089 elm_box_unpack(wd->main_box, wd->left_blank);
1090 evas_object_hide(wd->left_blank);
1091 elm_box_unpack(wd->main_box, wd->right_blank);
1092 evas_object_hide(wd->right_blank);
1096 _round_items_add(wd);
1099 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1101 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1103 // if more than 3 items should be displayed
1104 EINA_LIST_FOREACH(wd->under_items, elist, it)
1105 elm_box_pack_start(wd->main_box, VIEW(it));
1108 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1110 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1112 // if more than 3 items should be displayed
1113 EINA_LIST_FOREACH(wd->over_items, elist, it)
1114 elm_box_pack_end(wd->main_box, VIEW(it));
1118 _round_items_del(wd);
1119 elm_box_pack_start(wd->main_box, wd->left_blank);
1120 elm_box_pack_end(wd->main_box, wd->right_blank);
1121 eina_list_free(wd->r_items);
1125 _selected_item_indicate(wd->selected_item);
1130 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1132 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1133 Widget_Data *wd = elm_widget_data_get(obj);
1135 return wd->len_side;
1139 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1141 ELM_CHECK_WIDTYPE(obj, widtype);
1142 Widget_Data *wd = elm_widget_data_get(obj);
1148 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1150 ELM_CHECK_WIDTYPE(obj, widtype);
1151 Widget_Data *wd = elm_widget_data_get(obj);
1154 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1158 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1160 ELM_CHECK_WIDTYPE(obj, widtype);
1161 Widget_Data *wd = elm_widget_data_get(obj);
1163 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1167 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1169 ELM_CHECK_WIDTYPE(obj, widtype);
1170 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1171 Widget_Data *wd = elm_widget_data_get(obj);
1172 if ((!wd) || (!wd->scroller)) return;
1173 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1174 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1175 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1179 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1181 ELM_CHECK_WIDTYPE(obj, widtype);
1182 Widget_Data *wd = elm_widget_data_get(obj);
1183 if ((!wd) || (!wd->scroller)) return;
1184 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1185 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1187 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1191 elm_diskselector_clear(Evas_Object *obj)
1193 ELM_CHECK_WIDTYPE(obj, widtype);
1194 Widget_Data *wd = elm_widget_data_get(obj);
1195 Elm_Diskselector_Item *it;
1198 if (!wd->items) return;
1200 wd->selected_item = NULL;
1201 EINA_LIST_FREE(wd->items, it)
1204 elm_widget_item_free(it);
1206 _round_items_del(wd);
1210 EAPI const Eina_List *
1211 elm_diskselector_items_get(const Evas_Object *obj)
1213 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1214 Widget_Data *wd = elm_widget_data_get(obj);
1215 if (!wd) return NULL;
1219 EAPI Elm_Object_Item *
1220 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1222 Elm_Diskselector_Item *it;
1223 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1224 Widget_Data *wd = elm_widget_data_get(obj);
1225 if (!wd) return NULL;
1227 it = _item_new(obj, icon, label, func, data);
1228 wd->items = eina_list_append(wd->items, it);
1229 it->node = eina_list_last(wd->items);
1233 _round_items_del(wd);
1234 wd->r_items = eina_list_append(wd->r_items, it);
1235 _round_items_add(wd);
1237 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1239 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1240 elm_box_pack_end(wd->main_box, VIEW(it));
1242 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1244 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1248 elm_box_unpack(wd->main_box, wd->right_blank);
1249 elm_box_pack_end(wd->main_box, VIEW(it));
1250 elm_box_pack_end(wd->main_box, wd->right_blank);
1252 if (!wd->selected_item)
1253 wd->selected_item = it;
1255 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1257 return (Elm_Object_Item *)it;
1260 EAPI Elm_Object_Item *
1261 elm_diskselector_selected_item_get(const Evas_Object *obj)
1263 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1264 Widget_Data *wd = elm_widget_data_get(obj);
1265 if (!wd) return NULL;
1266 return (Elm_Object_Item *) wd->selected_item;
1270 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1272 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1274 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1275 wd = elm_widget_data_get(WIDGET(item));
1278 if ((wd->selected_item == item) && (selected))
1281 if ((wd->selected_item == item) && (!selected))
1282 wd->selected_item = eina_list_data_get(wd->items);
1285 wd->selected_item = item;
1286 _selected_item_indicate(wd->selected_item);
1290 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1294 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1296 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1297 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1298 if (!wd) return EINA_FALSE;
1299 return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1302 EAPI Elm_Object_Item *
1303 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1305 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1306 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1307 if (item->node->prev) return item->node->prev->data;
1311 EAPI Elm_Object_Item *
1312 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1314 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1315 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1316 if (item->node->next) return item->node->next->data;
1320 EAPI Elm_Object_Item *
1321 elm_diskselector_first_item_get(const Evas_Object *obj)
1323 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1324 Widget_Data *wd = elm_widget_data_get(obj);
1325 if (!wd || !wd->items) return NULL;
1326 return eina_list_data_get(wd->items);
1329 EAPI Elm_Object_Item *
1330 elm_diskselector_last_item_get(const Evas_Object *obj)
1332 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1333 Widget_Data *wd = elm_widget_data_get(obj);
1334 if (!wd || !wd->items) return NULL;
1335 return eina_list_data_get(eina_list_last(wd->items));
1339 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1341 ELM_CHECK_WIDTYPE(obj, widtype);
1342 Widget_Data *wd = elm_widget_data_get(obj);
1344 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1345 wd->display_item_num = num;
1346 wd->display_item_num_by_api = EINA_TRUE;
1350 elm_diskselector_display_item_num_get(const Evas_Object *item)
1352 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1353 Widget_Data *wd = elm_widget_data_get(item);
1355 return wd->display_item_num;