Merge "[scroller] change bottom bounce time <CQ : H0100135349>"
[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->tot_items_count[0])
527                {
528                   if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
529                   wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
530
531                   strcpy(wd->popup_str[0], last);
532                   edje_object_signal_emit(wd->base, "hide_2nd_level", "");
533                }
534              else
535                {
536                   edje_object_signal_emit(wd->base, "button.image.hidden", "");
537                   if(label)free(label);
538                   if(last) free(last);
539                   return;
540                }
541           }
542         if (view_level == 1 && wd->level_active[1])
543           {
544              if(wd->tot_items_count[1])
545                {
546                   wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
547
548                   strcpy(wd->popup_str[1], last);
549                   edje_object_signal_emit(wd->base, "hide_first_level", "");
550                }
551              else
552                {
553                   edje_object_signal_emit(wd->base, "button.image.hidden", "");
554                   if(label)free(label);
555                   if(last) free(last);
556                   return;
557                }
558           }
559         popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
560         sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
561         edje_object_part_text_set(wd->base, "elm.text", popup_text);
562
563         free(popup_text);
564      }
565
566    if(label)
567      free(label);
568    if(last)
569      free(last);
570 }
571
572 static void
573 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
574 {
575    Widget_Data *wd = elm_widget_data_get(data);
576    //   Evas_Event_Mouse_Wheel *ev = event_info;
577    //   Evas_Object *obj = o;
578    if (!wd) return;
579 }
580
581 static void
582 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
583 {
584    Widget_Data *wd = elm_widget_data_get(data);
585    Evas_Event_Mouse_Down *ev = event_info;
586    Evas_Coord x, y, w;
587    if (!wd) return;
588    if (ev->button != 1) return;
589    wd->down = 1;
590    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
591    wd->dx = ev->canvas.x - x;
592    wd->dy = ev->canvas.y - y;
593    elm_index_active_set(data, 1);
594    _sel_eval(data, ev->canvas.x, ev->canvas.y);
595    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
596                                    (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
597 }
598
599 static void
600 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
601 {
602    Widget_Data *wd = elm_widget_data_get(data);
603    Evas_Event_Mouse_Up *ev = event_info;
604    void *d;
605    Elm_Index_Item *it;
606    Eina_List *l;
607    int view_level;
608
609    if (!wd) return;
610    if (ev->button != 1) return;
611    if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
612    wd->delay = NULL;
613    wd->down = 0;
614    SET_VIEW_LEVEL(wd, view_level);
615    d = (void *)elm_index_item_selected_get(data, view_level);
616    EINA_LIST_FOREACH(wd->items, l, it)
617      {
618         edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
619      }
620    if (d) evas_object_smart_callback_call(data, SIG_SELECTED, d);
621    elm_index_active_set(data, 0);
622    edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
623 }
624
625 static void
626 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
627 {
628    Widget_Data *wd = elm_widget_data_get(data);
629    Evas_Event_Mouse_Move *ev = event_info;
630    Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
631    void *d;
632    char buf[1024];
633    if (!wd) return;
634    if (!wd->down) return;
635    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
636    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
637    x = ev->cur.canvas.x - x;
638    y = ev->cur.canvas.y - y;
639    dx = x - wd->dx;
640    adx = dx;
641    if (adx < 0) adx = -dx;
642    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
643                                    , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
644    if (!wd->horizontal)
645      {
646         if (adx > minw)
647           {
648              if (!wd->level)
649                {
650                   wd->level = 1;
651                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
652                   edje_object_signal_emit(wd->base, buf, "elm");
653                   evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
654                }
655           }
656         else
657           {
658              if (wd->level == 1)
659                {
660                   wd->level = 0;
661                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
662                   edje_object_signal_emit(wd->base, buf, "elm");
663                   d = (void *)elm_index_item_selected_get(data, wd->level);
664                   evas_object_smart_callback_call(data, "changed", d);
665                   if (wd->delay) ecore_timer_del(wd->delay);
666                   wd->delay = ecore_timer_add(0.2, _delay_change, data);
667                   evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
668                }
669           }
670      }
671    _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
672 }
673
674 static void
675 _index_box_refill_job(void *data)
676 {
677    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
678    if (!wd) return;
679
680    const char *string;
681    Evas_Coord pw, ph;
682
683    evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
684    wd->scale_factor = elm_scale_get();
685    if ( wd->scale_factor == 0.0 ) {
686      wd->scale_factor = 1.0;
687    }
688    string = edje_object_data_get(wd->base, "min_obj_height");
689    if(string)
690      wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
691    else
692      wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
693    if(!wd->min_obj_height) return;
694
695    wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
696    wd->items_count = ph/wd->min_obj_height;
697    wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
698
699    if(pw != wd->pwidth && ph != wd->pheight)
700      {
701         if(wd->down == 1)
702           {
703              wd->active = 0;
704              elm_index_active_set(data, 1);
705           }
706         _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
707         evas_object_smart_calculate( wd->bx[0]);
708         elm_index_item_go((Evas_Object *)data, wd->level);
709         wd->pwidth = pw;
710         wd->pheight = ph;
711      }
712 }
713
714 static void _index_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
715 {
716    Widget_Data *wd;
717    if(!data) return;
718    wd = elm_widget_data_get((Evas_Object *)data);
719    if(!wd) return;
720    ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
721 }
722
723 /**
724  * Add a new index to the parent
725  *
726  * @param parent The parent object
727  * @return The new object or NULL if it cannot be created
728  *
729  * @ingroup Index
730  */
731 EAPI Evas_Object *
732 elm_index_add(Evas_Object *parent)
733 {
734    Evas_Object *obj;
735    Evas_Object *o;
736    Evas *e;
737    Widget_Data *wd;
738    Evas_Coord minw, minh;
739    const char *string;
740
741    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
742
743    ELM_SET_WIDTYPE(widtype, "index");
744    elm_widget_type_set(obj, "index");
745    elm_widget_sub_object_add(parent, obj);
746    elm_widget_data_set(obj, wd);
747    elm_widget_del_hook_set(obj, _del_hook);
748    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
749    elm_widget_theme_hook_set(obj, _theme_hook);
750    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
751    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
752    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
753    elm_widget_can_focus_set(obj, EINA_FALSE);
754
755    wd->horizontal = EINA_FALSE;
756    wd->min_obj_height = 0;
757    wd->max_grp_size = 0;
758    wd->items_count = 0;
759    wd->max_supp_items_count = 0;
760    wd->tot_items_count[0] = 0;
761    wd->tot_items_count[1] = 0;
762    wd->hide_button = 0;
763    wd->special_char = edje_object_data_get(wd->base, "special_char");
764    if(wd->special_char == NULL)  wd->special_char = eina_stringshare_add("*");
765
766    wd->base = edje_object_add(e);
767    _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
768    elm_widget_resize_object_set(obj, wd->base);
769
770    o = evas_object_rectangle_add(e);
771    wd->event[0] = o;
772    evas_object_color_set(o, 0, 0, 0, 0);
773    minw = minh = 0;
774    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
775    evas_object_size_hint_min_set(o, minw, minh);
776    edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
777    elm_widget_sub_object_add(obj, o);
778    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
779    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
780    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
781    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
782    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
783    evas_object_show(o);
784    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
785      {
786         o = evas_object_rectangle_add(e);
787         wd->event[1] = o;
788         evas_object_color_set(o, 0, 0, 0, 0);
789         evas_object_size_hint_min_set(o, minw, minh);
790         edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
791         elm_widget_sub_object_add(obj, o);
792      }
793
794    wd->bx[0] = evas_object_box_add(e);
795    evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
796    elm_widget_sub_object_add(obj, wd->bx[0]);
797    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
798    evas_object_show(wd->bx[0]);
799
800    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
801      {
802         wd->bx[1] = evas_object_box_add(e);
803         evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
804         elm_widget_sub_object_add(obj, wd->bx[1]);
805         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
806         evas_object_show(wd->bx[1]);
807      }
808
809    evas_object_smart_callbacks_descriptions_set(obj, _signals);
810    wd->scale_factor = elm_scale_get();
811    if ( wd->scale_factor == 0.0 )
812                 wd->scale_factor = 1.0;
813    string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
814    if(string)
815      wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
816    else
817      wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
818    wd->popup_str[0] = calloc(1, sizeof(char) * 1);
819    wd->popup_str[1] = calloc(1, sizeof(char) * 1);
820
821    _mirrored_set(obj, elm_widget_mirrored_get(obj));
822    _sizing_eval(obj);
823    return obj;
824 }
825
826 static int
827 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
828 {
829    Widget_Data *wd = elm_widget_data_get(obj);
830    if (!wd) return 0;
831    int group_count = MIN_GRP_SIZE;
832    while(group_count <= wd->max_grp_size)
833      {
834         if(extraIndex <= wd->max_grp_size*adj_pos)
835           {
836              if(group_count*adj_pos>=extraIndex) return group_count;
837           }
838         else
839           return wd->max_grp_size;
840
841         group_count += MIN_GRP_SIZE;
842      }
843    return group_count;
844 }
845
846 static void
847 _index_process(Evas_Object *obj)
848 {
849    int extraIndex;
850    int j,i, group_count;
851    Eina_List *l;
852    Elm_Index_Item *it;
853    int count;
854    int n;
855
856    Widget_Data *wd = elm_widget_data_get(obj);
857    if (!wd) return;
858
859    if (wd->items_count == 0) return;
860
861    const int adj_pos = (wd->items_count-1)*0.5;
862    if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
863       n = wd->tot_items_count[wd->level];
864    else
865       n = wd->max_supp_items_count;
866    group_count = MIN_GRP_SIZE;
867
868    int *indx = (int*)calloc(n, sizeof(int));
869    if (!indx) return;
870
871    const int minh = wd->min_obj_height;
872    EINA_LIST_FOREACH(wd->items, l, it)
873      {
874         it->vis_letter = eina_stringshare_add(it->letter);
875         it->size =  minh;
876      }
877    int remainder;
878    int numberofparts;
879    int N = wd->items_count;
880
881    for (i=0;i<n;i++)
882      {
883         indx[i] = minh;
884      }
885    extraIndex=n-N;
886    if (extraIndex < 0) return;
887
888    group_count = _group_count(obj, extraIndex, adj_pos, N);
889    if (group_count <= 0)
890      {
891         if (indx)
892           free(indx);
893         indx = NULL;
894         return;
895      }
896
897    PlacementPart place[adj_pos];
898    remainder = extraIndex%group_count;
899    numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
900
901    for (i=0;i<numberofparts; i++)
902      {
903         place[i].count=group_count+1;
904         count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
905         place[i].start= count +i*group_count-1;
906      }
907    if (remainder)
908      place[numberofparts-1].count=remainder+1;
909
910    for (i=0;i<numberofparts;i++)
911      {
912         for (j=0;j<place[i].count; j++)
913           {
914              indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
915           }
916         indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
917      }
918    count = 0;
919    EINA_LIST_FOREACH(wd->items, l, it)
920      {
921         int size = indx[count];
922         count++;
923         if (size == minh)
924           {
925              it->vis_letter = eina_stringshare_add(it->letter);
926              continue;
927           }
928         else if (size == 1)
929           {
930              eina_stringshare_del(it->vis_letter);
931              it->vis_letter = eina_stringshare_add("");
932           }
933         else
934           {
935              eina_stringshare_del(it->vis_letter);
936              it->vis_letter = eina_stringshare_add(wd->special_char);
937           }
938         it->size = size*wd->scale_factor;
939      }
940    if (indx)
941      {
942         free(indx);
943         indx = NULL;
944      }
945 }
946
947 /**
948  * Set the active state of the index programatically
949  *
950  * @param obj The index object
951  * @param active The active state
952  *
953  * @ingroup Index
954  */
955 EAPI void
956 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
957 {
958    ELM_CHECK_WIDTYPE(obj, widtype);
959    Widget_Data *wd = elm_widget_data_get(obj);
960    if (!wd) return;
961    if (wd->active == active) return;
962    wd->active = active;
963    wd->level = 0;
964    if (wd->active)
965      {
966         _index_box_clear(obj, wd->bx[1], 1);
967         _index_process(obj);
968         _index_box_auto_fill(obj, wd->bx[0], 0);
969         if(wd->tot_items_count[wd->level])
970           edje_object_signal_emit(wd->base, "elm,state,active", "elm");
971         else
972           edje_object_signal_emit(wd->base, "button.image.hidden", "");
973      }
974    else
975      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
976 }
977
978 /**
979  * Get the active state of the index programatically
980  *
981  * @param obj The index object
982  * @return The active state
983  *
984  * @ingroup Index
985  */
986 EAPI Eina_Bool
987 elm_index_active_get(const Evas_Object *obj)
988 {
989    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
990    Widget_Data *wd = elm_widget_data_get(obj);
991    if (!wd) return EINA_FALSE;
992    return wd->active;
993 }
994
995 /**
996  * Sets the level of the item.
997  *
998  * @param obj The index object.
999  * @param level To be documented.
1000  *
1001  * @ingroup Index
1002  */
1003 EAPI void
1004 elm_index_item_level_set(Evas_Object *obj, int level)
1005 {
1006    ELM_CHECK_WIDTYPE(obj, widtype);
1007    Widget_Data *wd = elm_widget_data_get(obj);
1008    if (!wd) return;
1009    if (wd->level == level) return;
1010    wd->level = level;
1011 }
1012
1013 /**
1014  * Gets the level of the item.
1015  *
1016  * @param obj The index object
1017  *
1018  * @ingroup Index
1019  */
1020 EAPI int
1021 elm_index_item_level_get(const Evas_Object *obj)
1022 {
1023    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1024    Widget_Data *wd = elm_widget_data_get(obj);
1025    if (!wd) return 0;
1026    return wd->level;
1027 }
1028
1029 /**
1030  * Returns the selected item.
1031  *
1032  * @param obj The index object.
1033  * @param level to be documented.
1034  *
1035  * @ingroup Index
1036  */
1037 EAPI void *
1038 elm_index_item_selected_get(const Evas_Object *obj, int level)
1039 {
1040    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1041    Widget_Data *wd = elm_widget_data_get(obj);
1042    Eina_List *l;
1043    Elm_Index_Item *it;
1044    if (!wd) return NULL;
1045    EINA_LIST_FOREACH(wd->items, l, it)
1046      if ((it->selected) && (it->level == level))
1047        return elm_widget_item_data_get(it);
1048    return NULL;
1049 }
1050
1051 /**
1052  * Appends 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_append(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    if (!wd) return;
1067    it = _item_new(obj, letter, item);
1068    if (!it) return;
1069    wd->items = eina_list_append(wd->items, it);
1070    wd->tot_items_count[wd->level]++;
1071    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1072 }
1073
1074 /**
1075  * Prepends a new item.
1076  *
1077  * @param obj The index object.
1078  * @param letter Letter under which the item should be indexed
1079  * @param item The item to put in the index
1080  *
1081  * @ingroup Index
1082  */
1083 EAPI void
1084 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1085 {
1086    ELM_CHECK_WIDTYPE(obj, widtype);
1087    Widget_Data *wd = elm_widget_data_get(obj);
1088    Elm_Index_Item *it;
1089
1090    if (!wd) return;
1091    it = _item_new(obj, letter, item);
1092    if (!it) return;
1093    wd->items = eina_list_prepend(wd->items, it);
1094    wd->tot_items_count[wd->level]++;
1095    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1096 }
1097
1098 /**
1099  * Append an item after @p relative in letter @p letter.
1100  *
1101  * @param obj The index object
1102  * @param letter Letter under which the item should be indexed
1103  * @param item The item to put in the index
1104  * @param relative The item to put @p item after
1105  *
1106  * @ingroup Index
1107  */
1108 EAPI void
1109 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1110 {
1111    ELM_CHECK_WIDTYPE(obj, widtype);
1112    Widget_Data *wd = elm_widget_data_get(obj);
1113    Elm_Index_Item *it, *it_rel;
1114    if (!wd) return;
1115    if (!relative)
1116      {
1117         elm_index_item_append(obj, letter, item);
1118         wd->tot_items_count[wd->level]++;
1119         return;
1120      }
1121    it = _item_new(obj, letter, item);
1122    if (!it) return;
1123
1124    it_rel = _item_find(obj, relative);
1125    if (!it_rel)
1126      {
1127         elm_index_item_append(obj, letter, item);
1128         wd->tot_items_count[wd->level]++;
1129         return;
1130      }
1131
1132    wd->items = eina_list_append_relative(wd->items, it, it_rel);
1133    wd->tot_items_count[wd->level]++;
1134    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1135 }
1136
1137 /**
1138  * Prepend an item before @p relative in letter @p letter.
1139  *
1140  * @param obj The index object
1141  * @param letter Letter under which the item should be indexed
1142  * @param item The item to put in the index
1143  * @param relative The item to put @p item before
1144  *
1145  * @ingroup Index
1146  */
1147 EAPI void
1148 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1149 {
1150    ELM_CHECK_WIDTYPE(obj, widtype);
1151    Widget_Data *wd = elm_widget_data_get(obj);
1152    Elm_Index_Item *it, *it_rel;
1153    if (!wd) return;
1154    if (!relative)
1155      {
1156         elm_index_item_prepend(obj, letter, item);
1157         wd->tot_items_count[wd->level]++;
1158         return;
1159      }
1160    it = _item_new(obj, letter, item);
1161    if (!it) return;
1162
1163    it_rel = _item_find(obj, relative);
1164    if (!it_rel)
1165      {
1166         elm_index_item_append(obj, letter, item);
1167         wd->tot_items_count[wd->level]++;
1168         return;
1169      }
1170
1171    wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
1172    wd->tot_items_count[wd->level]++;
1173    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1174 }
1175
1176 /**
1177  * Insert a new @p item into the sorted index @p obj in @p letter.
1178  *
1179  * @param obj The index object
1180  * @param letter Letter under which the item should be indexed
1181  * @param item The item to put in the index
1182  * @param cmp_func The function called for the sort of index items.
1183  * @param cmp_data_func The function called for the sort of the data. It will
1184  * be used when cmp_func return 0. It means the index item already exists.
1185  * So, to decide which data item should be pointed by the index item, a function
1186  * to compare them is needed. If this function is not provided, index items
1187  * will be duplicated. If cmp_data_func returns a non-negative value, the
1188  * previous index item data will be replaced by the inserted @p item. So
1189  * if the previous data need to be free, it should be done in this function,
1190  * because the reference will be lost.
1191  *
1192  * @ingroup Index
1193  */
1194 EAPI void
1195 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)
1196 {
1197    ELM_CHECK_WIDTYPE(obj, widtype);
1198    Widget_Data *wd = elm_widget_data_get(obj);
1199    Eina_List *lnear;
1200    Elm_Index_Item *it;
1201    int cmp;
1202
1203    if (!wd) return;
1204    if (!(wd->items))
1205      {
1206         elm_index_item_append(obj, letter, item);
1207         return;
1208      }
1209
1210    it = _item_new(obj, letter, item);
1211    if (!it) return;
1212
1213    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1214    if (cmp < 0)
1215      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1216    else if (cmp > 0)
1217      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1218    else
1219      {
1220         /* If cmp_data_func is not provided, append a duplicated item */
1221         if (!cmp_data_func)
1222           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1223         else
1224           {
1225              Elm_Index_Item *p_it = eina_list_data_get(lnear);
1226              if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1227                p_it->base.data = it->base.data;
1228              _item_free(it);
1229           }
1230      }
1231
1232    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1233 }
1234
1235 /**
1236  * Remove an item from the index.
1237  *
1238  * @param obj The index object
1239  * @param item The item to remove from the index
1240  *
1241  * @ingroup Index
1242  */
1243 EAPI void
1244 elm_index_item_del(Evas_Object *obj, const void *item)
1245 {
1246    ELM_CHECK_WIDTYPE(obj, widtype);
1247    Widget_Data *wd = elm_widget_data_get(obj);
1248    Elm_Index_Item *it;
1249    if (!wd) return;
1250    it = _item_find(obj, item);
1251    if (!it) return;
1252    _item_free(it);
1253    wd->tot_items_count[wd->level]--;
1254    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1255 }
1256
1257 /**
1258  * Find an index item using item data.
1259  *
1260  * @param obj The index object
1261  * @param item The item pointed by index item
1262  * @return The index item pointing to @p item
1263  *
1264  * @ingroup Index
1265  */
1266 EAPI Elm_Index_Item *
1267 elm_index_item_find(Evas_Object *obj, const void *item)
1268 {
1269    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1270    Widget_Data *wd = elm_widget_data_get(obj);
1271    if (!wd) return NULL;
1272    return _item_find(obj, item);
1273 }
1274
1275 /**
1276  * Clears an index of its items.
1277  *
1278  * @param obj The index object.
1279  *
1280  * @ingroup Index
1281  */
1282 EAPI void
1283 elm_index_item_clear(Evas_Object *obj)
1284 {
1285    ELM_CHECK_WIDTYPE(obj, widtype);
1286    Widget_Data *wd = elm_widget_data_get(obj);
1287    Elm_Index_Item *it;
1288    Eina_List *l, *clear = NULL;
1289    if (!wd) return;
1290    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1291    EINA_LIST_FOREACH(wd->items, l, it)
1292      {
1293         if (it->level != wd->level) continue;
1294         clear = eina_list_append(clear, it);
1295      }
1296    EINA_LIST_FREE(clear, it)
1297      {
1298         _item_free(it);
1299         wd->tot_items_count[wd->level]--;
1300      }
1301 }
1302
1303 /**
1304  * Go to item at @p level
1305  *
1306  * @param obj The index object
1307  * @param level The index level
1308  *
1309  * @ingroup Index
1310  */
1311 EAPI void
1312 elm_index_item_go(Evas_Object *obj, int level)
1313 {
1314    ELM_CHECK_WIDTYPE(obj, widtype);
1315    Widget_Data *wd = elm_widget_data_get(obj);
1316    if (!wd) return;
1317    if(level == 0)
1318      _index_process(obj);
1319    _index_box_auto_fill(obj, wd->bx[0], 0);
1320    if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1321 }
1322
1323 /**
1324  * Returns the data associated with the item.
1325  *
1326  * @param it The list item
1327  * @return The data associated with @p it
1328  *
1329  * @ingroup Index
1330  */
1331 EAPI void *
1332 elm_index_item_data_get(const Elm_Index_Item *it)
1333 {
1334    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1335    return elm_widget_item_data_get(it);
1336 }
1337
1338 /**
1339  * Set the data item from the index item
1340  *
1341  * This set a new data value.
1342  *
1343  * @param it The item
1344  * @param data The new data pointer to set
1345  *
1346  * @ingroup Index
1347  */
1348 EAPI void
1349 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1350 {
1351    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1352    elm_widget_item_data_set(it, data);
1353 }
1354
1355 /**
1356  * Make the Central Button Image invisible.
1357  *
1358  * @param obj The Index.
1359  * @param invisible Whether button visible or not.
1360  * @return void.
1361  *
1362  * @ingroup Index
1363  */
1364 EAPI void
1365 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1366 {
1367    ELM_CHECK_WIDTYPE(obj, widtype);
1368    Widget_Data *wd = elm_widget_data_get(obj);
1369    wd->hide_button = invisible;
1370
1371    edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1372    return;
1373 }
1374
1375 /**
1376  * Set the function called when a index item is freed.
1377  *
1378  * @param it The item to set the callback on
1379  * @param func The function called
1380  *
1381  * @ingroup Index
1382  */
1383 EAPI void
1384 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1385 {
1386    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1387    elm_widget_item_del_cb_set(it, func);
1388 }
1389
1390 /**
1391  * Gets the letter of the item.
1392  *
1393  * @param it The list item
1394  * @return The letter of @p it
1395  *
1396  * @ingroup Index
1397  */
1398 EAPI const char *
1399 elm_index_item_letter_get(const Elm_Index_Item *it)
1400 {
1401    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1402    return it->letter;
1403 }
1404