Merge "[elm_label]Changed *.c file mode & Fix build fail & remove warning in TC"
[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)
870      {
871         if (indx)
872           free(indx);
873         indx = NULL;
874         return;
875      }
876
877    PlacementPart place[adj_pos];
878    remainder = extraIndex%group_count;
879    numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
880
881    for (i=0;i<numberofparts; i++)
882      {
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;
886      }
887    if (remainder)
888      place[numberofparts-1].count=remainder+1;
889
890    for (i=0;i<numberofparts;i++)
891      {
892         for (j=0;j<place[i].count; j++)
893           {
894              indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
895           }
896         indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
897      }
898    count = 0;
899    EINA_LIST_FOREACH(wd->items, l, it)
900      {
901         int size = indx[count];
902         count++;
903         if (size == minh)
904           {
905              it->vis_letter = eina_stringshare_add(it->letter);
906              continue;
907           }
908         else if (size == 1)
909           {
910              eina_stringshare_del(it->vis_letter);
911              it->vis_letter = eina_stringshare_add("");
912           }
913         else
914           {
915              eina_stringshare_del(it->vis_letter);
916              it->vis_letter = eina_stringshare_add(wd->special_char);
917           }
918         it->size = size*wd->scale_factor;
919      }
920    if (indx)
921      {
922         free(indx);
923         indx = NULL;
924      }
925 }
926
927 /**
928  * Set the active state of the index programatically
929  *
930  * @param obj The index object
931  * @param active The active state
932  *
933  * @ingroup Index
934  */
935 EAPI void
936 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
937 {
938    ELM_CHECK_WIDTYPE(obj, widtype);
939    Widget_Data *wd = elm_widget_data_get(obj);
940    if (!wd) return;
941    if (wd->active == active) return;
942    wd->active = active;
943    wd->level = 0;
944    if (wd->active)
945      {
946         _index_box_clear(obj, wd->bx[1], 1);
947         _index_process(obj);
948         _index_box_auto_fill(obj, wd->bx[0], 0);
949         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
950      }
951    else
952      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
953 }
954
955 /**
956  * Get the active state of the index programatically
957  *
958  * @param obj The index object
959  * @return The active state
960  *
961  * @ingroup Index
962  */
963 EAPI Eina_Bool
964 elm_index_active_get(const Evas_Object *obj)
965 {
966    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
967    Widget_Data *wd = elm_widget_data_get(obj);
968    if (!wd) return EINA_FALSE;
969    return wd->active;
970 }
971
972 /**
973  * Sets the level of the item.
974  *
975  * @param obj The index object.
976  * @param level To be documented.
977  *
978  * @ingroup Index
979  */
980 EAPI void
981 elm_index_item_level_set(Evas_Object *obj, int level)
982 {
983    ELM_CHECK_WIDTYPE(obj, widtype);
984    Widget_Data *wd = elm_widget_data_get(obj);
985    if (!wd) return;
986    if (wd->level == level) return;
987    wd->level = level;
988 }
989
990 /**
991  * Gets the level of the item.
992  *
993  * @param obj The index object
994  *
995  * @ingroup Index
996  */
997 EAPI int
998 elm_index_item_level_get(const Evas_Object *obj)
999 {
1000    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1001    Widget_Data *wd = elm_widget_data_get(obj);
1002    if (!wd) return 0;
1003    return wd->level;
1004 }
1005
1006 /**
1007  * Returns the selected item.
1008  *
1009  * @param obj The index object.
1010  * @param level to be documented.
1011  *
1012  * @ingroup Index
1013  */
1014 EAPI void *
1015 elm_index_item_selected_get(const Evas_Object *obj, int level)
1016 {
1017    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1018    Widget_Data *wd = elm_widget_data_get(obj);
1019    Eina_List *l;
1020    Elm_Index_Item *it;
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);
1025    return NULL;
1026 }
1027
1028 /**
1029  * Appends a new item.
1030  *
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
1034  *
1035  * @ingroup Index
1036  */
1037 EAPI void
1038 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1039 {
1040    ELM_CHECK_WIDTYPE(obj, widtype);
1041    Widget_Data *wd = elm_widget_data_get(obj);
1042    Elm_Index_Item *it;
1043    if (!wd) return;
1044    it = _item_new(obj, letter, item);
1045    if (!it) return;
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);
1049 }
1050
1051 /**
1052  * Prepends a new item.
1053  *
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
1057  *
1058  * @ingroup Index
1059  */
1060 EAPI void
1061 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1062 {
1063    ELM_CHECK_WIDTYPE(obj, widtype);
1064    Widget_Data *wd = elm_widget_data_get(obj);
1065    Elm_Index_Item *it;
1066
1067    if (!wd) return;
1068    it = _item_new(obj, letter, item);
1069    if (!it) return;
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);
1073 }
1074
1075 /**
1076  * Append an item after @p relative in letter @p letter.
1077  *
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
1082  *
1083  * @ingroup Index
1084  */
1085 EAPI void
1086 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1087 {
1088    ELM_CHECK_WIDTYPE(obj, widtype);
1089    Widget_Data *wd = elm_widget_data_get(obj);
1090    Elm_Index_Item *it, *it_rel;
1091    if (!wd) return;
1092    if (!relative)
1093      {
1094         elm_index_item_append(obj, letter, item);
1095         wd->tot_items_count[wd->level]++;
1096         return;
1097      }
1098    it = _item_new(obj, letter, item);
1099    if (!it) return;
1100
1101    it_rel = _item_find(obj, relative);
1102    if (!it_rel)
1103      {
1104         elm_index_item_append(obj, letter, item);
1105         wd->tot_items_count[wd->level]++;
1106         return;
1107      }
1108
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);
1112 }
1113
1114 /**
1115  * Prepend an item before @p relative in letter @p letter.
1116  *
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
1121  *
1122  * @ingroup Index
1123  */
1124 EAPI void
1125 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1126 {
1127    ELM_CHECK_WIDTYPE(obj, widtype);
1128    Widget_Data *wd = elm_widget_data_get(obj);
1129    Elm_Index_Item *it, *it_rel;
1130    if (!wd) return;
1131    if (!relative)
1132      {
1133         elm_index_item_prepend(obj, letter, item);
1134         wd->tot_items_count[wd->level]++;
1135         return;
1136      }
1137    it = _item_new(obj, letter, item);
1138    if (!it) return;
1139
1140    it_rel = _item_find(obj, relative);
1141    if (!it_rel)
1142      {
1143         elm_index_item_append(obj, letter, item);
1144         wd->tot_items_count[wd->level]++;
1145         return;
1146      }
1147
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);
1151 }
1152
1153 /**
1154  * Insert a new @p item into the sorted index @p obj in @p letter.
1155  *
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.
1168  *
1169  * @ingroup Index
1170  */
1171 EAPI void
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)
1173 {
1174    ELM_CHECK_WIDTYPE(obj, widtype);
1175    Widget_Data *wd = elm_widget_data_get(obj);
1176    Eina_List *lnear;
1177    Elm_Index_Item *it;
1178    int cmp;
1179
1180    if (!wd) return;
1181    if (!(wd->items))
1182      {
1183         elm_index_item_append(obj, letter, item);
1184         return;
1185      }
1186
1187    it = _item_new(obj, letter, item);
1188    if (!it) return;
1189
1190    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1191    if (cmp < 0)
1192      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1193    else if (cmp > 0)
1194      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1195    else
1196      {
1197         /* If cmp_data_func is not provided, append a duplicated item */
1198         if (!cmp_data_func)
1199           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1200         else
1201           {
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;
1205              _item_free(it);
1206           }
1207      }
1208
1209    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1210 }
1211
1212 /**
1213  * Remove an item from the index.
1214  *
1215  * @param obj The index object
1216  * @param item The item to remove from the index
1217  *
1218  * @ingroup Index
1219  */
1220 EAPI void
1221 elm_index_item_del(Evas_Object *obj, const void *item)
1222 {
1223    ELM_CHECK_WIDTYPE(obj, widtype);
1224    Widget_Data *wd = elm_widget_data_get(obj);
1225    Elm_Index_Item *it;
1226    if (!wd) return;
1227    it = _item_find(obj, item);
1228    if (!it) return;
1229    _item_free(it);
1230    wd->tot_items_count[wd->level]--;
1231    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1232 }
1233
1234 /**
1235  * Find an index item using item data.
1236  *
1237  * @param obj The index object
1238  * @param item The item pointed by index item
1239  * @return The index item pointing to @p item
1240  *
1241  * @ingroup Index
1242  */
1243 EAPI Elm_Index_Item *
1244 elm_index_item_find(Evas_Object *obj, const void *item)
1245 {
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);
1250 }
1251
1252 /**
1253  * Clears an index of its items.
1254  *
1255  * @param obj The index object.
1256  *
1257  * @ingroup Index
1258  */
1259 EAPI void
1260 elm_index_item_clear(Evas_Object *obj)
1261 {
1262    ELM_CHECK_WIDTYPE(obj, widtype);
1263    Widget_Data *wd = elm_widget_data_get(obj);
1264    Elm_Index_Item *it;
1265    Eina_List *l, *clear = NULL;
1266    if (!wd) return;
1267    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1268    EINA_LIST_FOREACH(wd->items, l, it)
1269      {
1270         if (it->level != wd->level) continue;
1271         clear = eina_list_append(clear, it);
1272      }
1273    EINA_LIST_FREE(clear, it)
1274      {
1275         _item_free(it);
1276         wd->tot_items_count[wd->level]--;
1277      }
1278 }
1279
1280 /**
1281  * Go to item at @p level
1282  *
1283  * @param obj The index object
1284  * @param level The index level
1285  *
1286  * @ingroup Index
1287  */
1288 EAPI void
1289 elm_index_item_go(Evas_Object *obj, int level)
1290 {
1291    ELM_CHECK_WIDTYPE(obj, widtype);
1292    Widget_Data *wd = elm_widget_data_get(obj);
1293    if (!wd) return;
1294    if(level == 0)
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);
1298 }
1299
1300 /**
1301  * Returns the data associated with the item.
1302  *
1303  * @param it The list item
1304  * @return The data associated with @p it
1305  *
1306  * @ingroup Index
1307  */
1308 EAPI void *
1309 elm_index_item_data_get(const Elm_Index_Item *it)
1310 {
1311    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1312    return elm_widget_item_data_get(it);
1313 }
1314
1315 /**
1316  * Set the data item from the index item
1317  *
1318  * This set a new data value.
1319  *
1320  * @param it The item
1321  * @param data The new data pointer to set
1322  *
1323  * @ingroup Index
1324  */
1325 EAPI void
1326 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1327 {
1328    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1329    elm_widget_item_data_set(it, data);
1330 }
1331
1332 /**
1333  * Make the Central Button Image invisible.
1334  *
1335  * @param obj The Index.
1336  * @param invisible Whether button visible or not.
1337  * @return void.
1338  *
1339  * @ingroup Index
1340  */
1341 EAPI void
1342 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1343 {
1344    ELM_CHECK_WIDTYPE(obj, widtype);
1345    Widget_Data *wd = elm_widget_data_get(obj);
1346    wd->hide_button = invisible;
1347
1348    edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1349    return;
1350 }
1351
1352 /**
1353  * Set the function called when a index item is freed.
1354  *
1355  * @param it The item to set the callback on
1356  * @param func The function called
1357  *
1358  * @ingroup Index
1359  */
1360 EAPI void
1361 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1362 {
1363    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1364    elm_widget_item_del_cb_set(it, func);
1365 }
1366
1367 /**
1368  * Gets the letter of the item.
1369  *
1370  * @param it The list item
1371  * @return The letter of @p it
1372  *
1373  * @ingroup Index
1374  */
1375 EAPI const char *
1376 elm_index_item_letter_get(const Elm_Index_Item *it)
1377 {
1378    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1379    return it->letter;
1380 }
1381