-/*
- * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
- */
#include <Elementary.h>
#include "elm_priv.h"
-
-/**
- * @defgroup Index Index
- * @ingroup Elementary
- *
- * An index object is a type of list that categorizes items in it
- * by letter.
- *
- * Signals that you can add callbacks for are:
- *
- * "changed" - when the selected index item changes
- * "delay,changed" - when the selected index item changes, but after some small i
- * dle period
- * "selected" - when the user releases a finger and selects an item
- * "level,up" - when the user moves a finger from the first level to the second
- * level
- * "level,down" - when the user moves a finger from the second level to the first
- * level
- */
-
-#define MIN_GRP_SIZE 2 //for symmetry it is 2, otherwise it can be 1 and zero have no meaning.
-#define MIN_PIXEL_VALUE 1 //Min pixel value is highly dependent on touch sensitivity support.
-#define MIN_OBJ_HEIGHT 24 //should be taken from .edc file.
-/*
- * use for find view toplevel
- */
-#define SET_VIEW_LEVEL(wd, view_level)\
- view_level = wd->level;\
- while ((!wd->tot_items_count[view_level]) && view_level)\
- {\
- view_level--; \
- }
+#include "els_box.h"
typedef struct _Widget_Data Widget_Data;
-
-typedef struct _PlacementPart PlacementPart;
+typedef struct _Elm_Index_Item Elm_Index_Item;
struct _Widget_Data
{
Evas_Object *event[2];
Evas_Object *bx[2]; // 2 - for now all that's supported
Eina_List *items; // 1 list. yes N levels, but only 2 for now and # of items will be small
- char *popup_str[2];
int level;
- int max_supp_items_count;
- int tot_items_count[2];
- int min_obj_height, max_grp_size;
- int min_1st_level_obj_height;
- int items_count;
Evas_Coord dx, dy;
- Evas_Coord pwidth, pheight;
Ecore_Timer *delay;
- const char *special_char;
Eina_Bool level_active[2];
Eina_Bool horizontal : 1;
- Eina_Bool active : 1;
+ Eina_Bool autohide_disabled : 1;
Eina_Bool down : 1;
- Eina_Bool hide_button : 1;
- double scale_factor;
+ Eina_Bool indicator_disabled : 1;
};
struct _Elm_Index_Item
{
- Elm_Widget_Item base;
- const char *letter, *vis_letter;
- int level, size;
+ ELM_WIDGET_ITEM;
+ const char *letter;
+ int level;
+ Evas_Smart_Cb func;
Eina_Bool selected : 1;
};
-struct _PlacementPart
-{
- int start;
- int count;
-};
-
static const char *widtype = NULL;
static void _del_hook(Evas_Object *obj);
static void _index_box_auto_fill(Evas_Object *obj, Evas_Object *box, int level);
static void _index_box_clear(Evas_Object *obj, Evas_Object *box, int level);
static void _item_free(Elm_Index_Item *it);
-static void _index_process(Evas_Object *obj);
static const char SIG_CHANGED[] = "changed";
static const char SIG_DELAY_CHANGED[] = "delay,changed";
{SIG_LEVEL_DOWN, ""},
{NULL, NULL}
};
-/* Free a block allocated by `malloc', `realloc' or `calloc' one by one*/
+
static void
_del_pre_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
+ Elm_Index_Item *it;
if (!wd) return;
_index_box_clear(obj, wd->bx[wd->level], wd->level);
_index_box_clear(obj, wd->bx[0], 0);
- while (wd->items) _item_free(wd->items->data);
+ while (wd->items)
+ {
+ it = wd->items->data;
+ _item_free(it);
+ elm_widget_item_free(it);
+ }
if (wd->delay) ecore_timer_del(wd->delay);
-
- if(wd->popup_str[0]) free(wd->popup_str[0]);
- if(wd->popup_str[1]) free(wd->popup_str[1]);
}
static void
{
Widget_Data *wd = data;
if (!wd) return;
- _els_box_layout(o, priv, wd->horizontal, 0, 0);
+ _els_box_layout(o, priv, wd->horizontal, 1, 0);
}
static void
edje_object_part_swallow(wd->base, "elm.swallow.event.0", wd->event[0]);
elm_coords_finger_size_adjust(1, &minw, 1, &minh);
evas_object_size_hint_min_set(wd->event[0], minw, minh);
-
edje_object_part_swallow(wd->base, "elm.swallow.index.0", wd->bx[0]);
if (edje_object_part_exists(wd->base, "elm.swallow.index.1"))
{
edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
_sizing_eval(obj);
_index_box_auto_fill(obj, wd->bx[0], 0);
- if (wd->active)
- if (wd->level == 1)
- _index_box_auto_fill(obj, wd->bx[1], 1);
+
+ if (wd->autohide_disabled)
+ {
+ if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
+ edje_object_signal_emit(wd->base, "elm,state,active", "elm");
+ }
+ else
+ edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
}
static void
evas_object_size_hint_max_set(obj, maxw, maxh);
}
+static Eina_Bool
+_item_del_pre_hook(Elm_Object_Item *it)
+{
+ Widget_Data *wd = elm_widget_data_get(WIDGET(it));
+ if (!wd) return EINA_FALSE;
+ _item_free((Elm_Index_Item *)it);
+ _index_box_clear(WIDGET(it), wd->bx[wd->level], wd->level);
+ return EINA_TRUE;
+}
+
static Elm_Index_Item *
-_item_new(Evas_Object *obj, const char *letter, const void *item)
+_item_new(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
Elm_Index_Item *it;
if (!wd) return NULL;
it = elm_widget_item_new(obj, Elm_Index_Item);
if (!it) return NULL;
- it->base.data = item;
+ elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
+ if (letter) it->letter = eina_stringshare_add(letter);
+ it->func = func;
+ it->base.data = data;
it->level = wd->level;
- if(wd->level == 0)
- it->size = wd->min_obj_height;
- else
- it->size = wd->min_1st_level_obj_height;
- if(letter)
- {
- it->letter = eina_stringshare_add(letter);
- it->vis_letter = eina_stringshare_add(letter);
- }
- else
- {
- _item_free(it);
- return NULL;
- }
return it;
}
static Elm_Index_Item *
-_item_find(Evas_Object *obj, const void *item)
+_item_find(Evas_Object *obj, const void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
Eina_List *l;
Elm_Index_Item *it;
if (!wd) return NULL;
EINA_LIST_FOREACH(wd->items, l, it)
- if (it->base.data == item) return it;
+ if (it->base.data == data) return it;
return NULL;
}
static void
_item_free(Elm_Index_Item *it)
{
-/* Automatically filling the box with index item*/
- Widget_Data *wd = elm_widget_data_get(it->base.widget);
+ Widget_Data *wd = elm_widget_data_get(WIDGET(it));
if (!wd) return;
-
wd->items = eina_list_remove(wd->items, it);
- elm_widget_item_pre_notify_del(it);
- eina_stringshare_del(it->letter);
- eina_stringshare_del(it->vis_letter);
- elm_widget_item_del(it);
+ if (it->letter) eina_stringshare_del(it->letter);
}
// FIXME: always have index filled
const char *stacking;
if (it->level != level) continue;
- if(i > wd->max_supp_items_count) break;
+
+//FIXME: Need to check. This cause one less items show up.
+// if(i > wd->max_supp_items_count) break;
o = edje_object_add(evas_object_evas_get(obj));
- it->base.view = o;
- edje_object_mirrored_set(it->base.view, rtl);
- if (i & 0x1)
- _elm_theme_object_set(obj, o, "index", "item_odd/vertical", elm_widget_style_get(obj));
+ VIEW(it) = o;
+ edje_object_mirrored_set(VIEW(it), rtl);
+
+ if (wd->horizontal)
+ {
+ if (i & 0x1)
+ _elm_theme_object_set(obj, o, "index", "item_odd/horizontal",
+ elm_widget_style_get(obj));
+ else
+ _elm_theme_object_set(obj, o, "index", "item/horizontal",
+ elm_widget_style_get(obj));
+ }
else
- _elm_theme_object_set(obj, o, "index", "item/vertical", elm_widget_style_get(obj));
- edje_object_part_text_set(o, "elm.text", it->letter);
+ {
+ if (i & 0x1)
+ _elm_theme_object_set(obj, o, "index", "item_odd/vertical",
+ elm_widget_style_get(obj));
+ else
+ _elm_theme_object_set(obj, o, "index", "item/vertical",
+ elm_widget_style_get(obj));
+ }
+
+ edje_object_part_text_escaped_set(o, "elm.text", it->letter);
edje_object_size_min_restricted_calc(o, &mw, &mh, 0, 0);
evas_object_size_hint_min_set(o, mw, mh);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
- edje_object_part_text_set(o, "elm.text", it->vis_letter);
- evas_object_size_hint_min_set(o, mw, it->size);
- evas_object_size_hint_max_set(o, mw, it->size);
- evas_object_resize(o, mw, it->size);
-
elm_widget_sub_object_add(obj, o);
evas_object_box_append(box, o);
stacking = edje_object_data_get(o, "stacking");
}
evas_object_show(o);
i++;
- if(level == 1)
- wd->tot_items_count[1] = i;
evas_object_smart_calculate(box); // force a calc so we know the size
evas_object_size_hint_min_get(box, &mw, &mh);
if (mh > h)
if (!wd->level_active[level]) return;
EINA_LIST_FOREACH(wd->items, l, it)
{
- if (!it->base.view) continue;
+ if (!VIEW(it)) continue;
if (it->level != level) continue;
- evas_object_del(it->base.view);
- it->base.view = NULL;
+ evas_object_del(VIEW(it));
+ VIEW(it) = NULL;
}
wd->level_active[level] = 0;
}
_delay_change(void *data)
{
Widget_Data *wd = elm_widget_data_get(data);
- void *d;
- int view_level;
+ Elm_Object_Item *item;
if (!wd) return ECORE_CALLBACK_CANCEL;
wd->delay = NULL;
- SET_VIEW_LEVEL(wd, view_level);
- d = (void *)elm_index_item_selected_get(data, view_level);
- if (d) evas_object_smart_callback_call(data, "delay,changed", d);
+ item = elm_index_selected_item_get(data, wd->level);
+ if (item) evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, item);
return ECORE_CALLBACK_CANCEL;
}
Eina_List *l;
Evas_Coord x, y, w, h, bx, by, bw, bh, xx, yy;
double cdv = 0.5;
- double cdvv = 0.0;
- double dmax = 0.0;
- double dmin = 0.0;
Evas_Coord dist;
- Eina_Bool change = EINA_FALSE;
char *label = NULL, *last = NULL;
int i;
- int view_level;
if (!wd) return;
-
- SET_VIEW_LEVEL(wd, view_level);
- for (i = 0; i <= view_level; i++)
+ for (i = 0; i <= wd->level; i++)
{
it_last = NULL;
it_closest = NULL;
dist = 0x7fffffff;
evas_object_geometry_get(wd->bx[i], &bx, &by, &bw, &bh);
- dmin = (double)(wd->min_1st_level_obj_height*wd->tot_items_count[1])/(2*(double)bh);
- dmax = 1.0-dmin-0.08;
EINA_LIST_FOREACH(wd->items, l, it)
{
- if (!((it->level == i) && (it->base.view))) continue;
+ if (it->level != i) continue;
+ if (it->level != wd->level)
+ {
+ if (it->selected)
+ {
+ it_closest = it;
+ break;
+ }
+ continue;
+ }
if (it->selected)
{
it_last = it;
it->selected = 0;
}
- evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
+ evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
xx = x + (w / 2);
yy = y + (h / 2);
x = evx - xx;
dist = x;
}
}
- if ((i == 0) && (view_level == 0))
- {
- if(cdv > dmax || cdv < dmin)
- {
- if(cdv > dmax)
- {
- cdvv = dmax;
- }
- else
- {
- cdvv = dmin;
- }
- edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdvv);
- }
- else
- {
- edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1", cdv, cdv);
- }
- }
+ if ((i == 0) && (wd->level == 0))
+ edje_object_part_drag_value_set(wd->base, "elm.dragable.index.1",
+ cdv, cdv);
if (it_closest) it_closest->selected = 1;
if (it_closest != it_last)
{
- change = 1;
if (it_last)
{
const char *stacking, *selectraise;
it = it_last;
- if(view_level == it->level)
- edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
- stacking = edje_object_data_get(it->base.view, "stacking");
- selectraise = edje_object_data_get(it->base.view, "selectraise");
+ edje_object_signal_emit(VIEW(it), "elm,state,inactive", "elm");
+ stacking = edje_object_data_get(VIEW(it), "stacking");
+ selectraise = edje_object_data_get(VIEW(it), "selectraise");
if ((selectraise) && (!strcmp(selectraise, "on")))
{
if ((stacking) && (!strcmp(stacking, "below")))
- evas_object_lower(it->base.view);
+ evas_object_lower(VIEW(it));
}
}
if (it_closest)
const char *selectraise;
it = it_closest;
- if(view_level == it->level)
- edje_object_signal_emit(it->base.view, "elm,state,active", "elm");
- selectraise = edje_object_data_get(it->base.view, "selectraise");
+ edje_object_signal_emit(VIEW(it), "elm,state,active", "elm");
+ selectraise = edje_object_data_get(VIEW(it), "selectraise");
if ((selectraise) && (!strcmp(selectraise, "on")))
- evas_object_raise(it->base.view);
- evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it->base.data);
+ evas_object_raise(VIEW(it));
+ evas_object_smart_callback_call((void *)obj, SIG_CHANGED, (void *)it);
if (wd->delay) ecore_timer_del(wd->delay);
wd->delay = ecore_timer_add(0.2, _delay_change, obj);
}
if (it_closest)
{
it = it_closest;
- if (!last)
+ if (!last && it->letter)
last = strdup(it->letter);
else
{
- if (!label) label = strdup(last);
+ if (!label && last) label = strdup(last);
else
{
- /* FIXME: realloc return NULL if the request fails */
- label = realloc(label, strlen(label) + strlen(last) + 1);
- strcat(label, last);
+ if (label && last)
+ {
+ label = realloc(label, strlen(label) +
+ strlen(last) + 1);
+ if (!label) return;
+ strcat(label, last);
+ }
}
free(last);
- last = strdup(it->letter);
+ if (it->letter) last = strdup(it->letter);
}
}
}
if (!label) label = strdup("");
if (!last) last = strdup("");
- if(!wd->hide_button)
- {
- char *popup_text;
-
- if(view_level == 0)
- {
- if (wd->popup_str[1]) wd->popup_str[1][0] = '\0';
- wd->popup_str[0] = (char *)realloc(wd->popup_str[0], (sizeof(char) * strlen(last) + 1));
-
- strcpy(wd->popup_str[0], last);
- edje_object_signal_emit(wd->base, "hide_2nd_level", "");
- }
- if (view_level == 1 && wd->level_active[1])
- {
- wd->popup_str[1] = (char *)realloc(wd->popup_str[1], (sizeof(char) * strlen(last) + 1));
-
- strcpy(wd->popup_str[1], last);
- edje_object_signal_emit(wd->base, "hide_first_level", "");
- }
- popup_text = (char *)malloc(sizeof(char) * (strlen(wd->popup_str[0]) + strlen(wd->popup_str[1]) + 1));
- sprintf(popup_text, "%s%s", wd->popup_str[0], wd->popup_str[1]);
- edje_object_part_text_set(wd->base, "elm.text", popup_text);
-
- free(popup_text);
- }
-
- if(label)
- free(label);
- if(last)
- free(last);
+ edje_object_part_text_escaped_set(wd->base, "elm.text.body", label);
+ edje_object_part_text_escaped_set(wd->base, "elm.text", last);
+ free(label);
+ free(last);
}
static void
evas_object_geometry_get(wd->base, &x, &y, &w, NULL);
wd->dx = ev->canvas.x - x;
wd->dy = ev->canvas.y - y;
- elm_index_active_set(data, 1);
+ if (!wd->autohide_disabled)
+ {
+ _index_box_clear(data, wd->bx[1], 1);
+ _index_box_auto_fill(data, wd->bx[0], 0);
+ edje_object_signal_emit(wd->base, "elm,state,active", "elm");
+ }
_sel_eval(data, ev->canvas.x, ev->canvas.y);
edje_object_part_drag_value_set(wd->base, "elm.dragable.pointer",
(!edje_object_mirrored_get(wd->base)) ? wd->dx : (wd->dx - w), wd->dy);
+ if (wd->items && !wd->indicator_disabled)
+ edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
}
static void
{
Widget_Data *wd = elm_widget_data_get(data);
Evas_Event_Mouse_Up *ev = event_info;
- void *d;
- Elm_Index_Item *it;
- Eina_List *l;
- int view_level;
-
+ Elm_Object_Item *item;
+ Elm_Index_Item *id_item;
if (!wd) return;
if (ev->button != 1) return;
- if (wd->level == 1 && wd->delay) ecore_timer_del(wd->delay);
- wd->delay = NULL;
wd->down = 0;
- SET_VIEW_LEVEL(wd, view_level);
- d = (void *)elm_index_item_selected_get(data, view_level);
- EINA_LIST_FOREACH(wd->items, l, it)
+ item = elm_index_selected_item_get(data, wd->level);
+ if (item)
{
- edje_object_signal_emit(it->base.view, "elm,state,inactive", "elm");
+ evas_object_smart_callback_call(data, SIG_SELECTED, item);
+ id_item = (Elm_Index_Item *)item;
+ if (id_item->func)
+ id_item->func((void *)id_item->base.data, WIDGET(id_item), id_item);
}
- if (d) evas_object_smart_callback_call(data, SIG_SELECTED, d);
- elm_index_active_set(data, 0);
+ if (!wd->autohide_disabled)
+ edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
edje_object_signal_emit(wd->base, "elm,state,level,0", "elm");
+ if (wd->items && !wd->indicator_disabled)
+ edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
}
static void
Widget_Data *wd = elm_widget_data_get(data);
Evas_Event_Mouse_Move *ev = event_info;
Evas_Coord minw = 0, minh = 0, x, y, dx, adx, w;
- void *d;
char buf[1024];
if (!wd) return;
if (!wd->down) return;
wd->level = 0;
snprintf(buf, sizeof(buf), "elm,state,level,%i", wd->level);
edje_object_signal_emit(wd->base, buf, "elm");
- d = (void *)elm_index_item_selected_get(data, wd->level);
- evas_object_smart_callback_call(data, "changed", d);
- if (wd->delay) ecore_timer_del(wd->delay);
- wd->delay = ecore_timer_add(0.2, _delay_change, data);
evas_object_smart_callback_call(data, SIG_LEVEL_DOWN, NULL);
}
}
_sel_eval(data, ev->cur.canvas.x, ev->cur.canvas.y);
}
-static void
-_index_box_refill_job(void *data)
-{
- Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
- if (!wd) return;
-
- const char *string;
- Evas_Coord pw, ph;
-
- evas_object_geometry_get(wd->base, NULL, NULL, &pw, &ph);
- wd->scale_factor = elm_scale_get();
- if ( wd->scale_factor == 0.0 ) {
- wd->scale_factor = 1.0;
- }
- string = edje_object_data_get(wd->base, "min_obj_height");
- if(string)
- wd->min_obj_height = (int) (atoi(string))*wd->scale_factor;
- else
- wd->min_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
- if(!wd->min_obj_height) return;
-
- wd->max_grp_size = wd->min_obj_height - 2*MIN_GRP_SIZE;
- wd->items_count = ph/wd->min_obj_height;
- wd->max_supp_items_count = wd->max_grp_size*(int)((wd->items_count-1)*0.5)+wd->items_count;
-
- if(pw != wd->pwidth && ph != wd->pheight)
- {
- if(wd->down == 1)
- {
- wd->active = 0;
- elm_index_active_set(data, 1);
- }
- _index_box_clear((Evas_Object *)data, wd->bx[0], 0);
- evas_object_smart_calculate( wd->bx[0]);
- elm_index_item_go((Evas_Object *)data, wd->level);
- wd->pwidth = pw;
- wd->pheight = ph;
- }
-}
-
-static void _index_object_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
- Widget_Data *wd;
- if(!data) return;
- wd = elm_widget_data_get((Evas_Object *)data);
- if(!wd) return;
- ecore_job_add(_index_box_refill_job, (Evas_Object *)data);
-}
-
-/**
- * Add a new index to the parent
- *
- * @param parent The parent object
- * @return The new object or NULL if it cannot be created
- *
- * @ingroup Index
- */
EAPI Evas_Object *
elm_index_add(Evas_Object *parent)
{
Evas *e;
Widget_Data *wd;
Evas_Coord minw, minh;
- const char *string;
-
+
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
ELM_SET_WIDTYPE(widtype, "index");
elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
elm_widget_can_focus_set(obj, EINA_FALSE);
+ wd->indicator_disabled = EINA_FALSE;
wd->horizontal = EINA_FALSE;
- wd->min_obj_height = 0;
- wd->max_grp_size = 0;
- wd->items_count = 0;
- wd->max_supp_items_count = 0;
- wd->tot_items_count[0] = 0;
- wd->tot_items_count[1] = 0;
- wd->hide_button = 0;
- wd->special_char = edje_object_data_get(wd->base, "special_char");
- if(wd->special_char == NULL) wd->special_char = eina_stringshare_add("*");
+ wd->autohide_disabled = EINA_FALSE;
wd->base = edje_object_add(e);
_elm_theme_object_set(obj, wd->base, "index", "base/vertical", "default");
evas_object_size_hint_min_set(o, minw, minh);
edje_object_part_swallow(wd->base, "elm.swallow.event.0", o);
elm_widget_sub_object_add(obj, o);
- evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _index_object_resize, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _wheel, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
}
evas_object_smart_callbacks_descriptions_set(obj, _signals);
- wd->scale_factor = elm_scale_get();
- if ( wd->scale_factor == 0.0 )
- wd->scale_factor = 1.0;
- string = edje_object_data_get(wd->base, "min_1st_level_obj_height");
- if(string)
- wd->min_1st_level_obj_height = (int) (atoi(string))*wd->scale_factor;
- else
- wd->min_1st_level_obj_height = MIN_OBJ_HEIGHT*wd->scale_factor;
- wd->popup_str[0] = calloc(1, sizeof(char) * 1);
- wd->popup_str[1] = calloc(1, sizeof(char) * 1);
_mirrored_set(obj, elm_widget_mirrored_get(obj));
_sizing_eval(obj);
return obj;
}
-static int
-_group_count(Evas_Object *obj, int extraIndex, int adj_pos, int vis_pos)
-{
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return 0;
- int group_count = MIN_GRP_SIZE;
- while(group_count <= wd->max_grp_size)
- {
- if(extraIndex <= wd->max_grp_size*adj_pos)
- {
- if(group_count*adj_pos>=extraIndex) return group_count;
- }
- else
- return wd->max_grp_size;
-
- group_count += MIN_GRP_SIZE;
- }
- return group_count;
-}
-
-static void
-_index_process(Evas_Object *obj)
-{
- int extraIndex;
- int j,i, group_count;
- Eina_List *l;
- Elm_Index_Item *it;
- int count;
- int n;
-
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
-
- if (wd->items_count == 0) return;
-
- const int adj_pos = (wd->items_count-1)*0.5;
- if(wd->tot_items_count[wd->level] <= wd->max_supp_items_count)
- n = wd->tot_items_count[wd->level];
- else
- n = wd->max_supp_items_count;
- group_count = MIN_GRP_SIZE;
-
- int *indx = (int*)calloc(n, sizeof(int));
- if (!indx) return;
-
- const int minh = wd->min_obj_height;
- EINA_LIST_FOREACH(wd->items, l, it)
- {
- it->vis_letter = eina_stringshare_add(it->letter);
- it->size = minh;
- }
- int remainder;
- int numberofparts;
- int N = wd->items_count;
-
- for (i=0;i<n;i++)
- {
- indx[i] = minh;
- }
- extraIndex=n-N;
- if (extraIndex < 0) return;
-
- group_count = _group_count(obj, extraIndex, adj_pos, N);
- if (group_count <= 0) return;
-
- PlacementPart place[adj_pos];
- remainder = extraIndex%group_count;
- numberofparts=(extraIndex/group_count)+(remainder == 0? 0: 1);
-
- for (i=0;i<numberofparts; i++)
- {
- place[i].count=group_count+1;
- count = (int)(((float)(i+1)/(float)(numberofparts+1))*N);
- place[i].start= count +i*group_count-1;
- }
- if (remainder)
- place[numberofparts-1].count=remainder+1;
-
- for (i=0;i<numberofparts;i++)
- {
- for (j=0;j<place[i].count; j++)
- {
- indx[((place[i].start)+j)]= MIN_PIXEL_VALUE;
- }
- indx[(place[i].start+(place[i].count)/2)] = minh-place[i].count+1;
- }
- count = 0;
- EINA_LIST_FOREACH(wd->items, l, it)
- {
- int size = indx[count];
- count++;
- if (size == minh)
- {
- it->vis_letter = eina_stringshare_add(it->letter);
- continue;
- }
- else if (size == 1)
- {
- eina_stringshare_del(it->vis_letter);
- it->vis_letter = eina_stringshare_add("");
- }
- else
- {
- eina_stringshare_del(it->vis_letter);
- it->vis_letter = eina_stringshare_add(wd->special_char);
- }
- it->size = size*wd->scale_factor;
- }
- if (indx)
- {
- free(indx);
- indx = NULL;
- }
-}
-
-/**
- * Set the active state of the index programatically
- *
- * @param obj The index object
- * @param active The active state
- *
- * @ingroup Index
- */
EAPI void
-elm_index_active_set(Evas_Object *obj, Eina_Bool active)
+elm_index_autohide_disabled_set(Evas_Object *obj, Eina_Bool disabled)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
- if (wd->active == active) return;
- wd->active = active;
+ disabled = !!disabled;
+ if (wd->autohide_disabled == disabled) return;
+ wd->autohide_disabled = disabled;
wd->level = 0;
- if (wd->active)
+ if (wd->autohide_disabled)
{
_index_box_clear(obj, wd->bx[1], 1);
- _index_process(obj);
_index_box_auto_fill(obj, wd->bx[0], 0);
edje_object_signal_emit(wd->base, "elm,state,active", "elm");
}
else
edje_object_signal_emit(wd->base, "elm,state,inactive", "elm");
+
+ //FIXME: Should be update indicator based on the indicator visiblility
}
-/**
- * Get the active state of the index programatically
- *
- * @param obj The index object
- * @return The active state
- *
- * @ingroup Index
- */
EAPI Eina_Bool
-elm_index_active_get(const Evas_Object *obj)
+elm_index_autohide_disabled_get(const Evas_Object *obj)
{
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return EINA_FALSE;
- return wd->active;
+ return wd->autohide_disabled;
}
-/**
- * Sets the level of the item.
- *
- * @param obj The index object.
- * @param level To be documented.
- *
- * @ingroup Index
- */
EAPI void
elm_index_item_level_set(Evas_Object *obj, int level)
{
wd->level = level;
}
-/**
- * Gets the level of the item.
- *
- * @param obj The index object
- *
- * @ingroup Index
- */
EAPI int
elm_index_item_level_get(const Evas_Object *obj)
{
return wd->level;
}
-/**
- * Returns the selected item.
- *
- * @param obj The index object.
- * @param level to be documented.
- *
- * @ingroup Index
- */
-EAPI void *
-elm_index_item_selected_get(const Evas_Object *obj, int level)
+EAPI void
+elm_index_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
+{
+ ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
+ Evas_Coord x, y, w, h;
+ Widget_Data *wd = elm_widget_data_get(WIDGET(it));
+ if (!wd) return;
+
+ //FIXME: Should be update indicator based on the autohidden status & indicator visiblility
+
+ if (selected)
+ {
+ evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
+ _sel_eval(WIDGET(it), x + (w/2), y + (h/2));
+ }
+ else
+ _sel_eval(WIDGET(it), -99999, -9999);
+
+}
+
+EAPI Elm_Object_Item *
+elm_index_selected_item_get(const Evas_Object *obj, int level)
{
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
Elm_Index_Item *it;
if (!wd) return NULL;
EINA_LIST_FOREACH(wd->items, l, it)
- if ((it->selected) && (it->level == level))
- return elm_widget_item_data_get(it);
+ {
+ if ((it->selected) && (it->level == level))
+ return (Elm_Object_Item *)it;
+ }
return NULL;
}
-/**
- * Appends a new item.
- *
- * @param obj The index object.
- * @param letter Letter under which the item should be indexed
- * @param item The item to put in the index
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_append(Evas_Object *obj, const char *letter, const void *item)
+EAPI Elm_Object_Item *
+elm_index_item_append(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
Elm_Index_Item *it;
- if (!wd) return;
- it = _item_new(obj, letter, item);
- if (!it) return;
+ if (!wd) return NULL;
+ it = _item_new(obj, letter, func, data);
+ if (!it) return NULL;
wd->items = eina_list_append(wd->items, it);
- wd->tot_items_count[wd->level]++;
_index_box_clear(obj, wd->bx[wd->level], wd->level);
+ return (Elm_Object_Item *)it;
}
-/**
- * Prepends a new item.
- *
- * @param obj The index object.
- * @param letter Letter under which the item should be indexed
- * @param item The item to put in the index
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_prepend(Evas_Object *obj, const char *letter, const void *item)
+EAPI Elm_Object_Item *
+elm_index_item_prepend(Evas_Object *obj, const char *letter, Evas_Smart_Cb func, const void *data)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
Elm_Index_Item *it;
- if (!wd) return;
- it = _item_new(obj, letter, item);
- if (!it) return;
+ if (!wd) return NULL;
+ it = _item_new(obj, letter, func, data);
+ if (!it) return NULL;
wd->items = eina_list_prepend(wd->items, it);
- wd->tot_items_count[wd->level]++;
_index_box_clear(obj, wd->bx[wd->level], wd->level);
+ return (Elm_Object_Item *)it;
}
-/**
- * Append an item after @p relative in letter @p letter.
- *
- * @param obj The index object
- * @param letter Letter under which the item should be indexed
- * @param item The item to put in the index
- * @param relative The item to put @p item after
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_append_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
+EINA_DEPRECATED EAPI Elm_Object_Item *
+elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const Elm_Object_Item *relative)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ return elm_index_item_insert_before(obj, (Elm_Object_Item *) relative, letter, NULL, item);
+}
+
+EAPI Elm_Object_Item *
+elm_index_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *letter, Evas_Smart_Cb func, const void *data)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
- Elm_Index_Item *it, *it_rel;
- if (!wd) return;
- if (!relative)
- {
- elm_index_item_append(obj, letter, item);
- wd->tot_items_count[wd->level]++;
- return;
- }
- it = _item_new(obj, letter, item);
- it_rel = _item_find(obj, relative);
- if (!it_rel)
- {
- elm_index_item_append(obj, letter, item);
- wd->tot_items_count[wd->level]++;
- return;
- }
- if (!it) return;
- wd->items = eina_list_append_relative(wd->items, it, it_rel);
- wd->tot_items_count[wd->level]++;
+ Elm_Index_Item *it;
+ if (!wd) return NULL;
+ if (!after) return elm_index_item_append(obj, letter, func, data);
+ it = _item_new(obj, letter, func, data);
+ if (!it) return NULL;
+ wd->items = eina_list_append_relative(wd->items, it, after);
_index_box_clear(obj, wd->bx[wd->level], wd->level);
+ return (Elm_Object_Item *)it;
}
-/**
- * Prepend an item before @p relative in letter @p letter.
- *
- * @param obj The index object
- * @param letter Letter under which the item should be indexed
- * @param item The item to put in the index
- * @param relative The item to put @p item before
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_prepend_relative(Evas_Object *obj, const char *letter, const void *item, const void *relative)
+EAPI Elm_Object_Item *
+elm_index_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *letter, Evas_Smart_Cb func, const void *data)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
- Elm_Index_Item *it, *it_rel;
- if (!wd) return;
- if (!relative)
- {
- elm_index_item_prepend(obj, letter, item);
- wd->tot_items_count[wd->level]++;
- return;
- }
- it = _item_new(obj, letter, item);
- it_rel = _item_find(obj, relative);
- if (!it_rel)
- {
- elm_index_item_append(obj, letter, item);
- wd->tot_items_count[wd->level]++;
- return;
- }
- if (!it) return;
- wd->items = eina_list_prepend_relative(wd->items, it, it_rel);
- wd->tot_items_count[wd->level]++;
+ Elm_Index_Item *it;
+ if (!wd) return NULL;
+ if (!before) return elm_index_item_prepend(obj, letter, func, data);
+ it = _item_new(obj, letter, func, data);
+ if (!it) return NULL;
+ wd->items = eina_list_prepend_relative(wd->items, it, before);
_index_box_clear(obj, wd->bx[wd->level], wd->level);
+ return (Elm_Object_Item *)it;
}
-/**
- * Insert a new @p item into the sorted index @p obj in @p letter.
- *
- * @param obj The index object
- * @param letter Letter under which the item should be indexed
- * @param item The item to put in the index
- * @param cmp_func The function called for the sort of index items.
- * @param cmp_data_func The function called for the sort of the data. It will
- * be used when cmp_func return 0. It means the index item already exists.
- * So, to decide which data item should be pointed by the index item, a function
- * to compare them is needed. If this function is not provided, index items
- * will be duplicated. If cmp_data_func returns a non-negative value, the
- * previous index item data will be replaced by the inserted @p item. So
- * if the previous data need to be free, it should be done in this function,
- * because the reference will be lost.
- *
- * @ingroup Index
- */
-EAPI void
-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)
+EAPI Elm_Object_Item *
+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)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
Eina_List *lnear;
Elm_Index_Item *it;
int cmp;
- if (!wd) return;
+ if (!wd) return NULL;
if (!(wd->items))
- {
- elm_index_item_append(obj, letter, item);
- return;
- }
+ return elm_index_item_append(obj, letter, func, data);
- it = _item_new(obj, letter, item);
- if (!it) return;
+ it = _item_new(obj, letter, func, data);
+ if (!it) return NULL;
lnear = eina_list_search_sorted_near_list(wd->items, cmp_func, it, &cmp);
if (cmp < 0)
if (cmp_data_func(p_it->base.data, it->base.data) >= 0)
p_it->base.data = it->base.data;
_item_free(it);
+ elm_widget_item_free(it);
}
}
-
_index_box_clear(obj, wd->bx[wd->level], wd->level);
+ return (Elm_Object_Item *)it;
}
-/**
- * Remove an item from the index.
- *
- * @param obj The index object
- * @param item The item to remove from the index
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_del(Evas_Object *obj, const void *item)
-{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- Elm_Index_Item *it;
- if (!wd) return;
- it = _item_find(obj, item);
- if (!it) return;
- _item_free(it);
- wd->tot_items_count[wd->level]--;
- _index_box_clear(obj, wd->bx[wd->level], wd->level);
-}
-
-/**
- * Find an index item using item data.
- *
- * @param obj The index object
- * @param item The item pointed by index item
- * @return The index item pointing to @p item
- *
- * @ingroup Index
- */
-EAPI Elm_Index_Item *
-elm_index_item_find(Evas_Object *obj, const void *item)
+EAPI Elm_Object_Item *
+elm_index_item_find(Evas_Object *obj, const void *data)
{
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return NULL;
- return _item_find(obj, item);
+ return (Elm_Object_Item *) _item_find(obj, data);
}
-/**
- * Clears an index of its items.
- *
- * @param obj The index object.
- *
- * @ingroup Index
- */
EAPI void
elm_index_item_clear(Evas_Object *obj)
{
EINA_LIST_FREE(clear, it)
{
_item_free(it);
- wd->tot_items_count[wd->level]--;
+ elm_widget_item_free(it);
}
}
-/**
- * Go to item at @p level
- *
- * @param obj The index object
- * @param level The index level
- *
- * @ingroup Index
- */
EAPI void
-elm_index_item_go(Evas_Object *obj, int level)
+elm_index_level_go(Evas_Object *obj, int level __UNUSED__)
{
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
- if(level == 0)
- _index_process(obj);
_index_box_auto_fill(obj, wd->bx[0], 0);
if (wd->level == 1) _index_box_auto_fill(obj, wd->bx[1], 1);
}
-/**
- * Returns the data associated with the item.
- *
- * @param it The list item
- * @return The data associated with @p it
- *
- * @ingroup Index
- */
-EAPI void *
-elm_index_item_data_get(const Elm_Index_Item *it)
-{
- ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
- return elm_widget_item_data_get(it);
-}
-
-/**
- * Set the data item from the index item
- *
- * This set a new data value.
- *
- * @param it The item
- * @param data The new data pointer to set
- *
- * @ingroup Index
- */
EAPI void
-elm_index_item_data_set(Elm_Index_Item *it, const void *data)
+elm_index_indicator_disabled_set(Evas_Object *obj, Eina_Bool disabled)
{
- ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
- elm_widget_item_data_set(it, data);
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ disabled = !!disabled;
+ if (wd->indicator_disabled == disabled) return;
+ wd->indicator_disabled = disabled;
+ if (!wd->items) return;
+ if (disabled)
+ edje_object_signal_emit(wd->base, "elm,indicator,state,inactive", "elm");
+ else
+ edje_object_signal_emit(wd->base, "elm,indicator,state,active", "elm");
}
-/**
- * Make the Central Button Image invisible.
- *
- * @param obj The Index.
- * @param invisible Whether button visible or not.
- * @return void.
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_button_image_invisible_set(Evas_Object *obj, Eina_Bool invisible)
+EAPI Eina_Bool
+elm_index_indicator_disabled_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
Widget_Data *wd = elm_widget_data_get(obj);
- wd->hide_button = invisible;
+ if (!wd) return EINA_FALSE;
- edje_object_signal_emit(wd->base, "elm,state,button,image,hide", "elm");
- return;
+ return wd->indicator_disabled;
}
-/**
- * Set the function called when a index item is freed.
- *
- * @param it The item to set the callback on
- * @param func The function called
- *
- * @ingroup Index
- */
-EAPI void
-elm_index_item_del_cb_set(Elm_Index_Item *it, Evas_Smart_Cb func)
+EAPI const char *
+elm_index_item_letter_get(const Elm_Object_Item *it)
{
- ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
- elm_widget_item_del_cb_set(it, func);
+ ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
+ return ((Elm_Index_Item *)it)->letter;
}
-/**
- * Gets the letter of the item.
- *
- * @param it The list item
- * @return The letter of @p it
- *
- * @ingroup Index
- */
-EAPI const char *
-elm_index_item_letter_get(const Elm_Index_Item *it)
+EAPI void
+elm_index_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
{
- ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
- return it->letter;
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ horizontal = !!horizontal;
+ if (horizontal == wd->horizontal) return;
+ wd->horizontal = horizontal;
+ _theme_hook(obj);
}
+EAPI Eina_Bool
+elm_index_horizontal_get(const Evas_Object *obj)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return EINA_FALSE;
+ return wd->horizontal;
+}