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;
20 Evas_Object *scroller;
21 Evas_Object *main_box;
22 Evas_Object *left_blank;
23 Evas_Object *right_blank;
24 Elm_Diskselector_Item *selected_item;
25 Elm_Diskselector_Item *first;
26 Elm_Diskselector_Item *second;
27 Elm_Diskselector_Item *s_last;
28 Elm_Diskselector_Item *last;
31 Eina_List *over_items;
32 Eina_List *under_items;
33 int item_count, len_threshold, len_side, display_item_num;
34 Ecore_Idle_Enterer *idler;
35 Ecore_Idle_Enterer *check_idler;
36 Evas_Coord minw, minh;
39 Eina_Bool display_item_num_by_api:1;
42 struct _Elm_Diskselector_Item
51 static const char *widtype = NULL;
53 #define ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, ...) \
54 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
55 ELM_CHECK_WIDTYPE(it->base.widget, widtype) __VA_ARGS__;
57 static Eina_Bool _move_scroller(void *data);
58 static void _del_hook(Evas_Object * obj);
59 static void _del_pre_hook(Evas_Object * obj);
60 static void _sizing_eval(Evas_Object * obj);
61 static void _theme_hook(Evas_Object * obj);
62 static void _on_focus_hook(void *data, Evas_Object *obj);
63 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
64 static void _sub_del(void *data, Evas_Object * obj, void *event_info);
65 static void _round_items_del(Widget_Data *wd);
66 static void _scroller_move_cb(void *data, Evas_Object *obj, void *event_info);
67 static void _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
68 const char *emission __UNUSED__,
69 const char *source __UNUSED__);
70 static void _selected_item_indicate(Elm_Diskselector_Item *it);
72 static const char SIG_SELECTED[] = "selected";
73 static const Evas_Smart_Cb_Description _signals[] = {
79 _diskselector_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
84 wd = elm_widget_data_get(data);
87 if ((wd->minw == -1) && (wd->minh == -1))
88 elm_coords_finger_size_adjust(6, &wd->minw, 1, &wd->minh);
89 edje_object_size_min_restricted_calc
90 (elm_smart_scroller_edje_object_get
91 (wd->scroller), &wd->minw, &wd->minh, wd->minw, wd->minh);
92 evas_object_size_hint_min_set(obj, wd->minw, wd->minh);
93 evas_object_size_hint_max_set(obj, -1, -1);
95 evas_object_geometry_get(wd->scroller, NULL, NULL, &w, &h);
97 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + (CEIL(wd->display_item_num) * 2)), h);
99 evas_object_resize(wd->main_box, (w / wd->display_item_num) * (wd->item_count + CEIL(wd->display_item_num)), h);
101 elm_smart_scroller_paging_set(wd->scroller, 0, 0,
102 (int)(w / wd->display_item_num), 0);
105 wd->idler = ecore_idle_enterer_before_add(_move_scroller, data);
108 static Elm_Diskselector_Item *
109 _item_new(Evas_Object *obj, Evas_Object *icon, const char *label, Evas_Smart_Cb func, const void *data)
111 Elm_Diskselector_Item *it;
112 const char *style = elm_widget_style_get(obj);
114 it = elm_widget_item_new(obj, Elm_Diskselector_Item);
115 if (!it) return NULL;
117 it->label = eina_stringshare_add(label);
120 it->base.data = data;
121 it->base.view = edje_object_add(evas_object_evas_get(obj));
122 _elm_theme_object_set(obj, it->base.view, "diskselector", "item", style);
123 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND,
125 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL,
127 evas_object_show(it->base.view);
131 edje_object_part_text_set(it->base.view, "elm.text", it->label);
132 edje_object_signal_callback_add(it->base.view, "elm,action,click", "", _item_click_cb, it);
136 evas_object_size_hint_min_set(it->icon, 24, 24);
137 evas_object_size_hint_max_set(it->icon, 40, 40);
138 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
139 evas_object_show(it->icon);
140 elm_widget_sub_object_add(obj, it->icon);
146 _item_del(Elm_Diskselector_Item *item)
149 eina_stringshare_del(item->label);
151 evas_object_del(item->icon);
152 elm_widget_item_del(item);
156 _theme_data_get(Widget_Data *wd)
159 str = edje_object_data_get(wd->right_blank, "len_threshold");
160 if (str) wd->len_threshold = MAX(0, atoi(str));
161 else wd->len_threshold = 0;
163 if (!wd->display_item_num_by_api)
165 str = edje_object_data_get(wd->right_blank, "display_item_num");
166 if (str) wd->display_item_num = MAX(DISPLAY_ITEM_NUM_MIN, atoi(str));
167 else wd->display_item_num = DISPLAY_ITEM_NUM_MIN;
170 str = edje_object_data_get(wd->right_blank, "min_width");
171 if (str) wd->minw = MAX(-1, atoi(str));
174 str = edje_object_data_get(wd->right_blank, "min_height");
175 if (str) wd->minh = MAX(-1, atoi(str));
180 _del_hook(Evas_Object * obj)
182 Widget_Data *wd = elm_widget_data_get(obj);
188 _del_pre_hook(Evas_Object * obj)
190 Elm_Diskselector_Item *it;
193 Widget_Data *wd = elm_widget_data_get(obj);
197 evas_object_del(wd->left_blank);
199 evas_object_del(wd->right_blank);
202 eina_stringshare_del(wd->last->label);
203 evas_object_del(wd->last->base.view);
208 eina_stringshare_del(wd->s_last->label);
209 evas_object_del(wd->s_last->base.view);
214 eina_stringshare_del(wd->second->label);
215 evas_object_del(wd->second->base.view);
220 eina_stringshare_del(wd->first->label);
221 evas_object_del(wd->first->base.view);
225 EINA_LIST_FOREACH(wd->under_items, l, it)
229 eina_stringshare_del(it->label);
230 evas_object_del(it->base.view);
235 EINA_LIST_FOREACH(wd->over_items, l, it)
239 eina_stringshare_del(it->label);
240 evas_object_del(it->base.view);
245 EINA_LIST_FREE(wd->items, it) _item_del(it);
246 eina_list_free(wd->r_items);
250 _sizing_eval(Evas_Object * obj)
252 Widget_Data *wd = elm_widget_data_get(obj);
254 _diskselector_object_resize(obj, NULL, obj, NULL);
258 _theme_hook(Evas_Object * obj)
261 Elm_Diskselector_Item *it;
262 Widget_Data *wd = elm_widget_data_get(obj);
266 elm_smart_scroller_object_theme_set(obj, wd->scroller, "diskselector",
267 "base", elm_widget_style_get(obj));
270 EINA_LIST_FOREACH(wd->r_items, l, it)
272 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
273 elm_widget_style_get(obj));
274 edje_object_part_text_set(it->base.view, "elm.text", it->label);
279 EINA_LIST_FOREACH(wd->items, l, it)
281 _elm_theme_object_set(obj, it->base.view, "diskselector", "item",
282 elm_widget_style_get(obj));
283 edje_object_part_text_set(it->base.view, "elm.text", it->label);
286 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
287 elm_widget_style_get(obj));
293 _sub_del(void *data __UNUSED__, Evas_Object * obj, void *event_info)
295 Widget_Data *wd = elm_widget_data_get(obj);
296 Evas_Object *sub = event_info;
297 Elm_Diskselector_Item *it;
302 if (sub == wd->scroller)
306 EINA_LIST_FOREACH(wd->items, l, it)
319 _select_item(Elm_Diskselector_Item *it)
322 Widget_Data *wd = elm_widget_data_get(it->base.widget);
323 wd->selected_item = it;
324 _selected_item_indicate(wd->selected_item);
325 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
326 evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
330 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
332 Widget_Data *wd = elm_widget_data_get(obj);
336 if (elm_widget_focus_get(obj))
338 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
339 evas_object_focus_set(wd->self, EINA_TRUE);
343 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
344 evas_object_focus_set(wd->self, EINA_FALSE);
349 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
351 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
352 Evas_Event_Key_Down *ev = event_info;
353 Widget_Data *wd = elm_widget_data_get(obj);
354 if (!wd) return EINA_FALSE;
355 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
356 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
358 Elm_Diskselector_Item *it = NULL;
361 if (!wd->selected_item) {
362 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
366 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")) ||
367 (!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
369 l = wd->selected_item->node->prev;
370 if ((!l) && (wd->round))
371 l = eina_list_last(wd->items);
373 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")) ||
374 (!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
376 l = wd->selected_item->node->next;
377 if ((!l) && (wd->round))
380 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
382 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
383 l = eina_list_last(wd->items);
384 else return EINA_FALSE;
387 it = eina_list_data_get(l);
391 wd->selected_item = it;
393 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
396 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
401 _count_letter(const char *str)
406 for (chnum = 0; ; chnum++)
408 pos = evas_string_char_next_get(str, pos, &code);
409 if (code == 0) break;
415 _check_letter(const char *str, int length)
420 for (chnum = 0; ; chnum++)
422 if (chnum == length) break;
423 pos = evas_string_char_next_get(str, pos, &code);
424 if (code == 0) break;
430 _check_string(void *data)
432 int mid, steps, length, diff;
433 Elm_Diskselector_Item *it;
437 Widget_Data *wd = data;
439 evas_object_geometry_get(wd->scroller, &ox, NULL, &ow, NULL);
449 EINA_LIST_FOREACH(list, l, it)
453 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
454 /* item not visible */
455 if ((x + w <= ox) || (x >= ox + ow))
458 len = _count_letter(it->label);
459 // // FIXME: len should be # of ut8f letters. ie count using utf8 string walk, not stringshare len
460 // len = eina_stringshare_strlen(it->label);
463 edje_object_signal_emit(it->base.view, "elm,state,left_side",
465 else if (x + w >= ox + ow - 5)
466 edje_object_signal_emit(it->base.view, "elm,state,right_side",
470 if ((wd->len_threshold) && (len > wd->len_threshold))
471 edje_object_signal_emit(it->base.view, "elm,state,center_small",
474 edje_object_signal_emit(it->base.view, "elm,state,center",
478 // if len is les that the limit len, skip anyway
479 if (len <= wd->len_side)
482 steps = len - wd->len_side + 1;
484 if (mid <= ox + ow / 2)
485 diff = (ox + ow / 2) - mid;
487 diff = mid - (ox + ow / 2);
489 length = len - (int)(diff * steps / (ow / 3));
490 length = MAX(length, wd->len_side);
491 // limit string len to "length" ut8f chars
492 length = _check_letter(it->label, length);
493 // cut it off at byte mark returned form _check_letter
494 strncpy(buf, it->label, length);
496 edje_object_part_text_set(it->base.view, "elm.text", buf);
500 ecore_idle_enterer_del(wd->check_idler);
501 wd->check_idler = NULL;
506 _selected_item_indicate(Elm_Diskselector_Item *it)
508 Elm_Diskselector_Item *item;
511 wd = elm_widget_data_get(it->base.widget);
515 EINA_LIST_FOREACH(wd->r_items, l, item)
517 if (!strcmp(item->label, it->label)) edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
519 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
524 _item_click_cb(void *data, Evas_Object *obj __UNUSED__,
525 const char *emission __UNUSED__, const char *source __UNUSED__)
527 Elm_Diskselector_Item *it = data;
532 wd = elm_widget_data_get(it->base.widget);
536 if (wd->selected_item != it)
538 wd->selected_item = it;
539 _selected_item_indicate(wd->selected_item);
542 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
546 _scroller_move_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
548 Evas_Coord x, y, w, h, bw;
549 Widget_Data *wd = data;
552 elm_smart_scroller_child_pos_get(obj, &x, &y);
553 elm_smart_scroller_child_viewport_size_get(obj, &w, &h);
556 evas_object_geometry_get(wd->main_box, NULL, NULL, &bw, NULL);
557 if (x > ((w / wd->display_item_num) * (wd->item_count + (wd->display_item_num % 2))))
558 elm_smart_scroller_child_region_show(wd->scroller,
559 x - ((w / wd->display_item_num) * wd->item_count),
562 elm_smart_scroller_child_region_show(wd->scroller,
563 x + ((w / wd->display_item_num) * wd->item_count),
569 _scroller_stop_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
571 Elm_Diskselector_Item *it;
572 Widget_Data *wd = data;
584 evas_object_geometry_get(wd->scroller, NULL, NULL, &ow, NULL);
585 EINA_LIST_FOREACH(list, l, it)
587 evas_object_geometry_get(it->base.view, &x, NULL, &w, NULL);
588 if (abs((int)(ow / 2 - (int)(x + w / 2))) < 10)
599 _move_scroller(void *data)
601 Evas_Object *obj = data;
604 Elm_Diskselector_Item *dit;
608 wd = elm_widget_data_get(obj);
609 if (!wd) return EINA_FALSE;
616 EINA_LIST_FOREACH(wd->items, l, dit)
618 if (wd->selected_item == dit)
625 (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
629 evas_object_geometry_get(wd->scroller, NULL, &y, &w, &h);
630 elm_smart_scroller_child_region_show(wd->scroller, w / wd->display_item_num * i, y, w, h);
634 ecore_idle_enterer_del(wd->idler);
637 wd->init = EINA_TRUE;
644 _round_item_del(Widget_Data *wd, Elm_Diskselector_Item *it)
647 elm_box_unpack(wd->main_box, it->base.view);
648 wd->r_items = eina_list_remove(wd->r_items, it);
649 eina_stringshare_del(it->label);
650 evas_object_del(it->base.view);
655 _round_items_del(Widget_Data *wd)
658 Elm_Diskselector_Item * it;
660 _round_item_del(wd, wd->last);
662 _round_item_del(wd, wd->s_last);
664 _round_item_del(wd, wd->second);
666 _round_item_del(wd, wd->first);
669 EINA_LIST_FOREACH(wd->under_items, l, it)
671 _round_item_del(wd, it);
675 EINA_LIST_FOREACH(wd->over_items, l, it)
677 _round_item_del(wd, it);
683 _round_items_add(Widget_Data *wd)
685 Elm_Diskselector_Item *dit;
686 Elm_Diskselector_Item *it;
687 Elm_Diskselector_Item *temp_it;
689 dit = it = eina_list_nth(wd->items, 0);
694 wd->first = _item_new(it->base.widget, it->icon, it->label, it->func,
696 wd->first->node = it->node;
697 wd->r_items = eina_list_append(wd->r_items, wd->first);
700 it = eina_list_nth(wd->items, 1);
705 wd->second = _item_new(it->base.widget, it->icon, it->label, it->func,
707 wd->second->node = it->node;
708 wd->r_items = eina_list_append(wd->r_items, wd->second);
711 // if more than 3 itmes should be displayed
712 for (i = 2; i < CEIL(wd->display_item_num); i++)
714 it = eina_list_nth(wd->items, i);
716 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
717 wd->over_items = eina_list_append(wd->over_items, temp_it);
718 wd->r_items = eina_list_append(wd->r_items, temp_it);
721 it = eina_list_nth(wd->items, wd->item_count - 1);
726 wd->last = _item_new(it->base.widget, it->icon, it->label, it->func,
728 wd->last->node = it->node;
729 wd->r_items = eina_list_prepend(wd->r_items, wd->last);
732 it = eina_list_nth(wd->items, wd->item_count - 2);
737 wd->s_last = _item_new(it->base.widget, it->icon, it->label, it->func,
739 wd->s_last->node = it->node;
740 wd->r_items = eina_list_prepend(wd->r_items, wd->s_last);
743 // if more than 3 itmes should be displayed
744 for (i = 3; i <= CEIL(wd->display_item_num); i++)
746 it = eina_list_nth(wd->items, wd->item_count - i);
748 temp_it = _item_new(it->base.widget, it->icon, it->label, it->func, it->base.data);
749 wd->under_items = eina_list_append(wd->under_items, temp_it);
750 wd->r_items = eina_list_prepend(wd->r_items, temp_it);
755 elm_diskselector_add(Evas_Object *parent)
761 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
763 ELM_SET_WIDTYPE(widtype, "diskselector");
764 elm_widget_type_set(obj, "diskselector");
765 elm_widget_sub_object_add(parent, obj);
766 elm_widget_data_set(obj, wd);
767 elm_widget_del_hook_set(obj, _del_hook);
768 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
769 elm_widget_theme_hook_set(obj, _theme_hook);
770 elm_widget_can_focus_set(obj, EINA_TRUE);
771 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
772 elm_widget_event_hook_set(obj, _event_hook);
776 wd->round = EINA_FALSE;
777 wd->init = EINA_FALSE;
779 wd->display_item_num_by_api = EINA_FALSE;
781 wd->scroller = elm_smart_scroller_add(e);
782 elm_smart_scroller_widget_set(wd->scroller, obj);
784 elm_widget_resize_object_set(obj, wd->scroller);
785 elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
786 ELM_SMART_SCROLLER_POLICY_OFF);
787 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_TRUE, EINA_FALSE);
788 evas_object_smart_callback_add(wd->scroller, "scroll", _scroller_move_cb,
790 evas_object_smart_callback_add(wd->scroller, "animate,stop",
791 _scroller_stop_cb, wd);
792 _elm_theme_object_set(obj, wd->scroller, "diskselector", "base",
794 evas_object_event_callback_add(wd->scroller, EVAS_CALLBACK_RESIZE,
795 _diskselector_object_resize, obj);
797 wd->main_box = elm_box_add(parent);
798 elm_box_horizontal_set(wd->main_box, EINA_TRUE);
799 elm_box_homogeneous_set(wd->main_box, EINA_TRUE);
800 evas_object_size_hint_weight_set(wd->main_box, EVAS_HINT_EXPAND,
802 evas_object_size_hint_align_set(wd->main_box, EVAS_HINT_FILL,
804 _elm_theme_object_set(obj, wd->main_box, "diskselector", "base",
806 elm_widget_sub_object_add(obj, wd->main_box);
808 elm_smart_scroller_child_set(wd->scroller, wd->main_box);
810 wd->left_blank = edje_object_add(evas_object_evas_get(obj));
811 _elm_theme_object_set(obj, wd->left_blank, "diskselector", "item",
813 evas_object_size_hint_weight_set(wd->left_blank, EVAS_HINT_EXPAND,
815 evas_object_size_hint_align_set(wd->left_blank, EVAS_HINT_FILL,
817 elm_box_pack_end(wd->main_box, wd->left_blank);
818 evas_object_show(wd->left_blank);
820 wd->right_blank = edje_object_add(evas_object_evas_get(obj));
821 _elm_theme_object_set(obj, wd->right_blank, "diskselector", "item",
823 evas_object_size_hint_weight_set(wd->right_blank, EVAS_HINT_EXPAND,
825 evas_object_size_hint_align_set(wd->right_blank, EVAS_HINT_FILL,
827 elm_box_pack_end(wd->main_box, wd->right_blank);
828 evas_object_show(wd->right_blank);
832 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
833 evas_object_smart_callbacks_descriptions_set(obj, _signals);
839 elm_diskselector_round_get(const Evas_Object *obj)
841 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
842 Widget_Data *wd = elm_widget_data_get(obj);
843 if (!wd) return EINA_FALSE;
848 elm_diskselector_round_set(Evas_Object * obj, Eina_Bool round)
851 Elm_Diskselector_Item *it;
853 ELM_CHECK_WIDTYPE(obj, widtype);
854 Widget_Data *wd = elm_widget_data_get(obj);
857 if (wd->round == round)
863 wd->r_items = eina_list_clone(wd->items);
864 elm_box_unpack(wd->main_box, wd->left_blank);
865 evas_object_hide(wd->left_blank);
866 elm_box_unpack(wd->main_box, wd->right_blank);
867 evas_object_hide(wd->right_blank);
871 _round_items_add(wd);
874 elm_box_pack_start(wd->main_box, wd->last->base.view);
876 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
878 // if more than 3 items should be displayed
879 EINA_LIST_FOREACH(wd->under_items, elist, it)
880 elm_box_pack_start(wd->main_box, it->base.view);
883 elm_box_pack_end(wd->main_box, wd->first->base.view);
885 elm_box_pack_end(wd->main_box, wd->second->base.view);
887 // if more than 3 items should be displayed
888 EINA_LIST_FOREACH(wd->over_items, elist, it)
889 elm_box_pack_end(wd->main_box, it->base.view);
893 _round_items_del(wd);
894 elm_box_pack_start(wd->main_box, wd->left_blank);
895 elm_box_pack_end(wd->main_box, wd->right_blank);
896 eina_list_free(wd->r_items);
900 _selected_item_indicate(wd->selected_item);
905 elm_diskselector_side_label_length_get(const Evas_Object *obj)
907 ELM_CHECK_WIDTYPE(obj, widtype) 0;
908 Widget_Data *wd = elm_widget_data_get(obj);
914 elm_diskselector_side_label_length_set(Evas_Object *obj, int len)
916 ELM_CHECK_WIDTYPE(obj, widtype);
917 Widget_Data *wd = elm_widget_data_get(obj);
923 elm_diskselector_side_label_lenght_set(Evas_Object *obj, int len)
925 return elm_diskselector_side_label_length_set(obj, len);
929 elm_diskselector_side_label_lenght_get(const Evas_Object *obj)
931 return elm_diskselector_side_label_length_get(obj);
935 elm_diskselector_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
937 ELM_CHECK_WIDTYPE(obj, widtype);
938 Widget_Data *wd = elm_widget_data_get(obj);
941 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
945 elm_diskselector_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
947 ELM_CHECK_WIDTYPE(obj, widtype);
948 Widget_Data *wd = elm_widget_data_get(obj);
950 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
954 elm_diskselector_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
956 ELM_CHECK_WIDTYPE(obj, widtype);
957 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
958 Widget_Data *wd = elm_widget_data_get(obj);
959 if ((!wd) || (!wd->scroller)) return;
960 elm_smart_scroller_policy_get(wd->scroller, &s_policy_h, &s_policy_v);
961 *policy_h = (Elm_Scroller_Policy) s_policy_h;
962 *policy_v = (Elm_Scroller_Policy) s_policy_v;
966 elm_diskselector_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
968 ELM_CHECK_WIDTYPE(obj, widtype);
969 Widget_Data *wd = elm_widget_data_get(obj);
970 if ((!wd) || (!wd->scroller)) return;
971 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
972 (policy_v >= ELM_SCROLLER_POLICY_LAST))
974 elm_smart_scroller_policy_set(wd->scroller, policy_h, policy_v);
978 elm_diskselector_clear(Evas_Object *obj)
980 ELM_CHECK_WIDTYPE(obj, widtype);
981 Widget_Data *wd = elm_widget_data_get(obj);
982 Elm_Diskselector_Item *it;
985 if (!wd->items) return;
987 wd->selected_item = NULL;
988 EINA_LIST_FREE(wd->items, it) _item_del(it);
989 _round_items_del(wd);
993 EAPI const Eina_List *
994 elm_diskselector_items_get(const Evas_Object *obj)
996 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
997 Widget_Data *wd = elm_widget_data_get(obj);
998 if (!wd) return NULL;
1002 EAPI Elm_Diskselector_Item *
1003 elm_diskselector_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1005 Elm_Diskselector_Item *it;
1006 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1007 Widget_Data *wd = elm_widget_data_get(obj);
1008 if (!wd) return NULL;
1010 it = _item_new(obj, icon, label, func, data);
1011 wd->items = eina_list_append(wd->items, it);
1012 it->node = eina_list_last(wd->items);
1016 _round_items_del(wd);
1017 wd->r_items = eina_list_append(wd->r_items, it);
1018 _round_items_add(wd);
1020 elm_box_pack_start(wd->main_box, wd->last->base.view);
1022 elm_box_pack_start(wd->main_box, wd->s_last->base.view);
1023 elm_box_pack_end(wd->main_box, it->base.view);
1025 elm_box_pack_end(wd->main_box, wd->first->base.view);
1027 elm_box_pack_end(wd->main_box, wd->second->base.view);
1031 elm_box_unpack(wd->main_box, wd->right_blank);
1032 elm_box_pack_end(wd->main_box, it->base.view);
1033 elm_box_pack_end(wd->main_box, wd->right_blank);
1035 if (!wd->selected_item)
1036 wd->selected_item = it;
1038 wd->idler = ecore_idle_enterer_before_add(_move_scroller, obj);
1044 elm_diskselector_item_del(Elm_Diskselector_Item * it)
1046 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1047 Elm_Diskselector_Item *dit;
1048 Elm_Diskselector_Item *item;
1051 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1054 elm_box_unpack(wd->main_box, it->base.view);
1057 wd->r_items = eina_list_remove(wd->r_items, it);
1059 wd->items = eina_list_remove(wd->items, it);
1061 if (wd->selected_item == it)
1063 dit = (Elm_Diskselector_Item *) eina_list_nth(wd->items, 0);
1065 wd->selected_item = dit;
1067 wd->selected_item = eina_list_nth(wd->items, 1);
1069 _selected_item_indicate(wd->selected_item);
1073 wd->item_count -= 1;
1077 if (!wd->item_count)
1079 evas_object_hide(wd->first->base.view);
1080 evas_object_hide(wd->second->base.view);
1081 evas_object_hide(wd->last->base.view);
1082 evas_object_hide(wd->s_last->base.view);
1084 EINA_LIST_FOREACH(wd->under_items, l, item)
1085 evas_object_hide(item->base.view);
1087 EINA_LIST_FOREACH(wd->over_items, l, item)
1088 evas_object_hide(item->base.view);
1092 dit = eina_list_nth(wd->items, 0);
1095 eina_stringshare_replace(&wd->first->label, dit->label);
1096 edje_object_part_text_set(wd->first->base.view, "elm.text",
1099 dit = eina_list_nth(wd->items, 1);
1102 eina_stringshare_replace(&wd->second->label, dit->label);
1103 edje_object_part_text_set(wd->second->base.view, "elm.text",
1106 // if more than 3 itmes should be displayed
1107 for (i = 2; i < CEIL(wd->display_item_num); i++)
1109 dit = eina_list_nth(wd->items, i);
1110 item = eina_list_nth(wd->over_items, i - 2);
1111 eina_stringshare_replace(&item->label, dit->label);
1112 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1115 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 1);
1118 eina_stringshare_replace(&wd->last->label, dit->label);
1119 edje_object_part_text_set(wd->last->base.view, "elm.text",
1122 dit = eina_list_nth(wd->items, eina_list_count(wd->items) - 2);
1125 eina_stringshare_replace(&wd->s_last->label, dit->label);
1126 edje_object_part_text_set(wd->s_last->base.view, "elm.text",
1129 // if more than 3 itmes should be displayed
1130 for (i = 3; i <= CEIL(wd->display_item_num); i++)
1132 dit = eina_list_nth(wd->items, wd->item_count - i);
1133 item = eina_list_nth(wd->under_items, i - 3);
1134 eina_stringshare_replace(&item->label, dit->label);
1135 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1139 wd->check_idler = ecore_idle_enterer_before_add(_check_string, wd);
1140 _sizing_eval(wd->self);
1144 elm_diskselector_item_label_get(const Elm_Diskselector_Item * it)
1146 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1151 elm_diskselector_item_label_set(Elm_Diskselector_Item * it, const char *label)
1153 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1154 eina_stringshare_replace(&it->label, label);
1155 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1158 EAPI Elm_Diskselector_Item *
1159 elm_diskselector_selected_item_get(const Evas_Object *obj)
1161 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1162 Widget_Data *wd = elm_widget_data_get(obj);
1163 if (!wd) return NULL;
1164 return wd->selected_item;
1168 elm_diskselector_item_selected_set(Elm_Diskselector_Item *it, Eina_Bool selected)
1170 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1172 wd = elm_widget_data_get(it->base.widget);
1175 if ((wd->selected_item == it) && (selected))
1178 if ((wd->selected_item == it) && (!selected))
1179 wd->selected_item = eina_list_data_get(wd->items);
1182 wd->selected_item = it;
1183 _selected_item_indicate(wd->selected_item);
1187 wd->idler = ecore_idle_enterer_before_add(_move_scroller, it->base.widget);
1191 elm_diskselector_item_selected_get(const Elm_Diskselector_Item *it)
1193 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1196 wd = elm_widget_data_get(it->base.widget);
1197 if (!wd) return EINA_FALSE;
1198 return (wd->selected_item == it);
1202 elm_diskselector_item_del_cb_set(Elm_Diskselector_Item *it, Evas_Smart_Cb func)
1204 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1205 elm_widget_item_del_cb_set(it, func);
1209 elm_diskselector_item_data_get(const Elm_Diskselector_Item *it)
1211 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1212 return elm_widget_item_data_get(it);
1216 elm_diskselector_item_icon_get(const Elm_Diskselector_Item *it)
1218 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1223 elm_diskselector_item_icon_set(Elm_Diskselector_Item *it, Evas_Object *icon)
1225 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it);
1226 if (it->icon == icon) return;
1228 evas_object_del(it->icon);
1232 evas_object_size_hint_min_set(it->icon, 24, 24);
1233 evas_object_size_hint_max_set(it->icon, 40, 40);
1234 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
1235 evas_object_show(it->icon);
1236 elm_widget_sub_object_add(it->base.widget, it->icon);
1240 EAPI Elm_Diskselector_Item *
1241 elm_diskselector_item_prev_get(const Elm_Diskselector_Item *it)
1243 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1244 if (it->node->prev) return it->node->prev->data;
1248 EAPI Elm_Diskselector_Item *
1249 elm_diskselector_item_next_get(const Elm_Diskselector_Item *it)
1251 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1252 if (it->node->next) return it->node->next->data;
1256 EAPI Elm_Diskselector_Item *
1257 elm_diskselector_first_item_get(const Evas_Object *obj)
1259 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1262 wd = elm_widget_data_get(obj);
1263 if (!wd || !wd->items)
1266 return eina_list_data_get(wd->items);
1269 EAPI Elm_Diskselector_Item *
1270 elm_diskselector_last_item_get(const Evas_Object *obj)
1272 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1275 wd = elm_widget_data_get(obj);
1276 if (!wd || !wd->items)
1279 return eina_list_data_get(eina_list_last(wd->items));
1283 elm_diskselector_item_tooltip_text_set(Elm_Diskselector_Item *item, const char *text)
1285 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1286 elm_widget_item_tooltip_text_set(item, text);
1290 elm_diskselector_item_tooltip_content_cb_set(Elm_Diskselector_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1292 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1293 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1297 elm_diskselector_item_tooltip_unset(Elm_Diskselector_Item *item)
1299 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1300 elm_widget_item_tooltip_unset(item);
1304 elm_diskselector_item_tooltip_style_set(Elm_Diskselector_Item *item, const char *style)
1306 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1307 elm_widget_item_tooltip_style_set(item, style);
1311 elm_diskselector_item_tooltip_style_get(const Elm_Diskselector_Item *item)
1313 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1314 return elm_widget_item_tooltip_style_get(item);
1318 elm_diskselector_item_cursor_set(Elm_Diskselector_Item *item, const char *cursor)
1320 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1321 elm_widget_item_cursor_set(item, cursor);
1325 elm_diskselector_item_cursor_get(const Elm_Diskselector_Item *item)
1327 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1328 return elm_widget_item_cursor_get(item);
1332 elm_diskselector_item_cursor_unset(Elm_Diskselector_Item *item)
1334 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1335 elm_widget_item_cursor_unset(item);
1339 elm_diskselector_item_cursor_style_set(Elm_Diskselector_Item *item, const char *style)
1341 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1342 elm_widget_item_cursor_style_set(item, style);
1346 elm_diskselector_item_cursor_style_get(const Elm_Diskselector_Item *item)
1348 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, NULL);
1349 return elm_widget_item_cursor_style_get(item);
1353 elm_diskselector_item_cursor_engine_only_set(Elm_Diskselector_Item *item, Eina_Bool engine_only)
1355 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item);
1356 elm_widget_item_cursor_engine_only_set(item, engine_only);
1360 elm_diskselector_item_cursor_engine_only_get(const Elm_Diskselector_Item *item)
1362 ELM_DISKSELECTOR_ITEM_CHECK_OR_RETURN(item, EINA_FALSE);
1363 return elm_widget_item_cursor_engine_only_get(item);
1367 elm_diskselector_display_item_num_set(Evas_Object *obj, int num)
1369 ELM_CHECK_WIDTYPE(obj, widtype);
1370 Widget_Data *wd = elm_widget_data_get(obj);
1372 if (num < DISPLAY_ITEM_NUM_MIN) num = DISPLAY_ITEM_NUM_MIN;
1373 wd->display_item_num = num;
1374 wd->display_item_num_by_api = EINA_TRUE;
1378 elm_diskselector_display_item_num_get(const Evas_Object *item)
1380 ELM_CHECK_WIDTYPE(item, widtype) (-1);
1381 Widget_Data *wd = elm_widget_data_get(item);
1383 return wd->display_item_num;