2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
8 * @defgroup Index Index
11 * An index object is a type of list that categorizes items in it
14 * Signals that you can add callbacks for are:
16 * "changed" - when the selected index item changes
17 * "delay,changed" - when the selected index item changes, but after some small i
19 * "selected" - when the user releases a finger and selects an item
20 * "level,up" - when the user moves a finger from the first level to the second
22 * "level,down" - when the user moves a finger from the second level to the first
26 #define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
27 #define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
28 #define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
30 * use for find view toplevel
32 #define SET_VIEW_LEVEL(wd, view_level)\
33 view_level = wd->level;\
34 while ((!wd->tot_items_count[view_level]) && view_level)\
39 typedef struct _Widget_Data Widget_Data;
41 typedef struct _PlacementPart PlacementPart;
46 Evas_Object *event[2];
47 Evas_Object *bx[2]; // 2 - for now all that's supported
48 Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
51 int max_supp_items_count;
52 int tot_items_count[2];
53 int min_obj_height, max_grp_size;
54 int min_1st_level_obj_height;
57 Evas_Coord pwidth, pheight;
59 const char *special_char;
60 Eina_Bool level_active[2];
61 Eina_Bool horizontal : 1;
64 Eina_Bool hide_button : 1;
68 struct _Elm_Index_Item
71 const char *letter, *vis_letter;
73 Eina_Bool selected : 1;
82 static const char *widtype = NULL;
84 static void _del_hook(Evas_Object *obj);
85 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
86 static void _theme_hook(Evas_Object *obj);
87 static void _sizing_eval(Evas_Object *obj);
88 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
89 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
90 static void _item_free(Elm_Index_Item *it);
91 static void _index_process(Evas_Object *obj);
93 static const char SIG_CHANGED[] = "changed";
94 static const char SIG_DELAY_CHANGED[] = "delay,changed";
95 static const char SIG_SELECTED[] = "selected";
96 static const char SIG_LEVEL_UP[] = "level,up";
97 static const char SIG_LEVEL_DOWN[] = "level,down";
99 static const Evas_Smart_Cb_Description _signals[] = {
101 {SIG_DELAY_CHANGED, ""},
104 {SIG_LEVEL_DOWN, ""},
107 /* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
109 _del_pre_hook(Evas_Object *obj)
111 Widget_Data *wd = elm_widget_data_get(obj);
113 _index_box_clear(obj, wd->bx[wd->level], wd->level);
114 _index_box_clear(obj, wd->bx[0], 0);
115 while (wd->items) _item_free(wd->items->data);
116 if (wd->delay) ecore_timer_del(wd->delay);
118 if(wd->popup_str[0]) free(wd->popup_str[0]);
119 if(wd->popup_str[1]) free(wd->popup_str[1]);
123 _del_hook(Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
130 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
132 Widget_Data *wd = data;
134 _els_box_layout(o, priv, wd->horizontal, 0, 0);
138 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
140 Widget_Data *wd = elm_widget_data_get(obj);
142 edje_object_signal_emit(wd->base, emission, source);
146 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
148 Widget_Data *wd = elm_widget_data_get(obj);
150 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
154 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
156 Widget_Data *wd = elm_widget_data_get(obj);
157 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
162 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
164 Widget_Data *wd = elm_widget_data_get(obj);
167 edje_object_mirrored_set(wd->base, rtl);
171 _theme_hook(Evas_Object *obj)
173 Evas_Coord minw = 0, minh = 0;
174 Widget_Data *wd = elm_widget_data_get(obj);
176 _elm_widget_mirrored_reload(obj);
178 _index_box_clear(obj, wd->bx[0], 0);
179 _index_box_clear(obj, wd->bx[1], 1);
181 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
184 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
185 _mirrored_set(obj, elm_widget_mirrored_get(obj));
187 edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
188 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
189 evas_object_size_hint_min_set(wd->event[0], minw, minh);
191 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
192 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
196 wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
197 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
198 elm_widget_sub_object_add(obj, wd->bx[1]);
200 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
201 evas_object_show(wd->bx[1]);
205 evas_object_del(wd->bx[1]);
208 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
212 wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
213 evas_object_color_set(wd->event[1], 0, 0, 0, 0);
214 elm_widget_sub_object_add(obj, wd->event[1]);
216 edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
217 evas_object_size_hint_min_set(wd->event[1], minw, minh);
219 else if (wd->event[1])
221 evas_object_del(wd->event[1]);
224 edje_object_message_signal_process(wd->base);
225 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
227 _index_box_auto_fill(obj, wd->bx[0], 0);
230 _index_box_auto_fill(obj, wd->bx[1], 1);
234 _sizing_eval(Evas_Object *obj)
236 Widget_Data *wd = elm_widget_data_get(obj);
237 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
239 edje_object_size_min_calc(wd->base, &minw, &minh);
240 evas_object_size_hint_min_set(obj, minw, minh);
241 evas_object_size_hint_max_set(obj, maxw, maxh);
244 static Elm_Index_Item *
245 _item_new(Evas_Object *obj, const char *letter, const void *item)
247 Widget_Data *wd = elm_widget_data_get(obj);
249 if (!wd) return NULL;
250 it = elm_widget_item_new(obj, Elm_Index_Item);
251 if (!it) return NULL;
252 it->base.data = item;
253 it->level = wd->level;
255 it->size = wd->min_obj_height;
257 it->size = wd->min_1st_level_obj_height;
260 it->letter = eina_stringshare_add(letter);
261 it->vis_letter = eina_stringshare_add(letter);
271 static Elm_Index_Item *
272 _item_find(Evas_Object *obj, const void *item)
274 Widget_Data *wd = elm_widget_data_get(obj);
277 if (!wd) return NULL;
278 EINA_LIST_FOREACH(wd->items, l, it)
279 if (it->base.data == item) return it;
284 _item_free(Elm_Index_Item *it)
286 /* Automatically filling the box with index item*/
287 Widget_Data *wd = elm_widget_data_get(it->base.widget);
290 wd->items = eina_list_remove(wd->items, it);
291 elm_widget_item_pre_notify_del(it);
292 eina_stringshare_del(it->letter);
293 eina_stringshare_del(it->vis_letter);
294 elm_widget_item_del(it);
297 // FIXME: always have index filled
299 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
301 Widget_Data *wd = elm_widget_data_get(obj);
305 Evas_Coord mw, mh, w, h;
308 if (wd->level_active[level]) return;
309 rtl = elm_widget_mirrored_get(obj);
310 evas_object_geometry_get(box, NULL, NULL, &w, &h);
311 EINA_LIST_FOREACH(wd->items, l, it)
314 const char *stacking;
316 if (it->level != level) continue;
317 if(i > wd->max_supp_items_count) break;
319 o = edje_object_add(evas_object_evas_get(obj));
321 edje_object_mirrored_set(it->base.view, rtl);
323 _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
325 _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
326 edje_object_part_text_set(o, "elm.text", it->letter);
327 edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
328 evas_object_size_hint_min_set(o, mw, mh);
329 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
331 edje_object_part_text_set(o, "elm.text", it->vis_letter);
332 evas_object_size_hint_min_set(o, mw, it->size);
333 evas_object_size_hint_max_set(o, mw, it->size);
334 evas_object_resize(o, mw, it->size);
336 elm_widget_sub_object_add(obj, o);
337 evas_object_box_append(box, o);
338 stacking = edje_object_data_get(o, "stacking");
341 if (!strcmp(stacking, "below")) evas_object_lower(o);
342 else if (!strcmp(stacking, "above")) evas_object_raise(o);
347 wd->tot_items_count[1] = i;
348 evas_object_smart_calculate(box); // force a calc so we know the size
349 evas_object_size_hint_min_get(box, &mw, &mh);
352 _index_box_clear(obj, box, level);
355 // FIXME: only i objects fit! try again. overflows right now
359 evas_object_smart_calculate(box);
360 wd->level_active[level] = 1;
364 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
366 Widget_Data *wd = elm_widget_data_get(obj);
370 if (!wd->level_active[level]) return;
371 EINA_LIST_FOREACH(wd->items, l, it)
373 if (!it->base.view) continue;
374 if (it->level != level) continue;
375 evas_object_del(it->base.view);
376 it->base.view = NULL;
378 wd->level_active[level] = 0;
382 _delay_change(void *data)
384 Widget_Data *wd = elm_widget_data_get(data);
387 if (!wd) return ECORE_CALLBACK_CANCEL;
389 SET_VIEW_LEVEL(wd, view_level);
390 d = (void *)elm_index_item_selected_get(data, view_level);
391 if (d) evas_object_smart_callback_call(data, "delay,changed", d);
392 return ECORE_CALLBACK_CANCEL;
396 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
398 Widget_Data *wd = elm_widget_data_get(obj);
399 Elm_Index_Item *it, *it_closest, *it_last;
401 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
407 Eina_Bool change = EINA_FALSE;
408 char *label = NULL, *last = NULL;
413 SET_VIEW_LEVEL(wd, view_level);
414 for (i = 0; i <= view_level; i++)
419 evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
420 dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
421 dmax = 1.0-dmin-0.08;
422 EINA_LIST_FOREACH(wd->items, l, it)
424 if (!((it->level == i) && (it->base.view))) continue;
430 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
435 x = (x * x) + (y * y);
436 if ((x < dist) || (!it_closest))
439 cdv = (double)(xx - bx) / (double)bw;
441 cdv = (double)(yy - by) / (double)bh;
446 if ((i == 0) && (view_level == 0))
448 if(cdv > dmax || cdv < dmin)
458 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
462 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
465 if (it_closest) it_closest->selected = 1;
466 if (it_closest != it_last)
471 const char *stacking, *selectraise;
474 if(view_level == it->level)
475 edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
476 stacking = edje_object_data_get(it->base.view, "stacking");
477 selectraise = edje_object_data_get(it->base.view, "selectraise");
478 if ((selectraise) && (!strcmp(selectraise, "on")))
480 if ((stacking) && (!strcmp(stacking, "below")))
481 evas_object_lower(it->base.view);
486 const char *selectraise;
489 if(view_level == it->level)
490 edje_object_signal_emit(it->base.view, "elm,state,active", "elm");
491 selectraise = edje_object_data_get(it->base.view, "selectraise");
492 if ((selectraise) && (!strcmp(selectraise, "on")))
493 evas_object_raise(it->base.view);
494 evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it->base.data);
495 if (wd->delay) ecore_timer_del(wd->delay);
496 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
503 last = strdup(it->letter);
506 if (!label) label = strdup(last);
509 /* FIXME: realloc return NULL if the request fails */
510 label = realloc(label, strlen(label) + strlen(last) + 1);
514 last = strdup(it->letter);
518 if (!label) label = strdup("");
519 if (!last) last = strdup("");
526 if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
527 wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
529 strcpy(wd->popup_str[0], last);
530 edje_object_signal_emit(wd->base, "hide_2nd_level", "");
532 if (view_level == 1 && wd->level_active[1])
534 wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
536 strcpy(wd->popup_str[1], last);
537 edje_object_signal_emit(wd->base, "hide_first_level", "");
539 popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
540 sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
541 edje_object_part_text_set(wd->base, "elm.text", popup_text);
553 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
555 Widget_Data *wd = elm_widget_data_get(data);
556 // Evas_Event_Mouse_Wheel *ev = event_info;
557 // Evas_Object *obj = o;
562 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
564 Widget_Data *wd = elm_widget_data_get(data);
565 Evas_Event_Mouse_Down *ev = event_info;
568 if (ev->button != 1) return;
570 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
571 wd->dx = ev->canvas.x - x;
572 wd->dy = ev->canvas.y - y;
573 elm_index_active_set(data, 1);
574 _sel_eval(data, ev->canvas.x, ev->canvas.y);
575 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
576 (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
580 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
582 Widget_Data *wd = elm_widget_data_get(data);
583 Evas_Event_Mouse_Up *ev = event_info;
590 if (ev->button != 1) return;
591 if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
594 SET_VIEW_LEVEL(wd, view_level);
595 d = (void *)elm_index_item_selected_get(data, view_level);
596 EINA_LIST_FOREACH(wd->items, l, it)
598 edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
600 if (d) evas_object_smart_callback_call(data, SIG_SELECTED, d);
601 elm_index_active_set(data, 0);
602 edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
606 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
608 Widget_Data *wd = elm_widget_data_get(data);
609 Evas_Event_Mouse_Move *ev = event_info;
610 Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
614 if (!wd->down) return;
615 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
616 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
617 x = ev->cur.canvas.x - x;
618 y = ev->cur.canvas.y - y;
621 if (adx < 0) adx = -dx;
622 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
623 , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
631 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
632 edje_object_signal_emit(wd->base, buf, "elm");
633 evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
641 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
642 edje_object_signal_emit(wd->base, buf, "elm");
643 d = (void *)elm_index_item_selected_get(data, wd->level);
644 evas_object_smart_callback_call(data, "changed", d);
645 if (wd->delay) ecore_timer_del(wd->delay);
646 wd->delay = ecore_timer_add(0.2, _delay_change, data);
647 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
651 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
655 _index_box_refill_job(void *data)
657 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
663 evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
664 wd->scale_factor = elm_scale_get();
665 if ( wd->scale_factor == 0.0 ) {
666 wd->scale_factor = 1.0;
668 string = edje_object_data_get(wd->base, "min_obj_height");
670 wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
672 wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
673 if(!wd->min_obj_height) return;
675 wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
676 wd->items_count = ph/wd->min_obj_height;
677 wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
679 if(pw != wd->pwidth && ph != wd->pheight)
684 elm_index_active_set(data, 1);
686 _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
687 evas_object_smart_calculate( wd->bx[0]);
688 elm_index_item_go((Evas_Object *)data, wd->level);
694 static void _index_object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
698 wd = elm_widget_data_get((Evas_Object *)data);
700 ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
704 * Add a new index to the parent
706 * @param parent The parent object
707 * @return The new object or NULL if it cannot be created
712 elm_index_add(Evas_Object *parent)
718 Evas_Coord minw, minh;
721 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
723 ELM_SET_WIDTYPE(widtype, "index");
724 elm_widget_type_set(obj, "index");
725 elm_widget_sub_object_add(parent, obj);
726 elm_widget_data_set(obj, wd);
727 elm_widget_del_hook_set(obj, _del_hook);
728 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
729 elm_widget_theme_hook_set(obj, _theme_hook);
730 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
731 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
732 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
733 elm_widget_can_focus_set(obj, EINA_FALSE);
735 wd->horizontal = EINA_FALSE;
736 wd->min_obj_height = 0;
737 wd->max_grp_size = 0;
739 wd->max_supp_items_count = 0;
740 wd->tot_items_count[0] = 0;
741 wd->tot_items_count[1] = 0;
743 wd->special_char = edje_object_data_get(wd->base, "special_char");
744 if(wd->special_char == NULL) wd->special_char = eina_stringshare_add("*");
746 wd->base = edje_object_add(e);
747 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
748 elm_widget_resize_object_set(obj, wd->base);
750 o = evas_object_rectangle_add(e);
752 evas_object_color_set(o, 0, 0, 0, 0);
754 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
755 evas_object_size_hint_min_set(o, minw, minh);
756 edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
757 elm_widget_sub_object_add(obj, o);
758 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
759 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
760 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
761 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
762 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
764 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
766 o = evas_object_rectangle_add(e);
768 evas_object_color_set(o, 0, 0, 0, 0);
769 evas_object_size_hint_min_set(o, minw, minh);
770 edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
771 elm_widget_sub_object_add(obj, o);
774 wd->bx[0] = evas_object_box_add(e);
775 evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
776 elm_widget_sub_object_add(obj, wd->bx[0]);
777 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
778 evas_object_show(wd->bx[0]);
780 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
782 wd->bx[1] = evas_object_box_add(e);
783 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
784 elm_widget_sub_object_add(obj, wd->bx[1]);
785 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
786 evas_object_show(wd->bx[1]);
789 evas_object_smart_callbacks_descriptions_set(obj, _signals);
790 wd->scale_factor = elm_scale_get();
791 if ( wd->scale_factor == 0.0 )
792 wd->scale_factor = 1.0;
793 string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
795 wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
797 wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
798 wd->popup_str[0] = calloc(1, sizeof(char) * 1);
799 wd->popup_str[1] = calloc(1, sizeof(char) * 1);
801 _mirrored_set(obj, elm_widget_mirrored_get(obj));
807 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
809 Widget_Data *wd = elm_widget_data_get(obj);
811 int group_count = MIN_GRP_SIZE;
812 while(group_count <= wd->max_grp_size)
814 if(extraIndex <= wd->max_grp_size*adj_pos)
816 if(group_count*adj_pos>=extraIndex) return group_count;
819 return wd->max_grp_size;
821 group_count += MIN_GRP_SIZE;
827 _index_process(Evas_Object *obj)
830 int j,i, group_count;
836 Widget_Data *wd = elm_widget_data_get(obj);
839 if (wd->items_count == 0) return;
841 const int adj_pos = (wd->items_count-1)*0.5;
842 if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
843 n = wd->tot_items_count[wd->level];
845 n = wd->max_supp_items_count;
846 group_count = MIN_GRP_SIZE;
848 int *indx = (int*)calloc(n, sizeof(int));
851 const int minh = wd->min_obj_height;
852 EINA_LIST_FOREACH(wd->items, l, it)
854 it->vis_letter = eina_stringshare_add(it->letter);
859 int N = wd->items_count;
866 if (extraIndex < 0) return;
868 group_count = _group_count(obj, extraIndex, adj_pos, N);
869 if (group_count <= 0)
877 PlacementPart place[adj_pos];
878 remainder = extraIndex%group_count;
879 numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
881 for (i=0;i<numberofparts; i++)
883 place[i].count=group_count+1;
884 count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
885 place[i].start= count +i*group_count-1;
888 place[numberofparts-1].count=remainder+1;
890 for (i=0;i<numberofparts;i++)
892 for (j=0;j<place[i].count; j++)
894 indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
896 indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
899 EINA_LIST_FOREACH(wd->items, l, it)
901 int size = indx[count];
905 it->vis_letter = eina_stringshare_add(it->letter);
910 eina_stringshare_del(it->vis_letter);
911 it->vis_letter = eina_stringshare_add("");
915 eina_stringshare_del(it->vis_letter);
916 it->vis_letter = eina_stringshare_add(wd->special_char);
918 it->size = size*wd->scale_factor;
928 * Set the active state of the index programatically
930 * @param obj The index object
931 * @param active The active state
936 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
938 ELM_CHECK_WIDTYPE(obj, widtype);
939 Widget_Data *wd = elm_widget_data_get(obj);
941 if (wd->active == active) return;
946 _index_box_clear(obj, wd->bx[1], 1);
948 _index_box_auto_fill(obj, wd->bx[0], 0);
949 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
952 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
956 * Get the active state of the index programatically
958 * @param obj The index object
959 * @return The active state
964 elm_index_active_get(const Evas_Object *obj)
966 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
967 Widget_Data *wd = elm_widget_data_get(obj);
968 if (!wd) return EINA_FALSE;
973 * Sets the level of the item.
975 * @param obj The index object.
976 * @param level To be documented.
981 elm_index_item_level_set(Evas_Object *obj, int level)
983 ELM_CHECK_WIDTYPE(obj, widtype);
984 Widget_Data *wd = elm_widget_data_get(obj);
986 if (wd->level == level) return;
991 * Gets the level of the item.
993 * @param obj The index object
998 elm_index_item_level_get(const Evas_Object *obj)
1000 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1001 Widget_Data *wd = elm_widget_data_get(obj);
1007 * Returns the selected item.
1009 * @param obj The index object.
1010 * @param level to be documented.
1015 elm_index_item_selected_get(const Evas_Object *obj, int level)
1017 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1018 Widget_Data *wd = elm_widget_data_get(obj);
1021 if (!wd) return NULL;
1022 EINA_LIST_FOREACH(wd->items, l, it)
1023 if ((it->selected) && (it->level == level))
1024 return elm_widget_item_data_get(it);
1029 * Appends a new item.
1031 * @param obj The index object.
1032 * @param letter Letter under which the item should be indexed
1033 * @param item The item to put in the index
1038 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1040 ELM_CHECK_WIDTYPE(obj, widtype);
1041 Widget_Data *wd = elm_widget_data_get(obj);
1044 it = _item_new(obj, letter, item);
1046 wd->items = eina_list_append(wd->items, it);
1047 wd->tot_items_count[wd->level]++;
1048 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1052 * Prepends a new item.
1054 * @param obj The index object.
1055 * @param letter Letter under which the item should be indexed
1056 * @param item The item to put in the index
1061 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1063 ELM_CHECK_WIDTYPE(obj, widtype);
1064 Widget_Data *wd = elm_widget_data_get(obj);
1068 it = _item_new(obj, letter, item);
1070 wd->items = eina_list_prepend(wd->items, it);
1071 wd->tot_items_count[wd->level]++;
1072 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1076 * Append an item after @p relative in letter @p letter.
1078 * @param obj The index object
1079 * @param letter Letter under which the item should be indexed
1080 * @param item The item to put in the index
1081 * @param relative The item to put @p item after
1086 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1088 ELM_CHECK_WIDTYPE(obj, widtype);
1089 Widget_Data *wd = elm_widget_data_get(obj);
1090 Elm_Index_Item *it, *it_rel;
1094 elm_index_item_append(obj, letter, item);
1095 wd->tot_items_count[wd->level]++;
1098 it = _item_new(obj, letter, item);
1101 it_rel = _item_find(obj, relative);
1104 elm_index_item_append(obj, letter, item);
1105 wd->tot_items_count[wd->level]++;
1109 wd->items = eina_list_append_relative(wd->items, it, it_rel);
1110 wd->tot_items_count[wd->level]++;
1111 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1115 * Prepend an item before @p relative in letter @p letter.
1117 * @param obj The index object
1118 * @param letter Letter under which the item should be indexed
1119 * @param item The item to put in the index
1120 * @param relative The item to put @p item before
1125 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1127 ELM_CHECK_WIDTYPE(obj, widtype);
1128 Widget_Data *wd = elm_widget_data_get(obj);
1129 Elm_Index_Item *it, *it_rel;
1133 elm_index_item_prepend(obj, letter, item);
1134 wd->tot_items_count[wd->level]++;
1137 it = _item_new(obj, letter, item);
1140 it_rel = _item_find(obj, relative);
1143 elm_index_item_append(obj, letter, item);
1144 wd->tot_items_count[wd->level]++;
1148 wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
1149 wd->tot_items_count[wd->level]++;
1150 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1154 * Insert a new @p item into the sorted index @p obj in @p letter.
1156 * @param obj The index object
1157 * @param letter Letter under which the item should be indexed
1158 * @param item The item to put in the index
1159 * @param cmp_func The function called for the sort of index items.
1160 * @param cmp_data_func The function called for the sort of the data. It will
1161 * be used when cmp_func return 0. It means the index item already exists.
1162 * So, to decide which data item should be pointed by the index item, a function
1163 * to compare them is needed. If this function is not provided, index items
1164 * will be duplicated. If cmp_data_func returns a non-negative value, the
1165 * previous index item data will be replaced by the inserted @p item. So
1166 * if the previous data need to be free, it should be done in this function,
1167 * because the reference will be lost.
1172 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)
1174 ELM_CHECK_WIDTYPE(obj, widtype);
1175 Widget_Data *wd = elm_widget_data_get(obj);
1183 elm_index_item_append(obj, letter, item);
1187 it = _item_new(obj, letter, item);
1190 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1192 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1194 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1197 /* If cmp_data_func is not provided, append a duplicated item */
1199 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1202 Elm_Index_Item *p_it = eina_list_data_get(lnear);
1203 if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1204 p_it->base.data = it->base.data;
1209 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1213 * Remove an item from the index.
1215 * @param obj The index object
1216 * @param item The item to remove from the index
1221 elm_index_item_del(Evas_Object *obj, const void *item)
1223 ELM_CHECK_WIDTYPE(obj, widtype);
1224 Widget_Data *wd = elm_widget_data_get(obj);
1227 it = _item_find(obj, item);
1230 wd->tot_items_count[wd->level]--;
1231 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1235 * Find an index item using item data.
1237 * @param obj The index object
1238 * @param item The item pointed by index item
1239 * @return The index item pointing to @p item
1243 EAPI Elm_Index_Item *
1244 elm_index_item_find(Evas_Object *obj, const void *item)
1246 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1247 Widget_Data *wd = elm_widget_data_get(obj);
1248 if (!wd) return NULL;
1249 return _item_find(obj, item);
1253 * Clears an index of its items.
1255 * @param obj The index object.
1260 elm_index_item_clear(Evas_Object *obj)
1262 ELM_CHECK_WIDTYPE(obj, widtype);
1263 Widget_Data *wd = elm_widget_data_get(obj);
1265 Eina_List *l, *clear = NULL;
1267 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1268 EINA_LIST_FOREACH(wd->items, l, it)
1270 if (it->level != wd->level) continue;
1271 clear = eina_list_append(clear, it);
1273 EINA_LIST_FREE(clear, it)
1276 wd->tot_items_count[wd->level]--;
1281 * Go to item at @p level
1283 * @param obj The index object
1284 * @param level The index level
1289 elm_index_item_go(Evas_Object *obj, int level)
1291 ELM_CHECK_WIDTYPE(obj, widtype);
1292 Widget_Data *wd = elm_widget_data_get(obj);
1295 _index_process(obj);
1296 _index_box_auto_fill(obj, wd->bx[0], 0);
1297 if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1301 * Returns the data associated with the item.
1303 * @param it The list item
1304 * @return The data associated with @p it
1309 elm_index_item_data_get(const Elm_Index_Item *it)
1311 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1312 return elm_widget_item_data_get(it);
1316 * Set the data item from the index item
1318 * This set a new data value.
1320 * @param it The item
1321 * @param data The new data pointer to set
1326 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1328 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1329 elm_widget_item_data_set(it, data);
1333 * Make the Central Button Image invisible.
1335 * @param obj The Index.
1336 * @param invisible Whether button visible or not.
1342 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1344 ELM_CHECK_WIDTYPE(obj, widtype);
1345 Widget_Data *wd = elm_widget_data_get(obj);
1346 wd->hide_button = invisible;
1348 edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1353 * Set the function called when a index item is freed.
1355 * @param it The item to set the callback on
1356 * @param func The function called
1361 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1363 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1364 elm_widget_item_del_cb_set(it, func);
1368 * Gets the letter of the item.
1370 * @param it The list item
1371 * @return The letter of @p it
1376 elm_index_item_letter_get(const Elm_Index_Item *it)
1378 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);