elm: Formatting. No spacing after casting.
[framework/uifw/elementary.git] / src / lib / elm_index.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_box.h"
4
5 typedef struct _Widget_Data Widget_Data;
6 typedef struct _Elm_Index_Item Elm_Index_Item;
7
8 struct _Widget_Data
9 {
10    Evas_Object *base;
11    Evas_Object *event[2];
12    Evas_Object *bx[2]; // 2 - for now all that's supported
13    Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
14    int level;
15    Evas_Coord dx, dy;
16    Ecore_Timer *delay;
17    Eina_Bool level_active[2];
18    Eina_Bool horizontal : 1;
19    Eina_Bool autohide_disabled : 1;
20    Eina_Bool down : 1;
21    Eina_Bool indicator_disabled : 1;
22 };
23
24 struct _Elm_Index_Item
25 {
26    ELM_WIDGET_ITEM;
27    const char *letter;
28    int level;
29    Evas_Smart_Cb func;
30    Eina_Bool selected : 1;
31 };
32
33 static const char *widtype = NULL;
34
35 static void _del_hook(Evas_Object *obj);
36 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
37 static void _theme_hook(Evas_Object *obj);
38 static void _sizing_eval(Evas_Object *obj);
39 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
40 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
41 static void _item_free(Elm_Index_Item *it);
42
43 static const char SIG_CHANGED[] = "changed";
44 static const char SIG_DELAY_CHANGED[] = "delay,changed";
45 static const char SIG_SELECTED[] = "selected";
46 static const char SIG_LEVEL_UP[] = "level,up";
47 static const char SIG_LEVEL_DOWN[] = "level,down";
48
49 static const Evas_Smart_Cb_Description _signals[] = {
50    {SIG_CHANGED, ""},
51    {SIG_DELAY_CHANGED, ""},
52    {SIG_SELECTED, ""},
53    {SIG_LEVEL_UP, ""},
54    {SIG_LEVEL_DOWN, ""},
55    {NULL, NULL}
56 };
57
58 static void
59 _del_pre_hook(Evas_Object *obj)
60 {
61    Widget_Data *wd = elm_widget_data_get(obj);
62    Elm_Index_Item *it;
63    if (!wd) return;
64    _index_box_clear(obj, wd->bx[wd->level], wd->level);
65    _index_box_clear(obj, wd->bx[0], 0);
66    while (wd->items)
67      {
68         it = wd->items->data;
69         _item_free(it);
70         elm_widget_item_free(it);
71      }
72    if (wd->delay) ecore_timer_del(wd->delay);
73 }
74
75 static void
76 _del_hook(Evas_Object *obj)
77 {
78    Widget_Data *wd = elm_widget_data_get(obj);
79    free(wd);
80 }
81
82 static void
83 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
84 {
85    Widget_Data *wd = data;
86    if (!wd) return;
87    _els_box_layout(o, priv, wd->horizontal, 1, 0);
88 }
89
90 static void
91 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
92 {
93    Widget_Data *wd = elm_widget_data_get(obj);
94    if (!wd) return;
95    edje_object_signal_emit(wd->base, emission, source);
96 }
97
98 static void
99 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
100 {
101    Widget_Data *wd = elm_widget_data_get(obj);
102    if (!wd) return;
103    edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
104 }
105
106 static void
107 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
108 {
109    Widget_Data *wd = elm_widget_data_get(obj);
110    edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
111                                         data);
112 }
113
114 static void
115 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
116 {
117    Widget_Data *wd = elm_widget_data_get(obj);
118    if (!wd) return;
119    if (!wd->horizontal)
120      edje_object_mirrored_set(wd->base, rtl);
121 }
122
123 static void
124 _theme_hook(Evas_Object *obj)
125 {
126    Evas_Coord minw = 0, minh = 0;
127    Widget_Data *wd = elm_widget_data_get(obj);
128    if (!wd) return;
129    _elm_widget_mirrored_reload(obj);
130
131    _index_box_clear(obj, wd->bx[0], 0);
132    _index_box_clear(obj, wd->bx[1], 1);
133    if (wd->horizontal)
134      _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
135    else
136      {
137         _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
138         _mirrored_set(obj, elm_widget_mirrored_get(obj));
139      }
140    edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
141    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
142    evas_object_size_hint_min_set(wd->event[0], minw, minh);
143    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
144    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
145      {
146         if (!wd->bx[1])
147           {
148              wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
149              evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
150              elm_widget_sub_object_add(obj, wd->bx[1]);
151           }
152         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
153         evas_object_show(wd->bx[1]);
154      }
155    else if (wd->bx[1])
156      {
157         evas_object_del(wd->bx[1]);
158         wd->bx[1] = NULL;
159      }
160    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
161      {
162         if (!wd->event[1])
163           {
164              wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
165              evas_object_color_set(wd->event[1], 0, 0, 0, 0);
166              elm_widget_sub_object_add(obj, wd->event[1]);
167           }
168         edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
169         evas_object_size_hint_min_set(wd->event[1], minw, minh);
170      }
171    else if (wd->event[1])
172      {
173         evas_object_del(wd->event[1]);
174         wd->event[1] = NULL;
175      }
176    edje_object_message_signal_process(wd->base);
177    edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
178    _sizing_eval(obj);
179    _index_box_auto_fill(obj, wd->bx[0], 0);
180
181    if (wd->autohide_disabled)
182      {
183         if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
184         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
185      }
186    else
187      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
188 }
189
190 static void
191 _sizing_eval(Evas_Object *obj)
192 {
193    Widget_Data *wd = elm_widget_data_get(obj);
194    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
195    if (!wd) return;
196    edje_object_size_min_calc(wd->base, &minw, &minh);
197    evas_object_size_hint_min_set(obj, minw, minh);
198    evas_object_size_hint_max_set(obj, maxw, maxh);
199 }
200
201 static Eina_Bool
202 _item_del_pre_hook(Elm_Object_Item *it)
203 {
204    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
205    if (!wd) return EINA_FALSE;
206    _item_free((Elm_Index_Item *)it);
207    _index_box_clear(WIDGET(it), wd->bx[wd->level], wd->level);
208    return EINA_TRUE;
209 }
210
211 static Elm_Index_Item *
212 _item_new(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
213 {
214    Widget_Data *wd = elm_widget_data_get(obj);
215    Elm_Index_Item *it;
216    if (!wd) return NULL;
217    it = elm_widget_item_new(obj, Elm_Index_Item);
218    if (!it) return NULL;
219    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
220    if (letter) it->letter = eina_stringshare_add(letter);
221    it->func = func;
222    it->base.data = data;
223    it->level = wd->level;
224    return it;
225 }
226
227 static Elm_Index_Item *
228 _item_find(Evas_Object *obj, const void *data)
229 {
230    Widget_Data *wd = elm_widget_data_get(obj);
231    Eina_List *l;
232    Elm_Index_Item *it;
233    if (!wd) return NULL;
234    EINA_LIST_FOREACH(wd->items, l, it)
235      if (it->base.data == data) return it;
236    return NULL;
237 }
238
239 static void
240 _item_free(Elm_Index_Item *it)
241 {
242    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
243    if (!wd) return;
244    wd->items = eina_list_remove(wd->items, it);
245    if (it->letter) eina_stringshare_del(it->letter);
246 }
247
248 // FIXME: always have index filled
249 static void
250 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
251 {
252    Widget_Data *wd = elm_widget_data_get(obj);
253    Eina_Bool rtl;
254    Eina_List *l;
255    Elm_Index_Item *it;
256    Evas_Coord mw, mh, w, h;
257    int i = 0;
258    if (!wd) return;
259    if (wd->level_active[level]) return;
260    rtl = elm_widget_mirrored_get(obj);
261    evas_object_geometry_get(box, NULL, NULL, &w, &h);
262    EINA_LIST_FOREACH(wd->items, l, it)
263      {
264         Evas_Object *o;
265         const char *stacking;
266
267         if (it->level != level) continue;
268         o = edje_object_add(evas_object_evas_get(obj));
269         VIEW(it) = o;
270         edje_object_mirrored_set(VIEW(it), rtl);
271         if (i & 0x1)
272           _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
273         else
274           _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
275         edje_object_part_text_set(o, "elm.text", it->letter);
276         edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
277         evas_object_size_hint_min_set(o, mw, mh);
278         evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279         evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
280         elm_widget_sub_object_add(obj, o);
281         evas_object_box_append(box, o);
282         stacking = edje_object_data_get(o, "stacking");
283         if (stacking)
284           {
285              if (!strcmp(stacking, "below")) evas_object_lower(o);
286              else if (!strcmp(stacking, "above")) evas_object_raise(o);
287           }
288         evas_object_show(o);
289         i++;
290         evas_object_smart_calculate(box); // force a calc so we know the size
291         evas_object_size_hint_min_get(box, &mw, &mh);
292         if (mh > h)
293           {
294              _index_box_clear(obj, box, level);
295              if (i > 0)
296                {
297                   // FIXME: only i objects fit! try again. overflows right now
298                }
299           }
300      }
301    evas_object_smart_calculate(box);
302    wd->level_active[level] = 1;
303 }
304
305 static void
306 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
307 {
308    Widget_Data *wd = elm_widget_data_get(obj);
309    Eina_List *l;
310    Elm_Index_Item *it;
311    if (!wd) return;
312    if (!wd->level_active[level]) return;
313    EINA_LIST_FOREACH(wd->items, l, it)
314      {
315         if (!VIEW(it)) continue;
316         if (it->level != level) continue;
317         evas_object_del(VIEW(it));
318         VIEW(it) = NULL;
319      }
320    wd->level_active[level] = 0;
321 }
322
323 static Eina_Bool
324 _delay_change(void *data)
325 {
326    Widget_Data *wd = elm_widget_data_get(data);
327    Elm_Object_Item *item;
328    if (!wd) return ECORE_CALLBACK_CANCEL;
329    wd->delay = NULL;
330    item = elm_index_selected_item_get(data, wd->level);
331    if (item) evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, item);
332    return ECORE_CALLBACK_CANCEL;
333 }
334
335 static void
336 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
337 {
338    Widget_Data *wd = elm_widget_data_get(obj);
339    Elm_Index_Item *it, *it_closest, *it_last;
340    Eina_List *l;
341    Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
342    double cdv = 0.5;
343    Evas_Coord dist;
344    char *label = NULL, *last = NULL;
345    int i;
346    if (!wd) return;
347    for (i = 0; i <= wd->level; i++)
348      {
349         it_last = NULL;
350         it_closest  = NULL;
351         dist = 0x7fffffff;
352         evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
353         EINA_LIST_FOREACH(wd->items, l, it)
354           {
355              if (!((it->level == i) && (VIEW(it)))) continue;
356              if ((VIEW(it)) && (it->level != wd->level))
357                {
358                   if (it->selected)
359                     {
360                        it_closest = it;
361                        break;
362                     }
363                   continue;
364                }
365              if (it->selected)
366                {
367                   it_last = it;
368                   it->selected = 0;
369                }
370              evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
371              xx = x + (w / 2);
372              yy = y + (h / 2);
373              x = evx - xx;
374              y = evy - yy;
375              x = (x * x) + (y * y);
376              if ((x < dist) || (!it_closest))
377                {
378                   if (wd->horizontal)
379                     cdv = (double)(xx - bx) / (double)bw;
380                   else
381                     cdv = (double)(yy - by) / (double)bh;
382                   it_closest = it;
383                   dist = x;
384                }
385           }
386         if ((i == 0) && (wd->level == 0))
387           edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
388                                           cdv, cdv);
389         if (it_closest) it_closest->selected = 1;
390         if (it_closest != it_last)
391           {
392              if (it_last)
393                {
394                   const char *stacking, *selectraise;
395
396                   it = it_last;
397                   edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
398                   stacking = edje_object_data_get(VIEW(it), "stacking");
399                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
400                   if ((selectraise) && (!strcmp(selectraise, "on")))
401                     {
402                        if ((stacking) && (!strcmp(stacking, "below")))
403                          evas_object_lower(VIEW(it));
404                     }
405                }
406              if (it_closest)
407                {
408                   const char *selectraise;
409
410                   it = it_closest;
411                   edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
412                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
413                   if ((selectraise) && (!strcmp(selectraise, "on")))
414                     evas_object_raise(VIEW(it));
415                   evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it);
416                   if (wd->delay) ecore_timer_del(wd->delay);
417                   wd->delay = ecore_timer_add(0.2, _delay_change, obj);
418                }
419           }
420         if (it_closest)
421           {
422              it = it_closest;
423              if (!last)
424                last = strdup(it->letter);
425              else
426                {
427                   if (!label) label = strdup(last);
428                   else
429                     {
430                        /* FIXME: realloc return NULL if the request fails */
431                        label = realloc(label, strlen(label) + strlen(last) + 1);
432                        strcat(label, last);
433                     }
434                   free(last);
435                   last = strdup(it->letter);
436                }
437           }
438      }
439    if (!label) label = strdup("");
440    if (!last) last = strdup("");
441    edje_object_part_text_set(wd->base, "elm.text.body", label);
442    edje_object_part_text_set(wd->base, "elm.text", last);
443    free(label);
444    free(last);
445 }
446
447 static void
448 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
449 {
450    Widget_Data *wd = elm_widget_data_get(data);
451    //   Evas_Event_Mouse_Wheel *ev = event_info;
452    //   Evas_Object *obj = o;
453    if (!wd) return;
454 }
455
456 static void
457 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
458 {
459    Widget_Data *wd = elm_widget_data_get(data);
460    Evas_Event_Mouse_Down *ev = event_info;
461    Evas_Coord x, y, w;
462    if (!wd) return;
463    if (ev->button != 1) return;
464    wd->down = 1;
465    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
466    wd->dx = ev->canvas.x - x;
467    wd->dy = ev->canvas.y - y;
468    if (!wd->autohide_disabled)
469      {
470         _index_box_clear(data, wd->bx[1], 1);
471         _index_box_auto_fill(data, wd->bx[0], 0);
472         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
473      }
474    _sel_eval(data, ev->canvas.x, ev->canvas.y);
475    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
476                                    (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
477    if (wd->items && !wd->indicator_disabled)
478      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
479 }
480
481 static void
482 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
483 {
484    Widget_Data *wd = elm_widget_data_get(data);
485    Evas_Event_Mouse_Up *ev = event_info;
486    Elm_Object_Item *item;
487    Elm_Index_Item *id_item;
488    if (!wd) return;
489    if (ev->button != 1) return;
490    wd->down = 0;
491    item = elm_index_selected_item_get(data, wd->level);
492    if (item)
493      {
494         evas_object_smart_callback_call(data, SIG_SELECTED, item);
495         id_item = (Elm_Index_Item *)item;
496         if (id_item->func)
497           id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
498      }
499    if (!wd->autohide_disabled)
500      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
501    edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
502    if (wd->items && !wd->indicator_disabled)
503      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
504 }
505
506 static void
507 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
508 {
509    Widget_Data *wd = elm_widget_data_get(data);
510    Evas_Event_Mouse_Move *ev = event_info;
511    Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
512    char buf[1024];
513    if (!wd) return;
514    if (!wd->down) return;
515    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
516    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
517    x = ev->cur.canvas.x - x;
518    y = ev->cur.canvas.y - y;
519    dx = x - wd->dx;
520    adx = dx;
521    if (adx < 0) adx = -dx;
522    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
523                                    , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
524    if (!wd->horizontal)
525      {
526         if (adx > minw)
527           {
528              if (!wd->level)
529                {
530                   wd->level = 1;
531                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
532                   edje_object_signal_emit(wd->base, buf, "elm");
533                   evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
534                }
535           }
536         else
537           {
538              if (wd->level == 1)
539                {
540                   wd->level = 0;
541                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
542                   edje_object_signal_emit(wd->base, buf, "elm");
543                   evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
544                }
545           }
546      }
547    _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
548 }
549
550 EAPI Evas_Object *
551 elm_index_add(Evas_Object *parent)
552 {
553    Evas_Object *obj;
554    Evas_Object *o;
555    Evas *e;
556    Widget_Data *wd;
557    Evas_Coord minw, minh;
558
559    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
560
561    ELM_SET_WIDTYPE(widtype, "index");
562    elm_widget_type_set(obj, "index");
563    elm_widget_sub_object_add(parent, obj);
564    elm_widget_data_set(obj, wd);
565    elm_widget_del_hook_set(obj, _del_hook);
566    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
567    elm_widget_theme_hook_set(obj, _theme_hook);
568    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
569    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
570    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
571    elm_widget_can_focus_set(obj, EINA_FALSE);
572
573    wd->indicator_disabled = EINA_FALSE;
574    wd->horizontal = EINA_FALSE;
575    wd->autohide_disabled = EINA_FALSE;
576
577    wd->base = edje_object_add(e);
578    _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
579    elm_widget_resize_object_set(obj, wd->base);
580
581    o = evas_object_rectangle_add(e);
582    wd->event[0] = o;
583    evas_object_color_set(o, 0, 0, 0, 0);
584    minw = minh = 0;
585    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
586    evas_object_size_hint_min_set(o, minw, minh);
587    edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
588    elm_widget_sub_object_add(obj, o);
589    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
590    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
591    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
592    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
593    evas_object_show(o);
594    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
595      {
596         o = evas_object_rectangle_add(e);
597         wd->event[1] = o;
598         evas_object_color_set(o, 0, 0, 0, 0);
599         evas_object_size_hint_min_set(o, minw, minh);
600         edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
601         elm_widget_sub_object_add(obj, o);
602      }
603
604    wd->bx[0] = evas_object_box_add(e);
605    evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
606    elm_widget_sub_object_add(obj, wd->bx[0]);
607    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
608    evas_object_show(wd->bx[0]);
609
610    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
611      {
612         wd->bx[1] = evas_object_box_add(e);
613         evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
614         elm_widget_sub_object_add(obj, wd->bx[1]);
615         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
616         evas_object_show(wd->bx[1]);
617      }
618
619    evas_object_smart_callbacks_descriptions_set(obj, _signals);
620
621    _mirrored_set(obj, elm_widget_mirrored_get(obj));
622    _sizing_eval(obj);
623    return obj;
624 }
625
626 EINA_DEPRECATED EAPI void
627 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
628 {
629    elm_index_autohide_disabled_set(obj, !active);
630 }
631
632 EINA_DEPRECATED EAPI Eina_Bool
633 elm_index_active_get(const Evas_Object *obj)
634 {
635    return !elm_index_autohide_disabled_get(obj);
636 }
637
638 EAPI void
639 elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
640 {
641    ELM_CHECK_WIDTYPE(obj, widtype);
642    Widget_Data *wd = elm_widget_data_get(obj);
643    if (!wd) return;
644    disabled = !!disabled;
645    if (wd->autohide_disabled == disabled) return;
646    wd->autohide_disabled = disabled;
647    wd->level = 0;
648    if (wd->autohide_disabled)
649      {
650         _index_box_clear(obj, wd->bx[1], 1);
651         _index_box_auto_fill(obj, wd->bx[0], 0);
652         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
653      }
654    else
655      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
656 }
657
658 EAPI Eina_Bool
659 elm_index_autohide_disabled_get(const Evas_Object *obj)
660 {
661    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
662    Widget_Data *wd = elm_widget_data_get(obj);
663    if (!wd) return EINA_FALSE;
664    return wd->autohide_disabled;
665 }
666
667 EAPI void
668 elm_index_item_level_set(Evas_Object *obj, int level)
669 {
670    ELM_CHECK_WIDTYPE(obj, widtype);
671    Widget_Data *wd = elm_widget_data_get(obj);
672    if (!wd) return;
673    if (wd->level == level) return;
674    wd->level = level;
675 }
676
677 EAPI int
678 elm_index_item_level_get(const Evas_Object *obj)
679 {
680    ELM_CHECK_WIDTYPE(obj, widtype) 0;
681    Widget_Data *wd = elm_widget_data_get(obj);
682    if (!wd) return 0;
683    return wd->level;
684 }
685
686 EINA_DEPRECATED EAPI Elm_Object_Item *
687 elm_index_item_selected_get(const Evas_Object *obj, int level)
688 {
689    return elm_index_selected_item_get(obj, level);
690 }
691
692 EAPI Elm_Object_Item *
693 elm_index_selected_item_get(const Evas_Object *obj, int level)
694 {
695    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
696    Widget_Data *wd = elm_widget_data_get(obj);
697    Eina_List *l;
698    Elm_Index_Item *it;
699    if (!wd) return NULL;
700    EINA_LIST_FOREACH(wd->items, l, it)
701      {
702         if ((it->selected) && (it->level == level))
703           return (Elm_Object_Item *)it;
704      }
705    return NULL;
706 }
707
708 EAPI Elm_Object_Item *
709 elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
710 {
711    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
712    Widget_Data *wd = elm_widget_data_get(obj);
713    Elm_Index_Item *it;
714    if (!wd) return NULL;
715    it = _item_new(obj, letter, func, data);
716    if (!it) return NULL;
717    wd->items = eina_list_append(wd->items, it);
718    _index_box_clear(obj, wd->bx[wd->level], wd->level);
719    return (Elm_Object_Item *)it;
720 }
721
722 EAPI Elm_Object_Item *
723 elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
724 {
725    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
726    Widget_Data *wd = elm_widget_data_get(obj);
727    Elm_Index_Item *it;
728
729    if (!wd) return NULL;
730    it = _item_new(obj, letter, func, data);
731    if (!it) return NULL;
732    wd->items = eina_list_prepend(wd->items, it);
733    _index_box_clear(obj, wd->bx[wd->level], wd->level);
734    return (Elm_Object_Item *)it;
735 }
736
737 EINA_DEPRECATED EAPI Elm_Object_Item *
738 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
739 {
740    return elm_index_item_insert_after(obj, (Elm_Object_Item *) relative, letter, NULL, item);
741 }
742
743 EINA_DEPRECATED EAPI Elm_Object_Item *
744 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
745 {
746    return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
747 }
748
749 EAPI Elm_Object_Item *
750 elm_index_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *letter, Evas_Smart_Cb func, const void *data)
751 {
752    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
753    Widget_Data *wd = elm_widget_data_get(obj);
754    Elm_Index_Item *it;
755    if (!wd) return NULL;
756    if (!after) return elm_index_item_append(obj, letter, func, data);
757    it = _item_new(obj, letter, func, data);
758    if (!it) return NULL;
759    wd->items = eina_list_append_relative(wd->items, it, after);
760    _index_box_clear(obj, wd->bx[wd->level], wd->level);
761    return (Elm_Object_Item *)it;
762 }
763
764 EAPI Elm_Object_Item *
765 elm_index_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *letter, Evas_Smart_Cb func, const void *data)
766 {
767    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
768    Widget_Data *wd = elm_widget_data_get(obj);
769    Elm_Index_Item *it;
770    if (!wd) return NULL;
771    if (!before) return elm_index_item_prepend(obj, letter, func, data);
772    it = _item_new(obj, letter, func, data);
773    if (!it) return NULL;
774    wd->items = eina_list_prepend_relative(wd->items, it, before);
775    _index_box_clear(obj, wd->bx[wd->level], wd->level);
776    return (Elm_Object_Item *)it;
777 }
778
779 EAPI Elm_Object_Item *
780 elm_index_item_sorted_insert(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data, Eina_Compare_Cb cmp_func, Eina_Compare_Cb cmp_data_func)
781 {
782    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
783    Widget_Data *wd = elm_widget_data_get(obj);
784    Eina_List *lnear;
785    Elm_Index_Item *it;
786    int cmp;
787
788    if (!wd) return NULL;
789    if (!(wd->items))
790      return elm_index_item_append(obj, letter, func, data);
791
792    it = _item_new(obj, letter, func, data);
793    if (!it) return NULL;
794
795    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
796    if (cmp < 0)
797      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
798    else if (cmp > 0)
799      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
800    else
801      {
802         /* If cmp_data_func is not provided, append a duplicated item */
803         if (!cmp_data_func)
804           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
805         else
806           {
807              Elm_Index_Item *p_it = eina_list_data_get(lnear);
808              if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
809                p_it->base.data = it->base.data;
810              _item_free(it);
811              elm_widget_item_free(it);
812           }
813      }
814    _index_box_clear(obj, wd->bx[wd->level], wd->level);
815    return (Elm_Object_Item *)it;
816 }
817
818 EAPI void
819 elm_index_item_del(Evas_Object *obj __UNUSED__, Elm_Object_Item *it)
820 {
821    elm_object_item_del(it);
822 }
823
824 EAPI Elm_Object_Item *
825 elm_index_item_find(Evas_Object *obj, const void *data)
826 {
827    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
828    Widget_Data *wd = elm_widget_data_get(obj);
829    if (!wd) return NULL;
830    return (Elm_Object_Item *) _item_find(obj, data);
831 }
832
833 EAPI void
834 elm_index_item_clear(Evas_Object *obj)
835 {
836    ELM_CHECK_WIDTYPE(obj, widtype);
837    Widget_Data *wd = elm_widget_data_get(obj);
838    Elm_Index_Item *it;
839    Eina_List *l, *clear = NULL;
840    if (!wd) return;
841    _index_box_clear(obj, wd->bx[wd->level], wd->level);
842    EINA_LIST_FOREACH(wd->items, l, it)
843      {
844         if (it->level != wd->level) continue;
845         clear = eina_list_append(clear, it);
846      }
847    EINA_LIST_FREE(clear, it)
848      {
849         _item_free(it);
850         elm_widget_item_free(it);
851      }
852 }
853
854 EINA_DEPRECATED EAPI void
855 elm_index_item_go(Evas_Object *obj, int level __UNUSED__)
856 {
857    elm_index_level_go(obj, level);
858 }
859
860 EAPI void
861 elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
862 {
863    ELM_CHECK_WIDTYPE(obj, widtype);
864    Widget_Data *wd = elm_widget_data_get(obj);
865    if (!wd) return;
866    _index_box_auto_fill(obj, wd->bx[0], 0);
867    if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
868 }
869
870 EAPI void *
871 elm_index_item_data_get(const Elm_Object_Item *it)
872 {
873    return elm_object_item_data_get(it);
874 }
875
876 EAPI void
877 elm_index_item_data_set(Elm_Object_Item *it, const void *data)
878 {
879    elm_object_item_data_set(it, (void *) data);
880 }
881
882 EAPI void
883 elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
884 {
885    ELM_CHECK_WIDTYPE(obj, widtype);
886    Widget_Data *wd = elm_widget_data_get(obj);
887    if (!wd) return;
888
889    disabled = !!disabled;
890    if (wd->indicator_disabled == disabled) return;
891    wd->indicator_disabled = disabled;
892    if (!wd->items) return;
893    if (disabled)
894      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
895    else
896      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
897 }
898
899 EAPI Eina_Bool
900 elm_index_indicator_disabled_get(const Evas_Object *obj)
901 {
902    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
903    Widget_Data *wd = elm_widget_data_get(obj);
904    if (!wd) return EINA_FALSE;
905
906    return wd->indicator_disabled;
907 }
908
909 EAPI void
910 elm_index_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
911 {
912    elm_object_item_del_cb_set(it, func);
913 }
914
915 EAPI const char *
916 elm_index_item_letter_get(const Elm_Object_Item *it)
917 {
918    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
919    return ((Elm_Index_Item *)it)->letter;
920 }
921