1 #include <Elementary.h>
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.
10 typedef struct _Widget_Data Widget_Data;
12 typedef struct _PlacementPart PlacementPart;
14 typedef struct _Widget_Data Widget_Data;
15 >>>>>>> remotes/origin/upstream
16 typedef struct _Elm_Index_Item Elm_Index_Item;
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
26 int tot_items_count[2];
27 int min_obj_height, max_grp_size;
28 int min_1st_level_obj_height;
31 Evas_Coord pwidth, pheight;
33 const char *special_char;
34 Eina_Bool level_active[2];
35 Eina_Bool horizontal : 1;
40 Eina_Bool level_active[2];
41 Eina_Bool horizontal : 1;
42 Eina_Bool autohide_disabled : 1;
43 >>>>>>> remotes/origin/upstream
45 Eina_Bool indicator_disabled : 1;
48 struct _Elm_Index_Item
52 const char *letter, *vis_letter;
54 Eina_Bool selected : 1;
67 Eina_Bool selected : 1;
70 >>>>>>> remotes/origin/upstream
71 static const char *widtype = NULL;
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);
81 static void _index_process(Evas_Object *obj);
83 >>>>>>> remotes/origin/upstream
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";
91 static const Evas_Smart_Cb_Description _signals[] = {
93 {SIG_DELAY_CHANGED, ""},
101 _del_pre_hook(Evas_Object *obj)
103 Widget_Data *wd = elm_widget_data_get(obj);
106 _index_box_clear(obj, wd->bx[wd->level], wd->level);
107 _index_box_clear(obj, wd->bx[0], 0);
110 it = wd->items->data;
112 elm_widget_item_free(it);
114 if (wd->delay) ecore_timer_del(wd->delay);
118 _del_hook(Evas_Object *obj)
120 Widget_Data *wd = elm_widget_data_get(obj);
125 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
127 Widget_Data *wd = data;
129 _els_box_layout(o, priv, wd->horizontal, 1, 0);
133 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
135 Widget_Data *wd = elm_widget_data_get(obj);
137 edje_object_signal_emit(wd->base, emission, source);
141 _signal_callback_add_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);
145 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
149 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
151 Widget_Data *wd = elm_widget_data_get(obj);
152 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb,
157 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
159 Widget_Data *wd = elm_widget_data_get(obj);
162 edje_object_mirrored_set(wd->base, rtl);
166 _theme_hook(Evas_Object *obj)
168 Evas_Coord minw = 0, minh = 0;
169 Widget_Data *wd = elm_widget_data_get(obj);
171 _elm_widget_mirrored_reload(obj);
173 _index_box_clear(obj, wd->bx[0], 0);
174 _index_box_clear(obj, wd->bx[1], 1);
176 _elm_theme_object_set(obj, wd->base, "index", "base/horizontal", elm_widget_style_get(obj));
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));
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"))
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]);
194 edje_object_part_swallow(wd->base, "elm.swallow.index.1", wd->bx[1]);
195 evas_object_show(wd->bx[1]);
199 evas_object_del(wd->bx[1]);
202 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
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]);
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);
213 else if (wd->event[1])
215 evas_object_del(wd->event[1]);
218 edje_object_message_signal_process(wd->base);
219 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
221 _index_box_auto_fill(obj, wd->bx[0], 0);
225 _index_box_auto_fill(obj, wd->bx[1], 1);
228 if (wd->autohide_disabled)
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");
234 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
235 >>>>>>> remotes/origin/upstream
239 _sizing_eval(Evas_Object *obj)
241 Widget_Data *wd = elm_widget_data_get(obj);
242 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
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);
250 _item_del_pre_hook(Elm_Object_Item *it)
252 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
253 if (!wd) return EINA_FALSE;
255 _item_free((Elm_Index_Item *) it);
257 _item_free((Elm_Index_Item *)it);
258 >>>>>>> remotes/origin/upstream
259 _index_box_clear(WIDGET(it), wd->bx[wd->level], wd->level);
263 static Elm_Index_Item *
265 _item_new(Evas_Object *obj, const char *letter, const void *item)
267 _item_new(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
268 >>>>>>> remotes/origin/upstream
270 Widget_Data *wd = elm_widget_data_get(obj);
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);
277 it->base.data = item;
278 it->level = wd->level;
280 it->size = wd->min_obj_height;
282 it->size = wd->min_1st_level_obj_height;
285 it->letter = eina_stringshare_add(letter);
286 it->vis_letter = eina_stringshare_add(letter);
289 if (letter) it->letter = eina_stringshare_add(letter);
291 it->base.data = data;
292 it->level = wd->level;
293 >>>>>>> remotes/origin/upstream
297 static Elm_Index_Item *
299 _item_find(Evas_Object *obj, const void *item)
301 _item_find(Evas_Object *obj, const void *data)
302 >>>>>>> remotes/origin/upstream
304 Widget_Data *wd = elm_widget_data_get(obj);
307 if (!wd) return NULL;
308 EINA_LIST_FOREACH(wd->items, l, it)
310 if (it->base.data == item) return it;
312 if (it->base.data == data) return it;
313 >>>>>>> remotes/origin/upstream
318 _item_free(Elm_Index_Item *it)
320 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
322 wd->items = eina_list_remove(wd->items, it);
323 if (it->letter) eina_stringshare_del(it->letter);
325 if (it->vis_letter) eina_stringshare_del(it->vis_letter);
327 >>>>>>> remotes/origin/upstream
330 // FIXME: always have index filled
332 _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level)
334 Widget_Data *wd = elm_widget_data_get(obj);
338 Evas_Coord mw, mh, w, h;
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)
347 const char *stacking;
349 if (it->level != level) continue;
350 o = edje_object_add(evas_object_evas_get(obj));
352 edje_object_mirrored_set(VIEW(it), rtl);
355 _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
357 _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
363 _elm_theme_object_set(obj, o, "index", "item_odd/horizontal",
364 elm_widget_style_get(obj));
366 _elm_theme_object_set(obj, o, "index", "item/horizontal",
367 elm_widget_style_get(obj));
372 _elm_theme_object_set(obj, o, "index", "item_odd/vertical",
373 elm_widget_style_get(obj));
375 _elm_theme_object_set(obj, o, "index", "item/vertical",
376 elm_widget_style_get(obj));
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);
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);
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");
397 if (!strcmp(stacking, "below")) evas_object_lower(o);
398 else if (!strcmp(stacking, "above")) evas_object_raise(o);
404 wd->tot_items_count[1] = i;
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);
411 _index_box_clear(obj, box, level);
414 // FIXME: only i objects fit! try again. overflows right now
418 evas_object_smart_calculate(box);
419 wd->level_active[level] = 1;
423 _index_box_clear(Evas_Object *obj, Evas_Object *box __UNUSED__, int level)
425 Widget_Data *wd = elm_widget_data_get(obj);
429 if (!wd->level_active[level]) return;
430 EINA_LIST_FOREACH(wd->items, l, it)
432 if (!VIEW(it)) continue;
433 if (it->level != level) continue;
434 evas_object_del(VIEW(it));
437 wd->level_active[level] = 0;
441 _delay_change(void *data)
443 Widget_Data *wd = elm_widget_data_get(data);
444 Elm_Object_Item *item;
445 if (!wd) return ECORE_CALLBACK_CANCEL;
448 item = elm_index_item_selected_get(data, wd->level);
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;
457 _sel_eval(Evas_Object *obj, Evas_Coord evx, Evas_Coord evy)
459 Widget_Data *wd = elm_widget_data_get(obj);
460 Elm_Index_Item *it, *it_closest, *it_last;
462 Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
468 >>>>>>> remotes/origin/upstream
470 char *label = NULL, *last = NULL;
473 for (i = 0; i <= wd->level; i++)
478 evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
481 dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
482 dmax = 1.0-dmin-0.08;
484 >>>>>>> remotes/origin/upstream
485 EINA_LIST_FOREACH(wd->items, l, it)
487 if (!((it->level == i) && (VIEW(it)))) continue;
488 if ((VIEW(it)) && (it->level != wd->level))
502 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
507 x = (x * x) + (y * y);
508 if ((x < dist) || (!it_closest))
511 cdv = (double)(xx - bx) / (double)bw;
513 cdv = (double)(yy - by) / (double)bh;
518 if ((i == 0) && (wd->level == 0))
519 edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
521 if (it_closest) it_closest->selected = 1;
522 if (it_closest != it_last)
526 const char *stacking, *selectraise;
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")))
534 if ((stacking) && (!strcmp(stacking, "below")))
535 evas_object_lower(VIEW(it));
540 const char *selectraise;
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);
556 last = strdup(it->letter);
559 if (!label) label = strdup(last);
562 /* FIXME: realloc return NULL if the request fails */
563 label = realloc(label, strlen(label) + strlen(last) + 1);
567 last = strdup(it->letter);
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);
576 edje_object_signal_emit(wd->base, "hide_2nd_level", "");
578 >>>>>>> remotes/origin/upstream
584 _wheel(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
586 Widget_Data *wd = elm_widget_data_get(data);
587 // Evas_Event_Mouse_Wheel *ev = event_info;
588 // Evas_Object *obj = o;
593 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
595 Widget_Data *wd = elm_widget_data_get(data);
596 Evas_Event_Mouse_Down *ev = event_info;
599 if (ev->button != 1) return;
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;
605 elm_index_active_set(data, 1);
607 if (!wd->autohide_disabled)
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");
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");
622 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
624 Widget_Data *wd = elm_widget_data_get(data);
625 Evas_Event_Mouse_Up *ev = event_info;
626 Elm_Object_Item *item;
629 if (ev->button != 1) return;
630 if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
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);
637 Elm_Index_Item *id_item;
639 if (ev->button != 1) return;
641 item = elm_index_selected_item_get(data, wd->level);
644 evas_object_smart_callback_call(data, SIG_SELECTED, item);
645 id_item = (Elm_Index_Item *)item;
647 id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
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");
658 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
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;
664 Elm_Object_Item *item;
666 >>>>>>> remotes/origin/upstream
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;
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);
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);
696 snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
697 edje_object_signal_emit(wd->base, buf, "elm");
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);
704 >>>>>>> remotes/origin/upstream
705 evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
709 _sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
714 _index_box_refill_job(void *data)
716 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
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;
726 wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
727 wd->items_count = ph/wd->min_obj_height;
729 if(pw != wd->pwidth && ph != wd->pheight)
734 elm_index_active_set(data, 1);
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);
744 static void _index_object_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
748 wd = elm_widget_data_get((Evas_Object *)data);
750 ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
754 >>>>>>> remotes/origin/upstream
756 elm_index_add(Evas_Object *parent)
762 Evas_Coord minw, minh;
764 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
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);
778 wd->indicator_disabled = EINA_FALSE;
779 wd->horizontal = EINA_FALSE;
781 wd->min_obj_height = 0;
782 wd->max_grp_size = 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("*");
789 wd->autohide_disabled = EINA_FALSE;
790 >>>>>>> remotes/origin/upstream
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);
796 o = evas_object_rectangle_add(e);
798 evas_object_color_set(o, 0, 0, 0, 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);
805 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
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);
813 if (edje_object_part_exists(wd->base, "elm.swallow.event.1"))
815 o = evas_object_rectangle_add(e);
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);
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]);
829 if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
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]);
838 evas_object_smart_callbacks_descriptions_set(obj, _signals);
840 wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT;
842 >>>>>>> remotes/origin/upstream
844 _mirrored_set(obj, elm_widget_mirrored_get(obj));
851 _group_count(Evas_Object *obj, int extraIndex, int adj_pos)
853 Widget_Data *wd = elm_widget_data_get(obj);
855 int group_count = MIN_GRP_SIZE;
856 while(group_count <= wd->max_grp_size)
858 if(extraIndex <= wd->max_grp_size*adj_pos)
860 if(group_count*adj_pos>=extraIndex) return group_count;
863 return wd->max_grp_size;
865 group_count += MIN_GRP_SIZE;
871 _index_process(Evas_Object *obj)
874 int j,i, group_count;
880 Widget_Data *wd = elm_widget_data_get(obj);
883 if (wd->items_count == 0) return;
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;
889 int *indx = (int*)calloc(n, sizeof(int));
892 const int minh = wd->min_obj_height;
893 EINA_LIST_FOREACH(wd->items, l, it)
895 it->vis_letter = eina_stringshare_add(it->letter);
900 int N = wd->items_count;
914 group_count = _group_count(obj, extraIndex, adj_pos);
915 if (group_count <= 0)
923 PlacementPart place[adj_pos];
924 remainder = extraIndex%group_count;
925 numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
927 for (i=0;i<numberofparts; i++)
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;
934 place[numberofparts-1].count=remainder+1;
936 for (i=0;i<numberofparts;i++)
938 for (j=0;j<place[i].count; j++)
940 indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
942 indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
945 EINA_LIST_FOREACH(wd->items, l, it)
947 int size = indx[count];
951 it->vis_letter = eina_stringshare_add(it->letter);
956 eina_stringshare_del(it->vis_letter);
957 it->vis_letter = eina_stringshare_add("");
961 eina_stringshare_del(it->vis_letter);
962 it->vis_letter = eina_stringshare_add(wd->special_char);
974 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
976 EINA_DEPRECATED EAPI void
977 elm_index_active_set(Evas_Object *obj, Eina_Bool active)
979 elm_index_autohide_disabled_set(obj, !active);
982 EINA_DEPRECATED EAPI Eina_Bool
983 elm_index_active_get(const Evas_Object *obj)
985 return !elm_index_autohide_disabled_get(obj);
989 elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
990 >>>>>>> remotes/origin/upstream
992 ELM_CHECK_WIDTYPE(obj, widtype);
993 Widget_Data *wd = elm_widget_data_get(obj);
996 if (wd->active == active) return;
1001 _index_box_clear(obj, wd->bx[1], 1);
1002 _index_process(obj);
1004 disabled = !!disabled;
1005 if (wd->autohide_disabled == disabled) return;
1006 wd->autohide_disabled = disabled;
1008 if (wd->autohide_disabled)
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");
1016 edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
1021 elm_index_active_get(const Evas_Object *obj)
1024 //FIXME: Should be update indicator based on the indicator visiblility
1028 elm_index_autohide_disabled_get(const Evas_Object *obj)
1029 >>>>>>> remotes/origin/upstream
1031 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1032 Widget_Data *wd = elm_widget_data_get(obj);
1033 if (!wd) return EINA_FALSE;
1037 return wd->autohide_disabled;
1038 >>>>>>> remotes/origin/upstream
1042 elm_index_item_level_set(Evas_Object *obj, int level)
1044 ELM_CHECK_WIDTYPE(obj, widtype);
1045 Widget_Data *wd = elm_widget_data_get(obj);
1047 if (wd->level == level) return;
1052 elm_index_item_level_get(const Evas_Object *obj)
1054 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1055 Widget_Data *wd = elm_widget_data_get(obj);
1061 EAPI Elm_Object_Item *
1062 elm_index_item_selected_get(const Evas_Object *obj, int level)
1066 elm_index_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
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));
1073 //FIXME: Should be update indicator based on the autohidden status & indicator visiblility
1077 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1078 _sel_eval(WIDGET(it), x + (w/2), y + (h/2));
1081 _sel_eval(WIDGET(it), -99999, -9999);
1085 EINA_DEPRECATED EAPI Elm_Object_Item *
1086 elm_index_item_selected_get(const Evas_Object *obj, int level)
1088 return elm_index_selected_item_get(obj, level);
1091 EAPI Elm_Object_Item *
1092 elm_index_selected_item_get(const Evas_Object *obj, int level)
1094 >>>>>>> remotes/origin/upstream
1095 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1096 Widget_Data *wd = elm_widget_data_get(obj);
1099 if (!wd) return NULL;
1100 EINA_LIST_FOREACH(wd->items, l, it)
1102 if ((it->selected) && (it->level == level))
1104 return (Elm_Object_Item *) it;
1106 return (Elm_Object_Item *)it;
1107 >>>>>>> remotes/origin/upstream
1114 elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
1116 ELM_CHECK_WIDTYPE(obj, widtype);
1117 Widget_Data *wd = elm_widget_data_get(obj);
1120 it = _item_new(obj, letter, item);
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);
1128 elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
1130 ELM_CHECK_WIDTYPE(obj, widtype);
1131 Widget_Data *wd = elm_widget_data_get(obj);
1135 it = _item_new(obj, letter, item);
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);
1143 elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1145 ELM_CHECK_WIDTYPE(obj, widtype);
1146 Widget_Data *wd = elm_widget_data_get(obj);
1151 elm_index_item_append(obj, letter, item);
1152 wd->tot_items_count[wd->level]++;
1155 it = _item_new(obj, letter, item);
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);
1163 elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
1165 ELM_CHECK_WIDTYPE(obj, widtype);
1166 Widget_Data *wd = elm_widget_data_get(obj);
1171 elm_index_item_prepend(obj, letter, item);
1172 wd->tot_items_count[wd->level]++;
1175 it = _item_new(obj, letter, item);
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);
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)
1185 ELM_CHECK_WIDTYPE(obj, widtype);
1187 EAPI Elm_Object_Item *
1188 elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
1190 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1191 Widget_Data *wd = elm_widget_data_get(obj);
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;
1201 EAPI Elm_Object_Item *
1202 elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
1204 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1205 Widget_Data *wd = elm_widget_data_get(obj);
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;
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)
1219 return elm_index_item_insert_after(obj, (Elm_Object_Item *) relative, letter, NULL, item);
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)
1225 return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
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)
1231 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232 Widget_Data *wd = elm_widget_data_get(obj);
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;
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)
1246 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1247 Widget_Data *wd = elm_widget_data_get(obj);
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;
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)
1261 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1262 >>>>>>> remotes/origin/upstream
1263 Widget_Data *wd = elm_widget_data_get(obj);
1272 elm_index_item_append(obj, letter, item);
1276 it = _item_new(obj, letter, item);
1279 if (!wd) return NULL;
1281 return elm_index_item_append(obj, letter, func, data);
1283 it = _item_new(obj, letter, func, data);
1284 if (!it) return NULL;
1285 >>>>>>> remotes/origin/upstream
1287 lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
1289 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
1291 wd->items = eina_list_prepend_relative_list(wd->items, it, lnear);
1294 /* If cmp_data_func is not provided, append a duplicated item */
1296 wd->items = eina_list_append_relative_list(wd->items, it, lnear);
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;
1303 elm_widget_item_free(it);
1308 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1310 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1311 return (Elm_Object_Item *)it;
1312 >>>>>>> remotes/origin/upstream
1316 elm_index_item_del(Evas_Object *obj __UNUSED__, Elm_Object_Item *it)
1318 elm_object_item_del(it);
1321 EAPI Elm_Object_Item *
1323 elm_index_item_find(Evas_Object *obj, const void *item)
1325 elm_index_item_find(Evas_Object *obj, const void *data)
1326 >>>>>>> remotes/origin/upstream
1328 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1329 Widget_Data *wd = elm_widget_data_get(obj);
1330 if (!wd) return NULL;
1332 return (Elm_Object_Item *) _item_find(obj, item);
1334 return (Elm_Object_Item *) _item_find(obj, data);
1335 >>>>>>> remotes/origin/upstream
1339 elm_index_item_clear(Evas_Object *obj)
1341 ELM_CHECK_WIDTYPE(obj, widtype);
1342 Widget_Data *wd = elm_widget_data_get(obj);
1344 Eina_List *l, *clear = NULL;
1346 _index_box_clear(obj, wd->bx[wd->level], wd->level);
1347 EINA_LIST_FOREACH(wd->items, l, it)
1349 if (it->level != wd->level) continue;
1350 clear = eina_list_append(clear, it);
1352 EINA_LIST_FREE(clear, it)
1355 wd->tot_items_count[wd->level]--;
1357 >>>>>>> remotes/origin/upstream
1359 elm_widget_item_free(it);
1365 elm_index_item_go(Evas_Object *obj, int level)
1367 EINA_DEPRECATED EAPI void
1368 elm_index_item_go(Evas_Object *obj, int level __UNUSED__)
1370 elm_index_level_go(obj, level);
1374 elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
1375 >>>>>>> remotes/origin/upstream
1377 ELM_CHECK_WIDTYPE(obj, widtype);
1378 Widget_Data *wd = elm_widget_data_get(obj);
1381 if(level == 0) _index_process(obj);
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);
1389 elm_index_item_data_get(const Elm_Object_Item *it)
1391 return elm_object_item_data_get(it);
1395 elm_index_item_data_set(Elm_Object_Item *it, const void *data)
1397 elm_object_item_data_set(it, (void *) data);
1401 elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
1403 ELM_CHECK_WIDTYPE(obj, widtype);
1404 Widget_Data *wd = elm_widget_data_get(obj);
1407 disabled = !!disabled;
1408 if (wd->indicator_disabled == disabled) return;
1409 wd->indicator_disabled = disabled;
1410 if (!wd->items) return;
1412 edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
1414 edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
1418 elm_index_indicator_disabled_get(const Evas_Object *obj)
1420 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1421 Widget_Data *wd = elm_widget_data_get(obj);
1422 if (!wd) return EINA_FALSE;
1424 return wd->indicator_disabled;
1428 elm_index_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1430 elm_object_item_del_cb_set(it, func);
1434 elm_index_item_letter_get(const Elm_Object_Item *it)
1436 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1438 return ((Elm_Index_Item *) it)->letter;
1442 return ((Elm_Index_Item *)it)->letter;
1446 elm_index_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1448 ELM_CHECK_WIDTYPE(obj, widtype);
1449 Widget_Data *wd = elm_widget_data_get(obj);
1452 horizontal = !!horizontal;
1453 if (horizontal == wd->horizontal) return;
1454 wd->horizontal = horizontal;
1459 elm_index_horizontal_get(const Evas_Object *obj)
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;
1468 >>>>>>> remotes/origin/upstream