Merge remote-tracking branch 'remotes/origin/upstream'
[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 <<<<<<< HEAD
6 #define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
7 #define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
8 #define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
9
10 typedef struct _Widget_Data Widget_Data;
11
12 typedef struct _PlacementPart PlacementPart;
13 =======
14 typedef struct _Widget_Data Widget_Data;
15 >>>>>>> remotes/origin/upstream
16 typedef struct _Elm_Index_Item Elm_Index_Item;
17
18 struct _Widget_Data
19 {
20    Evas_Object *base;
21    Evas_Object *event[2];
22    Evas_Object *bx[2]; // 2 - for now all that's supported
23    Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
24    int level;
25 <<<<<<< HEAD
26    int tot_items_count[2];
27    int min_obj_height, max_grp_size;
28    int min_1st_level_obj_height;
29    int items_count;
30    Evas_Coord dx, dy;
31    Evas_Coord pwidth, pheight;
32    Ecore_Timer *delay;
33    const char *special_char;
34    Eina_Bool level_active[2];
35    Eina_Bool horizontal : 1;
36    Eina_Bool active : 1;
37 =======
38    Evas_Coord dx, dy;
39    Ecore_Timer *delay;
40    Eina_Bool level_active[2];
41    Eina_Bool horizontal : 1;
42    Eina_Bool autohide_disabled : 1;
43 >>>>>>> remotes/origin/upstream
44    Eina_Bool down : 1;
45    Eina_Bool indicator_disabled : 1;
46 };
47
48 struct _Elm_Index_Item
49 {
50    ELM_WIDGET_ITEM;
51 <<<<<<< HEAD
52    const char *letter, *vis_letter;
53    int level, size;
54    Eina_Bool selected : 1;
55 };
56
57 struct _PlacementPart
58 {
59    int start;
60    int count;
61 };
62
63 =======
64    const char *letter;
65    int level;
66    Evas_Smart_Cb func;
67    Eina_Bool selected : 1;
68 };
69
70 >>>>>>> remotes/origin/upstream
71 static const char *widtype = NULL;
72
73 static void _del_hook(Evas_Object *obj);
74 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
75 static void _theme_hook(Evas_Object *obj);
76 static void _sizing_eval(Evas_Object *obj);
77 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
78 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
79 static void _item_free(Elm_Index_Item *it);
80 <<<<<<< HEAD
81 static void _index_process(Evas_Object *obj);
82 =======
83 >>>>>>> remotes/origin/upstream
84
85 static const char SIG_CHANGED[] = "changed";
86 static const char SIG_DELAY_CHANGED[] = "delay,changed";
87 static const char SIG_SELECTED[] = "selected";
88 static const char SIG_LEVEL_UP[] = "level,up";
89 static const char SIG_LEVEL_DOWN[] = "level,down";
90
91 static const Evas_Smart_Cb_Description _signals[] = {
92    {SIG_CHANGED, ""},
93    {SIG_DELAY_CHANGED, ""},
94    {SIG_SELECTED, ""},
95    {SIG_LEVEL_UP, ""},
96    {SIG_LEVEL_DOWN, ""},
97    {NULL, NULL}
98 };
99
100 static void
101 _del_pre_hook(Evas_Object *obj)
102 {
103    Widget_Data *wd = elm_widget_data_get(obj);
104    Elm_Index_Item *it;
105    if (!wd) return;
106    _index_box_clear(obj, wd->bx[wd->level], wd->level);
107    _index_box_clear(obj, wd->bx[0], 0);
108    while (wd->items)
109      {
110         it = wd->items->data;
111         _item_free(it);
112         elm_widget_item_free(it);
113      }
114    if (wd->delay) ecore_timer_del(wd->delay);
115 }
116
117 static void
118 _del_hook(Evas_Object *obj)
119 {
120    Widget_Data *wd = elm_widget_data_get(obj);
121    free(wd);
122 }
123
124 static void
125 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
126 {
127    Widget_Data *wd = data;
128    if (!wd) return;
129    _els_box_layout(o, priv, wd->horizontal, 1, 0);
130 }
131
132 static void
133 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
134 {
135    Widget_Data *wd = elm_widget_data_get(obj);
136    if (!wd) return;
137    edje_object_signal_emit(wd->base, emission, source);
138 }
139
140 static void
141 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
142 {
143    Widget_Data *wd = elm_widget_data_get(obj);
144    if (!wd) return;
145    edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
146 }
147
148 static void
149 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
150 {
151    Widget_Data *wd = elm_widget_data_get(obj);
152    edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
153                                         data);
154 }
155
156 static void
157 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
158 {
159    Widget_Data *wd = elm_widget_data_get(obj);
160    if (!wd) return;
161    if (!wd->horizontal)
162      edje_object_mirrored_set(wd->base, rtl);
163 }
164
165 static void
166 _theme_hook(Evas_Object *obj)
167 {
168    Evas_Coord minw = 0, minh = 0;
169    Widget_Data *wd = elm_widget_data_get(obj);
170    if (!wd) return;
171    _elm_widget_mirrored_reload(obj);
172
173    _index_box_clear(obj, wd->bx[0], 0);
174    _index_box_clear(obj, wd->bx[1], 1);
175    if (wd->horizontal)
176      _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
177    else
178      {
179         _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
180         _mirrored_set(obj, elm_widget_mirrored_get(obj));
181      }
182    edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
183    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
184    evas_object_size_hint_min_set(wd->event[0], minw, minh);
185    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
186    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
187      {
188         if (!wd->bx[1])
189           {
190              wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
191              evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
192              elm_widget_sub_object_add(obj, wd->bx[1]);
193           }
194         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
195         evas_object_show(wd->bx[1]);
196      }
197    else if (wd->bx[1])
198      {
199         evas_object_del(wd->bx[1]);
200         wd->bx[1] = NULL;
201      }
202    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
203      {
204         if (!wd->event[1])
205           {
206              wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
207              evas_object_color_set(wd->event[1], 0, 0, 0, 0);
208              elm_widget_sub_object_add(obj, wd->event[1]);
209           }
210         edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
211         evas_object_size_hint_min_set(wd->event[1], minw, minh);
212      }
213    else if (wd->event[1])
214      {
215         evas_object_del(wd->event[1]);
216         wd->event[1] = NULL;
217      }
218    edje_object_message_signal_process(wd->base);
219    edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
220    _sizing_eval(obj);
221    _index_box_auto_fill(obj, wd->bx[0], 0);
222 <<<<<<< HEAD
223    if (wd->active)
224      if (wd->level == 1)
225        _index_box_auto_fill(obj, wd->bx[1], 1);
226 =======
227
228    if (wd->autohide_disabled)
229      {
230         if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
231         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
232      }
233    else
234      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
235 >>>>>>> remotes/origin/upstream
236 }
237
238 static void
239 _sizing_eval(Evas_Object *obj)
240 {
241    Widget_Data *wd = elm_widget_data_get(obj);
242    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
243    if (!wd) return;
244    edje_object_size_min_calc(wd->base, &minw, &minh);
245    evas_object_size_hint_min_set(obj, minw, minh);
246    evas_object_size_hint_max_set(obj, maxw, maxh);
247 }
248
249 static Eina_Bool
250 _item_del_pre_hook(Elm_Object_Item *it)
251 {
252    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
253    if (!wd) return EINA_FALSE;
254 <<<<<<< HEAD
255    _item_free((Elm_Index_Item *) it);
256 =======
257    _item_free((Elm_Index_Item *)it);
258 >>>>>>> remotes/origin/upstream
259    _index_box_clear(WIDGET(it), wd->bx[wd->level], wd->level);
260    return EINA_TRUE;
261 }
262
263 static Elm_Index_Item *
264 <<<<<<< HEAD
265 _item_new(Evas_Object *obj, const char *letter, const void *item)
266 =======
267 _item_new(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
268 >>>>>>> remotes/origin/upstream
269 {
270    Widget_Data *wd = elm_widget_data_get(obj);
271    Elm_Index_Item *it;
272    if (!wd) return NULL;
273    it = elm_widget_item_new(obj, Elm_Index_Item);
274    if (!it) return NULL;
275    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
276 <<<<<<< HEAD
277    it->base.data = item;
278    it->level = wd->level;
279    if(wd->level == 0)
280      it->size =  wd->min_obj_height;
281    else
282      it->size =  wd->min_1st_level_obj_height;
283    if(letter)
284      {
285         it->letter = eina_stringshare_add(letter);
286         it->vis_letter = eina_stringshare_add(letter);
287      }
288 =======
289    if (letter) it->letter = eina_stringshare_add(letter);
290    it->func = func;
291    it->base.data = data;
292    it->level = wd->level;
293 >>>>>>> remotes/origin/upstream
294    return it;
295 }
296
297 static Elm_Index_Item *
298 <<<<<<< HEAD
299 _item_find(Evas_Object *obj, const void *item)
300 =======
301 _item_find(Evas_Object *obj, const void *data)
302 >>>>>>> remotes/origin/upstream
303 {
304    Widget_Data *wd = elm_widget_data_get(obj);
305    Eina_List *l;
306    Elm_Index_Item *it;
307    if (!wd) return NULL;
308    EINA_LIST_FOREACH(wd->items, l, it)
309 <<<<<<< HEAD
310      if (it->base.data == item) return it;
311 =======
312      if (it->base.data == data) return it;
313 >>>>>>> remotes/origin/upstream
314    return NULL;
315 }
316
317 static void
318 _item_free(Elm_Index_Item *it)
319 {
320    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
321    if (!wd) return;
322    wd->items = eina_list_remove(wd->items, it);
323    if (it->letter) eina_stringshare_del(it->letter);
324 <<<<<<< HEAD
325    if (it->vis_letter) eina_stringshare_del(it->vis_letter);
326 =======
327 >>>>>>> remotes/origin/upstream
328 }
329
330 // FIXME: always have index filled
331 static void
332 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
333 {
334    Widget_Data *wd = elm_widget_data_get(obj);
335    Eina_Bool rtl;
336    Eina_List *l;
337    Elm_Index_Item *it;
338    Evas_Coord mw, mh, w, h;
339    int i = 0;
340    if (!wd) return;
341    if (wd->level_active[level]) return;
342    rtl = elm_widget_mirrored_get(obj);
343    evas_object_geometry_get(box, NULL, NULL, &w, &h);
344    EINA_LIST_FOREACH(wd->items, l, it)
345      {
346         Evas_Object *o;
347         const char *stacking;
348
349         if (it->level != level) continue;
350         o = edje_object_add(evas_object_evas_get(obj));
351         VIEW(it) = o;
352         edje_object_mirrored_set(VIEW(it), rtl);
353 <<<<<<< HEAD
354         if (i & 0x1)
355           _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
356         else
357           _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
358 =======
359
360         if (wd->horizontal)
361           {
362              if (i & 0x1)
363                _elm_theme_object_set(obj, o, "index", "item_odd/horizontal",
364                                      elm_widget_style_get(obj));
365              else
366                _elm_theme_object_set(obj, o, "index", "item/horizontal",
367                                      elm_widget_style_get(obj));
368           }
369         else
370           {
371              if (i & 0x1)
372                _elm_theme_object_set(obj, o, "index", "item_odd/vertical",
373                                      elm_widget_style_get(obj));
374              else
375                _elm_theme_object_set(obj, o, "index", "item/vertical",
376                                      elm_widget_style_get(obj));
377           }
378
379 >>>>>>> remotes/origin/upstream
380         edje_object_part_text_set(o, "elm.text", it->letter);
381         edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
382         evas_object_size_hint_min_set(o, mw, mh);
383         evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
384         evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
385 <<<<<<< HEAD
386         edje_object_part_text_set(o, "elm.text", it->vis_letter);
387         evas_object_size_hint_min_set(o, mw, it->size);
388         evas_object_size_hint_max_set(o, mw, it->size);
389         evas_object_resize(o, mw, it->size);
390 =======
391 >>>>>>> remotes/origin/upstream
392         elm_widget_sub_object_add(obj, o);
393         evas_object_box_append(box, o);
394         stacking = edje_object_data_get(o, "stacking");
395         if (stacking)
396           {
397              if (!strcmp(stacking, "below")) evas_object_lower(o);
398              else if (!strcmp(stacking, "above")) evas_object_raise(o);
399           }
400         evas_object_show(o);
401         i++;
402 <<<<<<< HEAD
403         if(level == 1)
404           wd->tot_items_count[1] = i;
405 =======
406 >>>>>>> remotes/origin/upstream
407         evas_object_smart_calculate(box); // force a calc so we know the size
408         evas_object_size_hint_min_get(box, &mw, &mh);
409         if (mh > h)
410           {
411              _index_box_clear(obj, box, level);
412              if (i > 0)
413                {
414                   // FIXME: only i objects fit! try again. overflows right now
415                }
416           }
417      }
418    evas_object_smart_calculate(box);
419    wd->level_active[level] = 1;
420 }
421
422 static void
423 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
424 {
425    Widget_Data *wd = elm_widget_data_get(obj);
426    Eina_List *l;
427    Elm_Index_Item *it;
428    if (!wd) return;
429    if (!wd->level_active[level]) return;
430    EINA_LIST_FOREACH(wd->items, l, it)
431      {
432         if (!VIEW(it)) continue;
433         if (it->level != level) continue;
434         evas_object_del(VIEW(it));
435         VIEW(it) = NULL;
436      }
437    wd->level_active[level] = 0;
438 }
439
440 static Eina_Bool
441 _delay_change(void *data)
442 {
443    Widget_Data *wd = elm_widget_data_get(data);
444    Elm_Object_Item *item;
445    if (!wd) return ECORE_CALLBACK_CANCEL;
446    wd->delay = NULL;
447 <<<<<<< HEAD
448    item = elm_index_item_selected_get(data, wd->level);
449 =======
450    item = elm_index_selected_item_get(data, wd->level);
451 >>>>>>> remotes/origin/upstream
452    if (item) evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, item);
453    return ECORE_CALLBACK_CANCEL;
454 }
455
456 static void
457 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
458 {
459    Widget_Data *wd = elm_widget_data_get(obj);
460    Elm_Index_Item *it, *it_closest, *it_last;
461    Eina_List *l;
462    Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
463    double cdv = 0.5;
464 <<<<<<< HEAD
465    double dmax = 0.0;
466    double dmin = 0.0;
467 =======
468 >>>>>>> remotes/origin/upstream
469    Evas_Coord dist;
470    char *label = NULL, *last = NULL;
471    int i;
472    if (!wd) return;
473    for (i = 0; i <= wd->level; i++)
474      {
475         it_last = NULL;
476         it_closest  = NULL;
477         dist = 0x7fffffff;
478         evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
479 <<<<<<< HEAD
480
481         dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
482         dmax = 1.0-dmin-0.08;
483 =======
484 >>>>>>> remotes/origin/upstream
485         EINA_LIST_FOREACH(wd->items, l, it)
486           {
487              if (!((it->level == i) && (VIEW(it)))) continue;
488              if ((VIEW(it)) && (it->level != wd->level))
489                {
490                   if (it->selected)
491                     {
492                        it_closest = it;
493                        break;
494                     }
495                   continue;
496                }
497              if (it->selected)
498                {
499                   it_last = it;
500                   it->selected = 0;
501                }
502              evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
503              xx = x + (w / 2);
504              yy = y + (h / 2);
505              x = evx - xx;
506              y = evy - yy;
507              x = (x * x) + (y * y);
508              if ((x < dist) || (!it_closest))
509                {
510                   if (wd->horizontal)
511                     cdv = (double)(xx - bx) / (double)bw;
512                   else
513                     cdv = (double)(yy - by) / (double)bh;
514                   it_closest = it;
515                   dist = x;
516                }
517           }
518         if ((i == 0) && (wd->level == 0))
519           edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
520                                           cdv, cdv);
521         if (it_closest) it_closest->selected = 1;
522         if (it_closest != it_last)
523           {
524              if (it_last)
525                {
526                   const char *stacking, *selectraise;
527
528                   it = it_last;
529                   edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
530                   stacking = edje_object_data_get(VIEW(it), "stacking");
531                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
532                   if ((selectraise) && (!strcmp(selectraise, "on")))
533                     {
534                        if ((stacking) && (!strcmp(stacking, "below")))
535                          evas_object_lower(VIEW(it));
536                     }
537                }
538              if (it_closest)
539                {
540                   const char *selectraise;
541
542                   it = it_closest;
543                   edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
544                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
545                   if ((selectraise) && (!strcmp(selectraise, "on")))
546                     evas_object_raise(VIEW(it));
547                   evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it);
548                   if (wd->delay) ecore_timer_del(wd->delay);
549                   wd->delay = ecore_timer_add(0.2, _delay_change, obj);
550                }
551           }
552         if (it_closest)
553           {
554              it = it_closest;
555              if (!last)
556                last = strdup(it->letter);
557              else
558                {
559                   if (!label) label = strdup(last);
560                   else
561                     {
562                        /* FIXME: realloc return NULL if the request fails */
563                        label = realloc(label, strlen(label) + strlen(last) + 1);
564                        strcat(label, last);
565                     }
566                   free(last);
567                   last = strdup(it->letter);
568                }
569           }
570      }
571    if (!label) label = strdup("");
572    if (!last) last = strdup("");
573    edje_object_part_text_set(wd->base, "elm.text.body", label);
574    edje_object_part_text_set(wd->base, "elm.text", last);
575 <<<<<<< HEAD
576                   edje_object_signal_emit(wd->base, "hide_2nd_level", "");
577 =======
578 >>>>>>> remotes/origin/upstream
579    free(label);
580    free(last);
581 }
582
583 static void
584 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
585 {
586    Widget_Data *wd = elm_widget_data_get(data);
587    //   Evas_Event_Mouse_Wheel *ev = event_info;
588    //   Evas_Object *obj = o;
589    if (!wd) return;
590 }
591
592 static void
593 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
594 {
595    Widget_Data *wd = elm_widget_data_get(data);
596    Evas_Event_Mouse_Down *ev = event_info;
597    Evas_Coord x, y, w;
598    if (!wd) return;
599    if (ev->button != 1) return;
600    wd->down = 1;
601    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
602    wd->dx = ev->canvas.x - x;
603    wd->dy = ev->canvas.y - y;
604 <<<<<<< HEAD
605    elm_index_active_set(data, 1);
606 =======
607    if (!wd->autohide_disabled)
608      {
609         _index_box_clear(data, wd->bx[1], 1);
610         _index_box_auto_fill(data, wd->bx[0], 0);
611         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
612      }
613 >>>>>>> remotes/origin/upstream
614    _sel_eval(data, ev->canvas.x, ev->canvas.y);
615    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
616                                    (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
617    if (wd->items && !wd->indicator_disabled)
618      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
619 }
620
621 static void
622 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
623 {
624    Widget_Data *wd = elm_widget_data_get(data);
625    Evas_Event_Mouse_Up *ev = event_info;
626    Elm_Object_Item *item;
627 <<<<<<< HEAD
628    if (!wd) return;
629    if (ev->button != 1) return;
630    if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
631    wd->delay = NULL;
632    wd->down = 0;
633    item = elm_index_item_selected_get(data, wd->level);
634    if (item) evas_object_smart_callback_call(data, SIG_SELECTED, item);
635    elm_index_active_set(data, 0);
636 =======
637    Elm_Index_Item *id_item;
638    if (!wd) return;
639    if (ev->button != 1) return;
640    wd->down = 0;
641    item = elm_index_selected_item_get(data, wd->level);
642    if (item)
643      {
644         evas_object_smart_callback_call(data, SIG_SELECTED, item);
645         id_item = (Elm_Index_Item *)item;
646         if (id_item->func)
647           id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
648      }
649    if (!wd->autohide_disabled)
650      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
651 >>>>>>> remotes/origin/upstream
652    edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
653    if (wd->items && !wd->indicator_disabled)
654      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
655 }
656
657 static void
658 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
659 {
660    Widget_Data *wd = elm_widget_data_get(data);
661    Evas_Event_Mouse_Move *ev = event_info;
662    Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
663 <<<<<<< HEAD
664    Elm_Object_Item *item;
665 =======
666 >>>>>>> remotes/origin/upstream
667    char buf[1024];
668    if (!wd) return;
669    if (!wd->down) return;
670    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
671    evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
672    x = ev->cur.canvas.x - x;
673    y = ev->cur.canvas.y - y;
674    dx = x - wd->dx;
675    adx = dx;
676    if (adx < 0) adx = -dx;
677    edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
678                                    , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
679    if (!wd->horizontal)
680      {
681         if (adx > minw)
682           {
683              if (!wd->level)
684                {
685                   wd->level = 1;
686                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
687                   edje_object_signal_emit(wd->base, buf, "elm");
688                   evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
689                }
690           }
691         else
692           {
693              if (wd->level == 1)
694                {
695                   wd->level = 0;
696                   snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
697                   edje_object_signal_emit(wd->base, buf, "elm");
698 <<<<<<< HEAD
699                   item = elm_index_item_selected_get(data, wd->level);
700                   evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
701                   if (wd->delay) ecore_timer_del(wd->delay);
702                   wd->delay = ecore_timer_add(0.2, _delay_change, data);
703 =======
704 >>>>>>> remotes/origin/upstream
705                   evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
706                }
707           }
708      }
709    _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
710 }
711
712 <<<<<<< HEAD
713 static void
714 _index_box_refill_job(void *data)
715 {
716    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
717    if (!wd) return;
718
719    const char *string;
720    Evas_Coord pw, ph;
721
722    evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
723    string = edje_object_data_get(wd->base, "min_obj_height");
724    wd->min_obj_height = MIN_OBJ_HEIGHT;
725
726    wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
727    wd->items_count = ph/wd->min_obj_height;
728
729    if(pw != wd->pwidth && ph != wd->pheight)
730      {
731         if(wd->down == 1)
732           {
733              wd->active = 0;
734              elm_index_active_set(data, 1);
735           }
736         _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
737         evas_object_smart_calculate( wd->bx[0]);
738         elm_index_item_go((Evas_Object *)data, wd->level);
739         wd->pwidth = pw;
740         wd->pheight = ph;
741      }
742 }
743
744 static void _index_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
745 {
746    Widget_Data *wd;
747    if(!data) return;
748    wd = elm_widget_data_get((Evas_Object *)data);
749    if(!wd) return;
750    ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
751 }
752
753 =======
754 >>>>>>> remotes/origin/upstream
755 EAPI Evas_Object *
756 elm_index_add(Evas_Object *parent)
757 {
758    Evas_Object *obj;
759    Evas_Object *o;
760    Evas *e;
761    Widget_Data *wd;
762    Evas_Coord minw, minh;
763
764    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
765
766    ELM_SET_WIDTYPE(widtype, "index");
767    elm_widget_type_set(obj, "index");
768    elm_widget_sub_object_add(parent, obj);
769    elm_widget_data_set(obj, wd);
770    elm_widget_del_hook_set(obj, _del_hook);
771    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
772    elm_widget_theme_hook_set(obj, _theme_hook);
773    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
774    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
775    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
776    elm_widget_can_focus_set(obj, EINA_FALSE);
777
778    wd->indicator_disabled = EINA_FALSE;
779    wd->horizontal = EINA_FALSE;
780 <<<<<<< HEAD
781    wd->min_obj_height = 0;
782    wd->max_grp_size = 0;
783    wd->items_count = 0;
784    wd->tot_items_count[0] = 0;
785    wd->tot_items_count[1] = 0;
786    wd->special_char = edje_object_data_get(wd->base, "special_char");
787    if(!wd->special_char)  wd->special_char = eina_stringshare_add("*");
788 =======
789    wd->autohide_disabled = EINA_FALSE;
790 >>>>>>> remotes/origin/upstream
791
792    wd->base = edje_object_add(e);
793    _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
794    elm_widget_resize_object_set(obj, wd->base);
795
796    o = evas_object_rectangle_add(e);
797    wd->event[0] = o;
798    evas_object_color_set(o, 0, 0, 0, 0);
799    minw = minh = 0;
800    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
801    evas_object_size_hint_min_set(o, minw, minh);
802    edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
803    elm_widget_sub_object_add(obj, o);
804 <<<<<<< HEAD
805    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
806 =======
807 >>>>>>> remotes/origin/upstream
808    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
809    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
810    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
811    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
812    evas_object_show(o);
813    if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
814      {
815         o = evas_object_rectangle_add(e);
816         wd->event[1] = o;
817         evas_object_color_set(o, 0, 0, 0, 0);
818         evas_object_size_hint_min_set(o, minw, minh);
819         edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
820         elm_widget_sub_object_add(obj, o);
821      }
822
823    wd->bx[0] = evas_object_box_add(e);
824    evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
825    elm_widget_sub_object_add(obj, wd->bx[0]);
826    edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
827    evas_object_show(wd->bx[0]);
828
829    if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
830      {
831         wd->bx[1] = evas_object_box_add(e);
832         evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
833         elm_widget_sub_object_add(obj, wd->bx[1]);
834         edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
835         evas_object_show(wd->bx[1]);
836      }
837
838    evas_object_smart_callbacks_descriptions_set(obj, _signals);
839 <<<<<<< HEAD
840    wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT;
841 =======
842 >>>>>>> remotes/origin/upstream
843
844    _mirrored_set(obj, elm_widget_mirrored_get(obj));
845    _sizing_eval(obj);
846    return obj;
847 }
848
849 <<<<<<< HEAD
850 static int
851 _group_count(Evas_Object *obj, int extraIndex, int adj_pos)
852 {
853    Widget_Data *wd = elm_widget_data_get(obj);
854    if (!wd) return 0;
855    int group_count = MIN_GRP_SIZE;
856    while(group_count <= wd->max_grp_size)
857      {
858         if(extraIndex <= wd->max_grp_size*adj_pos)
859           {
860              if(group_count*adj_pos>=extraIndex) return group_count;
861           }
862         else
863           return wd->max_grp_size;
864
865         group_count += MIN_GRP_SIZE;
866      }
867    return group_count;
868 }
869
870 static void
871 _index_process(Evas_Object *obj)
872 {
873    int extraIndex;
874    int j,i, group_count;
875    Eina_List *l;
876    Elm_Index_Item *it;
877    int count;
878    int n;
879
880    Widget_Data *wd = elm_widget_data_get(obj);
881    if (!wd) return;
882
883    if (wd->items_count == 0) return;
884
885    const int adj_pos = (wd->items_count-1)*0.5;
886    n = wd->tot_items_count[wd->level];
887    group_count = MIN_GRP_SIZE;
888
889    int *indx = (int*)calloc(n, sizeof(int));
890    if (!indx) return;
891
892    const int minh = wd->min_obj_height;
893    EINA_LIST_FOREACH(wd->items, l, it)
894      {
895         it->vis_letter = eina_stringshare_add(it->letter);
896         it->size =  minh;
897      }
898    int remainder;
899    int numberofparts;
900    int N = wd->items_count;
901
902    for (i=0;i<n;i++)
903      {
904         indx[i] = minh;
905      }
906    extraIndex=n-N;
907    if (extraIndex < 0)
908      {
909         free(indx);
910         indx = NULL;
911         return;
912      }
913
914    group_count = _group_count(obj, extraIndex, adj_pos);
915    if (group_count <= 0)
916      {
917         if (indx)
918           free(indx);
919         indx = NULL;
920         return;
921      }
922
923    PlacementPart place[adj_pos];
924    remainder = extraIndex%group_count;
925    numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
926
927    for (i=0;i<numberofparts; i++)
928      {
929         place[i].count=group_count+1;
930         count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
931         place[i].start= count +i*group_count-1;
932      }
933    if (remainder)
934      place[numberofparts-1].count=remainder+1;
935
936    for (i=0;i<numberofparts;i++)
937      {
938         for (j=0;j<place[i].count; j++)
939           {
940              indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
941           }
942         indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
943      }
944    count = 0;
945    EINA_LIST_FOREACH(wd->items, l, it)
946      {
947         int size = indx[count];
948         count++;
949         if (size == minh)
950           {
951              it->vis_letter = eina_stringshare_add(it->letter);
952              continue;
953           }
954         else if (size == 1)
955           {
956              eina_stringshare_del(it->vis_letter);
957              it->vis_letter = eina_stringshare_add("");
958           }
959         else
960           {
961              eina_stringshare_del(it->vis_letter);
962              it->vis_letter = eina_stringshare_add(wd->special_char);
963           }
964         it->size = size;
965      }
966    if (indx)
967      {
968         free(indx);
969         indx = NULL;
970      }
971 }
972
973 EAPI void
974 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
975 =======
976 EINA_DEPRECATED EAPI void
977 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
978 {
979    elm_index_autohide_disabled_set(obj, !active);
980 }
981
982 EINA_DEPRECATED EAPI Eina_Bool
983 elm_index_active_get(const Evas_Object *obj)
984 {
985    return !elm_index_autohide_disabled_get(obj);
986 }
987
988 EAPI void
989 elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
990 >>>>>>> remotes/origin/upstream
991 {
992    ELM_CHECK_WIDTYPE(obj, widtype);
993    Widget_Data *wd = elm_widget_data_get(obj);
994    if (!wd) return;
995 <<<<<<< HEAD
996    if (wd->active == active) return;
997    wd->active = active;
998    wd->level = 0;
999    if (wd->active)
1000      {
1001         _index_box_clear(obj, wd->bx[1], 1);
1002         _index_process(obj);
1003 =======
1004    disabled = !!disabled;
1005    if (wd->autohide_disabled == disabled) return;
1006    wd->autohide_disabled = disabled;
1007    wd->level = 0;
1008    if (wd->autohide_disabled)
1009      {
1010         _index_box_clear(obj, wd->bx[1], 1);
1011 >>>>>>> remotes/origin/upstream
1012         _index_box_auto_fill(obj, wd->bx[0], 0);
1013         edje_object_signal_emit(wd->base, "elm,state,active", "elm");
1014      }
1015    else
1016      edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
1017 <<<<<<< HEAD
1018 }
1019
1020 EAPI Eina_Bool
1021 elm_index_active_get(const Evas_Object *obj)
1022 =======
1023
1024    //FIXME: Should be update indicator based on the indicator visiblility 
1025 }
1026
1027 EAPI Eina_Bool
1028 elm_index_autohide_disabled_get(const Evas_Object *obj)
1029 >>>>>>> remotes/origin/upstream
1030 {
1031    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1032    Widget_Data *wd = elm_widget_data_get(obj);
1033    if (!wd) return EINA_FALSE;
1034 <<<<<<< HEAD
1035    return wd->active;
1036 =======
1037    return wd->autohide_disabled;
1038 >>>>>>> remotes/origin/upstream
1039 }
1040
1041 EAPI void
1042 elm_index_item_level_set(Evas_Object *obj, int level)
1043 {
1044    ELM_CHECK_WIDTYPE(obj, widtype);
1045    Widget_Data *wd = elm_widget_data_get(obj);
1046    if (!wd) return;
1047    if (wd->level == level) return;
1048    wd->level = level;
1049 }
1050
1051 EAPI int
1052 elm_index_item_level_get(const Evas_Object *obj)
1053 {
1054    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1055    Widget_Data *wd = elm_widget_data_get(obj);
1056    if (!wd) return 0;
1057    return wd->level;
1058 }
1059
1060 <<<<<<< HEAD
1061 EAPI Elm_Object_Item *
1062 elm_index_item_selected_get(const Evas_Object *obj, int level)
1063 {
1064 =======
1065 EAPI void
1066 elm_index_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1067 {
1068    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1069    Evas_Coord x, y, w, h;
1070    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1071    if (!wd) return;
1072
1073    //FIXME: Should be update indicator based on the autohidden status & indicator visiblility 
1074
1075    if (selected)
1076      {
1077         evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1078         _sel_eval(WIDGET(it), x + (w/2), y + (h/2));
1079      }
1080    else
1081      _sel_eval(WIDGET(it), -99999, -9999);
1082
1083 }
1084
1085 EINA_DEPRECATED EAPI Elm_Object_Item *
1086 elm_index_item_selected_get(const Evas_Object *obj, int level)
1087 {
1088    return elm_index_selected_item_get(obj, level);
1089 }
1090
1091 EAPI Elm_Object_Item *
1092 elm_index_selected_item_get(const Evas_Object *obj, int level)
1093 {
1094 >>>>>>> remotes/origin/upstream
1095    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1096    Widget_Data *wd = elm_widget_data_get(obj);
1097    Eina_List *l;
1098    Elm_Index_Item *it;
1099    if (!wd) return NULL;
1100    EINA_LIST_FOREACH(wd->items, l, it)
1101      {
1102         if ((it->selected) && (it->level == level))
1103 <<<<<<< HEAD
1104           return (Elm_Object_Item *) it;
1105 =======
1106           return (Elm_Object_Item *)it;
1107 >>>>>>> remotes/origin/upstream
1108      }
1109    return NULL;
1110 }
1111
1112 <<<<<<< HEAD
1113 EAPI void
1114 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1115 {
1116    ELM_CHECK_WIDTYPE(obj, widtype);
1117    Widget_Data *wd = elm_widget_data_get(obj);
1118    Elm_Index_Item *it;
1119    if (!wd) return;
1120    it = _item_new(obj, letter, item);
1121    if (!it) return;
1122    wd->items = eina_list_append(wd->items, it);
1123    wd->tot_items_count[wd->level]++;
1124    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1125 }
1126
1127 EAPI void
1128 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1129 {
1130    ELM_CHECK_WIDTYPE(obj, widtype);
1131    Widget_Data *wd = elm_widget_data_get(obj);
1132    Elm_Index_Item *it;
1133
1134    if (!wd) return;
1135    it = _item_new(obj, letter, item);
1136    if (!it) return;
1137    wd->items = eina_list_prepend(wd->items, it);
1138    wd->tot_items_count[wd->level]++;
1139    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1140 }
1141
1142 EAPI void
1143 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1144 {
1145    ELM_CHECK_WIDTYPE(obj, widtype);
1146    Widget_Data *wd = elm_widget_data_get(obj);
1147    Elm_Index_Item *it;
1148    if (!wd) return;
1149    if (!relative)
1150      {
1151         elm_index_item_append(obj, letter, item);
1152         wd->tot_items_count[wd->level]++;
1153         return;
1154      }
1155    it = _item_new(obj, letter, item);
1156    if (!it) return;
1157    wd->items = eina_list_append_relative(wd->items, it, relative);
1158    wd->tot_items_count[wd->level]++;
1159    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1160 }
1161
1162 EAPI void
1163 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1164 {
1165    ELM_CHECK_WIDTYPE(obj, widtype);
1166    Widget_Data *wd = elm_widget_data_get(obj);
1167    Elm_Index_Item *it;
1168    if (!wd) return;
1169    if (!relative)
1170      {
1171         elm_index_item_prepend(obj, letter, item);
1172         wd->tot_items_count[wd->level]++;
1173         return;
1174      }
1175    it = _item_new(obj, letter, item);
1176    if (!it) return;
1177    wd->items = eina_list_prepend_relative(wd->items, it, relative);
1178    wd->tot_items_count[wd->level]++;
1179    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1180 }
1181
1182 EAPI void
1183 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)
1184 {
1185    ELM_CHECK_WIDTYPE(obj, widtype);
1186 =======
1187 EAPI Elm_Object_Item *
1188 elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
1189 {
1190    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1191    Widget_Data *wd = elm_widget_data_get(obj);
1192    Elm_Index_Item *it;
1193    if (!wd) return NULL;
1194    it = _item_new(obj, letter, func, data);
1195    if (!it) return NULL;
1196    wd->items = eina_list_append(wd->items, it);
1197    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1198    return (Elm_Object_Item *)it;
1199 }
1200
1201 EAPI Elm_Object_Item *
1202 elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
1203 {
1204    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1205    Widget_Data *wd = elm_widget_data_get(obj);
1206    Elm_Index_Item *it;
1207
1208    if (!wd) return NULL;
1209    it = _item_new(obj, letter, func, data);
1210    if (!it) return NULL;
1211    wd->items = eina_list_prepend(wd->items, it);
1212    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1213    return (Elm_Object_Item *)it;
1214 }
1215
1216 EINA_DEPRECATED EAPI Elm_Object_Item *
1217 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1218 {
1219    return elm_index_item_insert_after(obj, (Elm_Object_Item *) relative, letter, NULL, item);
1220 }
1221
1222 EINA_DEPRECATED EAPI Elm_Object_Item *
1223 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1224 {
1225    return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
1226 }
1227
1228 EAPI Elm_Object_Item *
1229 elm_index_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *letter, Evas_Smart_Cb func, const void *data)
1230 {
1231    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232    Widget_Data *wd = elm_widget_data_get(obj);
1233    Elm_Index_Item *it;
1234    if (!wd) return NULL;
1235    if (!after) return elm_index_item_append(obj, letter, func, data);
1236    it = _item_new(obj, letter, func, data);
1237    if (!it) return NULL;
1238    wd->items = eina_list_append_relative(wd->items, it, after);
1239    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1240    return (Elm_Object_Item *)it;
1241 }
1242
1243 EAPI Elm_Object_Item *
1244 elm_index_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *letter, Evas_Smart_Cb func, const void *data)
1245 {
1246    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1247    Widget_Data *wd = elm_widget_data_get(obj);
1248    Elm_Index_Item *it;
1249    if (!wd) return NULL;
1250    if (!before) return elm_index_item_prepend(obj, letter, func, data);
1251    it = _item_new(obj, letter, func, data);
1252    if (!it) return NULL;
1253    wd->items = eina_list_prepend_relative(wd->items, it, before);
1254    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1255    return (Elm_Object_Item *)it;
1256 }
1257
1258 EAPI Elm_Object_Item *
1259 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)
1260 {
1261    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1262 >>>>>>> remotes/origin/upstream
1263    Widget_Data *wd = elm_widget_data_get(obj);
1264    Eina_List *lnear;
1265    Elm_Index_Item *it;
1266    int cmp;
1267
1268 <<<<<<< HEAD
1269    if (!wd) return;
1270    if (!(wd->items))
1271      {
1272         elm_index_item_append(obj, letter, item);
1273         return;
1274      }
1275
1276    it = _item_new(obj, letter, item);
1277    if (!it) return;
1278 =======
1279    if (!wd) return NULL;
1280    if (!(wd->items))
1281      return elm_index_item_append(obj, letter, func, data);
1282
1283    it = _item_new(obj, letter, func, data);
1284    if (!it) return NULL;
1285 >>>>>>> remotes/origin/upstream
1286
1287    lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1288    if (cmp < 0)
1289      wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1290    else if (cmp > 0)
1291      wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1292    else
1293      {
1294         /* If cmp_data_func is not provided, append a duplicated item */
1295         if (!cmp_data_func)
1296           wd->items =  eina_list_append_relative_list(wd->items, it, lnear);
1297         else
1298           {
1299              Elm_Index_Item *p_it = eina_list_data_get(lnear);
1300              if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1301                p_it->base.data = it->base.data;
1302              _item_free(it);
1303              elm_widget_item_free(it);
1304           }
1305      }
1306 <<<<<<< HEAD
1307
1308    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1309 =======
1310    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1311    return (Elm_Object_Item *)it;
1312 >>>>>>> remotes/origin/upstream
1313 }
1314
1315 EAPI void
1316 elm_index_item_del(Evas_Object *obj __UNUSED__, Elm_Object_Item *it)
1317 {
1318    elm_object_item_del(it);
1319 }
1320
1321 EAPI Elm_Object_Item *
1322 <<<<<<< HEAD
1323 elm_index_item_find(Evas_Object *obj, const void *item)
1324 =======
1325 elm_index_item_find(Evas_Object *obj, const void *data)
1326 >>>>>>> remotes/origin/upstream
1327 {
1328    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1329    Widget_Data *wd = elm_widget_data_get(obj);
1330    if (!wd) return NULL;
1331 <<<<<<< HEAD
1332    return (Elm_Object_Item *) _item_find(obj, item);
1333 =======
1334    return (Elm_Object_Item *) _item_find(obj, data);
1335 >>>>>>> remotes/origin/upstream
1336 }
1337
1338 EAPI void
1339 elm_index_item_clear(Evas_Object *obj)
1340 {
1341    ELM_CHECK_WIDTYPE(obj, widtype);
1342    Widget_Data *wd = elm_widget_data_get(obj);
1343    Elm_Index_Item *it;
1344    Eina_List *l, *clear = NULL;
1345    if (!wd) return;
1346    _index_box_clear(obj, wd->bx[wd->level], wd->level);
1347    EINA_LIST_FOREACH(wd->items, l, it)
1348      {
1349         if (it->level != wd->level) continue;
1350         clear = eina_list_append(clear, it);
1351      }
1352    EINA_LIST_FREE(clear, it)
1353      {
1354 <<<<<<< HEAD
1355         wd->tot_items_count[wd->level]--;
1356 =======
1357 >>>>>>> remotes/origin/upstream
1358         _item_free(it);
1359         elm_widget_item_free(it);
1360      }
1361 }
1362
1363 <<<<<<< HEAD
1364 EAPI void
1365 elm_index_item_go(Evas_Object *obj, int level)
1366 =======
1367 EINA_DEPRECATED EAPI void
1368 elm_index_item_go(Evas_Object *obj, int level __UNUSED__)
1369 {
1370    elm_index_level_go(obj, level);
1371 }
1372
1373 EAPI void
1374 elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
1375 >>>>>>> remotes/origin/upstream
1376 {
1377    ELM_CHECK_WIDTYPE(obj, widtype);
1378    Widget_Data *wd = elm_widget_data_get(obj);
1379    if (!wd) return;
1380 <<<<<<< HEAD
1381    if(level == 0) _index_process(obj);
1382 =======
1383 >>>>>>> remotes/origin/upstream
1384    _index_box_auto_fill(obj, wd->bx[0], 0);
1385    if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1386 }
1387
1388 EAPI void *
1389 elm_index_item_data_get(const Elm_Object_Item *it)
1390 {
1391    return elm_object_item_data_get(it);
1392 }
1393
1394 EAPI void
1395 elm_index_item_data_set(Elm_Object_Item *it, const void *data)
1396 {
1397    elm_object_item_data_set(it, (void *) data);
1398 }
1399
1400 EAPI void
1401 elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
1402 {
1403    ELM_CHECK_WIDTYPE(obj, widtype);
1404    Widget_Data *wd = elm_widget_data_get(obj);
1405    if (!wd) return;
1406
1407    disabled = !!disabled;
1408    if (wd->indicator_disabled == disabled) return;
1409    wd->indicator_disabled = disabled;
1410    if (!wd->items) return;
1411    if (disabled)
1412      edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
1413    else
1414      edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
1415 }
1416
1417 EAPI Eina_Bool
1418 elm_index_indicator_disabled_get(const Evas_Object *obj)
1419 {
1420    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1421    Widget_Data *wd = elm_widget_data_get(obj);
1422    if (!wd) return EINA_FALSE;
1423
1424    return wd->indicator_disabled;
1425 }
1426
1427 EAPI void
1428 elm_index_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1429 {
1430    elm_object_item_del_cb_set(it, func);
1431 }
1432
1433 EAPI const char *
1434 elm_index_item_letter_get(const Elm_Object_Item *it)
1435 {
1436    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1437 <<<<<<< HEAD
1438    return ((Elm_Index_Item *) it)->letter;
1439 }
1440
1441 =======
1442    return ((Elm_Index_Item *)it)->letter;
1443 }
1444
1445 EAPI void
1446 elm_index_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1447 {
1448    ELM_CHECK_WIDTYPE(obj, widtype);
1449    Widget_Data *wd = elm_widget_data_get(obj);
1450    if (!wd) return;
1451
1452    horizontal = !!horizontal;
1453    if (horizontal == wd->horizontal) return;
1454    wd->horizontal = horizontal;
1455    _theme_hook(obj);
1456 }
1457
1458 EAPI Eina_Bool
1459 elm_index_horizontal_get(const Evas_Object *obj)
1460 {
1461    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1462    Widget_Data *wd = elm_widget_data_get(obj);
1463    if (!wd) return EINA_FALSE;
1464    return wd->horizontal;
1465 }
1466
1467
1468 >>>>>>> remotes/origin/upstream