1 #include <Elementary.h>
5 #define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
6 #define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
7 #define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
9 * use for find view toplevel
11 #define SET_VIEW_LEVEL(wd, view_level)\
12 view_level = wd->level;\
13 while ((!wd->tot_items_count[view_level]) && view_level)\
18 typedef struct _Widget_Data Widget_Data;
20 typedef struct _PlacementPart PlacementPart;
21 typedef struct _Elm_Index_Item Elm_Index_Item;
26 Evas_Object *event[2];
27 Evas_Object *bx[2]; // 2 - for now all that's supported
28 Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
31 int max_supp_items_count;
32 int tot_items_count[2];
33 int min_obj_height, max_grp_size;
34 int min_1st_level_obj_height;
37 Evas_Coord pwidth, pheight;
39 const char *special_char;
40 Eina_Bool level_active[2];
41 Eina_Bool horizontal : 1;
44 Eina_Bool hide_button : 1;
48 struct _Elm_Index_Item
51 const char *letter, *vis_letter;
53 Eina_Bool selected : 1;
62 static const char *widtype = NULL;
64 static void _del_hook(Evas_Object *obj);
65 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
66 static void _theme_hook(Evas_Object *obj);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
69 static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
70 static void _item_free(Elm_Index_Item *it);
71 static void _index_process(Evas_Object *obj);
73 static const char SIG_CHANGED[] = "changed";
74 static const char SIG_DELAY_CHANGED[] = "delay,changed";
75 static const char SIG_SELECTED[] = "selected";
76 static const char SIG_LEVEL_UP[] = "level,up";
77 static const char SIG_LEVEL_DOWN[] = "level,down";
79 static const Evas_Smart_Cb_Description _signals[] = {
81 {SIG_DELAY_CHANGED, ""},
88 /* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
91 _del_pre_hook(Evas_Object *obj)
93 Widget_Data *wd = elm_widget_data_get(obj);
96 _index_box_clear(obj, wd->bx[wd->level], wd->level);
97 _index_box_clear(obj, wd->bx[0], 0);
100 it = wd->items->data;
102 elm_widget_item_free(it);
104 if (wd->delay) ecore_timer_del(wd->delay);
105 if(wd->popup_str[0]) free(wd->popup_str[0]);
106 if(wd->popup_str[1]) free(wd->popup_str[1]);
110 _del_hook(Evas_Object *obj)
112 Widget_Data *wd = elm_widget_data_get(obj);
117 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
119 Widget_Data *wd = data;
121 _els_box_layout(o, priv, wd->horizontal, 1, 0);
125 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
127 Widget_Data *wd = elm_widget_data_get(obj);
129 edje_object_signal_emit(wd->base, emission, source);
133 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
135 Widget_Data *wd = elm_widget_data_get(obj);
137 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
141 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
143 Widget_Data *wd = elm_widget_data_get(obj);
144 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
149 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
151 Widget_Data *wd = elm_widget_data_get(obj);
154 edje_object_mirrored_set(wd->base, rtl);
158 _theme_hook(Evas_Object *obj)
160 Evas_Coord minw = 0, minh = 0;
161 Widget_Data *wd = elm_widget_data_get(obj);
163 _elm_widget_mirrored_reload(obj);
165 _index_box_clear(obj, wd->bx[0], 0);
166 _index_box_clear(obj, wd->bx[1], 1);
168 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
171 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", elm_widget_style_get(obj));
172 _mirrored_set(obj, elm_widget_mirrored_get(obj));
174 edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
175 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
176 evas_object_size_hint_min_set(wd->event[0], minw, minh);
177 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
178 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
182 wd->bx[1] = evas_object_box_add(evas_object_evas_get(wd->base));
183 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
184 elm_widget_sub_object_add(obj, wd->bx[1]);
186 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
187 evas_object_show(wd->bx[1]);
191 evas_object_del(wd->bx[1]);
194 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
198 wd->event[1] = evas_object_rectangle_add(evas_object_evas_get(wd->base));
199 evas_object_color_set(wd->event[1], 0, 0, 0, 0);
200 elm_widget_sub_object_add(obj, wd->event[1]);
202 edje_object_part_swallow(wd->base, "elm.swallow.event.1", wd->event[1]);
203 evas_object_size_hint_min_set(wd->event[1], minw, minh);
205 else if (wd->event[1])
207 evas_object_del(wd->event[1]);
210 edje_object_message_signal_process(wd->base);
211 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
213 _index_box_auto_fill(obj, wd->bx[0], 0);
216 _index_box_auto_fill(obj, wd->bx[1], 1);
220 _sizing_eval(Evas_Object *obj)
222 Widget_Data *wd = elm_widget_data_get(obj);
223 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
225 edje_object_size_min_calc(wd->base, &minw, &minh);
226 evas_object_size_hint_min_set(obj, minw, minh);
227 evas_object_size_hint_max_set(obj, maxw, maxh);
231 _item_del_pre_hook(Elm_Object_Item *it)
233 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
234 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
235 if (!wd) return EINA_FALSE;
236 _item_free((Elm_Index_Item *) it);
237 _index_box_clear(WIDGET(it), wd->bx[wd->level], wd->level);
241 static Elm_Index_Item *
242 _item_new(Evas_Object *obj, const char *letter, const void *item)
244 Widget_Data *wd = elm_widget_data_get(obj);
246 if (!wd) return NULL;
247 it = elm_widget_item_new(obj, Elm_Index_Item);
248 if (!it) return NULL;
250 it->base.data = item;
251 it->level = wd->level;
253 it->size = wd->min_obj_height;
255 it->size = wd->min_1st_level_obj_height;
258 it->letter = eina_stringshare_add(letter);
259 it->vis_letter = eina_stringshare_add(letter);
266 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
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 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
289 wd->items = eina_list_remove(wd->items, it);
290 elm_widget_item_pre_notify_del(it);
291 if (it->letter) eina_stringshare_del(it->letter);
292 if (it->vis_letter) eina_stringshare_del(it->vis_letter);
295 // FIXME: always have index filled
297 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
299 Widget_Data *wd = elm_widget_data_get(obj);
303 Evas_Coord mw, mh, w, h;
306 if (wd->level_active[level]) return;
307 rtl = elm_widget_mirrored_get(obj);
308 evas_object_geometry_get(box, NULL, NULL, &w, &h);
309 EINA_LIST_FOREACH(wd->items, l, it)
312 const char *stacking;
314 if (it->level != level) continue;
316 if(i > wd->max_supp_items_count) break;
318 o = edje_object_add(evas_object_evas_get(obj));
320 edje_object_mirrored_set(VIEW(it), rtl);
322 _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
324 _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
325 edje_object_part_text_set(o, "elm.text", it->letter);
326 edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
327 evas_object_size_hint_min_set(o, mw, mh);
328 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
329 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
330 edje_object_part_text_set(o, "elm.text", it->vis_letter);
331 evas_object_size_hint_min_set(o, mw, it->size);
332 evas_object_size_hint_max_set(o, mw, it->size);
333 evas_object_resize(o, mw, it->size);
334 elm_widget_sub_object_add(obj, o);
335 evas_object_box_append(box, o);
336 stacking = edje_object_data_get(o, "stacking");
339 if (!strcmp(stacking, "below")) evas_object_lower(o);
340 else if (!strcmp(stacking, "above")) evas_object_raise(o);
345 wd->tot_items_count[1] = i;
346 evas_object_smart_calculate(box); // force a calc so we know the size
347 evas_object_size_hint_min_get(box, &mw, &mh);
350 _index_box_clear(obj, box, level);
353 // FIXME: only i objects fit! try again. overflows right now
357 evas_object_smart_calculate(box);
358 wd->level_active[level] = 1;
362 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
364 Widget_Data *wd = elm_widget_data_get(obj);
368 if (!wd->level_active[level]) return;
369 EINA_LIST_FOREACH(wd->items, l, it)
371 if (!VIEW(it)) continue;
372 if (it->level != level) continue;
373 evas_object_del(VIEW(it));
376 wd->level_active[level] = 0;
380 _delay_change(void *data)
382 Widget_Data *wd = elm_widget_data_get(data);
383 Elm_Object_Item *item;
385 if (!wd) return ECORE_CALLBACK_CANCEL;
387 SET_VIEW_LEVEL(wd, view_level);
388 item = elm_index_item_selected_get(data, view_level);
389 if (item) evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, item);
391 return ECORE_CALLBACK_CANCEL;
395 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
397 Widget_Data *wd = elm_widget_data_get(obj);
398 Elm_Index_Item *it, *it_closest, *it_last;
400 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
406 Eina_Bool change = EINA_FALSE;
407 char *label = NULL, *last = NULL;
412 SET_VIEW_LEVEL(wd, view_level);
413 for (i = 0; i <= view_level; i++)
418 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) && (VIEW(it)))) continue;
425 if ((VIEW(it)) && (it->level != wd->level))
439 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
444 x = (x * x) + (y * y);
445 if ((x < dist) || (!it_closest))
448 cdv = (double)(xx - bx) / (double)bw;
450 cdv = (double)(yy - by) / (double)bh;
455 if ((i == 0) && (view_level == 0))
457 if(cdv > dmax || cdv < dmin)
467 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
471 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
474 if (it_closest) it_closest->selected = 1;
475 if (it_closest != it_last)
480 const char *stacking, *selectraise;
483 if(view_level == it->level)
484 edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
485 stacking = edje_object_data_get(VIEW(it), "stacking");
486 selectraise = edje_object_data_get(VIEW(it), "selectraise");
487 if ((selectraise) && (!strcmp(selectraise, "on")))
489 if ((stacking) && (!strcmp(stacking, "below")))
490 evas_object_lower(VIEW(it));
495 const char *selectraise;
498 if(view_level == it->level)
499 edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
500 selectraise = edje_object_data_get(VIEW(it), "selectraise");
501 if ((selectraise) && (!strcmp(selectraise, "on")))
502 evas_object_raise(VIEW(it));
503 evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it);
504 if (wd->delay) ecore_timer_del(wd->delay);
505 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
512 last = strdup(it->letter);
515 if (!label) label = strdup(last);
518 /* FIXME: realloc return NULL if the request fails */
519 label = realloc(label, strlen(label) + strlen(last) + 1);
523 last = strdup(it->letter);
527 if (!label) label = strdup("");
528 if (!last) last = strdup("");
535 if(wd->tot_items_count[0])
537 if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
538 wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
540 strcpy(wd->popup_str[0], last);
541 edje_object_signal_emit(wd->base, "hide_2nd_level", "");
545 edje_object_signal_emit(wd->base, "button.image.hidden", "");
546 if(label)free(label);
551 if (view_level == 1 && wd->level_active[1])
553 if(wd->tot_items_count[1])
555 wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
557 strcpy(wd->popup_str[1], last);
558 edje_object_signal_emit(wd->base, "hide_first_level", "");
562 edje_object_signal_emit(wd->base, "button.image.hidden", "");
563 if(label)free(label);
568 popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
569 sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
570 edje_object_part_text_set(wd->base, "elm.text", popup_text);
582 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
584 Widget_Data *wd = elm_widget_data_get(data);
585 // Evas_Event_Mouse_Wheel *ev = event_info;
586 // Evas_Object *obj = o;
591 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
593 Widget_Data *wd = elm_widget_data_get(data);
594 Evas_Event_Mouse_Down *ev = event_info;
597 if (ev->button != 1) return;
599 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
600 wd->dx = ev->canvas.x - x;
601 wd->dy = ev->canvas.y - y;
602 elm_index_active_set(data, 1);
603 _sel_eval(data, ev->canvas.x, ev->canvas.y);
604 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
605 (!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
607 edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
611 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
613 Widget_Data *wd = elm_widget_data_get(data);
614 Evas_Event_Mouse_Up *ev = event_info;
615 Elm_Object_Item *item;
620 if (ev->button != 1) return;
621 if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
624 SET_VIEW_LEVEL(wd, view_level);
625 item = elm_index_item_selected_get(data, view_level);
626 EINA_LIST_FOREACH(wd->items, l, item)
628 edje_object_signal_emit(item->base.view, "elm,state,inactive", "elm");
630 if (item) evas_object_smart_callback_call(data, SIG_SELECTED, item);
631 elm_index_active_set(data, 0);
632 edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
633 edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
637 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
639 Widget_Data *wd = elm_widget_data_get(data);
640 Evas_Event_Mouse_Move *ev = event_info;
641 Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
643 Elm_Object_Item *item;
646 if (!wd->down) return;
647 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
648 evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
649 x = ev->cur.canvas.x - x;
650 y = ev->cur.canvas.y - y;
653 if (adx < 0) adx = -dx;
654 edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer"
655 , (!edje_object_mirrored_get(wd->base)) ? x : (x - w), y);
663 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
664 edje_object_signal_emit(wd->base, buf, "elm");
665 evas_object_smart_callback_call(data, SIG_LEVEL_UP, NULL);
673 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
674 edje_object_signal_emit(wd->base, buf, "elm");
675 item = elm_index_item_selected_get(data, wd->level);
676 evas_object_smart_callback_call(data, "changed", d);
677 if (wd->delay) ecore_timer_del(wd->delay);
678 wd->delay = ecore_timer_add(0.2, _delay_change, data);
679 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
683 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
687 _index_box_refill_job(void *data)
689 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
695 evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
696 wd->scale_factor = elm_scale_get();
697 if ( wd->scale_factor == 0.0 ) {
698 wd->scale_factor = 1.0;
700 string = edje_object_data_get(wd->base, "min_obj_height");
702 wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
704 wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
705 if(!wd->min_obj_height) return;
707 wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
708 wd->items_count = ph/wd->min_obj_height;
709 wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
711 if(pw != wd->pwidth && ph != wd->pheight)
716 elm_index_active_set(data, 1);
718 _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
719 evas_object_smart_calculate( wd->bx[0]);
720 elm_index_item_go((Evas_Object *)data, wd->level);
726 static void _index_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
730 wd = elm_widget_data_get((Evas_Object *)data);
732 ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
736 elm_index_add(Evas_Object *parent)
742 Evas_Coord minw, minh;
745 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
747 ELM_SET_WIDTYPE(widtype, "index");
748 elm_widget_type_set(obj, "index");
749 elm_widget_sub_object_add(parent, obj);
750 elm_widget_data_set(obj, wd);
751 elm_widget_del_hook_set(obj, _del_hook);
752 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
753 elm_widget_theme_hook_set(obj, _theme_hook);
754 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
755 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
756 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
757 elm_widget_can_focus_set(obj, EINA_FALSE);
759 wd->horizontal = EINA_FALSE;
760 wd->min_obj_height = 0;
761 wd->max_grp_size = 0;
763 wd->max_supp_items_count = 0;
764 wd->tot_items_count[0] = 0;
765 wd->tot_items_count[1] = 0;
767 wd->special_char = edje_object_data_get(wd->base, "special_char");
768 if(wd->special_char == NULL) wd->special_char = eina_stringshare_add("*");
770 wd->base = edje_object_add(e);
771 _elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
772 elm_widget_resize_object_set(obj, wd->base);
774 o = evas_object_rectangle_add(e);
776 evas_object_color_set(o, 0, 0, 0, 0);
778 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
779 evas_object_size_hint_min_set(o, minw, minh);
780 edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
781 elm_widget_sub_object_add(obj, o);
782 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
783 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
784 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
785 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
786 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, obj);
788 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
790 o = evas_object_rectangle_add(e);
792 evas_object_color_set(o, 0, 0, 0, 0);
793 evas_object_size_hint_min_set(o, minw, minh);
794 edje_object_part_swallow(wd->base, "elm.swallow.event.1", o);
795 elm_widget_sub_object_add(obj, o);
798 wd->bx[0] = evas_object_box_add(e);
799 evas_object_box_layout_set(wd->bx[0], _layout, wd, NULL);
800 elm_widget_sub_object_add(obj, wd->bx[0]);
801 edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
802 evas_object_show(wd->bx[0]);
804 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
806 wd->bx[1] = evas_object_box_add(e);
807 evas_object_box_layout_set(wd->bx[1], _layout, wd, NULL);
808 elm_widget_sub_object_add(obj, wd->bx[1]);
809 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
810 evas_object_show(wd->bx[1]);
813 evas_object_smart_callbacks_descriptions_set(obj, _signals);
814 wd->scale_factor = elm_scale_get();
815 if ( wd->scale_factor == 0.0 )
816 wd->scale_factor = 1.0;
817 string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
819 wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
821 wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
822 wd->popup_str[0] = calloc(1, sizeof(char) * 1);
823 wd->popup_str[1] = calloc(1, sizeof(char) * 1);
825 _mirrored_set(obj, elm_widget_mirrored_get(obj));
831 _group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
833 Widget_Data *wd = elm_widget_data_get(obj);
835 int group_count = MIN_GRP_SIZE;
836 while(group_count <= wd->max_grp_size)
838 if(extraIndex <= wd->max_grp_size*adj_pos)
840 if(group_count*adj_pos>=extraIndex) return group_count;
843 return wd->max_grp_size;
845 group_count += MIN_GRP_SIZE;
851 _index_process(Evas_Object *obj)
854 int j,i, group_count;
860 Widget_Data *wd = elm_widget_data_get(obj);
863 if (wd->items_count == 0) return;
865 const int adj_pos = (wd->items_count-1)*0.5;
866 if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
867 n = wd->tot_items_count[wd->level];
869 n = wd->max_supp_items_count;
870 group_count = MIN_GRP_SIZE;
872 int *indx = (int*)calloc(n, sizeof(int));
875 const int minh = wd->min_obj_height;
876 EINA_LIST_FOREACH(wd->items, l, it)
878 it->vis_letter = eina_stringshare_add(it->letter);
883 int N = wd->items_count;
897 group_count = _group_count(obj, extraIndex, adj_pos, N);
898 if (group_count <= 0)
906 PlacementPart place[adj_pos];
907 remainder = extraIndex%group_count;
908 numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
910 for (i=0;i<numberofparts; i++)
912 place[i].count=group_count+1;
913 count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
914 place[i].start= count +i*group_count-1;
917 place[numberofparts-1].count=remainder+1;
919 for (i=0;i<numberofparts;i++)
921 for (j=0;j<place[i].count; j++)
923 indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
925 indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
928 EINA_LIST_FOREACH(wd->items, l, it)
930 int size = indx[count];
934 it->vis_letter = eina_stringshare_add(it->letter);
939 eina_stringshare_del(it->vis_letter);
940 it->vis_letter = eina_stringshare_add("");
944 eina_stringshare_del(it->vis_letter);
945 it->vis_letter = eina_stringshare_add(wd->special_char);
947 it->size = size*wd->scale_factor;
957 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
959 ELM_CHECK_WIDTYPE(obj, widtype);
960 Widget_Data *wd = elm_widget_data_get(obj);
962 if (wd->active == active) return;
967 _index_box_clear(obj, wd->bx[1], 1);
969 _index_box_auto_fill(obj, wd->bx[0], 0);
970 if(wd->tot_items_count[wd->level])
971 edje_object_signal_emit(wd->base, "elm,state,active", "elm");
973 edje_object_signal_emit(wd->base, "button.image.hidden", "");
976 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
980 elm_index_active_get(const Evas_Object *obj)
982 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
983 Widget_Data *wd = elm_widget_data_get(obj);
984 if (!wd) return EINA_FALSE;
989 elm_index_item_level_set(Evas_Object *obj, int level)
991 ELM_CHECK_WIDTYPE(obj, widtype);
992 Widget_Data *wd = elm_widget_data_get(obj);
994 if (wd->level == level) return;
999 elm_index_item_level_get(const Evas_Object *obj)
1001 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1002 Widget_Data *wd = elm_widget_data_get(obj);
1007 EAPI Elm_Object_Item *
1008 elm_index_item_selected_get(const Evas_Object *obj, int level)
1010 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1011 Widget_Data *wd = elm_widget_data_get(obj);
1014 if (!wd) return NULL;
1015 EINA_LIST_FOREACH(wd->items, l, it)
1017 if ((it->selected) && (it->level == level))
1018 return (Elm_Object_Item *) it;
1024 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1026 ELM_CHECK_WIDTYPE(obj, widtype);
1027 Widget_Data *wd = elm_widget_data_get(obj);
1030 it = _item_new(obj, letter, item);
1032 wd->items = eina_list_append(wd->items, it);
1033 wd->tot_items_count[wd->level]++;
1034 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1038 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1040 ELM_CHECK_WIDTYPE(obj, widtype);
1041 Widget_Data *wd = elm_widget_data_get(obj);
1045 it = _item_new(obj, letter, item);
1047 wd->items = eina_list_prepend(wd->items, it);
1048 wd->tot_items_count[wd->level]++;
1049 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1053 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1055 ELM_CHECK_WIDTYPE(obj, widtype);
1056 Widget_Data *wd = elm_widget_data_get(obj);
1061 elm_index_item_append(obj, letter, item);
1062 wd->tot_items_count[wd->level]++;
1065 it = _item_new(obj, letter, item);
1067 wd->items = eina_list_append_relative(wd->items, it, relative);
1068 wd->tot_items_count[wd->level]++;
1069 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1073 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1075 ELM_CHECK_WIDTYPE(obj, widtype);
1076 Widget_Data *wd = elm_widget_data_get(obj);
1081 elm_index_item_prepend(obj, letter, item);
1082 wd->tot_items_count[wd->level]++;
1085 it = _item_new(obj, letter, item);
1088 wd->items = eina_list_prepend_relative(wd->items, it, relative);
1089 wd->tot_items_count[wd->level]++;
1090 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1094 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)
1096 ELM_CHECK_WIDTYPE(obj, widtype);
1097 Widget_Data *wd = elm_widget_data_get(obj);
1105 elm_index_item_append(obj, letter, item);
1109 it = _item_new(obj, letter, item);
1112 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1114 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1116 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1119 /* If cmp_data_func is not provided, append a duplicated item */
1121 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1124 Elm_Index_Item *p_it = eina_list_data_get(lnear);
1125 if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
1126 p_it->base.data = it->base.data;
1127 elm_widget_item_free(it);
1131 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1135 elm_index_item_del(Evas_Object *obj __UNUSED__, Elm_Object_Item *it)
1137 elm_object_item_del(it);
1140 EAPI Elm_Object_Item *
1141 elm_index_item_find(Evas_Object *obj, const void *item)
1143 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1144 Widget_Data *wd = elm_widget_data_get(obj);
1145 if (!wd) return NULL;
1147 return (Elm_Object_Item *) _item_find(obj, item);
1151 elm_index_item_clear(Evas_Object *obj)
1153 ELM_CHECK_WIDTYPE(obj, widtype);
1154 Widget_Data *wd = elm_widget_data_get(obj);
1156 Eina_List *l, *clear = NULL;
1158 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1159 EINA_LIST_FOREACH(wd->items, l, it)
1161 if (it->level != wd->level) continue;
1162 clear = eina_list_append(clear, it);
1164 EINA_LIST_FREE(clear, it)
1166 wd->tot_items_count[wd->level]--;
1167 elm_widget_item_del(it);
1172 elm_index_item_go(Evas_Object *obj, int level)
1174 ELM_CHECK_WIDTYPE(obj, widtype);
1175 Widget_Data *wd = elm_widget_data_get(obj);
1178 _index_process(obj);
1179 _index_box_auto_fill(obj, wd->bx[0], 0);
1180 if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
1184 elm_index_item_data_get(const Elm_Object_Item *it)
1186 return elm_object_item_data_get(it);
1190 elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
1192 ELM_CHECK_WIDTYPE(obj, widtype);
1193 Widget_Data *wd = elm_widget_data_get(obj);
1194 wd->hide_button = invisible;
1196 edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
1201 elm_index_item_data_set(Elm_Object_Item *it, const void *data)
1203 elm_object_item_data_set(it, (void *) data);
1207 elm_index_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1209 elm_object_item_del_cb_set(it, func);
1213 elm_index_item_letter_get(const Elm_Object_Item *it)
1215 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1216 return ((Elm_Index_Item *) it)->letter;