Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_index.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4 #include <Elementary.h>
5 #include "elm_priv.h"
6
7 /**
8  * @defgroup Index Index
9  * @ingroup Elementary
10  *
11  * An index object is a type of list that categorizes items in it
12  * by letter.
13  *
14  * Signals that you can add callbacks for are:
15  *
16  * "changed" - when the selected index item changes
17  * "delay,changed" - when the selected index item changes, but after some small i
18  *                   dle period
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
21  *              level
22  * "level,down" - when the user moves a finger from the second level to the first
23  *                level
24  */
25
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.
29 /*
30  *  use for find view toplevel
31  */
32 #define SET_VIEW_LEVEL(wd, view_level)\
33    view_level = wd->level;\
34    while ((!wd->tot_items_count[view_level]) && view_level)\
35      {\
36         view_level--; \
37      }
38
39 typedef struct _Widget_Data Widget_Data;
40
41 typedef struct _PlacementPart PlacementPart;
42
43 struct _Widget_Data
44 {
45    Evas_Object *base;
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
49    char *popup_str[2];
50    int level;
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;
55    int items_count;
56    Evas_Coord dx, dy;
57    Evas_Coord pwidth, pheight;
58    Ecore_Timer *delay;
59    const char *special_char;
60    Eina_Bool level_active[2];
61    Eina_Bool horizontal : 1;
62    Eina_Bool active : 1;
63    Eina_Bool down : 1;
64    Eina_Bool hide_button : 1;
65    double scale_factor;
66 };
67
68 struct _Elm_Index_Item
69 {
70    Elm_Widget_Item base;
71    const char *letter, *vis_letter;
72    int level, size;
73    Eina_Bool selected : 1;
74 };
75
76 struct _PlacementPart
77 {
78    int start;
79    int count;
80 };
81
82 static const char *widtype = NULL;
83
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);
92
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";
98
99 static const Evas_Smart_Cb_Description _signals[] = {
100    {SIG_CHANGED, ""},
101    {SIG_DELAY_CHANGED, ""},
102    {SIG_SELECTED, ""},
103    {SIG_LEVEL_UP, ""},
104    {SIG_LEVEL_DOWN, ""},
105    {NULL, NULL}
106 };
107 /* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
108 static void
109 _del_pre_hook(Evas_Object *obj)
110 {
111    Widget_Data *wd = elm_widget_data_get(obj);
112    if (!wd) return;
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);
117
118    if(wd->popup_str[0]) free(wd->popup_str[0]);
119    if(wd->popup_str[1]) free(wd->popup_str[1]);
120 }
121
122 static void
123 _del_hook(Evas_Object *obj)
124 {
125    Widget_Data *wd = elm_widget_data_get(obj);
126    free(wd);
127 }
128
129 static void
130 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
131 {
132    Widget_Data *wd = data;
133    if (!wd) return;
134    _els_box_layout(o, priv, wd->horizontal, 0, 0);
135 }
136
137 static void
138 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
139 {
140    Widget_Data *wd = elm_widget_data_get(obj);
141    if (!wd) return;
142    edje_object_signal_emit(wd->base, emission, source);
143 }
144
145 static void
146 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
147 {
148    Widget_Data *wd = elm_widget_data_get(obj);
149    if (!wd) return;
150    edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
151 }
152
153 static void
154 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
155 {
156    Widget_Data *wd = elm_widget_data_get(obj);
157    edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
158                                         data);
159 }
160
161 static void
162 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
163 {
164    Widget_Data *wd = elm_widget_data_get(obj);
165    if (!wd) return;
166    if (!wd->horizontal)
167      edje_object_mirrored_set(wd->base, rtl);
168 }
169
170 static void
171 _theme_hook(Evas_Object *obj)
172 {
173    Evas_Coord minw = 0, minh = 0;
174    Widget_Data *wd = elm_widget_data_get(obj);
175    if (!wd) return;
176    _elm_widget_mirrored_reload(obj);
177
178    _index_box_clear(obj, wd->bx[0], 0);
179    _index_box_clear(obj, wd->bx[1], 1);
180    if (wd->horizontal)
181      _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
182    else
183      {
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));
186      }
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);
190
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"))
193      {
194         if (!wd->bx[1])
195           {
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]);
199           }
200         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
201         evas_object_show(wd->bx[1]);
202      }
203    else if (wd->bx[1])
204      {
205         evas_object_del(wd->bx[1]);
206         wd->bx[1] = NULL;
207      }
208    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
209      {
210         if (!wd->event[1])
211           {
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]);
215           }
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);
218      }
219    else if (wd->event[1])
220      {
221         evas_object_del(wd->event[1]);
222         wd->event[1] = NULL;
223      }
224    edje_object_message_signal_process(wd->base);
225    edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
226    _sizing_eval(obj);
227    _index_box_auto_fill(obj, wd->bx[0], 0);
228    if (wd->active)
229      if (wd->level == 1)
230        _index_box_auto_fill(obj, wd->bx[1], 1);
231 }
232
233 static void
234 _sizing_eval(Evas_Object *obj)
235 {
236    Widget_Data *wd = elm_widget_data_get(obj);
237    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
238    if (!wd) return;
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);
242 }
243
244 static Elm_Index_Item *
245 _item_new(Evas_Object *obj, const char *letter, const void *item)
246 {
247    Widget_Data *wd = elm_widget_data_get(obj);
248    Elm_Index_Item *it;
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;
254    if(wd->level == 0)
255      it->size =  wd->min_obj_height;
256    else
257      it->size =  wd->min_1st_level_obj_height;
258    if(letter)
259      {
260         it->letter = eina_stringshare_add(letter);
261         it->vis_letter = eina_stringshare_add(letter);
262      }
263    else
264      {
265         _item_free(it);
266         return NULL;
267      }
268    return it;
269 }
270
271 static Elm_Index_Item *
272 _item_find(Evas_Object *obj, const void *item)
273 {
274    Widget_Data *wd = elm_widget_data_get(obj);
275    Eina_List *l;
276    Elm_Index_Item *it;
277    if (!wd) return NULL;
278    EINA_LIST_FOREACH(wd->items, l, it)
279       if (it->base.data == item) return it;
280    return NULL;
281 }
282
283 static void
284 _item_free(Elm_Index_Item *it)
285 {
286 /* Automatically filling the box with index item*/
287    Widget_Data *wd = elm_widget_data_get(it->base.widget);
288    if (!wd) return;
289
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);
295 }
296
297 // FIXME: always have index filled
298 static void
299 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
300 {
301    Widget_Data *wd = elm_widget_data_get(obj);
302    Eina_Bool rtl;
303    Eina_List *l;
304    Elm_Index_Item *it;
305    Evas_Coord mw, mh, w, h;
306    int i = 0;
307    if (!wd) return;
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)
312      {
313         Evas_Object *o;
314         const char *stacking;
315
316         if (it->level != level) continue;
317         if(i > wd->max_supp_items_count) break;
318
319         o = edje_object_add(evas_object_evas_get(obj));
320         it->base.view = o;
321         edje_object_mirrored_set(it->base.view, rtl);
322         if (i & 0x1)
323           _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
324         else
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);
335
336         elm_widget_sub_object_add(obj, o);
337         evas_object_box_append(box, o);
338         stacking = edje_object_data_get(o, "stacking");
339         if (stacking)
340           {
341              if (!strcmp(stacking, "below")) evas_object_lower(o);
342              else if (!strcmp(stacking, "above")) evas_object_raise(o);
343           }
344         evas_object_show(o);
345         i++;
346         if(level == 1)
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);
350         if (mh > h)
351           {
352              _index_box_clear(obj, box, level);
353              if (i > 0)
354                {
355                   // FIXME: only i objects fit! try again. overflows right now
356                }
357           }
358      }
359    evas_object_smart_calculate(box);
360    wd->level_active[level] = 1;
361 }
362
363 static void
364 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
365 {
366    Widget_Data *wd = elm_widget_data_get(obj);
367    Eina_List *l;
368    Elm_Index_Item *it;
369    if (!wd) return;
370    if (!wd->level_active[level]) return;
371    EINA_LIST_FOREACH(wd->items, l, it)
372      {
373         if (!it->base.view) continue;
374         if (it->level != level) continue;
375         evas_object_del(it->base.view);
376         it->base.view = NULL;
377      }
378    wd->level_active[level] = 0;
379 }
380
381 static Eina_Bool
382 _delay_change(void *data)
383 {
384    Widget_Data *wd = elm_widget_data_get(data);
385    void *d;
386    int view_level;
387    if (!wd) return ECORE_CALLBACK_CANCEL;
388    wd->delay = NULL;
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;
393 }
394
395 static void
396 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
397 {
398    Widget_Data *wd = elm_widget_data_get(obj);
399    Elm_Index_Item *it, *it_closest, *it_last;
400    Eina_List *l;
401    Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
402    double cdv = 0.5;
403    double cdvv = 0.0;
404    double dmax = 0.0;
405    double dmin = 0.0;
406    Evas_Coord dist;
407    Eina_Bool change = EINA_FALSE;
408    char *label = NULL, *last = NULL;
409    int i;
410    int view_level;
411    if (!wd) return;
412
413    SET_VIEW_LEVEL(wd, view_level);
414    for (i = 0; i <= view_level; i++)
415      {
416         it_last = NULL;
417         it_closest  = NULL;
418         dist = 0x7fffffff;
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)
423           {
424              if (!((it->level == i) && (it->base.view))) continue;
425              if (it->selected)
426                {
427                   it_last = it;
428                   it->selected = 0;
429                }
430              evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
431              xx = x + (w / 2);
432              yy = y + (h / 2);
433              x = evx - xx;
434              y = evy - yy;
435              x = (x * x) + (y * y);
436              if ((x < dist) || (!it_closest))
437                {
438                   if (wd->horizontal)
439                     cdv = (double)(xx - bx) / (double)bw;
440                   else
441                     cdv = (double)(yy - by) / (double)bh;
442                   it_closest = it;
443                   dist = x;
444                }
445           }
446           if ((i == 0) && (view_level == 0))
447             {
448                if(cdv > dmax || cdv < dmin)
449                  {
450                     if(cdv > dmax)
451                       {
452                          cdvv = dmax;
453                       }
454                     else
455                       {
456                          cdvv = dmin;
457                       }
458                     edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
459                  }
460                else
461                  {
462                     edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
463                  }
464             }
465         if (it_closest) it_closest->selected = 1;
466         if (it_closest != it_last)
467           {
468              change = 1;
469              if (it_last)
470                {
471                   const char *stacking, *selectraise;
472
473                   it = it_last;
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")))
479                     {
480                        if ((stacking) && (!strcmp(stacking, "below")))
481                          evas_object_lower(it->base.view);
482                     }
483                }
484              if (it_closest)
485                {
486                   const char *selectraise;
487
488                   it = it_closest;
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);
497                }
498           }
499         if (it_closest)
500           {
501              it = it_closest;
502              if (!last)
503                last = strdup(it->letter);
504              else
505                {
506                   if (!label) label = strdup(last);
507                   else
508                     {
509                        /* FIXME: realloc return NULL if the request fails */
510                        label = realloc(label, strlen(label) + strlen(last) + 1);
511                        strcat(label, last);
512                     }
513                   free(last);
514                   last = strdup(it->letter);
515                }
516           }
517      }
518    if (!label) label = strdup("");
519    if (!last) last = strdup("");
520    if(!wd->hide_button)
521      {
522         char *popup_text;
523
524         if(view_level == 0)
525           {
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));
528
529              strcpy(wd->popup_str[0], last);
530              edje_object_signal_emit(wd->base, "hide_2nd_level", "");
531           }
532         if (view_level == 1 && wd->level_active[1])
533           {
534              wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
535
536              strcpy(wd->popup_str[1], last);
537              edje_object_signal_emit(wd->base, "hide_first_level", "");
538           }
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);
542
543         free(popup_text);
544      }
545
546    if(label)
547      free(label);
548    if(last)
549      free(last);
550 }
551
552 static void
553 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
554 {
555    Widget_Data *wd = elm_widget_data_get(data);
556    //   Evas_Event_Mouse_Wheel *ev = event_info;
557    //   Evas_Object *obj = o;
558    if (!wd) return;
559 }
560
561 static void
562 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
563 {
564    Widget_Data *wd = elm_widget_data_get(data);
565    Evas_Event_Mouse_Down *ev = event_info;
566    Evas_Coord x, y, w;
567    if (!wd) return;
568    if (ev->button != 1) return;
569    wd->down = 1;
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);
577 }
578
579 static void
580 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
581 {
582    Widget_Data *wd = elm_widget_data_get(data);
583    Evas_Event_Mouse_Up *ev = event_info;
584    void *d;
585    Elm_Index_Item *it;
586    Eina_List *l;
587    int view_level;
588
589    if (!wd) return;
590    if (ev->button != 1) return;
591    if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
592    wd->delay = NULL;
593    wd->down = 0;
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)
597      {
598         edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
599      }
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");
603 }
604
605 static void
606 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
607 {
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;
611    void *d;
612    char buf[1024];
613    if (!wd) return;
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;
619    dx = x - wd->dx;
620    adx = dx;
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);
624    if (!wd->horizontal)
625      {
626         if (adx > minw)
627           {
628              if (!wd->level)
629                {
630                   wd->level = 1;
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);
634                }
635           }
636         else
637           {
638              if (wd->level == 1)
639                {
640                   wd->level = 0;
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);
648                }
649           }
650      }
651    _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
652 }
653
654 static void
655 _index_box_refill_job(void *data)
656 {
657    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
658    if (!wd) return;
659
660    const char *string;
661    Evas_Coord pw, ph;
662
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;
667    }
668    string = edje_object_data_get(wd->base, "min_obj_height");
669    if(string)
670      wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
671    else
672      wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
673    if(!wd->min_obj_height) return;
674
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;
678
679    if(pw != wd->pwidth && ph != wd->pheight)
680      {
681         if(wd->down == 1)
682           {
683              wd->active = 0;
684              elm_index_active_set(data, 1);
685           }
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);
689         wd->pwidth = pw;
690         wd->pheight = ph;
691      }
692 }
693
694 static void _index_object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
695 {
696    Widget_Data *wd;
697    if(!data) return;
698    wd = elm_widget_data_get((Evas_Object *)data);
699    if(!wd) return;
700    ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
701 }
702
703 /**
704  * Add a new index to the parent
705  *
706  * @param parent The parent object
707  * @return The new object or NULL if it cannot be created
708  *
709  * @ingroup Index
710  */
711 EAPI Evas_Object *
712 elm_index_add(Evas_Object *parent)
713 {
714    Evas_Object *obj;
715    Evas_Object *o;
716    Evas *e;
717    Widget_Data *wd;
718    Evas_Coord minw, minh;
719    const char *string;
720   
721    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
722
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);
734
735    wd->horizontal = EINA_FALSE;
736    wd->min_obj_height = 0;
737    wd->max_grp_size = 0;
738    wd->items_count = 0;
739    wd->max_supp_items_count = 0;
740    wd->tot_items_count[0] = 0;
741    wd->tot_items_count[1] = 0;
742    wd->hide_button = 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("*");
745
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);
749
750    o = evas_object_rectangle_add(e);
751    wd->event[0] = o;
752    evas_object_color_set(o, 0, 0, 0, 0);
753    minw = minh = 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);
763    evas_object_show(o);
764    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
765      {
766         o = evas_object_rectangle_add(e);
767         wd->event[1] = o;
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);
772      }
773
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]);
779
780    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
781      {
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]);
787      }
788
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");
794    if(string)
795      wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
796    else
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);
800
801    _mirrored_set(obj, elm_widget_mirrored_get(obj));
802    _sizing_eval(obj);
803    return obj;
804 }
805
806 static int
807 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
808 {
809    Widget_Data *wd = elm_widget_data_get(obj);
810    if (!wd) return 0;
811    int group_count = MIN_GRP_SIZE;
812    while(group_count <= wd->max_grp_size)
813      {
814         if(extraIndex <= wd->max_grp_size*adj_pos)
815           {
816              if(group_count*adj_pos>=extraIndex) return group_count;
817           }
818         else
819           return wd->max_grp_size;
820
821         group_count += MIN_GRP_SIZE;
822      }
823    return group_count;
824 }
825
826 static void
827 _index_process(Evas_Object *obj)
828 {
829    int extraIndex;
830    int j,i, group_count;
831    Eina_List *l;
832    Elm_Index_Item *it;
833    int count;
834    int n;
835
836    Widget_Data *wd = elm_widget_data_get(obj);
837    if (!wd) return;
838
839    if (wd->items_count == 0) return;
840
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];
844    else
845       n = wd->max_supp_items_count;
846    group_count = MIN_GRP_SIZE;
847
848    int *indx = (int*)calloc(n, sizeof(int));
849    if (!indx) return;
850
851    const int minh = wd->min_obj_height;
852    EINA_LIST_FOREACH(wd->items, l, it)
853      {
854         it->vis_letter = eina_stringshare_add(it->letter);
855         it->size =  minh;
856      }
857    int remainder;
858    int numberofparts;
859    int N = wd->items_count;
860
861    for (i=0;i<n;i++)
862      {
863         indx[i] = minh;
864      }
865    extraIndex=n-N;
866    if (extraIndex < 0) return;
867
868    group_count = _group_count(obj, extraIndex, adj_pos, N);
869    if (group_count <= 0) return;
870
871    PlacementPart place[adj_pos];
872    remainder = extraIndex%group_count;
873    numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
874
875    for (i=0;i<numberofparts; i++)
876      {
877         place[i].count=group_count+1;
878         count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
879         place[i].start= count +i*group_count-1;
880      }
881    if (remainder)
882      place[numberofparts-1].count=remainder+1;
883
884    for (i=0;i<numberofparts;i++)
885      {
886         for (j=0;j<place[i].count; j++)
887           {
888              indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
889           }
890         indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
891      }
892    count = 0;
893    EINA_LIST_FOREACH(wd->items, l, it)
894      {
895         int size = indx[count];
896         count++;
897         if (size == minh)
898           {
899              it->vis_letter = eina_stringshare_add(it->letter);
900              continue;
901           }
902         else if (size == 1)
903           {
904              eina_stringshare_del(it->vis_letter);
905              it->vis_letter = eina_stringshare_add("");
906           }
907         else
908           {
909              eina_stringshare_del(it->vis_letter);
910              it->vis_letter = eina_stringshare_add(wd->special_char);
911           }
912         it->size = size*wd->scale_factor;
913      }
914    if (indx)
915      {
916         free(indx);
917         indx = NULL;
918      }
919 }
920
921 /**
922  * Set the active state of the index programatically
923  *
924  * @param obj The index object
925  * @param active The active state
926  *
927  * @ingroup Index
928  */
929 EAPI void
930 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
931 {
932    ELM_CHECK_WIDTYPE(obj, widtype);
933    Widget_Data *wd = elm_widget_data_get(obj);
934    if (!wd) return;
935    if (wd->active == active) return;
936    wd->active = active;
937    wd->level = 0;
938    if (wd->active)
939      {
940         _index_box_clear(obj, wd->bx[1], 1);
941         _index_process(obj);
942         _index_box_auto_fill(obj, wd->bx[0], 0);
943         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
944      }
945    else
946      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
947 }
948
949 /**
950  * Get the active state of the index programatically
951  *
952  * @param obj The index object
953  * @return The active state
954  *
955  * @ingroup Index
956  */
957 EAPI Eina_Bool
958 elm_index_active_get(const Evas_Object *obj)
959 {
960    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
961    Widget_Data *wd = elm_widget_data_get(obj);
962    if (!wd) return EINA_FALSE;
963    return wd->active;
964 }
965
966 /**
967  * Sets the level of the item.
968  *
969  * @param obj The index object.
970  * @param level To be documented.
971  *
972  * @ingroup Index
973  */
974 EAPI void
975 elm_index_item_level_set(Evas_Object *obj, int level)
976 {
977    ELM_CHECK_WIDTYPE(obj, widtype);
978    Widget_Data *wd = elm_widget_data_get(obj);
979    if (!wd) return;
980    if (wd->level == level) return;
981    wd->level = level;
982 }
983
984 /**
985  * Gets the level of the item.
986  *
987  * @param obj The index object
988  *
989  * @ingroup Index
990  */
991 EAPI int
992 elm_index_item_level_get(const Evas_Object *obj)
993 {
994    ELM_CHECK_WIDTYPE(obj, widtype) 0;
995    Widget_Data *wd = elm_widget_data_get(obj);
996    if (!wd) return 0;
997    return wd->level;
998 }
999
1000 /**
1001  * Returns the selected item.
1002  *
1003  * @param obj The index object.
1004  * @param level to be documented.
1005  *
1006  * @ingroup Index
1007  */
1008 EAPI void *
1009 elm_index_item_selected_get(const Evas_Object *obj, int level)
1010 {
1011    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1012    Widget_Data *wd = elm_widget_data_get(obj);
1013    Eina_List *l;
1014    Elm_Index_Item *it;
1015    if (!wd) return NULL;
1016    EINA_LIST_FOREACH(wd->items, l, it)
1017      if ((it->selected) && (it->level == level))
1018        return elm_widget_item_data_get(it);
1019    return NULL;
1020 }
1021
1022 /**
1023  * Appends a new item.
1024  *
1025  * @param obj The index object.
1026  * @param letter Letter under which the item should be indexed
1027  * @param item The item to put in the index
1028  *
1029  * @ingroup Index
1030  */
1031 EAPI void
1032 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1033 {
1034    ELM_CHECK_WIDTYPE(obj, widtype);
1035    Widget_Data *wd = elm_widget_data_get(obj);
1036    Elm_Index_Item *it;
1037    if (!wd) return;
1038    it = _item_new(obj, letter, item);
1039    if (!it) return;
1040    wd->items = eina_list_append(wd->items, it);
1041    wd->tot_items_count[wd->level]++;
1042    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1043 }
1044
1045 /**
1046  * Prepends a new item.
1047  *
1048  * @param obj The index object.
1049  * @param letter Letter under which the item should be indexed
1050  * @param item The item to put in the index
1051  *
1052  * @ingroup Index
1053  */
1054 EAPI void
1055 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1056 {
1057    ELM_CHECK_WIDTYPE(obj, widtype);
1058    Widget_Data *wd = elm_widget_data_get(obj);
1059    Elm_Index_Item *it;
1060
1061    if (!wd) return;
1062    it = _item_new(obj, letter, item);
1063    if (!it) return;
1064    wd->items = eina_list_prepend(wd->items, it);
1065    wd->tot_items_count[wd->level]++;
1066    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1067 }
1068
1069 /**
1070  * Append an item after @p relative in letter @p letter.
1071  *
1072  * @param obj The index object
1073  * @param letter Letter under which the item should be indexed
1074  * @param item The item to put in the index
1075  * @param relative The item to put @p item after
1076  *
1077  * @ingroup Index
1078  */
1079 EAPI void
1080 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1081 {
1082    ELM_CHECK_WIDTYPE(obj, widtype);
1083    Widget_Data *wd = elm_widget_data_get(obj);
1084    Elm_Index_Item *it, *it_rel;
1085    if (!wd) return;
1086    if (!relative)
1087      {
1088         elm_index_item_append(obj, letter, item);
1089         wd->tot_items_count[wd->level]++;
1090         return;
1091      }
1092    it = _item_new(obj, letter, item);
1093    it_rel = _item_find(obj, relative);
1094    if (!it_rel)
1095      {
1096         elm_index_item_append(obj, letter, item);
1097         wd->tot_items_count[wd->level]++;
1098         return;
1099      }
1100    if (!it) return;
1101    wd->items = eina_list_append_relative(wd->items, it, it_rel);
1102    wd->tot_items_count[wd->level]++;
1103    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1104 }
1105
1106 /**
1107  * Prepend an item before @p relative in letter @p letter.
1108  *
1109  * @param obj The index object
1110  * @param letter Letter under which the item should be indexed
1111  * @param item The item to put in the index
1112  * @param relative The item to put @p item before
1113  *
1114  * @ingroup Index
1115  */
1116 EAPI void
1117 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1118 {
1119    ELM_CHECK_WIDTYPE(obj, widtype);
1120    Widget_Data *wd = elm_widget_data_get(obj);
1121    Elm_Index_Item *it, *it_rel;
1122    if (!wd) return;
1123    if (!relative)
1124      {
1125         elm_index_item_prepend(obj, letter, item);
1126         wd->tot_items_count[wd->level]++;
1127         return;
1128      }
1129    it = _item_new(obj, letter, item);
1130    it_rel = _item_find(obj, relative);
1131    if (!it_rel)
1132      {
1133         elm_index_item_append(obj, letter, item);
1134         wd->tot_items_count[wd->level]++;
1135         return;
1136      }
1137    if (!it) return;
1138    wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
1139    wd->tot_items_count[wd->level]++;
1140    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1141 }
1142
1143 /**
1144  * Insert a new @p item into the sorted index @p obj in @p letter.
1145  *
1146  * @param obj The index object
1147  * @param letter Letter under which the item should be indexed
1148  * @param item The item to put in the index
1149  * @param cmp_func The function called for the sort of index items.
1150  * @param cmp_data_func The function called for the sort of the data. It will
1151  * be used when cmp_func return 0. It means the index item already exists.
1152  * So, to decide which data item should be pointed by the index item, a function
1153  * to compare them is needed. If this function is not provided, index items
1154  * will be duplicated. If cmp_data_func returns a non-negative value, the
1155  * previous index item data will be replaced by the inserted @p item. So
1156  * if the previous data need to be free, it should be done in this function,
1157  * because the reference will be lost.
1158  *
1159  * @ingroup Index
1160  */
1161 EAPI void
1162 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)
1163 {
1164    ELM_CHECK_WIDTYPE(obj, widtype);
1165    Widget_Data *wd = elm_widget_data_get(obj);
1166    Eina_List *lnear;
1167    Elm_Index_Item *it;
1168    int cmp;
1169
1170    if (!wd) return;
1171    if (!(wd->items))
1172      {
1173         elm_index_item_append(obj, letter, item);
1174         return;
1175      }
1176
1177    it = _item_new(obj, letter, item);
1178    if (!it) return;
1179
1180    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1181    if (cmp < 0)
1182      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1183    else if (cmp > 0)
1184      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1185    else
1186      {
1187         /* If cmp_data_func is not provided, append a duplicated item */
1188         if (!cmp_data_func)
1189           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1190         else
1191           {
1192              Elm_Index_Item *p_it = eina_list_data_get(lnear);
1193              if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1194                p_it->base.data = it->base.data;
1195              _item_free(it);
1196           }
1197      }
1198
1199    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1200 }
1201
1202 /**
1203  * Remove an item from the index.
1204  *
1205  * @param obj The index object
1206  * @param item The item to remove from the index
1207  *
1208  * @ingroup Index
1209  */
1210 EAPI void
1211 elm_index_item_del(Evas_Object *obj, const void *item)
1212 {
1213    ELM_CHECK_WIDTYPE(obj, widtype);
1214    Widget_Data *wd = elm_widget_data_get(obj);
1215    Elm_Index_Item *it;
1216    if (!wd) return;
1217    it = _item_find(obj, item);
1218    if (!it) return;
1219    _item_free(it);
1220    wd->tot_items_count[wd->level]--;
1221    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1222 }
1223
1224 /**
1225  * Find an index item using item data.
1226  *
1227  * @param obj The index object
1228  * @param item The item pointed by index item
1229  * @return The index item pointing to @p item
1230  *
1231  * @ingroup Index
1232  */
1233 EAPI Elm_Index_Item *
1234 elm_index_item_find(Evas_Object *obj, const void *item)
1235 {
1236    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1237    Widget_Data *wd = elm_widget_data_get(obj);
1238    if (!wd) return NULL;
1239    return _item_find(obj, item);
1240 }
1241
1242 /**
1243  * Clears an index of its items.
1244  *
1245  * @param obj The index object.
1246  *
1247  * @ingroup Index
1248  */
1249 EAPI void
1250 elm_index_item_clear(Evas_Object *obj)
1251 {
1252    ELM_CHECK_WIDTYPE(obj, widtype);
1253    Widget_Data *wd = elm_widget_data_get(obj);
1254    Elm_Index_Item *it;
1255    Eina_List *l, *clear = NULL;
1256    if (!wd) return;
1257    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1258    EINA_LIST_FOREACH(wd->items, l, it)
1259      {
1260         if (it->level != wd->level) continue;
1261         clear = eina_list_append(clear, it);
1262      }
1263    EINA_LIST_FREE(clear, it)
1264      {
1265         _item_free(it);
1266         wd->tot_items_count[wd->level]--;
1267      }
1268 }
1269
1270 /**
1271  * Go to item at @p level
1272  *
1273  * @param obj The index object
1274  * @param level The index level
1275  *
1276  * @ingroup Index
1277  */
1278 EAPI void
1279 elm_index_item_go(Evas_Object *obj, int level)
1280 {
1281    ELM_CHECK_WIDTYPE(obj, widtype);
1282    Widget_Data *wd = elm_widget_data_get(obj);
1283    if (!wd) return;
1284    if(level == 0)
1285      _index_process(obj);
1286    _index_box_auto_fill(obj, wd->bx[0], 0);
1287    if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1288 }
1289
1290 /**
1291  * Returns the data associated with the item.
1292  *
1293  * @param it The list item
1294  * @return The data associated with @p it
1295  *
1296  * @ingroup Index
1297  */
1298 EAPI void *
1299 elm_index_item_data_get(const Elm_Index_Item *it)
1300 {
1301    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1302    return elm_widget_item_data_get(it);
1303 }
1304
1305 /**
1306  * Set the data item from the index item
1307  *
1308  * This set a new data value.
1309  *
1310  * @param it The item
1311  * @param data The new data pointer to set
1312  *
1313  * @ingroup Index
1314  */
1315 EAPI void
1316 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1317 {
1318    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1319    elm_widget_item_data_set(it, data);
1320 }
1321
1322 /**
1323  * Make the Central Button Image invisible.
1324  *
1325  * @param obj The Index.
1326  * @param invisible Whether button visible or not.
1327  * @return void.
1328  *
1329  * @ingroup Index
1330  */
1331 EAPI void
1332 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1333 {
1334    ELM_CHECK_WIDTYPE(obj, widtype);
1335    Widget_Data *wd = elm_widget_data_get(obj);
1336    wd->hide_button = invisible;
1337
1338    edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1339    return;
1340 }
1341
1342 /**
1343  * Set the function called when a index item is freed.
1344  *
1345  * @param it The item to set the callback on
1346  * @param func The function called
1347  *
1348  * @ingroup Index
1349  */
1350 EAPI void
1351 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1352 {
1353    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1354    elm_widget_item_del_cb_set(it, func);
1355 }
1356
1357 /**
1358  * Gets the letter of the item.
1359  *
1360  * @param it The list item
1361  * @return The letter of @p it
1362  *
1363  * @ingroup Index
1364  */
1365 EAPI const char *
1366 elm_index_item_letter_get(const Elm_Index_Item *it)
1367 {
1368    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1369    return it->letter;
1370 }
1371