1 #include <Elementary.h>
5 typedef struct _Widget_Data Widget_Data;
6 typedef struct _Elm_Index_Item Elm_Index_Item;
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
17 Eina_Bool level_active[2];
18 Eina_Bool horizontal : 1;
19 Eina_Bool autohide_disabled : 1;
21 Eina_Bool indicator_disabled : 1;
24 struct _Elm_Index_Item
30 Eina_Bool selected : 1;
33 static const char *widtype = NULL;
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);
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";
49 static const Evas_Smart_Cb_Description _signals[] = {
51 {SIG_DELAY_CHANGED, ""},
59 _del_pre_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
64 _index_box_clear(obj, wd->bx[wd->level], wd->level);
65 _index_box_clear(obj, wd->bx[0], 0);
70 elm_widget_item_free(it);
72 if (wd->delay) ecore_timer_del(wd->delay);
76 _del_hook(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
83 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
85 Widget_Data *wd = data;
87 _els_box_layout(o, priv, wd->horizontal, 1, 0);
91 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
93 Widget_Data *wd = elm_widget_data_get(obj);
95 edje_object_signal_emit(wd->base, emission, source);
99 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
101 Widget_Data *wd = elm_widget_data_get(obj);
103 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
107 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
109 Widget_Data *wd = elm_widget_data_get(obj);
110 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
115 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
117 Widget_Data *wd = elm_widget_data_get(obj);
120 edje_object_mirrored_set(wd->base, rtl);
124 _theme_hook(Evas_Object *obj)
126 Evas_Coord minw = 0, minh = 0;
127 Widget_Data *wd = elm_widget_data_get(obj);
129 _elm_widget_mirrored_reload(obj);
131 _index_box_clear(obj, wd->bx[0], 0);
132 _index_box_clear(obj, wd->bx[1], 1);
134 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
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));
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"))
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]);
152 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
153 evas_object_show(wd->bx[1]);
157 evas_object_del(wd->bx[1]);
160 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
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]);
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);
171 else if (wd->event[1])
173 evas_object_del(wd->event[1]);
176 edje_object_message_signal_process(wd->base);
177 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
179 _index_box_auto_fill(obj, wd->bx[0], 0);
181 if (wd->autohide_disabled)
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");
187 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
191 _sizing_eval(Evas_Object *obj)
193 Widget_Data *wd = elm_widget_data_get(obj);
194 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
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);
202 _item_del_pre_hook(Elm_Object_Item *it)
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);
211 static Elm_Index_Item *
212 _item_new(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
214 Widget_Data *wd = elm_widget_data_get(obj);
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);
222 it->base.data = data;
223 it->level = wd->level;
227 static Elm_Index_Item *
228 _item_find(Evas_Object *obj, const void *data)
230 Widget_Data *wd = elm_widget_data_get(obj);
233 if (!wd) return NULL;
234 EINA_LIST_FOREACH(wd->items, l, it)
235 if (it->base.data == data) return it;
240 _item_free(Elm_Index_Item *it)
242 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
244 wd->items = eina_list_remove(wd->items, it);
245 if (it->letter) eina_stringshare_del(it->letter);
248 // FIXME: always have index filled
250 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
252 Widget_Data *wd = elm_widget_data_get(obj);
256 Evas_Coord mw, mh, w, h;
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)
265 const char *stacking;
267 if (it->level != level) continue;
268 o = edje_object_add(evas_object_evas_get(obj));
270 edje_object_mirrored_set(VIEW(it), rtl);
275 _elm_theme_object_set(obj, o, "index", "item_odd/horizontal",
276 elm_widget_style_get(obj));
278 _elm_theme_object_set(obj, o, "index", "item/horizontal",
279 elm_widget_style_get(obj));
284 _elm_theme_object_set(obj, o, "index", "item_odd/vertical",
285 elm_widget_style_get(obj));
287 _elm_theme_object_set(obj, o, "index", "item/vertical",
288 elm_widget_style_get(obj));
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");
301 if (!strcmp(stacking, "below")) evas_object_lower(o);
302 else if (!strcmp(stacking, "above")) evas_object_raise(o);
306 evas_object_smart_calculate(box); // force a calc so we know the size
307 evas_object_size_hint_min_get(box, &mw, &mh);
310 _index_box_clear(obj, box, level);
313 // FIXME: only i objects fit! try again. overflows right now
317 evas_object_smart_calculate(box);
318 wd->level_active[level] = 1;
322 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
324 Widget_Data *wd = elm_widget_data_get(obj);
328 if (!wd->level_active[level]) return;
329 EINA_LIST_FOREACH(wd->items, l, it)
331 if (!VIEW(it)) continue;
332 if (it->level != level) continue;
333 evas_object_del(VIEW(it));
336 wd->level_active[level] = 0;
340 _delay_change(void *data)
342 Widget_Data *wd = elm_widget_data_get(data);
343 Elm_Object_Item *item;
344 if (!wd) return ECORE_CALLBACK_CANCEL;
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;
352 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
354 Widget_Data *wd = elm_widget_data_get(obj);
355 Elm_Index_Item *it, *it_closest, *it_last;
357 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
360 char *label = NULL, *last = NULL;
363 for (i = 0; i <= wd->level; i++)
368 evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
369 EINA_LIST_FOREACH(wd->items, l, it)
371 if (!((it->level == i) && (VIEW(it)))) continue;
372 if ((VIEW(it)) && (it->level != wd->level))
386 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
391 x = (x * x) + (y * y);
392 if ((x < dist) || (!it_closest))
395 cdv = (double)(xx - bx) / (double)bw;
397 cdv = (double)(yy - by) / (double)bh;
402 if ((i == 0) && (wd->level == 0))
403 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
405 if (it_closest) it_closest->selected = 1;
406 if (it_closest != it_last)
410 const char *stacking, *selectraise;
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")))
418 if ((stacking) && (!strcmp(stacking, "below")))
419 evas_object_lower(VIEW(it));
424 const char *selectraise;
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);
440 last = strdup(it->letter);
443 if (!label) label = strdup(last);
446 /* FIXME: realloc return NULL if the request fails */
447 label = realloc(label, strlen(label) + strlen(last) + 1);
451 last = strdup(it->letter);
455 if (!label) label = strdup("");
456 if (!last) last = strdup("");
457 edje_object_part_text_set(wd->base, "elm.text.body", label);
458 edje_object_part_text_set(wd->base, "elm.text", last);
464 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
466 Widget_Data *wd = elm_widget_data_get(data);
467 // Evas_Event_Mouse_Wheel *ev = event_info;
468 // Evas_Object *obj = o;
473 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
475 Widget_Data *wd = elm_widget_data_get(data);
476 Evas_Event_Mouse_Down *ev = event_info;
479 if (ev->button != 1) return;
481 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
482 wd->dx = ev->canvas.x - x;
483 wd->dy = ev->canvas.y - y;
484 if (!wd->autohide_disabled)
486 _index_box_clear(data, wd->bx[1], 1);
487 _index_box_auto_fill(data, wd->bx[0], 0);
488 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
490 _sel_eval(data, ev->canvas.x, ev->canvas.y);
491 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
492 (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
493 if (wd->items && !wd->indicator_disabled)
494 edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
498 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
500 Widget_Data *wd = elm_widget_data_get(data);
501 Evas_Event_Mouse_Up *ev = event_info;
502 Elm_Object_Item *item;
503 Elm_Index_Item *id_item;
505 if (ev->button != 1) return;
507 item = elm_index_selected_item_get(data, wd->level);
510 evas_object_smart_callback_call(data, SIG_SELECTED, item);
511 id_item = (Elm_Index_Item *)item;
513 id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
515 if (!wd->autohide_disabled)
516 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
517 edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
518 if (wd->items && !wd->indicator_disabled)
519 edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
523 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
525 Widget_Data *wd = elm_widget_data_get(data);
526 Evas_Event_Mouse_Move *ev = event_info;
527 Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
530 if (!wd->down) return;
531 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
532 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
533 x = ev->cur.canvas.x - x;
534 y = ev->cur.canvas.y - y;
537 if (adx < 0) adx = -dx;
538 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
539 , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
547 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
548 edje_object_signal_emit(wd->base, buf, "elm");
549 evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
557 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
558 edje_object_signal_emit(wd->base, buf, "elm");
559 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
563 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
567 elm_index_add(Evas_Object *parent)
573 Evas_Coord minw, minh;
575 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
577 ELM_SET_WIDTYPE(widtype, "index");
578 elm_widget_type_set(obj, "index");
579 elm_widget_sub_object_add(parent, obj);
580 elm_widget_data_set(obj, wd);
581 elm_widget_del_hook_set(obj, _del_hook);
582 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
583 elm_widget_theme_hook_set(obj, _theme_hook);
584 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
585 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
586 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
587 elm_widget_can_focus_set(obj, EINA_FALSE);
589 wd->indicator_disabled = EINA_FALSE;
590 wd->horizontal = EINA_FALSE;
591 wd->autohide_disabled = EINA_FALSE;
593 wd->base = edje_object_add(e);
594 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
595 elm_widget_resize_object_set(obj, wd->base);
597 o = evas_object_rectangle_add(e);
599 evas_object_color_set(o, 0, 0, 0, 0);
601 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
602 evas_object_size_hint_min_set(o, minw, minh);
603 edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
604 elm_widget_sub_object_add(obj, o);
605 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
606 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
607 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
608 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
610 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
612 o = evas_object_rectangle_add(e);
614 evas_object_color_set(o, 0, 0, 0, 0);
615 evas_object_size_hint_min_set(o, minw, minh);
616 edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
617 elm_widget_sub_object_add(obj, o);
620 wd->bx[0] = evas_object_box_add(e);
621 evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
622 elm_widget_sub_object_add(obj, wd->bx[0]);
623 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
624 evas_object_show(wd->bx[0]);
626 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
628 wd->bx[1] = evas_object_box_add(e);
629 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
630 elm_widget_sub_object_add(obj, wd->bx[1]);
631 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
632 evas_object_show(wd->bx[1]);
635 evas_object_smart_callbacks_descriptions_set(obj, _signals);
637 _mirrored_set(obj, elm_widget_mirrored_get(obj));
642 EINA_DEPRECATED EAPI void
643 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
645 elm_index_autohide_disabled_set(obj, !active);
648 EINA_DEPRECATED EAPI Eina_Bool
649 elm_index_active_get(const Evas_Object *obj)
651 return !elm_index_autohide_disabled_get(obj);
655 elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
657 ELM_CHECK_WIDTYPE(obj, widtype);
658 Widget_Data *wd = elm_widget_data_get(obj);
660 disabled = !!disabled;
661 if (wd->autohide_disabled == disabled) return;
662 wd->autohide_disabled = disabled;
664 if (wd->autohide_disabled)
666 _index_box_clear(obj, wd->bx[1], 1);
667 _index_box_auto_fill(obj, wd->bx[0], 0);
668 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
671 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
675 elm_index_autohide_disabled_get(const Evas_Object *obj)
677 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
678 Widget_Data *wd = elm_widget_data_get(obj);
679 if (!wd) return EINA_FALSE;
680 return wd->autohide_disabled;
684 elm_index_item_level_set(Evas_Object *obj, int level)
686 ELM_CHECK_WIDTYPE(obj, widtype);
687 Widget_Data *wd = elm_widget_data_get(obj);
689 if (wd->level == level) return;
694 elm_index_item_level_get(const Evas_Object *obj)
696 ELM_CHECK_WIDTYPE(obj, widtype) 0;
697 Widget_Data *wd = elm_widget_data_get(obj);
702 EINA_DEPRECATED EAPI Elm_Object_Item *
703 elm_index_item_selected_get(const Evas_Object *obj, int level)
705 return elm_index_selected_item_get(obj, level);
708 EAPI Elm_Object_Item *
709 elm_index_selected_item_get(const Evas_Object *obj, int level)
711 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
712 Widget_Data *wd = elm_widget_data_get(obj);
715 if (!wd) return NULL;
716 EINA_LIST_FOREACH(wd->items, l, it)
718 if ((it->selected) && (it->level == level))
719 return (Elm_Object_Item *)it;
724 EAPI Elm_Object_Item *
725 elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
727 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
728 Widget_Data *wd = elm_widget_data_get(obj);
730 if (!wd) return NULL;
731 it = _item_new(obj, letter, func, data);
732 if (!it) return NULL;
733 wd->items = eina_list_append(wd->items, it);
734 _index_box_clear(obj, wd->bx[wd->level], wd->level);
735 return (Elm_Object_Item *)it;
738 EAPI Elm_Object_Item *
739 elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
741 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
742 Widget_Data *wd = elm_widget_data_get(obj);
745 if (!wd) return NULL;
746 it = _item_new(obj, letter, func, data);
747 if (!it) return NULL;
748 wd->items = eina_list_prepend(wd->items, it);
749 _index_box_clear(obj, wd->bx[wd->level], wd->level);
750 return (Elm_Object_Item *)it;
753 EINA_DEPRECATED EAPI Elm_Object_Item *
754 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
756 return elm_index_item_insert_after(obj, (Elm_Object_Item *) relative, letter, NULL, item);
759 EINA_DEPRECATED EAPI Elm_Object_Item *
760 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
762 return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
765 EAPI Elm_Object_Item *
766 elm_index_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *letter, Evas_Smart_Cb func, const void *data)
768 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
769 Widget_Data *wd = elm_widget_data_get(obj);
771 if (!wd) return NULL;
772 if (!after) return elm_index_item_append(obj, letter, func, data);
773 it = _item_new(obj, letter, func, data);
774 if (!it) return NULL;
775 wd->items = eina_list_append_relative(wd->items, it, after);
776 _index_box_clear(obj, wd->bx[wd->level], wd->level);
777 return (Elm_Object_Item *)it;
780 EAPI Elm_Object_Item *
781 elm_index_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *letter, Evas_Smart_Cb func, const void *data)
783 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
784 Widget_Data *wd = elm_widget_data_get(obj);
786 if (!wd) return NULL;
787 if (!before) return elm_index_item_prepend(obj, letter, func, data);
788 it = _item_new(obj, letter, func, data);
789 if (!it) return NULL;
790 wd->items = eina_list_prepend_relative(wd->items, it, before);
791 _index_box_clear(obj, wd->bx[wd->level], wd->level);
792 return (Elm_Object_Item *)it;
795 EAPI Elm_Object_Item *
796 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)
798 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
799 Widget_Data *wd = elm_widget_data_get(obj);
804 if (!wd) return NULL;
806 return elm_index_item_append(obj, letter, func, data);
808 it = _item_new(obj, letter, func, data);
809 if (!it) return NULL;
811 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
813 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
815 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
818 /* If cmp_data_func is not provided, append a duplicated item */
820 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
823 Elm_Index_Item *p_it = eina_list_data_get(lnear);
824 if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
825 p_it->base.data = it->base.data;
827 elm_widget_item_free(it);
830 _index_box_clear(obj, wd->bx[wd->level], wd->level);
831 return (Elm_Object_Item *)it;
835 elm_index_item_del(Evas_Object *obj __UNUSED__, Elm_Object_Item *it)
837 elm_object_item_del(it);
840 EAPI Elm_Object_Item *
841 elm_index_item_find(Evas_Object *obj, const void *data)
843 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
844 Widget_Data *wd = elm_widget_data_get(obj);
845 if (!wd) return NULL;
846 return (Elm_Object_Item *) _item_find(obj, data);
850 elm_index_item_clear(Evas_Object *obj)
852 ELM_CHECK_WIDTYPE(obj, widtype);
853 Widget_Data *wd = elm_widget_data_get(obj);
855 Eina_List *l, *clear = NULL;
857 _index_box_clear(obj, wd->bx[wd->level], wd->level);
858 EINA_LIST_FOREACH(wd->items, l, it)
860 if (it->level != wd->level) continue;
861 clear = eina_list_append(clear, it);
863 EINA_LIST_FREE(clear, it)
866 elm_widget_item_free(it);
870 EINA_DEPRECATED EAPI void
871 elm_index_item_go(Evas_Object *obj, int level __UNUSED__)
873 elm_index_level_go(obj, level);
877 elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
879 ELM_CHECK_WIDTYPE(obj, widtype);
880 Widget_Data *wd = elm_widget_data_get(obj);
882 _index_box_auto_fill(obj, wd->bx[0], 0);
883 if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
887 elm_index_item_data_get(const Elm_Object_Item *it)
889 return elm_object_item_data_get(it);
893 elm_index_item_data_set(Elm_Object_Item *it, const void *data)
895 elm_object_item_data_set(it, (void *) data);
899 elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
901 ELM_CHECK_WIDTYPE(obj, widtype);
902 Widget_Data *wd = elm_widget_data_get(obj);
905 disabled = !!disabled;
906 if (wd->indicator_disabled == disabled) return;
907 wd->indicator_disabled = disabled;
908 if (!wd->items) return;
910 edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
912 edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
916 elm_index_indicator_disabled_get(const Evas_Object *obj)
918 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
919 Widget_Data *wd = elm_widget_data_get(obj);
920 if (!wd) return EINA_FALSE;
922 return wd->indicator_disabled;
926 elm_index_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
928 elm_object_item_del_cb_set(it, func);
932 elm_index_item_letter_get(const Elm_Object_Item *it)
934 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
935 return ((Elm_Index_Item *)it)->letter;
939 elm_index_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
941 ELM_CHECK_WIDTYPE(obj, widtype);
942 Widget_Data *wd = elm_widget_data_get(obj);
945 horizontal = !!horizontal;
946 if (horizontal == wd->horizontal) return;
947 wd->horizontal = horizontal;
952 elm_index_horizontal_get(const Evas_Object *obj)
954 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
955 Widget_Data *wd = elm_widget_data_get(obj);
956 if (!wd) return EINA_FALSE;
957 return wd->horizontal;