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, EINA_FALSE);
233 Elm_Diskselector_Item *item, *item2, *dit;
237 item = (Elm_Diskselector_Item *) it;
238 wd = elm_widget_data_get(WIDGET(item));
239 if (!wd) return EINA_FALSE;
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);
333 static Elm_Diskselector_Item *
334 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
336 Elm_Diskselector_Item *it;
337 const char *style = elm_widget_style_get(obj);
339 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
340 if (!it) return NULL;
342 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
343 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
344 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
345 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
346 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
348 it->label = eina_stringshare_add(label);
351 it->base.data = data;
352 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
353 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
354 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
356 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
358 evas_object_show(VIEW(it));
362 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
363 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
367 evas_object_size_hint_min_set(it->icon, 24, 24);
368 evas_object_size_hint_max_set(it->icon, 40, 40);
369 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
370 evas_object_show(it->icon);
371 elm_widget_sub_object_add(obj, it->icon);
377 _theme_data_get(Widget_Data *wd)
380 str = edje_object_data_get(wd->right_blank, "len_threshold");
381 if (str) wd->len_threshold = MAX(0, atoi(str));
382 else wd->len_threshold = 0;
384 if (!wd->display_item_num_by_api)
386 str = edje_object_data_get(wd->right_blank, "display_item_num");
387 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
388 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
391 str = edje_object_data_get(wd->right_blank, "min_width");
392 if (str) wd->minw = MAX(-1, atoi(str));
395 str = edje_object_data_get(wd->right_blank, "min_height");
396 if (str) wd->minh = MAX(-1, atoi(str));
401 _del_hook(Evas_Object * obj)
403 Widget_Data *wd = elm_widget_data_get(obj);
409 _del_pre_hook(Evas_Object * obj)
411 Elm_Diskselector_Item *it;
414 Widget_Data *wd = elm_widget_data_get(obj);
418 evas_object_del(wd->left_blank);
420 evas_object_del(wd->right_blank);
423 eina_stringshare_del(wd->last->label);
424 evas_object_del(wd->VIEW(last));
429 eina_stringshare_del(wd->s_last->label);
430 evas_object_del(wd->VIEW(s_last));
435 eina_stringshare_del(wd->second->label);
436 evas_object_del(wd->VIEW(second));
441 eina_stringshare_del(wd->first->label);
442 evas_object_del(wd->VIEW(first));
446 EINA_LIST_FOREACH(wd->under_items, l, it)
450 eina_stringshare_del(it->label);
451 evas_object_del(VIEW(it));
456 EINA_LIST_FOREACH(wd->over_items, l, it)
460 eina_stringshare_del(it->label);
461 evas_object_del(VIEW(it));
466 EINA_LIST_FREE(wd->items, it)
469 elm_widget_item_free(it);
471 eina_list_free(wd->r_items);
475 _sizing_eval(Evas_Object * obj)
477 Widget_Data *wd = elm_widget_data_get(obj);
479 _diskselector_object_resize(obj, NULL, obj, NULL);
483 _theme_hook(Evas_Object * obj)
486 Elm_Diskselector_Item *it;
487 Widget_Data *wd = elm_widget_data_get(obj);
491 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
492 "base", elm_widget_style_get(obj));
495 EINA_LIST_FOREACH(wd->r_items, l, it)
497 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
498 elm_widget_style_get(obj));
499 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
504 EINA_LIST_FOREACH(wd->items, l, it)
506 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
507 elm_widget_style_get(obj));
508 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
511 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
512 elm_widget_style_get(obj));
518 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
520 Widget_Data *wd = elm_widget_data_get(obj);
521 Evas_Object *sub = event_info;
522 Elm_Diskselector_Item *it;
527 if (sub == wd->scroller)
531 EINA_LIST_FOREACH(wd->items, l, it)
544 _select_item(Elm_Diskselector_Item *it)
547 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
548 wd->selected_item = it;
549 _selected_item_indicate(wd->selected_item);
550 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
551 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
555 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
557 Widget_Data *wd = elm_widget_data_get(obj);
561 if (elm_widget_focus_get(obj))
563 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
564 evas_object_focus_set(wd->self, EINA_TRUE);
568 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
569 evas_object_focus_set(wd->self, EINA_FALSE);
574 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
576 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
577 Evas_Event_Key_Down *ev = event_info;
578 Widget_Data *wd = elm_widget_data_get(obj);
579 if (!wd) return EINA_FALSE;
580 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
581 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
583 Elm_Diskselector_Item *it = NULL;
586 if (!wd->selected_item) {
587 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
591 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
592 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
594 l = wd->selected_item->node->prev;
595 if ((!l) && (wd->round))
596 l = eina_list_last(wd->items);
598 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
599 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
601 l = wd->selected_item->node->next;
602 if ((!l) && (wd->round))
605 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
607 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
608 l = eina_list_last(wd->items);
609 else return EINA_FALSE;
612 it = eina_list_data_get(l);
616 wd->selected_item = it;
618 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
621 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
626 _selected_item_indicate(Elm_Diskselector_Item *it)
628 Elm_Diskselector_Item *item;
631 wd = elm_widget_data_get(WIDGET(it));
635 EINA_LIST_FOREACH(wd->r_items, l, item)
637 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
639 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
644 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
645 const char *emission __UNUSED__, const char *source __UNUSED__)
647 Elm_Diskselector_Item *it = data;
652 wd = elm_widget_data_get(WIDGET(it));
656 if (wd->selected_item != it)
658 wd->selected_item = it;
659 _selected_item_indicate(wd->selected_item);
662 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
666 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
668 Evas_Coord x, y, w, h, bw;
669 Widget_Data *wd = data;
672 elm_smart_scroller_child_pos_get(obj, &x, &y);
673 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
676 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
677 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
678 elm_smart_scroller_child_region_show(wd->scroller,
679 x - ((w / wd->display_item_num) * wd->item_count),
682 elm_smart_scroller_child_region_show(wd->scroller,
683 x + ((w / wd->display_item_num) * wd->item_count),
689 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
691 Elm_Diskselector_Item *it;
692 Widget_Data *wd = data;
696 if (wd->idler) return;
703 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
704 EINA_LIST_FOREACH(list, l, it)
706 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
707 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
715 _move_scroller(void *data)
717 Evas_Object *obj = data;
720 Elm_Diskselector_Item *dit;
724 wd = elm_widget_data_get(obj);
725 if (!wd) return EINA_FALSE;
738 EINA_LIST_FOREACH(list, l, dit)
740 if (wd->selected_item == dit)
745 if (wd->round) i -= CEIL(wd->display_item_num);
750 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
754 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
755 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
759 ecore_idle_enterer_del(wd->idler);
762 wd->init = EINA_TRUE;
769 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
772 elm_box_unpack(wd->main_box, VIEW(it));
773 wd->r_items = eina_list_remove(wd->r_items, it);
774 eina_stringshare_del(it->label);
775 elm_widget_item_free(it);
779 _round_items_del(Widget_Data *wd)
782 Elm_Diskselector_Item * it;
784 _round_item_del(wd, wd->last);
786 _round_item_del(wd, wd->s_last);
788 _round_item_del(wd, wd->second);
790 _round_item_del(wd, wd->first);
793 EINA_LIST_FOREACH(wd->under_items, l, it)
795 _round_item_del(wd, it);
797 wd->under_items = eina_list_free(wd->under_items);
799 EINA_LIST_FOREACH(wd->over_items, l, it)
801 _round_item_del(wd, it);
803 wd->over_items = eina_list_free(wd->over_items);
807 _round_items_add(Widget_Data *wd)
809 Elm_Diskselector_Item *dit;
810 Elm_Diskselector_Item *it;
811 Elm_Diskselector_Item *temp_it;
813 dit = it = eina_list_nth(wd->items, 0);
818 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
820 wd->first->node = it->node;
821 wd->r_items = eina_list_append(wd->r_items, wd->first);
824 it = eina_list_nth(wd->items, 1);
829 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
831 wd->second->node = it->node;
832 wd->r_items = eina_list_append(wd->r_items, wd->second);
835 // if more than 3 itmes should be displayed
836 for (i = 2; i < CEIL(wd->display_item_num); i++)
838 it = eina_list_nth(wd->items, i);
840 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
841 wd->over_items = eina_list_append(wd->over_items, temp_it);
842 wd->r_items = eina_list_append(wd->r_items, temp_it);
845 it = eina_list_nth(wd->items, wd->item_count - 1);
850 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
852 wd->last->node = it->node;
853 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
856 it = eina_list_nth(wd->items, wd->item_count - 2);
861 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
863 wd->s_last->node = it->node;
864 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
867 // if more than 3 itmes should be displayed
868 for (i = 3; i <= CEIL(wd->display_item_num); i++)
870 it = eina_list_nth(wd->items, wd->item_count - i);
872 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
873 wd->under_items = eina_list_append(wd->under_items, temp_it);
874 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
879 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
881 if (it->icon == icon) return;
883 evas_object_del(it->icon);
887 evas_object_size_hint_min_set(it->icon, 24, 24);
888 evas_object_size_hint_max_set(it->icon, 40, 40);
889 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
890 evas_object_show(it->icon);
891 elm_widget_sub_object_add(WIDGET(it), it->icon);
896 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
899 Elm_Diskselector_Item *dit;
905 wd = elm_widget_data_get(WIDGET(it));
910 // Get index from indentical item from round items
911 EINA_LIST_FOREACH(wd->r_items, l, dit)
913 if (it == dit) break;
918 ic = eina_list_count(wd->r_items);
919 if (idx >= ic) return;
922 // Number of added items: CEIL(wd->display_item_num)
923 ac = CEIL(wd->display_item_num);
925 if (((idx >= 0) && (idx < ac)) ||
926 ((idx >= ac) && (idx < (2 * ac))))
928 // Selected item: under, low region
929 dit = eina_list_nth(wd->r_items,
930 idx + ic - (2 * ac));
932 else if (((idx >= (ic - ac)) && (idx < ic)) ||
933 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
935 // Selected item: over, high region
936 dit = eina_list_nth(wd->r_items,
937 idx - ic + (2 * ac));
940 if(dit) _item_icon_set(dit, icon);
941 _sizing_eval(wd->self);
946 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
948 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
949 Elm_Diskselector_Item *item;
950 if (part && strcmp(part, "default")) return;
951 item = (Elm_Diskselector_Item *) it;
952 eina_stringshare_replace(&item->label, label);
953 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
957 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
959 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
960 if (part && strcmp(part, "default")) return NULL;
961 return ((Elm_Diskselector_Item *) it)->label;
965 _item_content_set_hook(Elm_Object_Item *it,
967 Evas_Object *content)
969 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
970 if (part && strcmp(part, "icon")) return;
971 _item_icon_set((Elm_Diskselector_Item *) it, content);
972 _check_identical_item((Elm_Diskselector_Item *) it, content);
976 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
978 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
979 if (part && strcmp(part, "icon")) return NULL;
980 return ((Elm_Diskselector_Item *) it)->icon;
985 elm_diskselector_add(Evas_Object *parent)
991 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
993 ELM_SET_WIDTYPE(widtype, "diskselector");
994 elm_widget_type_set(obj, "diskselector");
995 elm_widget_sub_object_add(parent, obj);
996 elm_widget_data_set(obj, wd);
997 elm_widget_del_hook_set(obj, _del_hook);
998 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
999 elm_widget_theme_hook_set(obj, _theme_hook);
1000 elm_widget_can_focus_set(obj, EINA_TRUE);
1001 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1002 elm_widget_event_hook_set(obj, _event_hook);
1006 wd->round = EINA_FALSE;
1007 wd->init = EINA_FALSE;
1009 wd->display_item_num_by_api = EINA_FALSE;
1011 wd->scroller = elm_smart_scroller_add(e);
1012 elm_smart_scroller_widget_set(wd->scroller, obj);
1014 elm_widget_resize_object_set(obj, wd->scroller);
1015 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1016 ELM_SMART_SCROLLER_POLICY_OFF);
1017 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1018 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1020 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1021 _scroller_stop_cb, wd);
1022 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1024 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1025 _diskselector_object_resize, obj);
1027 wd->main_box = elm_box_add(parent);
1028 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1029 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1030 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1032 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1034 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1036 elm_widget_sub_object_add(obj, wd->main_box);
1038 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1040 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1041 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1043 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1045 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1047 elm_box_pack_end(wd->main_box, wd->left_blank);
1048 evas_object_show(wd->left_blank);
1050 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1051 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1053 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1055 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1057 elm_box_pack_end(wd->main_box, wd->right_blank);
1058 evas_object_show(wd->right_blank);
1060 _theme_data_get(wd);
1062 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1063 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1069 elm_diskselector_round_get(const Evas_Object *obj)
1071 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1072 Widget_Data *wd = elm_widget_data_get(obj);
1073 if (!wd) return EINA_FALSE;
1078 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
1081 Elm_Diskselector_Item *it;
1083 ELM_CHECK_WIDTYPE(obj, widtype);
1084 Widget_Data *wd = elm_widget_data_get(obj);
1087 if (wd->round == round)
1093 wd->r_items = eina_list_clone(wd->items);
1094 elm_box_unpack(wd->main_box, wd->left_blank);
1095 evas_object_hide(wd->left_blank);
1096 elm_box_unpack(wd->main_box, wd->right_blank);
1097 evas_object_hide(wd->right_blank);
1101 _round_items_add(wd);
1104 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1106 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1108 // if more than 3 items should be displayed
1109 EINA_LIST_FOREACH(wd->under_items, elist, it)
1110 elm_box_pack_start(wd->main_box, VIEW(it));
1113 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1115 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1117 // if more than 3 items should be displayed
1118 EINA_LIST_FOREACH(wd->over_items, elist, it)
1119 elm_box_pack_end(wd->main_box, VIEW(it));
1123 _round_items_del(wd);
1124 elm_box_pack_start(wd->main_box, wd->left_blank);
1125 elm_box_pack_end(wd->main_box, wd->right_blank);
1126 eina_list_free(wd->r_items);
1130 _selected_item_indicate(wd->selected_item);
1135 elm_diskselector_side_label_length_get(const Evas_Object *obj)
1137 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1138 Widget_Data *wd = elm_widget_data_get(obj);
1140 return wd->len_side;
1144 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
1146 ELM_CHECK_WIDTYPE(obj, widtype);
1147 Widget_Data *wd = elm_widget_data_get(obj);
1153 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
1155 return elm_diskselector_side_label_length_set(obj, len);
1159 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1161 return elm_diskselector_side_label_length_get(obj);
1165 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1167 ELM_CHECK_WIDTYPE(obj, widtype);
1168 Widget_Data *wd = elm_widget_data_get(obj);
1171 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1175 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1177 ELM_CHECK_WIDTYPE(obj, widtype);
1178 Widget_Data *wd = elm_widget_data_get(obj);
1180 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1184 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1186 ELM_CHECK_WIDTYPE(obj, widtype);
1187 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1188 Widget_Data *wd = elm_widget_data_get(obj);
1189 if ((!wd) || (!wd->scroller)) return;
1190 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1191 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1192 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1196 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1198 ELM_CHECK_WIDTYPE(obj, widtype);
1199 Widget_Data *wd = elm_widget_data_get(obj);
1200 if ((!wd) || (!wd->scroller)) return;
1201 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1202 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1204 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1208 elm_diskselector_clear(Evas_Object *obj)
1210 ELM_CHECK_WIDTYPE(obj, widtype);
1211 Widget_Data *wd = elm_widget_data_get(obj);
1212 Elm_Diskselector_Item *it;
1215 if (!wd->items) return;
1217 wd->selected_item = NULL;
1218 EINA_LIST_FREE(wd->items, it)
1221 elm_widget_item_free(it);
1223 _round_items_del(wd);
1227 EAPI const Eina_List *
1228 elm_diskselector_items_get(const Evas_Object *obj)
1230 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1231 Widget_Data *wd = elm_widget_data_get(obj);
1232 if (!wd) return NULL;
1236 EAPI Elm_Object_Item *
1237 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1239 Elm_Diskselector_Item *it;
1240 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1241 Widget_Data *wd = elm_widget_data_get(obj);
1242 if (!wd) return NULL;
1244 it = _item_new(obj, icon, label, func, data);
1245 wd->items = eina_list_append(wd->items, it);
1246 it->node = eina_list_last(wd->items);
1250 _round_items_del(wd);
1251 wd->r_items = eina_list_append(wd->r_items, it);
1252 _round_items_add(wd);
1254 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1256 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1257 elm_box_pack_end(wd->main_box, VIEW(it));
1259 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1261 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1265 elm_box_unpack(wd->main_box, wd->right_blank);
1266 elm_box_pack_end(wd->main_box, VIEW(it));
1267 elm_box_pack_end(wd->main_box, wd->right_blank);
1269 if (!wd->selected_item)
1270 wd->selected_item = it;
1272 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1274 return (Elm_Object_Item *) it;
1278 elm_diskselector_item_del(Elm_Object_Item * it)
1280 elm_object_item_del(it);
1284 elm_diskselector_item_label_get(const Elm_Object_Item * it)
1286 return _item_text_get_hook(it, NULL);
1290 elm_diskselector_item_label_set(Elm_Object_Item * it, const char *label)
1292 _item_text_set_hook(it, NULL, label);
1295 EAPI Elm_Object_Item *
1296 elm_diskselector_selected_item_get(const Evas_Object *obj)
1298 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1299 Widget_Data *wd = elm_widget_data_get(obj);
1300 if (!wd) return NULL;
1301 return (Elm_Object_Item *) wd->selected_item;
1305 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1307 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1309 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1310 wd = elm_widget_data_get(WIDGET(item));
1313 if ((wd->selected_item == item) && (selected))
1316 if ((wd->selected_item == item) && (!selected))
1317 wd->selected_item = eina_list_data_get(wd->items);
1320 wd->selected_item = item;
1321 _selected_item_indicate(wd->selected_item);
1325 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1329 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1331 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1332 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1333 if (!wd) return EINA_FALSE;
1334 return (wd->selected_item == ((Elm_Diskselector_Item *) it));
1338 elm_diskselector_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1340 elm_object_item_del_cb_set(it, func);
1344 elm_diskselector_item_data_get(const Elm_Object_Item *it)
1346 return elm_object_item_data_get(it);
1350 elm_diskselector_item_icon_get(const Elm_Object_Item *it)
1352 return _item_content_get_hook(it, NULL);
1356 elm_diskselector_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1358 _item_content_set_hook(it, NULL, icon);
1361 EAPI Elm_Object_Item *
1362 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1364 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1365 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1366 if (item->node->prev) return item->node->prev->data;
1370 EAPI Elm_Object_Item *
1371 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1373 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1374 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1375 if (item->node->next) return item->node->next->data;
1379 EAPI Elm_Object_Item *
1380 elm_diskselector_first_item_get(const Evas_Object *obj)
1382 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1383 Widget_Data *wd = elm_widget_data_get(obj);
1384 if (!wd || !wd->items) return NULL;
1385 return eina_list_data_get(wd->items);
1388 EAPI Elm_Object_Item *
1389 elm_diskselector_last_item_get(const Evas_Object *obj)
1391 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1392 Widget_Data *wd = elm_widget_data_get(obj);
1393 if (!wd || !wd->items) return NULL;
1394 return eina_list_data_get(eina_list_last(wd->items));
1398 elm_diskselector_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1400 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1401 elm_widget_item_tooltip_text_set(it, text);
1405 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)
1407 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1408 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1412 elm_diskselector_item_tooltip_unset(Elm_Object_Item *it)
1414 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1415 elm_widget_item_tooltip_unset(it);
1419 elm_diskselector_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1421 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1422 elm_widget_item_tooltip_style_set(it, style);
1426 elm_diskselector_item_tooltip_style_get(const Elm_Object_Item *it)
1428 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1429 return elm_widget_item_tooltip_style_get(it);
1433 elm_diskselector_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1435 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1436 elm_widget_item_cursor_set(it, cursor);
1440 elm_diskselector_item_cursor_get(const Elm_Object_Item *it)
1442 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1443 return elm_widget_item_cursor_get(it);
1447 elm_diskselector_item_cursor_unset(Elm_Object_Item *it)
1449 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1450 elm_widget_item_cursor_unset(it);
1454 elm_diskselector_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1456 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1457 elm_widget_item_cursor_style_set(it, style);
1461 elm_diskselector_item_cursor_style_get(const Elm_Object_Item *it)
1463 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1464 return elm_widget_item_cursor_style_get(it);
1468 elm_diskselector_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1470 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1471 elm_widget_item_cursor_engine_only_set(it, engine_only);
1475 elm_diskselector_item_cursor_engine_only_get(const Elm_Object_Item *it)
1477 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1478 return elm_widget_item_cursor_engine_only_get(it);
1482 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1484 ELM_CHECK_WIDTYPE(obj, widtype);
1485 Widget_Data *wd = elm_widget_data_get(obj);
1487 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1488 wd->display_item_num = num;
1489 wd->display_item_num_by_api = EINA_TRUE;
1493 elm_diskselector_display_item_num_get(const Evas_Object *item)
1495 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1496 Widget_Data *wd = elm_widget_data_get(item);
1498 return wd->display_item_num;