2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
8 * @defgroup Index Index
11 * An index object is a type of list that categorizes items in it
14 * Signals that you can add callbacks for are:
16 * "changed" - when the selected index item changes
17 * "delay,changed" - when the selected index item changes, but after some small i
19 * "selected" - when the user releases a finger and selects an item
20 * "level,up" - when the user moves a finger from the first level to the second
22 * "level,down" - when the user moves a finger from the second level to the first
26 #define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
27 #define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
28 #define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
30 * use for find view toplevel
32 #define SET_VIEW_LEVEL(wd, view_level)\
33 view_level = wd->level;\
34 while ((!wd->tot_items_count[view_level]) && view_level)\
39 typedef struct _Widget_Data Widget_Data;
41 typedef struct _PlacementPart PlacementPart;
46 Evas_Object *event[2];
47 Evas_Object *bx[2]; // 2 - for now all that's supported
48 Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
51 int max_supp_items_count;
52 int tot_items_count[2];
53 int min_obj_height, max_grp_size;
54 int min_1st_level_obj_height;
57 Evas_Coord pwidth, pheight;
59 const char *special_char;
60 Eina_Bool level_active[2];
61 Eina_Bool horizontal : 1;
64 Eina_Bool hide_button : 1;
68 struct _Elm_Index_Item
71 const char *letter, *vis_letter;
73 Eina_Bool selected : 1;
82 static const char *widtype = NULL;
84 static void _del_hook(Evas_Object *obj);
85 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
86 static void _theme_hook(Evas_Object *obj);
87 static void _sizing_eval(Evas_Object *obj);
88 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
89 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
90 static void _item_free(Elm_Index_Item *it);
91 static void _index_process(Evas_Object *obj);
93 static const char SIG_CHANGED[] = "changed";
94 static const char SIG_DELAY_CHANGED[] = "delay,changed";
95 static const char SIG_SELECTED[] = "selected";
96 static const char SIG_LEVEL_UP[] = "level,up";
97 static const char SIG_LEVEL_DOWN[] = "level,down";
99 static const Evas_Smart_Cb_Description _signals[] = {
101 {SIG_DELAY_CHANGED, ""},
104 {SIG_LEVEL_DOWN, ""},
107 /* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
109 _del_pre_hook(Evas_Object *obj)
111 Widget_Data *wd = elm_widget_data_get(obj);
113 _index_box_clear(obj, wd->bx[wd->level], wd->level);
114 _index_box_clear(obj, wd->bx[0], 0);
115 while (wd->items) _item_free(wd->items->data);
116 if (wd->delay) ecore_timer_del(wd->delay);
118 if(wd->popup_str[0]) free(wd->popup_str[0]);
119 if(wd->popup_str[1]) free(wd->popup_str[1]);
123 _del_hook(Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
130 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
132 Widget_Data *wd = data;
134 _els_box_layout(o, priv, wd->horizontal, 0, 0);
138 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
140 Widget_Data *wd = elm_widget_data_get(obj);
142 edje_object_signal_emit(wd->base, emission, source);
146 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
148 Widget_Data *wd = elm_widget_data_get(obj);
150 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
154 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
156 Widget_Data *wd = elm_widget_data_get(obj);
157 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
162 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
164 Widget_Data *wd = elm_widget_data_get(obj);
167 edje_object_mirrored_set(wd->base, rtl);
171 _theme_hook(Evas_Object *obj)
173 Evas_Coord minw = 0, minh = 0;
174 Widget_Data *wd = elm_widget_data_get(obj);
176 _elm_widget_mirrored_reload(obj);
178 _index_box_clear(obj, wd->bx[0], 0);
179 _index_box_clear(obj, wd->bx[1], 1);
181 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
184 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
185 _mirrored_set(obj, elm_widget_mirrored_get(obj));
187 edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
188 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
189 evas_object_size_hint_min_set(wd->event[0], minw, minh);
191 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
192 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
196 wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
197 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
198 elm_widget_sub_object_add(obj, wd->bx[1]);
200 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
201 evas_object_show(wd->bx[1]);
205 evas_object_del(wd->bx[1]);
208 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
212 wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
213 evas_object_color_set(wd->event[1], 0, 0, 0, 0);
214 elm_widget_sub_object_add(obj, wd->event[1]);
216 edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
217 evas_object_size_hint_min_set(wd->event[1], minw, minh);
219 else if (wd->event[1])
221 evas_object_del(wd->event[1]);
224 edje_object_message_signal_process(wd->base);
225 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
227 _index_box_auto_fill(obj, wd->bx[0], 0);
230 _index_box_auto_fill(obj, wd->bx[1], 1);
234 _sizing_eval(Evas_Object *obj)
236 Widget_Data *wd = elm_widget_data_get(obj);
237 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
239 edje_object_size_min_calc(wd->base, &minw, &minh);
240 evas_object_size_hint_min_set(obj, minw, minh);
241 evas_object_size_hint_max_set(obj, maxw, maxh);
244 static Elm_Index_Item *
245 _item_new(Evas_Object *obj, const char *letter, const void *item)
247 Widget_Data *wd = elm_widget_data_get(obj);
249 if (!wd) return NULL;
250 it = elm_widget_item_new(obj, Elm_Index_Item);
251 if (!it) return NULL;
252 it->base.data = item;
253 it->level = wd->level;
255 it->size = wd->min_obj_height;
257 it->size = wd->min_1st_level_obj_height;
260 it->letter = eina_stringshare_add(letter);
261 it->vis_letter = eina_stringshare_add(letter);
271 static Elm_Index_Item *
272 _item_find(Evas_Object *obj, const void *item)
274 Widget_Data *wd = elm_widget_data_get(obj);
277 if (!wd) return NULL;
278 EINA_LIST_FOREACH(wd->items, l, it)
279 if (it->base.data == item) return it;
284 _item_free(Elm_Index_Item *it)
286 /* Automatically filling the box with index item*/
287 Widget_Data *wd = elm_widget_data_get(it->base.widget);
290 wd->items = eina_list_remove(wd->items, it);
291 elm_widget_item_pre_notify_del(it);
292 eina_stringshare_del(it->letter);
293 eina_stringshare_del(it->vis_letter);
294 elm_widget_item_del(it);
297 // FIXME: always have index filled
299 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
301 Widget_Data *wd = elm_widget_data_get(obj);
305 Evas_Coord mw, mh, w, h;
308 if (wd->level_active[level]) return;
309 rtl = elm_widget_mirrored_get(obj);
310 evas_object_geometry_get(box, NULL, NULL, &w, &h);
311 EINA_LIST_FOREACH(wd->items, l, it)
314 const char *stacking;
316 if (it->level != level) continue;
317 if(i > wd->max_supp_items_count) break;
319 o = edje_object_add(evas_object_evas_get(obj));
321 edje_object_mirrored_set(it->base.view, rtl);
323 _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
325 _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
326 edje_object_part_text_set(o, "elm.text", it->letter);
327 edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
328 evas_object_size_hint_min_set(o, mw, mh);
329 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
331 edje_object_part_text_set(o, "elm.text", it->vis_letter);
332 evas_object_size_hint_min_set(o, mw, it->size);
333 evas_object_size_hint_max_set(o, mw, it->size);
334 evas_object_resize(o, mw, it->size);
336 elm_widget_sub_object_add(obj, o);
337 evas_object_box_append(box, o);
338 stacking = edje_object_data_get(o, "stacking");
341 if (!strcmp(stacking, "below")) evas_object_lower(o);
342 else if (!strcmp(stacking, "above")) evas_object_raise(o);
347 wd->tot_items_count[1] = i;
348 evas_object_smart_calculate(box); // force a calc so we know the size
349 evas_object_size_hint_min_get(box, &mw, &mh);
352 _index_box_clear(obj, box, level);
355 // FIXME: only i objects fit! try again. overflows right now
359 evas_object_smart_calculate(box);
360 wd->level_active[level] = 1;
364 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
366 Widget_Data *wd = elm_widget_data_get(obj);
370 if (!wd->level_active[level]) return;
371 EINA_LIST_FOREACH(wd->items, l, it)
373 if (!it->base.view) continue;
374 if (it->level != level) continue;
375 evas_object_del(it->base.view);
376 it->base.view = NULL;
378 wd->level_active[level] = 0;
382 _delay_change(void *data)
384 Widget_Data *wd = elm_widget_data_get(data);
387 if (!wd) return ECORE_CALLBACK_CANCEL;
389 SET_VIEW_LEVEL(wd, view_level);
390 d = (void *)elm_index_item_selected_get(data, view_level);
391 if (d) evas_object_smart_callback_call(data, "delay,changed", d);
392 return ECORE_CALLBACK_CANCEL;
396 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
398 Widget_Data *wd = elm_widget_data_get(obj);
399 Elm_Index_Item *it, *it_closest, *it_last;
401 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
407 Eina_Bool change = EINA_FALSE;
408 char *label = NULL, *last = NULL;
413 SET_VIEW_LEVEL(wd, view_level);
414 for (i = 0; i <= view_level; i++)
419 evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
420 dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
421 dmax = 1.0-dmin-0.08;
422 EINA_LIST_FOREACH(wd->items, l, it)
424 if (!((it->level == i) && (it->base.view))) continue;
430 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
435 x = (x * x) + (y * y);
436 if ((x < dist) || (!it_closest))
439 cdv = (double)(xx - bx) / (double)bw;
441 cdv = (double)(yy - by) / (double)bh;
446 if ((i == 0) && (view_level == 0))
448 if(cdv > dmax || cdv < dmin)
458 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
462 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
465 if (it_closest) it_closest->selected = 1;
466 if (it_closest != it_last)
471 const char *stacking, *selectraise;
474 if(view_level == it->level)
475 edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
476 stacking = edje_object_data_get(it->base.view, "stacking");
477 selectraise = edje_object_data_get(it->base.view, "selectraise");
478 if ((selectraise) && (!strcmp(selectraise, "on")))
480 if ((stacking) && (!strcmp(stacking, "below")))
481 evas_object_lower(it->base.view);
486 const char *selectraise;
489 if(view_level == it->level)
490 edje_object_signal_emit(it->base.view, "elm,state,active", "elm");
491 selectraise = edje_object_data_get(it->base.view, "selectraise");
492 if ((selectraise) && (!strcmp(selectraise, "on")))
493 evas_object_raise(it->base.view);
494 evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it->base.data);
495 if (wd->delay) ecore_timer_del(wd->delay);
496 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
503 last = strdup(it->letter);
506 if (!label) label = strdup(last);
509 /* FIXME: realloc return NULL if the request fails */
510 label = realloc(label, strlen(label) + strlen(last) + 1);
514 last = strdup(it->letter);
518 if (!label) label = strdup("");
519 if (!last) last = strdup("");
526 if(wd->tot_items_count[0])
528 if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
529 wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
531 strcpy(wd->popup_str[0], last);
532 edje_object_signal_emit(wd->base, "hide_2nd_level", "");
536 edje_object_signal_emit(wd->base, "button.image.hidden", "");
537 if(label)free(label);
542 if (view_level == 1 && wd->level_active[1])
544 if(wd->tot_items_count[1])
546 wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
548 strcpy(wd->popup_str[1], last);
549 edje_object_signal_emit(wd->base, "hide_first_level", "");
553 edje_object_signal_emit(wd->base, "button.image.hidden", "");
554 if(label)free(label);
559 popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
560 sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
561 edje_object_part_text_set(wd->base, "elm.text", popup_text);
573 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
575 Widget_Data *wd = elm_widget_data_get(data);
576 // Evas_Event_Mouse_Wheel *ev = event_info;
577 // Evas_Object *obj = o;
582 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
584 Widget_Data *wd = elm_widget_data_get(data);
585 Evas_Event_Mouse_Down *ev = event_info;
588 if (ev->button != 1) return;
590 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
591 wd->dx = ev->canvas.x - x;
592 wd->dy = ev->canvas.y - y;
593 elm_index_active_set(data, 1);
594 _sel_eval(data, ev->canvas.x, ev->canvas.y);
595 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
596 (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
600 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
602 Widget_Data *wd = elm_widget_data_get(data);
603 Evas_Event_Mouse_Up *ev = event_info;
610 if (ev->button != 1) return;
611 if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
614 SET_VIEW_LEVEL(wd, view_level);
615 d = (void *)elm_index_item_selected_get(data, view_level);
616 EINA_LIST_FOREACH(wd->items, l, it)
618 edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
620 if (d) evas_object_smart_callback_call(data, SIG_SELECTED, d);
621 elm_index_active_set(data, 0);
622 edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
626 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
628 Widget_Data *wd = elm_widget_data_get(data);
629 Evas_Event_Mouse_Move *ev = event_info;
630 Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
634 if (!wd->down) return;
635 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
636 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
637 x = ev->cur.canvas.x - x;
638 y = ev->cur.canvas.y - y;
641 if (adx < 0) adx = -dx;
642 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
643 , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
651 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
652 edje_object_signal_emit(wd->base, buf, "elm");
653 evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
661 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
662 edje_object_signal_emit(wd->base, buf, "elm");
663 d = (void *)elm_index_item_selected_get(data, wd->level);
664 evas_object_smart_callback_call(data, "changed", d);
665 if (wd->delay) ecore_timer_del(wd->delay);
666 wd->delay = ecore_timer_add(0.2, _delay_change, data);
667 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
671 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
675 _index_box_refill_job(void *data)
677 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
683 evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
684 wd->scale_factor = elm_scale_get();
685 if ( wd->scale_factor == 0.0 ) {
686 wd->scale_factor = 1.0;
688 string = edje_object_data_get(wd->base, "min_obj_height");
690 wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
692 wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
693 if(!wd->min_obj_height) return;
695 wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
696 wd->items_count = ph/wd->min_obj_height;
697 wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
699 if(pw != wd->pwidth && ph != wd->pheight)
704 elm_index_active_set(data, 1);
706 _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
707 evas_object_smart_calculate( wd->bx[0]);
708 elm_index_item_go((Evas_Object *)data, wd->level);
714 static void _index_object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
718 wd = elm_widget_data_get((Evas_Object *)data);
720 ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
724 * Add a new index to the parent
726 * @param parent The parent object
727 * @return The new object or NULL if it cannot be created
732 elm_index_add(Evas_Object *parent)
738 Evas_Coord minw, minh;
741 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
743 ELM_SET_WIDTYPE(widtype, "index");
744 elm_widget_type_set(obj, "index");
745 elm_widget_sub_object_add(parent, obj);
746 elm_widget_data_set(obj, wd);
747 elm_widget_del_hook_set(obj, _del_hook);
748 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
749 elm_widget_theme_hook_set(obj, _theme_hook);
750 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
751 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
752 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
753 elm_widget_can_focus_set(obj, EINA_FALSE);
755 wd->horizontal = EINA_FALSE;
756 wd->min_obj_height = 0;
757 wd->max_grp_size = 0;
759 wd->max_supp_items_count = 0;
760 wd->tot_items_count[0] = 0;
761 wd->tot_items_count[1] = 0;
763 wd->special_char = edje_object_data_get(wd->base, "special_char");
764 if(wd->special_char == NULL) wd->special_char = eina_stringshare_add("*");
766 wd->base = edje_object_add(e);
767 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
768 elm_widget_resize_object_set(obj, wd->base);
770 o = evas_object_rectangle_add(e);
772 evas_object_color_set(o, 0, 0, 0, 0);
774 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
775 evas_object_size_hint_min_set(o, minw, minh);
776 edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
777 elm_widget_sub_object_add(obj, o);
778 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
779 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
780 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
781 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
782 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
784 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
786 o = evas_object_rectangle_add(e);
788 evas_object_color_set(o, 0, 0, 0, 0);
789 evas_object_size_hint_min_set(o, minw, minh);
790 edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
791 elm_widget_sub_object_add(obj, o);
794 wd->bx[0] = evas_object_box_add(e);
795 evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
796 elm_widget_sub_object_add(obj, wd->bx[0]);
797 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
798 evas_object_show(wd->bx[0]);
800 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
802 wd->bx[1] = evas_object_box_add(e);
803 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
804 elm_widget_sub_object_add(obj, wd->bx[1]);
805 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
806 evas_object_show(wd->bx[1]);
809 evas_object_smart_callbacks_descriptions_set(obj, _signals);
810 wd->scale_factor = elm_scale_get();
811 if ( wd->scale_factor == 0.0 )
812 wd->scale_factor = 1.0;
813 string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
815 wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
817 wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
818 wd->popup_str[0] = calloc(1, sizeof(char) * 1);
819 wd->popup_str[1] = calloc(1, sizeof(char) * 1);
821 _mirrored_set(obj, elm_widget_mirrored_get(obj));
827 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
829 Widget_Data *wd = elm_widget_data_get(obj);
831 int group_count = MIN_GRP_SIZE;
832 while(group_count <= wd->max_grp_size)
834 if(extraIndex <= wd->max_grp_size*adj_pos)
836 if(group_count*adj_pos>=extraIndex) return group_count;
839 return wd->max_grp_size;
841 group_count += MIN_GRP_SIZE;
847 _index_process(Evas_Object *obj)
850 int j,i, group_count;
856 Widget_Data *wd = elm_widget_data_get(obj);
859 if (wd->items_count == 0) return;
861 const int adj_pos = (wd->items_count-1)*0.5;
862 if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
863 n = wd->tot_items_count[wd->level];
865 n = wd->max_supp_items_count;
866 group_count = MIN_GRP_SIZE;
868 int *indx = (int*)calloc(n, sizeof(int));
871 const int minh = wd->min_obj_height;
872 EINA_LIST_FOREACH(wd->items, l, it)
874 it->vis_letter = eina_stringshare_add(it->letter);
879 int N = wd->items_count;
886 if (extraIndex < 0) return;
888 group_count = _group_count(obj, extraIndex, adj_pos, N);
889 if (group_count <= 0)
897 PlacementPart place[adj_pos];
898 remainder = extraIndex%group_count;
899 numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
901 for (i=0;i<numberofparts; i++)
903 place[i].count=group_count+1;
904 count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
905 place[i].start= count +i*group_count-1;
908 place[numberofparts-1].count=remainder+1;
910 for (i=0;i<numberofparts;i++)
912 for (j=0;j<place[i].count; j++)
914 indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
916 indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
919 EINA_LIST_FOREACH(wd->items, l, it)
921 int size = indx[count];
925 it->vis_letter = eina_stringshare_add(it->letter);
930 eina_stringshare_del(it->vis_letter);
931 it->vis_letter = eina_stringshare_add("");
935 eina_stringshare_del(it->vis_letter);
936 it->vis_letter = eina_stringshare_add(wd->special_char);
938 it->size = size*wd->scale_factor;
948 * Set the active state of the index programatically
950 * @param obj The index object
951 * @param active The active state
956 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
958 ELM_CHECK_WIDTYPE(obj, widtype);
959 Widget_Data *wd = elm_widget_data_get(obj);
961 if (wd->active == active) return;
966 _index_box_clear(obj, wd->bx[1], 1);
968 _index_box_auto_fill(obj, wd->bx[0], 0);
969 if(wd->tot_items_count[wd->level])
970 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
972 edje_object_signal_emit(wd->base, "button.image.hidden", "");
975 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
979 * Get the active state of the index programatically
981 * @param obj The index object
982 * @return The active state
987 elm_index_active_get(const Evas_Object *obj)
989 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
990 Widget_Data *wd = elm_widget_data_get(obj);
991 if (!wd) return EINA_FALSE;
996 * Sets the level of the item.
998 * @param obj The index object.
999 * @param level To be documented.
1004 elm_index_item_level_set(Evas_Object *obj, int level)
1006 ELM_CHECK_WIDTYPE(obj, widtype);
1007 Widget_Data *wd = elm_widget_data_get(obj);
1009 if (wd->level == level) return;
1014 * Gets the level of the item.
1016 * @param obj The index object
1021 elm_index_item_level_get(const Evas_Object *obj)
1023 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1024 Widget_Data *wd = elm_widget_data_get(obj);
1030 * Returns the selected item.
1032 * @param obj The index object.
1033 * @param level to be documented.
1038 elm_index_item_selected_get(const Evas_Object *obj, int level)
1040 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1041 Widget_Data *wd = elm_widget_data_get(obj);
1044 if (!wd) return NULL;
1045 EINA_LIST_FOREACH(wd->items, l, it)
1046 if ((it->selected) && (it->level == level))
1047 return elm_widget_item_data_get(it);
1052 * Appends a new item.
1054 * @param obj The index object.
1055 * @param letter Letter under which the item should be indexed
1056 * @param item The item to put in the index
1061 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1063 ELM_CHECK_WIDTYPE(obj, widtype);
1064 Widget_Data *wd = elm_widget_data_get(obj);
1067 it = _item_new(obj, letter, item);
1069 wd->items = eina_list_append(wd->items, it);
1070 wd->tot_items_count[wd->level]++;
1071 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1075 * Prepends a new item.
1077 * @param obj The index object.
1078 * @param letter Letter under which the item should be indexed
1079 * @param item The item to put in the index
1084 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1086 ELM_CHECK_WIDTYPE(obj, widtype);
1087 Widget_Data *wd = elm_widget_data_get(obj);
1091 it = _item_new(obj, letter, item);
1093 wd->items = eina_list_prepend(wd->items, it);
1094 wd->tot_items_count[wd->level]++;
1095 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1099 * Append an item after @p relative in letter @p letter.
1101 * @param obj The index object
1102 * @param letter Letter under which the item should be indexed
1103 * @param item The item to put in the index
1104 * @param relative The item to put @p item after
1109 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1111 ELM_CHECK_WIDTYPE(obj, widtype);
1112 Widget_Data *wd = elm_widget_data_get(obj);
1113 Elm_Index_Item *it, *it_rel;
1117 elm_index_item_append(obj, letter, item);
1118 wd->tot_items_count[wd->level]++;
1121 it = _item_new(obj, letter, item);
1124 it_rel = _item_find(obj, relative);
1127 elm_index_item_append(obj, letter, item);
1128 wd->tot_items_count[wd->level]++;
1132 wd->items = eina_list_append_relative(wd->items, it, it_rel);
1133 wd->tot_items_count[wd->level]++;
1134 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1138 * Prepend an item before @p relative in letter @p letter.
1140 * @param obj The index object
1141 * @param letter Letter under which the item should be indexed
1142 * @param item The item to put in the index
1143 * @param relative The item to put @p item before
1148 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
1150 ELM_CHECK_WIDTYPE(obj, widtype);
1151 Widget_Data *wd = elm_widget_data_get(obj);
1152 Elm_Index_Item *it, *it_rel;
1156 elm_index_item_prepend(obj, letter, item);
1157 wd->tot_items_count[wd->level]++;
1160 it = _item_new(obj, letter, item);
1163 it_rel = _item_find(obj, relative);
1166 elm_index_item_append(obj, letter, item);
1167 wd->tot_items_count[wd->level]++;
1171 wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
1172 wd->tot_items_count[wd->level]++;
1173 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1177 * Insert a new @p item into the sorted index @p obj in @p letter.
1179 * @param obj The index object
1180 * @param letter Letter under which the item should be indexed
1181 * @param item The item to put in the index
1182 * @param cmp_func The function called for the sort of index items.
1183 * @param cmp_data_func The function called for the sort of the data. It will
1184 * be used when cmp_func return 0. It means the index item already exists.
1185 * So, to decide which data item should be pointed by the index item, a function
1186 * to compare them is needed. If this function is not provided, index items
1187 * will be duplicated. If cmp_data_func returns a non-negative value, the
1188 * previous index item data will be replaced by the inserted @p item. So
1189 * if the previous data need to be free, it should be done in this function,
1190 * because the reference will be lost.
1195 elm_index_item_sorted_insert(Evas_Object *obj, const char *letter, const void *item, Eina_Compare_Cb cmp_func, Eina_Compare_Cb cmp_data_func)
1197 ELM_CHECK_WIDTYPE(obj, widtype);
1198 Widget_Data *wd = elm_widget_data_get(obj);
1206 elm_index_item_append(obj, letter, item);
1210 it = _item_new(obj, letter, item);
1213 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1215 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1217 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1220 /* If cmp_data_func is not provided, append a duplicated item */
1222 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1225 Elm_Index_Item *p_it = eina_list_data_get(lnear);
1226 if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1227 p_it->base.data = it->base.data;
1232 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1236 * Remove an item from the index.
1238 * @param obj The index object
1239 * @param item The item to remove from the index
1244 elm_index_item_del(Evas_Object *obj, const void *item)
1246 ELM_CHECK_WIDTYPE(obj, widtype);
1247 Widget_Data *wd = elm_widget_data_get(obj);
1250 it = _item_find(obj, item);
1253 wd->tot_items_count[wd->level]--;
1254 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1258 * Find an index item using item data.
1260 * @param obj The index object
1261 * @param item The item pointed by index item
1262 * @return The index item pointing to @p item
1266 EAPI Elm_Index_Item *
1267 elm_index_item_find(Evas_Object *obj, const void *item)
1269 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1270 Widget_Data *wd = elm_widget_data_get(obj);
1271 if (!wd) return NULL;
1272 return _item_find(obj, item);
1276 * Clears an index of its items.
1278 * @param obj The index object.
1283 elm_index_item_clear(Evas_Object *obj)
1285 ELM_CHECK_WIDTYPE(obj, widtype);
1286 Widget_Data *wd = elm_widget_data_get(obj);
1288 Eina_List *l, *clear = NULL;
1290 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1291 EINA_LIST_FOREACH(wd->items, l, it)
1293 if (it->level != wd->level) continue;
1294 clear = eina_list_append(clear, it);
1296 EINA_LIST_FREE(clear, it)
1299 wd->tot_items_count[wd->level]--;
1304 * Go to item at @p level
1306 * @param obj The index object
1307 * @param level The index level
1312 elm_index_item_go(Evas_Object *obj, int level)
1314 ELM_CHECK_WIDTYPE(obj, widtype);
1315 Widget_Data *wd = elm_widget_data_get(obj);
1318 _index_process(obj);
1319 _index_box_auto_fill(obj, wd->bx[0], 0);
1320 if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1324 * Returns the data associated with the item.
1326 * @param it The list item
1327 * @return The data associated with @p it
1332 elm_index_item_data_get(const Elm_Index_Item *it)
1334 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1335 return elm_widget_item_data_get(it);
1339 * Set the data item from the index item
1341 * This set a new data value.
1343 * @param it The item
1344 * @param data The new data pointer to set
1349 elm_index_item_data_set(Elm_Index_Item *it, const void *data)
1351 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1352 elm_widget_item_data_set(it, data);
1356 * Make the Central Button Image invisible.
1358 * @param obj The Index.
1359 * @param invisible Whether button visible or not.
1365 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1367 ELM_CHECK_WIDTYPE(obj, widtype);
1368 Widget_Data *wd = elm_widget_data_get(obj);
1369 wd->hide_button = invisible;
1371 edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1376 * Set the function called when a index item is freed.
1378 * @param it The item to set the callback on
1379 * @param func The function called
1384 elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
1386 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
1387 elm_widget_item_del_cb_set(it, func);
1391 * Gets the letter of the item.
1393 * @param it The list item
1394 * @return The letter of @p it
1399 elm_index_item_letter_get(const Elm_Index_Item *it)
1401 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);