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)
233 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
235 >>>>>>> remotes/origin/upstream
236 Elm_Diskselector_Item *item, *item2, *dit;
241 item = (Elm_Diskselector_Item *) it;
243 item = (Elm_Diskselector_Item *)it;
244 >>>>>>> remotes/origin/upstream
245 wd = elm_widget_data_get(WIDGET(item));
246 if (!wd) return EINA_FALSE;
248 elm_box_unpack(wd->main_box, VIEW(item));
251 wd->r_items = eina_list_remove(wd->r_items, item);
253 wd->items = eina_list_remove(wd->items, item);
255 if (wd->selected_item == item)
257 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
259 wd->selected_item = dit;
261 wd->selected_item = eina_list_nth(wd->items, 1);
263 _selected_item_indicate(wd->selected_item);
273 evas_object_hide(wd->VIEW(first));
274 evas_object_hide(wd->VIEW(second));
275 evas_object_hide(wd->VIEW(last));
276 evas_object_hide(wd->VIEW(s_last));
278 EINA_LIST_FOREACH(wd->under_items, l, item2)
279 evas_object_hide(VIEW(item2));
281 EINA_LIST_FOREACH(wd->over_items, l, item2)
282 evas_object_hide(VIEW(item2));
286 dit = eina_list_nth(wd->items, 0);
289 eina_stringshare_replace(&wd->first->label, dit->label);
290 edje_object_part_text_set(wd->VIEW(first), "elm.text",
293 dit = eina_list_nth(wd->items, 1);
296 eina_stringshare_replace(&wd->second->label, dit->label);
297 edje_object_part_text_set(wd->VIEW(second), "elm.text",
300 // if more than 3 itmes should be displayed
301 for (i = 2; i < CEIL(wd->display_item_num); i++)
303 dit = eina_list_nth(wd->items, i);
304 item2 = eina_list_nth(wd->over_items, i - 2);
305 eina_stringshare_replace(&item2->label, dit->label);
306 edje_object_part_text_set(VIEW(item2), "elm.text", item2->label);
309 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
312 eina_stringshare_replace(&wd->last->label, dit->label);
313 edje_object_part_text_set(wd->VIEW(last), "elm.text",
316 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
319 eina_stringshare_replace(&wd->s_last->label, dit->label);
320 edje_object_part_text_set(wd->VIEW(s_last), "elm.text",
323 // if more than 3 itmes should be displayed
324 for (i = 3; i <= CEIL(wd->display_item_num); i++)
326 dit = eina_list_nth(wd->items, wd->item_count - i);
327 item2 = eina_list_nth(wd->under_items, i - 3);
328 eina_stringshare_replace(&item2->label, dit->label);
329 edje_object_part_text_set(VIEW(item2), "elm.text",
334 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
335 _sizing_eval(wd->self);
340 static Elm_Diskselector_Item *
341 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
343 Elm_Diskselector_Item *it;
344 const char *style = elm_widget_style_get(obj);
346 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
347 if (!it) return NULL;
349 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
350 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
351 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
352 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
353 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
355 it->label = eina_stringshare_add(label);
358 it->base.data = data;
359 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
360 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item", style);
361 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND,
363 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL,
365 evas_object_show(VIEW(it));
369 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
370 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "", _item_click_cb, it);
374 evas_object_size_hint_min_set(it->icon, 24, 24);
375 evas_object_size_hint_max_set(it->icon, 40, 40);
376 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
377 evas_object_show(it->icon);
378 elm_widget_sub_object_add(obj, it->icon);
384 _theme_data_get(Widget_Data *wd)
390 >>>>>>> remotes/origin/upstream
391 str = edje_object_data_get(wd->right_blank, "len_threshold");
392 if (str) wd->len_threshold = MAX(0, atoi(str));
393 else wd->len_threshold = 0;
395 if (!wd->display_item_num_by_api)
397 str = edje_object_data_get(wd->right_blank, "display_item_num");
398 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
399 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
402 str = edje_object_data_get(wd->right_blank, "min_width");
404 if (str) wd->minw = MAX(-1, atoi(str)) * elm_scale_get();
407 parent = elm_widget_parent_widget_get(wd->self);
408 if (!parent) wd->minw = -1;
409 else evas_object_geometry_get(parent, NULL, NULL, &wd->minw, NULL);
412 str = edje_object_data_get(wd->right_blank, "min_height");
413 if (str) wd->minh = MAX(-1, atoi(str)) * elm_scale_get();
415 if (str) wd->minw = MAX(-1, atoi(str));
418 str = edje_object_data_get(wd->right_blank, "min_height");
419 if (str) wd->minh = MAX(-1, atoi(str));
420 >>>>>>> remotes/origin/upstream
425 _del_hook(Evas_Object * obj)
427 Widget_Data *wd = elm_widget_data_get(obj);
433 _del_pre_hook(Evas_Object * obj)
435 Elm_Diskselector_Item *it;
438 Widget_Data *wd = elm_widget_data_get(obj);
442 evas_object_del(wd->left_blank);
444 evas_object_del(wd->right_blank);
447 eina_stringshare_del(wd->last->label);
448 evas_object_del(wd->VIEW(last));
453 eina_stringshare_del(wd->s_last->label);
454 evas_object_del(wd->VIEW(s_last));
459 eina_stringshare_del(wd->second->label);
460 evas_object_del(wd->VIEW(second));
465 eina_stringshare_del(wd->first->label);
466 evas_object_del(wd->VIEW(first));
470 EINA_LIST_FOREACH(wd->under_items, l, it)
474 eina_stringshare_del(it->label);
475 evas_object_del(VIEW(it));
480 EINA_LIST_FOREACH(wd->over_items, l, it)
484 eina_stringshare_del(it->label);
485 evas_object_del(VIEW(it));
490 EINA_LIST_FREE(wd->items, it)
493 elm_widget_item_free(it);
495 eina_list_free(wd->r_items);
499 _sizing_eval(Evas_Object * obj)
501 Widget_Data *wd = elm_widget_data_get(obj);
503 _diskselector_object_resize(obj, NULL, obj, NULL);
507 _theme_hook(Evas_Object * obj)
510 Elm_Diskselector_Item *it;
511 Widget_Data *wd = elm_widget_data_get(obj);
515 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
516 "base", elm_widget_style_get(obj));
519 EINA_LIST_FOREACH(wd->r_items, l, it)
521 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
522 elm_widget_style_get(obj));
523 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
528 EINA_LIST_FOREACH(wd->items, l, it)
530 _elm_theme_object_set(obj, VIEW(it), "diskselector", "item",
531 elm_widget_style_get(obj));
532 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
535 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
536 elm_widget_style_get(obj));
542 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
544 Widget_Data *wd = elm_widget_data_get(obj);
545 Evas_Object *sub = event_info;
546 Elm_Diskselector_Item *it;
551 if (sub == wd->scroller)
555 EINA_LIST_FOREACH(wd->items, l, it)
568 _select_item(Elm_Diskselector_Item *it)
571 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
572 wd->selected_item = it;
573 _selected_item_indicate(wd->selected_item);
574 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
575 evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
579 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
581 Widget_Data *wd = elm_widget_data_get(obj);
585 if (elm_widget_focus_get(obj))
587 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
588 evas_object_focus_set(wd->self, EINA_TRUE);
592 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
593 evas_object_focus_set(wd->self, EINA_FALSE);
598 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
600 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
601 Evas_Event_Key_Down *ev = event_info;
602 Widget_Data *wd = elm_widget_data_get(obj);
603 if (!wd) return EINA_FALSE;
604 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
605 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
607 Elm_Diskselector_Item *it = NULL;
610 if (!wd->selected_item) {
611 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
615 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
616 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
618 l = wd->selected_item->node->prev;
619 if ((!l) && (wd->round))
620 l = eina_list_last(wd->items);
622 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
623 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
625 l = wd->selected_item->node->next;
626 if ((!l) && (wd->round))
629 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
631 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
632 l = eina_list_last(wd->items);
633 else return EINA_FALSE;
636 it = eina_list_data_get(l);
640 wd->selected_item = it;
642 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
645 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
650 _selected_item_indicate(Elm_Diskselector_Item *it)
652 Elm_Diskselector_Item *item;
655 wd = elm_widget_data_get(WIDGET(it));
659 EINA_LIST_FOREACH(wd->r_items, l, item)
661 if (!strcmp(item->label, it->label)) edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
663 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
668 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
669 const char *emission __UNUSED__, const char *source __UNUSED__)
671 Elm_Diskselector_Item *it = data;
676 wd = elm_widget_data_get(WIDGET(it));
680 if (wd->selected_item != it)
682 wd->selected_item = it;
683 _selected_item_indicate(wd->selected_item);
686 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
690 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
692 Evas_Coord x, y, w, h, bw;
693 Widget_Data *wd = data;
696 elm_smart_scroller_child_pos_get(obj, &x, &y);
697 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
700 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
701 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
702 elm_smart_scroller_child_region_show(wd->scroller,
703 x - ((w / wd->display_item_num) * wd->item_count),
706 elm_smart_scroller_child_region_show(wd->scroller,
707 x + ((w / wd->display_item_num) * wd->item_count),
713 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
715 Elm_Diskselector_Item *it;
716 Widget_Data *wd = data;
720 if (wd->idler) return;
727 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
728 EINA_LIST_FOREACH(list, l, it)
730 evas_object_geometry_get(VIEW(it), &x, NULL, &w, NULL);
731 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10) break;
739 _move_scroller(void *data)
741 Evas_Object *obj = data;
744 Elm_Diskselector_Item *dit;
748 wd = elm_widget_data_get(obj);
749 if (!wd) return EINA_FALSE;
762 EINA_LIST_FOREACH(list, l, dit)
764 if (wd->selected_item == dit)
769 if (wd->round) i -= CEIL(wd->display_item_num);
774 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
778 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
780 //move scroller in two steps for getting smooth launching effect.
782 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * (i-2), y, w, h);
783 elm_smart_scroller_region_bring_in(wd->scroller, w / wd->display_item_num * i, y, w, h);
786 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
787 >>>>>>> remotes/origin/upstream
791 ecore_idle_enterer_del(wd->idler);
794 wd->init = EINA_TRUE;
801 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
804 elm_box_unpack(wd->main_box, VIEW(it));
805 wd->r_items = eina_list_remove(wd->r_items, it);
806 eina_stringshare_del(it->label);
807 elm_widget_item_free(it);
811 _round_items_del(Widget_Data *wd)
814 Elm_Diskselector_Item * it;
816 _round_item_del(wd, wd->last);
818 _round_item_del(wd, wd->s_last);
820 _round_item_del(wd, wd->second);
822 _round_item_del(wd, wd->first);
825 EINA_LIST_FOREACH(wd->under_items, l, it)
827 _round_item_del(wd, it);
829 wd->under_items = eina_list_free(wd->under_items);
831 EINA_LIST_FOREACH(wd->over_items, l, it)
833 _round_item_del(wd, it);
835 wd->over_items = eina_list_free(wd->over_items);
839 _round_items_add(Widget_Data *wd)
841 Elm_Diskselector_Item *dit;
842 Elm_Diskselector_Item *it;
843 Elm_Diskselector_Item *temp_it;
845 dit = it = eina_list_nth(wd->items, 0);
850 wd->first = _item_new(WIDGET(it), it->icon, it->label, it->func,
852 wd->first->node = it->node;
853 wd->r_items = eina_list_append(wd->r_items, wd->first);
856 it = eina_list_nth(wd->items, 1);
861 wd->second = _item_new(WIDGET(it), it->icon, it->label, it->func,
863 wd->second->node = it->node;
864 wd->r_items = eina_list_append(wd->r_items, wd->second);
867 // if more than 3 itmes should be displayed
868 for (i = 2; i < CEIL(wd->display_item_num); i++)
870 it = eina_list_nth(wd->items, i);
872 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
873 wd->over_items = eina_list_append(wd->over_items, temp_it);
874 wd->r_items = eina_list_append(wd->r_items, temp_it);
877 it = eina_list_nth(wd->items, wd->item_count - 1);
882 wd->last = _item_new(WIDGET(it), it->icon, it->label, it->func,
884 wd->last->node = it->node;
885 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
888 it = eina_list_nth(wd->items, wd->item_count - 2);
893 wd->s_last = _item_new(WIDGET(it), it->icon, it->label, it->func,
895 wd->s_last->node = it->node;
896 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
899 // if more than 3 itmes should be displayed
900 for (i = 3; i <= CEIL(wd->display_item_num); i++)
902 it = eina_list_nth(wd->items, wd->item_count - i);
904 temp_it = _item_new(WIDGET(it), it->icon, it->label, it->func, it->base.data);
905 wd->under_items = eina_list_append(wd->under_items, temp_it);
906 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
911 _item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
913 if (it->icon == icon) return;
915 evas_object_del(it->icon);
919 evas_object_size_hint_min_set(it->icon, 24, 24);
920 evas_object_size_hint_max_set(it->icon, 40, 40);
921 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
922 evas_object_show(it->icon);
923 elm_widget_sub_object_add(WIDGET(it), it->icon);
928 _check_identical_item(Elm_Diskselector_Item *it, Evas_Object *icon)
931 Elm_Diskselector_Item *dit;
937 wd = elm_widget_data_get(WIDGET(it));
942 // Get index from indentical item from round items
943 EINA_LIST_FOREACH(wd->r_items, l, dit)
945 if (it == dit) break;
950 ic = eina_list_count(wd->r_items);
951 if (idx >= ic) return;
954 // Number of added items: CEIL(wd->display_item_num)
955 ac = CEIL(wd->display_item_num);
957 if (((idx >= 0) && (idx < ac)) ||
958 ((idx >= ac) && (idx < (2 * ac))))
960 // Selected item: under, low region
961 dit = eina_list_nth(wd->r_items,
962 idx + ic - (2 * ac));
964 else if (((idx >= (ic - ac)) && (idx < ic)) ||
965 ((idx >= (ic - (2 * ac))) && (idx < ic - ac)))
967 // Selected item: over, high region
968 dit = eina_list_nth(wd->r_items,
969 idx - ic + (2 * ac));
972 if(dit) _item_icon_set(dit, icon);
973 _sizing_eval(wd->self);
978 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
981 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
982 Elm_Diskselector_Item *item;
983 if (part && strcmp(part, "default")) return;
984 item = (Elm_Diskselector_Item *) it;
986 Elm_Diskselector_Item *item;
987 if (part && strcmp(part, "default")) return;
988 item = (Elm_Diskselector_Item *)it;
989 >>>>>>> remotes/origin/upstream
990 eina_stringshare_replace(&item->label, label);
991 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
995 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
998 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
999 if (part && strcmp(part, "default")) return NULL;
1000 return ((Elm_Diskselector_Item *) it)->label;
1002 if (part && strcmp(part, "default")) return NULL;
1003 return ((Elm_Diskselector_Item *)it)->label;
1004 >>>>>>> remotes/origin/upstream
1008 _item_content_set_hook(Elm_Object_Item *it,
1010 Evas_Object *content)
1013 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1014 if (part && strcmp(part, "icon")) return;
1015 _item_icon_set((Elm_Diskselector_Item *) it, content);
1016 _check_identical_item((Elm_Diskselector_Item *) it, content);
1018 if (part && strcmp(part, "icon")) return;
1019 _item_icon_set((Elm_Diskselector_Item *)it, content);
1020 _check_identical_item((Elm_Diskselector_Item *)it, content);
1021 >>>>>>> remotes/origin/upstream
1024 static Evas_Object *
1025 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1028 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1029 if (part && strcmp(part, "icon")) return NULL;
1030 return ((Elm_Diskselector_Item *) it)->icon;
1034 if (part && strcmp(part, "icon")) return NULL;
1035 return ((Elm_Diskselector_Item *)it)->icon;
1039 >>>>>>> remotes/origin/upstream
1041 elm_diskselector_add(Evas_Object *parent)
1047 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1049 ELM_SET_WIDTYPE(widtype, "diskselector");
1050 elm_widget_type_set(obj, "diskselector");
1051 elm_widget_sub_object_add(parent, obj);
1052 elm_widget_data_set(obj, wd);
1053 elm_widget_del_hook_set(obj, _del_hook);
1054 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1055 elm_widget_theme_hook_set(obj, _theme_hook);
1056 elm_widget_can_focus_set(obj, EINA_TRUE);
1057 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1058 elm_widget_event_hook_set(obj, _event_hook);
1062 wd->round = EINA_FALSE;
1063 wd->init = EINA_FALSE;
1065 wd->display_item_num_by_api = EINA_FALSE;
1067 wd->scroller = elm_smart_scroller_add(e);
1068 elm_smart_scroller_widget_set(wd->scroller, obj);
1070 elm_widget_resize_object_set(obj, wd->scroller);
1071 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
1072 ELM_SMART_SCROLLER_POLICY_OFF);
1073 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
1074 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
1076 evas_object_smart_callback_add(wd->scroller, "animate,stop",
1077 _scroller_stop_cb, wd);
1078 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
1080 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
1081 _diskselector_object_resize, obj);
1083 wd->main_box = elm_box_add(parent);
1084 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
1085 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
1086 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
1088 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
1090 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
1092 elm_widget_sub_object_add(obj, wd->main_box);
1094 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
1096 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
1097 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
1099 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
1101 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
1103 elm_box_pack_end(wd->main_box, wd->left_blank);
1104 evas_object_show(wd->left_blank);
1106 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
1107 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
1109 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
1111 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
1113 elm_box_pack_end(wd->main_box, wd->right_blank);
1114 evas_object_show(wd->right_blank);
1116 _theme_data_get(wd);
1118 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1119 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1126 elm_diskselector_round_get(const Evas_Object *obj)
1128 elm_diskselector_round_enabled_get(const Evas_Object *obj)
1129 >>>>>>> remotes/origin/upstream
1131 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1132 Widget_Data *wd = elm_widget_data_get(obj);
1133 if (!wd) return EINA_FALSE;
1139 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
1141 elm_diskselector_round_enabled_set(Evas_Object * obj, Eina_Bool enabled)
1142 >>>>>>> remotes/origin/upstream
1145 Elm_Diskselector_Item *it;
1147 ELM_CHECK_WIDTYPE(obj, widtype);
1148 Widget_Data *wd = elm_widget_data_get(obj);
1152 if (wd->round == round)
1158 if (wd->round == enabled)
1161 wd->round = !!enabled;
1163 >>>>>>> remotes/origin/upstream
1165 wd->r_items = eina_list_clone(wd->items);
1166 elm_box_unpack(wd->main_box, wd->left_blank);
1167 evas_object_hide(wd->left_blank);
1168 elm_box_unpack(wd->main_box, wd->right_blank);
1169 evas_object_hide(wd->right_blank);
1173 _round_items_add(wd);
1176 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1178 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1180 // if more than 3 items should be displayed
1181 EINA_LIST_FOREACH(wd->under_items, elist, it)
1182 elm_box_pack_start(wd->main_box, VIEW(it));
1185 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1187 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1189 // if more than 3 items should be displayed
1190 EINA_LIST_FOREACH(wd->over_items, elist, it)
1191 elm_box_pack_end(wd->main_box, VIEW(it));
1195 _round_items_del(wd);
1196 elm_box_pack_start(wd->main_box, wd->left_blank);
1197 elm_box_pack_end(wd->main_box, wd->right_blank);
1198 eina_list_free(wd->r_items);
1202 _selected_item_indicate(wd->selected_item);
1208 elm_diskselector_side_label_length_get(const Evas_Object *obj)
1210 elm_diskselector_side_text_max_length_get(const Evas_Object *obj)
1211 >>>>>>> remotes/origin/upstream
1213 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1214 Widget_Data *wd = elm_widget_data_get(obj);
1216 return wd->len_side;
1221 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
1223 elm_diskselector_side_text_max_length_set(Evas_Object *obj, int len)
1224 >>>>>>> remotes/origin/upstream
1226 ELM_CHECK_WIDTYPE(obj, widtype);
1227 Widget_Data *wd = elm_widget_data_get(obj);
1234 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
1236 return elm_diskselector_side_label_length_set(obj, len);
1240 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
1242 return elm_diskselector_side_label_length_get(obj);
1247 >>>>>>> remotes/origin/upstream
1248 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1250 ELM_CHECK_WIDTYPE(obj, widtype);
1251 Widget_Data *wd = elm_widget_data_get(obj);
1254 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
1258 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1260 ELM_CHECK_WIDTYPE(obj, widtype);
1261 Widget_Data *wd = elm_widget_data_get(obj);
1263 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
1267 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1269 ELM_CHECK_WIDTYPE(obj, widtype);
1270 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1271 Widget_Data *wd = elm_widget_data_get(obj);
1272 if ((!wd) || (!wd->scroller)) return;
1273 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
1274 *policy_h = (Elm_Scroller_Policy) s_policy_h;
1275 *policy_v = (Elm_Scroller_Policy) s_policy_v;
1279 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1281 ELM_CHECK_WIDTYPE(obj, widtype);
1282 Widget_Data *wd = elm_widget_data_get(obj);
1283 if ((!wd) || (!wd->scroller)) return;
1284 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1285 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1287 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
1291 elm_diskselector_clear(Evas_Object *obj)
1293 ELM_CHECK_WIDTYPE(obj, widtype);
1294 Widget_Data *wd = elm_widget_data_get(obj);
1295 Elm_Diskselector_Item *it;
1298 if (!wd->items) return;
1300 wd->selected_item = NULL;
1301 EINA_LIST_FREE(wd->items, it)
1304 elm_widget_item_free(it);
1306 _round_items_del(wd);
1310 EAPI const Eina_List *
1311 elm_diskselector_items_get(const Evas_Object *obj)
1313 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1314 Widget_Data *wd = elm_widget_data_get(obj);
1315 if (!wd) return NULL;
1319 EAPI Elm_Object_Item *
1320 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1322 Elm_Diskselector_Item *it;
1323 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1324 Widget_Data *wd = elm_widget_data_get(obj);
1325 if (!wd) return NULL;
1327 it = _item_new(obj, icon, label, func, data);
1328 wd->items = eina_list_append(wd->items, it);
1329 it->node = eina_list_last(wd->items);
1333 _round_items_del(wd);
1334 wd->r_items = eina_list_append(wd->r_items, it);
1335 _round_items_add(wd);
1337 elm_box_pack_start(wd->main_box, wd->VIEW(last));
1339 elm_box_pack_start(wd->main_box, wd->VIEW(s_last));
1340 elm_box_pack_end(wd->main_box, VIEW(it));
1342 elm_box_pack_end(wd->main_box, wd->VIEW(first));
1344 elm_box_pack_end(wd->main_box, wd->VIEW(second));
1348 elm_box_unpack(wd->main_box, wd->right_blank);
1349 elm_box_pack_end(wd->main_box, VIEW(it));
1350 elm_box_pack_end(wd->main_box, wd->right_blank);
1352 if (!wd->selected_item)
1353 wd->selected_item = it;
1355 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1358 return (Elm_Object_Item *) it;
1362 elm_diskselector_item_del(Elm_Object_Item * it)
1364 elm_object_item_del(it);
1368 elm_diskselector_item_label_get(const Elm_Object_Item * it)
1370 return _item_text_get_hook(it, NULL);
1374 elm_diskselector_item_label_set(Elm_Object_Item * it, const char *label)
1376 _item_text_set_hook(it, NULL, label);
1378 return (Elm_Object_Item *)it;
1379 >>>>>>> remotes/origin/upstream
1382 EAPI Elm_Object_Item *
1383 elm_diskselector_selected_item_get(const Evas_Object *obj)
1385 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1386 Widget_Data *wd = elm_widget_data_get(obj);
1387 if (!wd) return NULL;
1388 return (Elm_Object_Item *) wd->selected_item;
1392 elm_diskselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1394 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1397 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1399 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1400 >>>>>>> remotes/origin/upstream
1401 wd = elm_widget_data_get(WIDGET(item));
1404 if ((wd->selected_item == item) && (selected))
1407 if ((wd->selected_item == item) && (!selected))
1408 wd->selected_item = eina_list_data_get(wd->items);
1411 wd->selected_item = item;
1412 _selected_item_indicate(wd->selected_item);
1416 wd->idler = ecore_idle_enterer_before_add(_move_scroller, WIDGET(item));
1420 elm_diskselector_item_selected_get(const Elm_Object_Item *it)
1422 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1423 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1424 if (!wd) return EINA_FALSE;
1426 return (wd->selected_item == ((Elm_Diskselector_Item *) it));
1430 elm_diskselector_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1432 elm_object_item_del_cb_set(it, func);
1436 elm_diskselector_item_data_get(const Elm_Object_Item *it)
1438 return elm_object_item_data_get(it);
1442 elm_diskselector_item_icon_get(const Elm_Object_Item *it)
1444 return _item_content_get_hook(it, NULL);
1448 elm_diskselector_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1450 _item_content_set_hook(it, NULL, icon);
1452 return (wd->selected_item == ((Elm_Diskselector_Item *)it));
1453 >>>>>>> remotes/origin/upstream
1456 EAPI Elm_Object_Item *
1457 elm_diskselector_item_prev_get(const Elm_Object_Item *it)
1459 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1461 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1463 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1464 >>>>>>> remotes/origin/upstream
1465 if (item->node->prev) return item->node->prev->data;
1469 EAPI Elm_Object_Item *
1470 elm_diskselector_item_next_get(const Elm_Object_Item *it)
1472 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1474 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *) it;
1476 Elm_Diskselector_Item *item = (Elm_Diskselector_Item *)it;
1477 >>>>>>> remotes/origin/upstream
1478 if (item->node->next) return item->node->next->data;
1482 EAPI Elm_Object_Item *
1483 elm_diskselector_first_item_get(const Evas_Object *obj)
1485 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1486 Widget_Data *wd = elm_widget_data_get(obj);
1487 if (!wd || !wd->items) return NULL;
1488 return eina_list_data_get(wd->items);
1491 EAPI Elm_Object_Item *
1492 elm_diskselector_last_item_get(const Evas_Object *obj)
1494 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1495 Widget_Data *wd = elm_widget_data_get(obj);
1496 if (!wd || !wd->items) return NULL;
1497 return eina_list_data_get(eina_list_last(wd->items));
1502 elm_diskselector_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1504 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1505 elm_widget_item_tooltip_text_set(it, text);
1509 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)
1511 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1512 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1516 elm_diskselector_item_tooltip_unset(Elm_Object_Item *it)
1518 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1519 elm_widget_item_tooltip_unset(it);
1523 elm_diskselector_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1525 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1526 elm_widget_item_tooltip_style_set(it, style);
1530 elm_diskselector_item_tooltip_style_get(const Elm_Object_Item *it)
1532 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1533 return elm_widget_item_tooltip_style_get(it);
1537 elm_diskselector_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1539 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1540 elm_widget_item_cursor_set(it, cursor);
1544 elm_diskselector_item_cursor_get(const Elm_Object_Item *it)
1546 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1547 return elm_widget_item_cursor_get(it);
1551 elm_diskselector_item_cursor_unset(Elm_Object_Item *it)
1553 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1554 elm_widget_item_cursor_unset(it);
1558 elm_diskselector_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1560 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1561 elm_widget_item_cursor_style_set(it, style);
1565 elm_diskselector_item_cursor_style_get(const Elm_Object_Item *it)
1567 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1568 return elm_widget_item_cursor_style_get(it);
1572 elm_diskselector_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1574 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1575 elm_widget_item_cursor_engine_only_set(it, engine_only);
1579 elm_diskselector_item_cursor_engine_only_get(const Elm_Object_Item *it)
1581 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1582 return elm_widget_item_cursor_engine_only_get(it);
1587 >>>>>>> remotes/origin/upstream
1588 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1590 ELM_CHECK_WIDTYPE(obj, widtype);
1591 Widget_Data *wd = elm_widget_data_get(obj);
1593 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1594 wd->display_item_num = num;
1595 wd->display_item_num_by_api = EINA_TRUE;
1599 elm_diskselector_display_item_num_get(const Evas_Object *item)
1601 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1602 Widget_Data *wd = elm_widget_data_get(item);
1604 return wd->display_item_num;