remove deprecated code related with
[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
272         if (wd->horizontal)
273           {
274              if (i & 0x1)
275                _elm_theme_object_set(obj, o, "index", "item_odd/horizontal",
276                                      elm_widget_style_get(obj));
277              else
278                _elm_theme_object_set(obj, o, "index", "item/horizontal",
279                                      elm_widget_style_get(obj));
280           }
281         else
282           {
283              if (i & 0x1)
284                _elm_theme_object_set(obj, o, "index", "item_odd/vertical",
285                                      elm_widget_style_get(obj));
286              else
287                _elm_theme_object_set(obj, o, "index", "item/vertical",
288                                      elm_widget_style_get(obj));
289           }
290
291         edje_object_part_text_set(o, "elm.text", it->letter);
292         edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
293         evas_object_size_hint_min_set(o, mw, mh);
294         evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
295         evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
296         elm_widget_sub_object_add(obj, o);
297         evas_object_box_append(box, o);
298         stacking = edje_object_data_get(o, "stacking");
299         if (stacking)
300           {
301              if (!strcmp(stacking, "below")) evas_object_lower(o);
302              else if (!strcmp(stacking, "above")) evas_object_raise(o);
303           }
304         evas_object_show(o);
305         i++;
306         evas_object_smart_calculate(box); // force a calc so we know the size
307         evas_object_size_hint_min_get(box, &mw, &mh);
308         if (mh > h)
309           {
310              _index_box_clear(obj, box, level);
311              if (i > 0)
312                {
313                   // FIXME: only i objects fit! try again. overflows right now
314                }
315           }
316      }
317    evas_object_smart_calculate(box);
318    wd->level_active[level] = 1;
319 }
320
321 static void
322 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
323 {
324    Widget_Data *wd = elm_widget_data_get(obj);
325    Eina_List *l;
326    Elm_Index_Item *it;
327    if (!wd) return;
328    if (!wd->level_active[level]) return;
329    EINA_LIST_FOREACH(wd->items, l, it)
330      {
331         if (!VIEW(it)) continue;
332         if (it->level != level) continue;
333         evas_object_del(VIEW(it));
334         VIEW(it) = NULL;
335      }
336    wd->level_active[level] = 0;
337 }
338
339 static Eina_Bool
340 _delay_change(void *data)
341 {
342    Widget_Data *wd = elm_widget_data_get(data);
343    Elm_Object_Item *item;
344    if (!wd) return ECORE_CALLBACK_CANCEL;
345    wd->delay = NULL;
346    item = elm_index_selected_item_get(data, wd->level);
347    if (item) evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, item);
348    return ECORE_CALLBACK_CANCEL;
349 }
350
351 static void
352 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
353 {
354    Widget_Data *wd = elm_widget_data_get(obj);
355    Elm_Index_Item *it, *it_closest, *it_last;
356    Eina_List *l;
357    Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
358    double cdv = 0.5;
359    Evas_Coord dist;
360    char *label = NULL, *last = NULL;
361    int i;
362    if (!wd) return;
363    for (i = 0; i <= wd->level; i++)
364      {
365         it_last = NULL;
366         it_closest  = NULL;
367         dist = 0x7fffffff;
368         evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
369         EINA_LIST_FOREACH(wd->items, l, it)
370           {
371              if (it->level != i) continue;
372              if (it->level != wd->level)
373                {
374                   if (it->selected)
375                     {
376                        it_closest = it;
377                        break;
378                     }
379                   continue;
380                }
381              if (it->selected)
382                {
383                   it_last = it;
384                   it->selected = 0;
385                }
386              evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
387              xx = x + (w / 2);
388              yy = y + (h / 2);
389              x = evx - xx;
390              y = evy - yy;
391              x = (x * x) + (y * y);
392              if ((x < dist) || (!it_closest))
393                {
394                   if (wd->horizontal)
395                     cdv = (double)(xx - bx) / (double)bw;
396                   else
397                     cdv = (double)(yy - by) / (double)bh;
398                   it_closest = it;
399                   dist = x;
400                }
401           }
402         if ((i == 0) && (wd->level == 0))
403           edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
404                                           cdv, cdv);
405         if (it_closest) it_closest->selected = 1;
406         if (it_closest != it_last)
407           {
408              if (it_last)
409                {
410                   const char *stacking, *selectraise;
411
412                   it = it_last;
413                   edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
414                   stacking = edje_object_data_get(VIEW(it), "stacking");
415                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
416                   if ((selectraise) && (!strcmp(selectraise, "on")))
417                     {
418                        if ((stacking) && (!strcmp(stacking, "below")))
419                          evas_object_lower(VIEW(it));
420                     }
421                }
422              if (it_closest)
423                {
424                   const char *selectraise;
425
426                   it = it_closest;
427                   edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
428                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
429                   if ((selectraise) && (!strcmp(selectraise, "on")))
430                     evas_object_raise(VIEW(it));
431                   evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it);
432                   if (wd->delay) ecore_timer_del(wd->delay);
433                   wd->delay = ecore_timer_add(0.2, _delay_change, obj);
434                }
435           }
436         if (it_closest)
437           {
438              it = it_closest;
439              if (!last)
440                last = strdup(it->letter);
441              else
442                {
443                   if (!label) label = strdup(last);
444                   else
445                     {
446                        label = realloc(label, strlen(label) + strlen(last) + 1);
447                        if (!label) return;
448                        strcat(label, last);
449                     }
450                   free(last);
451                   last = strdup(it->letter);
452                }
453           }
454      }
455
456    if (!label) label = strdup("");
457    if (!last) last = strdup("");
458    edje_object_part_text_set(wd->base, "elm.text.body", label);
459    edje_object_part_text_set(wd->base, "elm.text", last);
460    free(label);
461    free(last);
462 }
463
464 static void
465 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
466 {
467    Widget_Data *wd = elm_widget_data_get(data);
468    //   Evas_Event_Mouse_Wheel *ev = event_info;
469    //   Evas_Object *obj = o;
470    if (!wd) return;
471 }
472
473 static void
474 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
475 {
476    Widget_Data *wd = elm_widget_data_get(data);
477    Evas_Event_Mouse_Down *ev = event_info;
478    Evas_Coord x, y, w;
479    if (!wd) return;
480    if (ev->button != 1) return;
481    wd->down = 1;
482    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
483    wd->dx = ev->canvas.x - x;
484    wd->dy = ev->canvas.y - y;
485    if (!wd->autohide_disabled)
486      {
487         _index_box_clear(data, wd->bx[1], 1);
488         _index_box_auto_fill(data, wd->bx[0], 0);
489         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
490      }
491    _sel_eval(data, ev->canvas.x, ev->canvas.y);
492    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
493                                    (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
494    if (wd->items && !wd->indicator_disabled)
495      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
496 }
497
498 static void
499 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
500 {
501    Widget_Data *wd = elm_widget_data_get(data);
502    Evas_Event_Mouse_Up *ev = event_info;
503    Elm_Object_Item *item;
504    Elm_Index_Item *id_item;
505    if (!wd) return;
506    if (ev->button != 1) return;
507    wd->down = 0;
508    item = elm_index_selected_item_get(data, wd->level);
509    if (item)
510      {
511         evas_object_smart_callback_call(data, SIG_SELECTED, item);
512         id_item = (Elm_Index_Item *)item;
513         if (id_item->func)
514           id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
515      }
516    if (!wd->autohide_disabled)
517      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
518    edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
519    if (wd->items && !wd->indicator_disabled)
520      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
521 }
522
523 static void
524 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
525 {
526    Widget_Data *wd = elm_widget_data_get(data);
527    Evas_Event_Mouse_Move *ev = event_info;
528    Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
529    char buf[1024];
530    if (!wd) return;
531    if (!wd->down) return;
532    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
533    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
534    x = ev->cur.canvas.x - x;
535    y = ev->cur.canvas.y - y;
536    dx = x - wd->dx;
537    adx = dx;
538    if (adx < 0) adx = -dx;
539    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
540                                    , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
541    if (!wd->horizontal)
542      {
543         if (adx > minw)
544           {
545              if (!wd->level)
546                {
547                   wd->level = 1;
548                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
549                   edje_object_signal_emit(wd->base, buf, "elm");
550                   evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
551                }
552           }
553         else
554           {
555              if (wd->level == 1)
556                {
557                   wd->level = 0;
558                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
559                   edje_object_signal_emit(wd->base, buf, "elm");
560                   evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
561                }
562           }
563      }
564    _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
565 }
566
567 EAPI Evas_Object *
568 elm_index_add(Evas_Object *parent)
569 {
570    Evas_Object *obj;
571    Evas_Object *o;
572    Evas *e;
573    Widget_Data *wd;
574    Evas_Coord minw, minh;
575
576    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
577
578    ELM_SET_WIDTYPE(widtype, "index");
579    elm_widget_type_set(obj, "index");
580    elm_widget_sub_object_add(parent, obj);
581    elm_widget_data_set(obj, wd);
582    elm_widget_del_hook_set(obj, _del_hook);
583    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
584    elm_widget_theme_hook_set(obj, _theme_hook);
585    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
586    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
587    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
588    elm_widget_can_focus_set(obj, EINA_FALSE);
589
590    wd->indicator_disabled = EINA_FALSE;
591    wd->horizontal = EINA_FALSE;
592    wd->autohide_disabled = EINA_FALSE;
593
594    wd->base = edje_object_add(e);
595    _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
596    elm_widget_resize_object_set(obj, wd->base);
597
598    o = evas_object_rectangle_add(e);
599    wd->event[0] = o;
600    evas_object_color_set(o, 0, 0, 0, 0);
601    minw = minh = 0;
602    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
603    evas_object_size_hint_min_set(o, minw, minh);
604    edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
605    elm_widget_sub_object_add(obj, o);
606    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
607    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
608    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
609    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
610    evas_object_show(o);
611    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
612      {
613         o = evas_object_rectangle_add(e);
614         wd->event[1] = o;
615         evas_object_color_set(o, 0, 0, 0, 0);
616         evas_object_size_hint_min_set(o, minw, minh);
617         edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
618         elm_widget_sub_object_add(obj, o);
619      }
620
621    wd->bx[0] = evas_object_box_add(e);
622    evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
623    elm_widget_sub_object_add(obj, wd->bx[0]);
624    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
625    evas_object_show(wd->bx[0]);
626
627    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
628      {
629         wd->bx[1] = evas_object_box_add(e);
630         evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
631         elm_widget_sub_object_add(obj, wd->bx[1]);
632         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
633         evas_object_show(wd->bx[1]);
634      }
635
636    evas_object_smart_callbacks_descriptions_set(obj, _signals);
637
638    _mirrored_set(obj, elm_widget_mirrored_get(obj));
639    _sizing_eval(obj);
640    return obj;
641 }
642
643 EINA_DEPRECATED EAPI void
644 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
645 {
646    elm_index_autohide_disabled_set(obj, !active);
647 }
648
649 EINA_DEPRECATED EAPI Eina_Bool
650 elm_index_active_get(const Evas_Object *obj)
651 {
652    return !elm_index_autohide_disabled_get(obj);
653 }
654
655 EAPI void
656 elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
657 {
658    ELM_CHECK_WIDTYPE(obj, widtype);
659    Widget_Data *wd = elm_widget_data_get(obj);
660    if (!wd) return;
661    disabled = !!disabled;
662    if (wd->autohide_disabled == disabled) return;
663    wd->autohide_disabled = disabled;
664    wd->level = 0;
665    if (wd->autohide_disabled)
666      {
667         _index_box_clear(obj, wd->bx[1], 1);
668         _index_box_auto_fill(obj, wd->bx[0], 0);
669         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
670      }
671    else
672      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
673
674    //FIXME: Should be update indicator based on the indicator visiblility 
675 }
676
677 EAPI Eina_Bool
678 elm_index_autohide_disabled_get(const Evas_Object *obj)
679 {
680    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
681    Widget_Data *wd = elm_widget_data_get(obj);
682    if (!wd) return EINA_FALSE;
683    return wd->autohide_disabled;
684 }
685
686 EAPI void
687 elm_index_item_level_set(Evas_Object *obj, int level)
688 {
689    ELM_CHECK_WIDTYPE(obj, widtype);
690    Widget_Data *wd = elm_widget_data_get(obj);
691    if (!wd) return;
692    if (wd->level == level) return;
693    wd->level = level;
694 }
695
696 EAPI int
697 elm_index_item_level_get(const Evas_Object *obj)
698 {
699    ELM_CHECK_WIDTYPE(obj, widtype) 0;
700    Widget_Data *wd = elm_widget_data_get(obj);
701    if (!wd) return 0;
702    return wd->level;
703 }
704
705 EAPI void
706 elm_index_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
707 {
708    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
709    Evas_Coord x, y, w, h;
710    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
711    if (!wd) return;
712
713    //FIXME: Should be update indicator based on the autohidden status & indicator visiblility 
714
715    if (selected)
716      {
717         evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
718         _sel_eval(WIDGET(it), x + (w/2), y + (h/2));
719      }
720    else
721      _sel_eval(WIDGET(it), -99999, -9999);
722
723 }
724
725 EINA_DEPRECATED EAPI Elm_Object_Item *
726 elm_index_item_selected_get(const Evas_Object *obj, int level)
727 {
728    return elm_index_selected_item_get(obj, level);
729 }
730
731 EAPI Elm_Object_Item *
732 elm_index_selected_item_get(const Evas_Object *obj, int level)
733 {
734    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
735    Widget_Data *wd = elm_widget_data_get(obj);
736    Eina_List *l;
737    Elm_Index_Item *it;
738    if (!wd) return NULL;
739    EINA_LIST_FOREACH(wd->items, l, it)
740      {
741         if ((it->selected) && (it->level == level))
742           return (Elm_Object_Item *)it;
743      }
744    return NULL;
745 }
746
747 EAPI Elm_Object_Item *
748 elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
749 {
750    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
751    Widget_Data *wd = elm_widget_data_get(obj);
752    Elm_Index_Item *it;
753    if (!wd) return NULL;
754    it = _item_new(obj, letter, func, data);
755    if (!it) return NULL;
756    wd->items = eina_list_append(wd->items, it);
757    _index_box_clear(obj, wd->bx[wd->level], wd->level);
758    return (Elm_Object_Item *)it;
759 }
760
761 EAPI Elm_Object_Item *
762 elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
763 {
764    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
765    Widget_Data *wd = elm_widget_data_get(obj);
766    Elm_Index_Item *it;
767
768    if (!wd) return NULL;
769    it = _item_new(obj, letter, func, data);
770    if (!it) return NULL;
771    wd->items = eina_list_prepend(wd->items, it);
772    _index_box_clear(obj, wd->bx[wd->level], wd->level);
773    return (Elm_Object_Item *)it;
774 }
775
776 EINA_DEPRECATED EAPI Elm_Object_Item *
777 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
778 {
779    return elm_index_item_insert_after(obj, (Elm_Object_Item *) relative, letter, NULL, item);
780 }
781
782 EINA_DEPRECATED EAPI Elm_Object_Item *
783 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
784 {
785    return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
786 }
787
788 EAPI Elm_Object_Item *
789 elm_index_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *letter, Evas_Smart_Cb func, const void *data)
790 {
791    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
792    Widget_Data *wd = elm_widget_data_get(obj);
793    Elm_Index_Item *it;
794    if (!wd) return NULL;
795    if (!after) return elm_index_item_append(obj, letter, func, data);
796    it = _item_new(obj, letter, func, data);
797    if (!it) return NULL;
798    wd->items = eina_list_append_relative(wd->items, it, after);
799    _index_box_clear(obj, wd->bx[wd->level], wd->level);
800    return (Elm_Object_Item *)it;
801 }
802
803 EAPI Elm_Object_Item *
804 elm_index_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *letter, Evas_Smart_Cb func, const void *data)
805 {
806    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
807    Widget_Data *wd = elm_widget_data_get(obj);
808    Elm_Index_Item *it;
809    if (!wd) return NULL;
810    if (!before) return elm_index_item_prepend(obj, letter, func, data);
811    it = _item_new(obj, letter, func, data);
812    if (!it) return NULL;
813    wd->items = eina_list_prepend_relative(wd->items, it, before);
814    _index_box_clear(obj, wd->bx[wd->level], wd->level);
815    return (Elm_Object_Item *)it;
816 }
817
818 EAPI Elm_Object_Item *
819 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)
820 {
821    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
822    Widget_Data *wd = elm_widget_data_get(obj);
823    Eina_List *lnear;
824    Elm_Index_Item *it;
825    int cmp;
826
827    if (!wd) return NULL;
828    if (!(wd->items))
829      return elm_index_item_append(obj, letter, func, data);
830
831    it = _item_new(obj, letter, func, data);
832    if (!it) return NULL;
833
834    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
835    if (cmp < 0)
836      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
837    else if (cmp > 0)
838      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
839    else
840      {
841         /* If cmp_data_func is not provided, append a duplicated item */
842         if (!cmp_data_func)
843           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
844         else
845           {
846              Elm_Index_Item *p_it = eina_list_data_get(lnear);
847              if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
848                p_it->base.data = it->base.data;
849              _item_free(it);
850              elm_widget_item_free(it);
851           }
852      }
853    _index_box_clear(obj, wd->bx[wd->level], wd->level);
854    return (Elm_Object_Item *)it;
855 }
856
857 EAPI Elm_Object_Item *
858 elm_index_item_find(Evas_Object *obj, const void *data)
859 {
860    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
861    Widget_Data *wd = elm_widget_data_get(obj);
862    if (!wd) return NULL;
863    return (Elm_Object_Item *) _item_find(obj, data);
864 }
865
866 EAPI void
867 elm_index_item_clear(Evas_Object *obj)
868 {
869    ELM_CHECK_WIDTYPE(obj, widtype);
870    Widget_Data *wd = elm_widget_data_get(obj);
871    Elm_Index_Item *it;
872    Eina_List *l, *clear = NULL;
873    if (!wd) return;
874    _index_box_clear(obj, wd->bx[wd->level], wd->level);
875    EINA_LIST_FOREACH(wd->items, l, it)
876      {
877         if (it->level != wd->level) continue;
878         clear = eina_list_append(clear, it);
879      }
880    EINA_LIST_FREE(clear, it)
881      {
882         _item_free(it);
883         elm_widget_item_free(it);
884      }
885 }
886
887 EAPI void
888 elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
889 {
890    ELM_CHECK_WIDTYPE(obj, widtype);
891    Widget_Data *wd = elm_widget_data_get(obj);
892    if (!wd) return;
893    _index_box_auto_fill(obj, wd->bx[0], 0);
894    if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
895 }
896
897 EAPI void
898 elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
899 {
900    ELM_CHECK_WIDTYPE(obj, widtype);
901    Widget_Data *wd = elm_widget_data_get(obj);
902    if (!wd) return;
903
904    disabled = !!disabled;
905    if (wd->indicator_disabled == disabled) return;
906    wd->indicator_disabled = disabled;
907    if (!wd->items) return;
908    if (disabled)
909      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
910    else
911      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
912 }
913
914 EAPI Eina_Bool
915 elm_index_indicator_disabled_get(const Evas_Object *obj)
916 {
917    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
918    Widget_Data *wd = elm_widget_data_get(obj);
919    if (!wd) return EINA_FALSE;
920
921    return wd->indicator_disabled;
922 }
923
924 EAPI const char *
925 elm_index_item_letter_get(const Elm_Object_Item *it)
926 {
927    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
928    return ((Elm_Index_Item *)it)->letter;
929 }
930
931 EAPI void
932 elm_index_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
933 {
934    ELM_CHECK_WIDTYPE(obj, widtype);
935    Widget_Data *wd = elm_widget_data_get(obj);
936    if (!wd) return;
937
938    horizontal = !!horizontal;
939    if (horizontal == wd->horizontal) return;
940    wd->horizontal = horizontal;
941    _theme_hook(obj);
942 }
943
944 EAPI Eina_Bool
945 elm_index_horizontal_get(const Evas_Object *obj)
946 {
947    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
948    Widget_Data *wd = elm_widget_data_get(obj);
949    if (!wd) return EINA_FALSE;
950    return wd->horizontal;
951 }
952
953