2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
8 #define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
9 #define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
10 #define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
12 * use for find view toplevel
14 #define SET_VIEW_LEVEL(wd, view_level)\
15 view_level = wd->level;\
16 while ((!wd->tot_items_count[view_level]) && view_level)\
21 typedef struct _Widget_Data Widget_Data;
23 typedef struct _PlacementPart PlacementPart;
28 Evas_Object *event[2];
29 Evas_Object *bx[2]; // 2 - for now all that's supported
30 Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
33 int max_supp_items_count;
34 int tot_items_count[2];
35 int min_obj_height, max_grp_size;
36 int min_1st_level_obj_height;
39 Evas_Coord pwidth, pheight;
41 const char *special_char;
42 Eina_Bool level_active[2];
43 Eina_Bool horizontal : 1;
46 Eina_Bool hide_button : 1;
50 struct _Elm_Index_Item
53 const char *letter, *vis_letter;
55 Eina_Bool selected : 1;
64 static const char *widtype = NULL;
66 static void _del_hook(Evas_Object *obj);
67 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
68 static void _theme_hook(Evas_Object *obj);
69 static void _sizing_eval(Evas_Object *obj);
70 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
71 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
72 static void _item_free(Elm_Index_Item *it);
73 static void _index_process(Evas_Object *obj);
75 static const char SIG_CHANGED[] = "changed";
76 static const char SIG_DELAY_CHANGED[] = "delay,changed";
77 static const char SIG_SELECTED[] = "selected";
78 static const char SIG_LEVEL_UP[] = "level,up";
79 static const char SIG_LEVEL_DOWN[] = "level,down";
81 static const Evas_Smart_Cb_Description _signals[] = {
83 {SIG_DELAY_CHANGED, ""},
89 /* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
91 _del_pre_hook(Evas_Object *obj)
93 Widget_Data *wd = elm_widget_data_get(obj);
95 _index_box_clear(obj, wd->bx[wd->level], wd->level);
96 _index_box_clear(obj, wd->bx[0], 0);
97 while (wd->items) _item_free(wd->items->data);
98 if (wd->delay) ecore_timer_del(wd->delay);
100 if(wd->popup_str[0]) free(wd->popup_str[0]);
101 if(wd->popup_str[1]) free(wd->popup_str[1]);
105 _del_hook(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
112 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
114 Widget_Data *wd = data;
116 _els_box_layout(o, priv, wd->horizontal, 0, 0);
120 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
122 Widget_Data *wd = elm_widget_data_get(obj);
124 edje_object_signal_emit(wd->base, emission, source);
128 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
130 Widget_Data *wd = elm_widget_data_get(obj);
132 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
136 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
138 Widget_Data *wd = elm_widget_data_get(obj);
139 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
144 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
146 Widget_Data *wd = elm_widget_data_get(obj);
149 edje_object_mirrored_set(wd->base, rtl);
153 _theme_hook(Evas_Object *obj)
155 Evas_Coord minw = 0, minh = 0;
156 Widget_Data *wd = elm_widget_data_get(obj);
158 _elm_widget_mirrored_reload(obj);
160 _index_box_clear(obj, wd->bx[0], 0);
161 _index_box_clear(obj, wd->bx[1], 1);
163 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
166 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
167 _mirrored_set(obj, elm_widget_mirrored_get(obj));
169 edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
170 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
171 evas_object_size_hint_min_set(wd->event[0], minw, minh);
173 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
174 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
178 wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
179 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
180 elm_widget_sub_object_add(obj, wd->bx[1]);
182 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
183 evas_object_show(wd->bx[1]);
187 evas_object_del(wd->bx[1]);
190 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
194 wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
195 evas_object_color_set(wd->event[1], 0, 0, 0, 0);
196 elm_widget_sub_object_add(obj, wd->event[1]);
198 edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
199 evas_object_size_hint_min_set(wd->event[1], minw, minh);
201 else if (wd->event[1])
203 evas_object_del(wd->event[1]);
206 edje_object_message_signal_process(wd->base);
207 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
209 _index_box_auto_fill(obj, wd->bx[0], 0);
212 _index_box_auto_fill(obj, wd->bx[1], 1);
216 _sizing_eval(Evas_Object *obj)
218 Widget_Data *wd = elm_widget_data_get(obj);
219 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
221 edje_object_size_min_calc(wd->base, &minw, &minh);
222 evas_object_size_hint_min_set(obj, minw, minh);
223 evas_object_size_hint_max_set(obj, maxw, maxh);
226 static Elm_Index_Item *
227 _item_new(Evas_Object *obj, const char *letter, const void *item)
229 Widget_Data *wd = elm_widget_data_get(obj);
231 if (!wd) return NULL;
232 it = elm_widget_item_new(obj, Elm_Index_Item);
233 if (!it) return NULL;
234 it->base.data = item;
235 it->level = wd->level;
237 it->size = wd->min_obj_height;
239 it->size = wd->min_1st_level_obj_height;
242 it->letter = eina_stringshare_add(letter);
243 it->vis_letter = eina_stringshare_add(letter);
253 static Elm_Index_Item *
254 _item_find(Evas_Object *obj, const void *item)
256 Widget_Data *wd = elm_widget_data_get(obj);
259 if (!wd) return NULL;
260 EINA_LIST_FOREACH(wd->items, l, it)
261 if (it->base.data == item) return it;
266 _item_free(Elm_Index_Item *it)
268 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
271 wd->items = eina_list_remove(wd->items, it);
272 elm_widget_item_pre_notify_del(it);
273 eina_stringshare_del(it->letter);
274 eina_stringshare_del(it->vis_letter);
275 elm_widget_item_del(it);
278 // FIXME: always have index filled
280 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
282 Widget_Data *wd = elm_widget_data_get(obj);
286 Evas_Coord mw, mh, w, h;
289 if (wd->level_active[level]) return;
290 rtl = elm_widget_mirrored_get(obj);
291 evas_object_geometry_get(box, NULL, NULL, &w, &h);
292 EINA_LIST_FOREACH(wd->items, l, it)
295 const char *stacking;
297 if (it->level != level) continue;
298 if(i > wd->max_supp_items_count) break;
300 o = edje_object_add(evas_object_evas_get(obj));
302 edje_object_mirrored_set(VIEW(it), rtl);
304 _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
306 _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
307 edje_object_part_text_set(o, "elm.text", it->letter);
308 edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
309 evas_object_size_hint_min_set(o, mw, mh);
310 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
311 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
312 edje_object_part_text_set(o, "elm.text", it->vis_letter);
313 evas_object_size_hint_min_set(o, mw, it->size);
314 evas_object_size_hint_max_set(o, mw, it->size);
315 evas_object_resize(o, mw, it->size);
317 elm_widget_sub_object_add(obj, o);
318 evas_object_box_append(box, o);
319 stacking = edje_object_data_get(o, "stacking");
322 if (!strcmp(stacking, "below")) evas_object_lower(o);
323 else if (!strcmp(stacking, "above")) evas_object_raise(o);
328 wd->tot_items_count[1] = i;
329 evas_object_smart_calculate(box); // force a calc so we know the size
330 evas_object_size_hint_min_get(box, &mw, &mh);
333 _index_box_clear(obj, box, level);
336 // FIXME: only i objects fit! try again. overflows right now
340 evas_object_smart_calculate(box);
341 wd->level_active[level] = 1;
345 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
347 Widget_Data *wd = elm_widget_data_get(obj);
351 if (!wd->level_active[level]) return;
352 EINA_LIST_FOREACH(wd->items, l, it)
354 if (!VIEW(it)) continue;
355 if (it->level != level) continue;
356 evas_object_del(VIEW(it));
359 wd->level_active[level] = 0;
363 _delay_change(void *data)
365 Widget_Data *wd = elm_widget_data_get(data);
368 if (!wd) return ECORE_CALLBACK_CANCEL;
370 SET_VIEW_LEVEL(wd, view_level);
371 d = (void *)elm_index_item_selected_get(data, view_level);
372 if (d) evas_object_smart_callback_call(data, "delay,changed", d);
373 return ECORE_CALLBACK_CANCEL;
377 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
379 Widget_Data *wd = elm_widget_data_get(obj);
380 Elm_Index_Item *it, *it_closest, *it_last;
382 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
388 Eina_Bool change = EINA_FALSE;
389 char *label = NULL, *last = NULL;
394 SET_VIEW_LEVEL(wd, view_level);
395 for (i = 0; i <= view_level; i++)
400 evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
401 dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
402 dmax = 1.0-dmin-0.08;
403 EINA_LIST_FOREACH(wd->items, l, it)
405 if (!((it->level == i) && (VIEW(it)))) continue;
411 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
416 x = (x * x) + (y * y);
417 if ((x < dist) || (!it_closest))
420 cdv = (double)(xx - bx) / (double)bw;
422 cdv = (double)(yy - by) / (double)bh;
427 if ((i == 0) && (view_level == 0))
429 if(cdv > dmax || cdv < dmin)
439 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
443 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
446 if (it_closest) it_closest->selected = 1;
447 if (it_closest != it_last)
452 const char *stacking, *selectraise;
455 if(view_level == it->level)
456 edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
457 stacking = edje_object_data_get(VIEW(it), "stacking");
458 selectraise = edje_object_data_get(VIEW(it), "selectraise");
459 if ((selectraise) && (!strcmp(selectraise, "on")))
461 if ((stacking) && (!strcmp(stacking, "below")))
462 evas_object_lower(VIEW(it));
467 const char *selectraise;
470 if(view_level == it->level)
471 edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
472 selectraise = edje_object_data_get(VIEW(it), "selectraise");
473 if ((selectraise) && (!strcmp(selectraise, "on")))
474 evas_object_raise(VIEW(it));
475 evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it->base.data);
476 if (wd->delay) ecore_timer_del(wd->delay);
477 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
484 last = strdup(it->letter);
487 if (!label) label = strdup(last);
490 /* FIXME: realloc return NULL if the request fails */
491 label = realloc(label, strlen(label) + strlen(last) + 1);
495 last = strdup(it->letter);
499 if (!label) label = strdup("");
500 if (!last) last = strdup("");
507 if(wd->tot_items_count[0])
509 if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
510 wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
512 strcpy(wd->popup_str[0], last);
513 edje_object_signal_emit(wd->base, "hide_2nd_level", "");
517 edje_object_signal_emit(wd->base, "button.image.hidden", "");
518 if(label)free(label);
523 if (view_level == 1 && wd->level_active[1])
525 if(wd->tot_items_count[1])
527 wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
529 strcpy(wd->popup_str[1], last);
530 edje_object_signal_emit(wd->base, "hide_first_level", "");
534 edje_object_signal_emit(wd->base, "button.image.hidden", "");
535 if(label)free(label);
540 popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
541 sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
542 edje_object_part_text_set(wd->base, "elm.text", popup_text);
554 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
556 Widget_Data *wd = elm_widget_data_get(data);
557 // Evas_Event_Mouse_Wheel *ev = event_info;
558 // Evas_Object *obj = o;
563 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
565 Widget_Data *wd = elm_widget_data_get(data);
566 Evas_Event_Mouse_Down *ev = event_info;
569 if (ev->button != 1) return;
571 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
572 wd->dx = ev->canvas.x - x;
573 wd->dy = ev->canvas.y - y;
574 elm_index_active_set(data, 1);
575 _sel_eval(data, ev->canvas.x, ev->canvas.y);
576 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
577 (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
581 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
583 Widget_Data *wd = elm_widget_data_get(data);
584 Evas_Event_Mouse_Up *ev = event_info;
591 if (ev->button != 1) return;
592 if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
595 SET_VIEW_LEVEL(wd, view_level);
596 d = (void *)elm_index_item_selected_get(data, view_level);
597 EINA_LIST_FOREACH(wd->items, l, it)
599 edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
601 if (d) evas_object_smart_callback_call(data, SIG_SELECTED, d);
602 elm_index_active_set(data, 0);
603 edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
607 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
609 Widget_Data *wd = elm_widget_data_get(data);
610 Evas_Event_Mouse_Move *ev = event_info;
611 Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
615 if (!wd->down) return;
616 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
617 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
618 x = ev->cur.canvas.x - x;
619 y = ev->cur.canvas.y - y;
622 if (adx < 0) adx = -dx;
623 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
624 , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
632 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
633 edje_object_signal_emit(wd->base, buf, "elm");
634 evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
642 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
643 edje_object_signal_emit(wd->base, buf, "elm");
644 d = (void *)elm_index_item_selected_get(data, wd->level);
645 evas_object_smart_callback_call(data, "changed", d);
646 if (wd->delay) ecore_timer_del(wd->delay);
647 wd->delay = ecore_timer_add(0.2, _delay_change, data);
648 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
652 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
656 _index_box_refill_job(void *data)
658 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
664 evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
665 wd->scale_factor = elm_scale_get();
666 if ( wd->scale_factor == 0.0 ) {
667 wd->scale_factor = 1.0;
669 string = edje_object_data_get(wd->base, "min_obj_height");
671 wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
673 wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
674 if(!wd->min_obj_height) return;
676 wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
677 wd->items_count = ph/wd->min_obj_height;
678 wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
680 if(pw != wd->pwidth && ph != wd->pheight)
685 elm_index_active_set(data, 1);
687 _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
688 evas_object_smart_calculate( wd->bx[0]);
689 elm_index_item_go((Evas_Object *)data, wd->level);
695 static void _index_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
699 wd = elm_widget_data_get((Evas_Object *)data);
701 ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
705 elm_index_add(Evas_Object *parent)
711 Evas_Coord minw, minh;
714 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
716 ELM_SET_WIDTYPE(widtype, "index");
717 elm_widget_type_set(obj, "index");
718 elm_widget_sub_object_add(parent, obj);
719 elm_widget_data_set(obj, wd);
720 elm_widget_del_hook_set(obj, _del_hook);
721 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
722 elm_widget_theme_hook_set(obj, _theme_hook);
723 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
724 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
725 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
726 elm_widget_can_focus_set(obj, EINA_FALSE);
728 wd->horizontal = EINA_FALSE;
729 wd->min_obj_height = 0;
730 wd->max_grp_size = 0;
732 wd->max_supp_items_count = 0;
733 wd->tot_items_count[0] = 0;
734 wd->tot_items_count[1] = 0;
736 wd->special_char = edje_object_data_get(wd->base, "special_char");
737 if(wd->special_char == NULL) wd->special_char = eina_stringshare_add("*");
739 wd->base = edje_object_add(e);
740 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
741 elm_widget_resize_object_set(obj, wd->base);
743 o = evas_object_rectangle_add(e);
745 evas_object_color_set(o, 0, 0, 0, 0);
747 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
748 evas_object_size_hint_min_set(o, minw, minh);
749 edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
750 elm_widget_sub_object_add(obj, o);
751 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
752 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
753 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
754 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
755 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
757 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
759 o = evas_object_rectangle_add(e);
761 evas_object_color_set(o, 0, 0, 0, 0);
762 evas_object_size_hint_min_set(o, minw, minh);
763 edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
764 elm_widget_sub_object_add(obj, o);
767 wd->bx[0] = evas_object_box_add(e);
768 evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
769 elm_widget_sub_object_add(obj, wd->bx[0]);
770 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
771 evas_object_show(wd->bx[0]);
773 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
775 wd->bx[1] = evas_object_box_add(e);
776 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
777 elm_widget_sub_object_add(obj, wd->bx[1]);
778 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
779 evas_object_show(wd->bx[1]);
782 evas_object_smart_callbacks_descriptions_set(obj, _signals);
783 wd->scale_factor = elm_scale_get();
784 if ( wd->scale_factor == 0.0 )
785 wd->scale_factor = 1.0;
786 string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
788 wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
790 wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
791 wd->popup_str[0] = calloc(1, sizeof(char) * 1);
792 wd->popup_str[1] = calloc(1, sizeof(char) * 1);
794 _mirrored_set(obj, elm_widget_mirrored_get(obj));
800 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
802 Widget_Data *wd = elm_widget_data_get(obj);
804 int group_count = MIN_GRP_SIZE;
805 while(group_count <= wd->max_grp_size)
807 if(extraIndex <= wd->max_grp_size*adj_pos)
809 if(group_count*adj_pos>=extraIndex) return group_count;
812 return wd->max_grp_size;
814 group_count += MIN_GRP_SIZE;
820 _index_process(Evas_Object *obj)
823 int j,i, group_count;
829 Widget_Data *wd = elm_widget_data_get(obj);
832 if (wd->items_count == 0) return;
834 const int adj_pos = (wd->items_count-1)*0.5;
835 if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
836 n = wd->tot_items_count[wd->level];
838 n = wd->max_supp_items_count;
839 group_count = MIN_GRP_SIZE;
841 int *indx = (int*)calloc(n, sizeof(int));
844 const int minh = wd->min_obj_height;
845 EINA_LIST_FOREACH(wd->items, l, it)
847 it->vis_letter = eina_stringshare_add(it->letter);
852 int N = wd->items_count;
866 group_count = _group_count(obj, extraIndex, adj_pos, N);
867 if (group_count <= 0)
875 PlacementPart place[adj_pos];
876 remainder = extraIndex%group_count;
877 numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
879 for (i=0;i<numberofparts; i++)
881 place[i].count=group_count+1;
882 count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
883 place[i].start= count +i*group_count-1;
886 place[numberofparts-1].count=remainder+1;
888 for (i=0;i<numberofparts;i++)
890 for (j=0;j<place[i].count; j++)
892 indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
894 indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
897 EINA_LIST_FOREACH(wd->items, l, it)
899 int size = indx[count];
903 it->vis_letter = eina_stringshare_add(it->letter);
908 eina_stringshare_del(it->vis_letter);
909 it->vis_letter = eina_stringshare_add("");
913 eina_stringshare_del(it->vis_letter);
914 it->vis_letter = eina_stringshare_add(wd->special_char);
916 it->size = size*wd->scale_factor;
926 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
928 ELM_CHECK_WIDTYPE(obj, widtype);
929 Widget_Data *wd = elm_widget_data_get(obj);
931 if (wd->active == active) return;
936 _index_box_clear(obj, wd->bx[1], 1);
938 _index_box_auto_fill(obj, wd->bx[0], 0);
939 if(wd->tot_items_count[wd->level])
940 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
942 edje_object_signal_emit(wd->base, "button.image.hidden", "");
945 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
949 elm_index_active_get(const Evas_Object *obj)
951 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
952 Widget_Data *wd = elm_widget_data_get(obj);
953 if (!wd) return EINA_FALSE;
958 elm_index_item_level_set(Evas_Object *obj, int level)
960 ELM_CHECK_WIDTYPE(obj, widtype);
961 Widget_Data *wd = elm_widget_data_get(obj);
963 if (wd->level == level) return;
968 elm_index_item_level_get(const Evas_Object *obj)
970 ELM_CHECK_WIDTYPE(obj, widtype) 0;
971 Widget_Data *wd = elm_widget_data_get(obj);
977 elm_index_item_selected_get(const Evas_Object *obj, int level)
979 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
980 Widget_Data *wd = elm_widget_data_get(obj);
983 if (!wd) return NULL;
984 EINA_LIST_FOREACH(wd->items, l, it)
985 if ((it->selected) && (it->level == level))
986 return elm_widget_item_data_get(it);
991 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
993 ELM_CHECK_WIDTYPE(obj, widtype);
994 Widget_Data *wd = elm_widget_data_get(obj);
997 it = _item_new(obj, letter, item);
999 wd->items = eina_list_append(wd->items, it);
1000 wd->tot_items_count[wd->level]++;
1001 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1005 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1007 ELM_CHECK_WIDTYPE(obj, widtype);
1008 Widget_Data *wd = elm_widget_data_get(obj);
1012 it = _item_new(obj, letter, item);
1014 wd->items = eina_list_prepend(wd->items, it);
1015 wd->tot_items_count[wd->level]++;
1016 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1020 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1022 ELM_CHECK_WIDTYPE(obj, widtype);
1023 Widget_Data *wd = elm_widget_data_get(obj);
1024 Elm_Index_Item *it, *it_rel;
1028 elm_index_item_append(obj, letter, item);
1029 wd->tot_items_count[wd->level]++;
1032 it = _item_new(obj, letter, item);
1035 it_rel = _item_find(obj, relative);
1038 elm_index_item_append(obj, letter, item);
1039 wd->tot_items_count[wd->level]++;
1044 wd->items = eina_list_append_relative(wd->items, it, it_rel);
1045 wd->tot_items_count[wd->level]++;
1046 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1050 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1052 ELM_CHECK_WIDTYPE(obj, widtype);
1053 Widget_Data *wd = elm_widget_data_get(obj);
1054 Elm_Index_Item *it, *it_rel;
1058 elm_index_item_prepend(obj, letter, item);
1059 wd->tot_items_count[wd->level]++;
1062 it = _item_new(obj, letter, item);
1065 it_rel = _item_find(obj, relative);
1068 elm_index_item_append(obj, letter, item);
1069 wd->tot_items_count[wd->level]++;
1074 wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
1075 wd->tot_items_count[wd->level]++;
1076 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1080 elm_index_item_sorted_insert(Evas_Object *obj, const char *letter, const void *item, Eina_Compare_Cb cmp_func, Eina_Compare_Cb cmp_data_func)
1082 ELM_CHECK_WIDTYPE(obj, widtype);
1083 Widget_Data *wd = elm_widget_data_get(obj);
1091 elm_index_item_append(obj, letter, item);
1095 it = _item_new(obj, letter, item);
1098 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1100 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1102 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1105 /* If cmp_data_func is not provided, append a duplicated item */
1107 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1110 Elm_Index_Item *p_it = eina_list_data_get(lnear);
1111 if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1112 p_it->base.data = it->base.data;
1117 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1121 elm_index_item_del(Evas_Object *obj, const void *item)
1123 ELM_CHECK_WIDTYPE(obj, widtype);
1124 Widget_Data *wd = elm_widget_data_get(obj);
1127 it = _item_find(obj, item);
1130 wd->tot_items_count[wd->level]--;
1131 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1134 EAPI Elm_Index_Item *
1135 elm_index_item_find(Evas_Object *obj, const void *item)
1137 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1138 Widget_Data *wd = elm_widget_data_get(obj);
1139 if (!wd) return NULL;
1140 return _item_find(obj, item);
1144 elm_index_item_clear(Evas_Object *obj)
1146 ELM_CHECK_WIDTYPE(obj, widtype);
1147 Widget_Data *wd = elm_widget_data_get(obj);
1149 Eina_List *l, *clear = NULL;
1151 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1152 EINA_LIST_FOREACH(wd->items, l, it)
1154 if (it->level != wd->level) continue;
1155 clear = eina_list_append(clear, it);
1157 EINA_LIST_FREE(clear, it)
1160 wd->tot_items_count[wd->level]--;
1165 elm_index_item_go(Evas_Object *obj, int level)
1167 ELM_CHECK_WIDTYPE(obj, widtype);
1168 Widget_Data *wd = elm_widget_data_get(obj);
1171 _index_process(obj);
1172 _index_box_auto_fill(obj, wd->bx[0], 0);
1173 if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1177 elm_index_item_data_get(const Elm_Index_Item *it)
1179 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1180 return elm_widget_item_data_get(it);
1184 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1186 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1187 elm_widget_item_data_set(it, data);
1191 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1193 ELM_CHECK_WIDTYPE(obj, widtype);
1194 Widget_Data *wd = elm_widget_data_get(obj);
1195 wd->hide_button = invisible;
1197 edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1202 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1204 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1205 elm_widget_item_del_cb_set(it, func);
1209 elm_index_item_letter_get(const Elm_Index_Item *it)
1211 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);