X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Felm_flipselector.c;h=7939aba8e08a3eaf5fa721d46310eb70ed69a60f;hb=8b32f3712183fc44ce1f965e8a95069fe2bbc6cd;hp=0936b07c72062c00241b8bb8ea89800e484d669b;hpb=bb8afc406744a8b4b5f0c5db15809114b7d6e92e;p=framework%2Fuifw%2Felementary.git diff --git a/src/lib/elm_flipselector.c b/src/lib/elm_flipselector.c index 0936b07..7939aba 100644 --- a/src/lib/elm_flipselector.c +++ b/src/lib/elm_flipselector.c @@ -1,29 +1,12 @@ #include #include "elm_priv.h" -/** - * @addtogroup Flipselector Flipselector - * - * A flip selector is a widget to show a set of label items, one at a - * time, with an animation when one changes the current selection - * (like the flip of calendar sheets, in the default theme). - * - * Signals that you can add callbacks for are: - * - * "selected" - when flipselector selected item is changed - * "overflowed" - when flipselector item is changed to first item - * from last item - * "underflowed" - when flipselector item is changed to last item - * from first item. - */ - /* TODO: ideally, the default theme would use map{} blocks on the TEXT parts to implement their fading in/out propertly (as in the clock widget) */ /* TODO: if one ever wants to extend it to receiving generic widgets as items, be my guest. in this case, remember to implement the items tooltip infra. */ -/* TODO: implement disabled mode -- disable_hook() and stuff. */ /* TODO: fix default theme image borders for looong strings as item labels. */ /* TODO: set text elipsis on labels if one enforces mininum size on @@ -42,7 +25,7 @@ struct _Elm_Flipselector_Item { - Elm_Widget_Item base; + ELM_WIDGET_ITEM; const char *label; Evas_Smart_Cb func; void *data; @@ -50,6 +33,7 @@ struct _Elm_Flipselector_Item }; typedef struct _Widget_Data Widget_Data; +typedef struct _Elm_Flipselector_Item Elm_Flipselector_Item; struct _Widget_Data { @@ -72,6 +56,7 @@ static void _update_view(Evas_Object *obj); static void _callbacks_set(Evas_Object *obj); static void _flip_up(Widget_Data *wd); static void _flip_down(Widget_Data *wd); +static Eina_Bool _item_del_pre_hook(Elm_Object_Item *it); static const char SIG_SELECTED[] = "selected"; static const char SIG_UNDERFLOWED[] = "underflowed"; @@ -83,13 +68,55 @@ static const Evas_Smart_Cb_Description _signals[] = { {NULL, NULL} }; -#define ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(it, ...) \ - ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, __VA_ARGS__); \ - if (it->deleted) \ - { \ - ERR(""#it" has been DELETED.\n"); \ - return __VA_ARGS__; \ - } \ +static void +_item_text_set_hook(Elm_Object_Item *it, + const char *part, + const char *label) +{ + Widget_Data *wd; + Eina_List *l; + Elm_Flipselector_Item *item; + + if (!label) return; + + if (part && strcmp(part ,"default")) return; + + item = (Elm_Flipselector_Item *)it; + wd = elm_widget_data_get(WIDGET(item)); + if ((!wd) || (!wd->items)) return; + + l = eina_list_data_find_list(wd->items, item); + if (!l) return; + + eina_stringshare_del(item->label); + item->label = eina_stringshare_add_length(label, wd->max_len); + + if (strlen(label) > strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))) + wd->sentinel = l; + + if (wd->current == l) + { + _update_view(WIDGET(item)); + _sizing_eval(wd->self); + } +} + +static const char * +_item_text_get_hook(const Elm_Object_Item *it, const char *part) +{ + if (part && strcmp(part ,"default")) return NULL; + + return ((Elm_Flipselector_Item *)it)->label; +} + +static void +_item_signal_emit_hook(Elm_Object_Item *it, + const char *emission, + const char *source) +{ + Elm_Flipselector_Item *item = (Elm_Flipselector_Item *)it; + edje_object_signal_emit(VIEW(item), emission, source); +} static Elm_Flipselector_Item * _item_new(Evas_Object *obj, const char *label, Evas_Smart_Cb func, const void *data) @@ -99,8 +126,12 @@ _item_new(Evas_Object *obj, const char *label, Evas_Smart_Cb func, const void *d Widget_Data *wd = elm_widget_data_get(obj); it = elm_widget_item_new(obj, Elm_Flipselector_Item); - if (!it) - return NULL; + if (!it) return NULL; + + elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook); + elm_widget_item_text_set_hook_set(it, _item_text_set_hook); + elm_widget_item_text_get_hook_set(it, _item_text_get_hook); + elm_widget_item_signal_emit_hook_set(it, _item_signal_emit_hook); len = strlen(label); if (len > wd->max_len) @@ -119,7 +150,7 @@ static inline void _item_free(Elm_Flipselector_Item *it) { eina_stringshare_del(it->label); - elm_widget_item_del(it); + elm_widget_item_free(it); } static void @@ -128,28 +159,37 @@ _del_hook(Evas_Object *obj) Elm_Flipselector_Item *item; Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; - if (wd->walking) - ERR("flipselector deleted while walking.\n"); + if (wd->walking) ERR("flipselector deleted while walking.\n"); EINA_LIST_FREE(wd->items, item) - _item_free(item); + _item_free(item); if (wd->spin) ecore_timer_del(wd->spin); free(wd); } static void +_disable_hook(Evas_Object *obj) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + + if (elm_widget_disabled_get(obj)) + edje_object_signal_emit(wd->base, "elm,state,disabled", "elm"); + else + edje_object_signal_emit(wd->base, "elm,state,enabled", "elm"); +} + +static void _theme_hook(Evas_Object *obj) { Widget_Data *wd; const char *max_len; wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; _elm_theme_object_set(obj, wd->base, "flipselector", "base", elm_widget_style_get(obj)); @@ -186,8 +226,8 @@ _sentinel_eval(Widget_Data *wd) EINA_LIST_FOREACH(wd->items, l, it) { - if (strlen(elm_flipselector_item_label_get(it)) > - strlen(elm_flipselector_item_label_get(DATA_GET(wd->sentinel)))) + if (strlen(elm_object_item_text_get((Elm_Object_Item *)it)) > + strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))) wd->sentinel = l; } } @@ -205,14 +245,12 @@ _flipselector_process_deletions(Widget_Data *wd) EINA_LIST_FOREACH(wd->items, l, it) { - if (!it->deleted) - continue; + if (!it->deleted) continue; if (wd->current == l) { if (wd->current == wd->sentinel) sentinel_eval = EINA_TRUE; - wd->current = eina_list_prev(wd->current); } wd->items = eina_list_remove(wd->items, it); @@ -258,9 +296,7 @@ _flipselector_unwalk(Widget_Data *wd) ERR("walking became negative. fixed!\n"); wd->walking = 0; } - - if (wd->walking) - return; + if (wd->walking) return; _flipselector_process_deletions(wd); } @@ -272,19 +308,15 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty Widget_Data *wd; Eina_Bool is_up = EINA_TRUE; - if (type != EVAS_CALLBACK_KEY_DOWN) - return EINA_FALSE; + if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE; wd = elm_widget_data_get(obj); - if (!wd) - return EINA_FALSE; + if (!wd) return EINA_FALSE; ev = event_info; - if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) - return EINA_FALSE; + if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE; - if (elm_widget_disabled_get(obj)) - return EINA_FALSE; + if (elm_widget_disabled_get(obj)) return EINA_FALSE; if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down"))) is_up = EINA_FALSE; @@ -292,14 +324,13 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty return EINA_FALSE; if (wd->spin) ecore_timer_del(wd->spin); + wd->spin = NULL; /* TODO: if direction setting via API is not coming in, replace these calls by flip_{next,prev} */ _flipselector_walk(wd); - if (is_up) - _flip_up(wd); - else - _flip_down(wd); + if (is_up) _flip_up(wd); + else _flip_down(wd); _flipselector_unwalk(wd); ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; @@ -310,8 +341,7 @@ static void _on_focus_hook(void *data __UNUSED__, Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; /* FIXME: no treatment of this signal so far */ if (elm_widget_focus_get(obj)) @@ -334,26 +364,22 @@ _sizing_eval(Evas_Object *obj) Evas_Coord minw = -1, minh = -1, w, h; wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; elm_coords_finger_size_adjust(1, &minw, 2, &minh); if (wd->sentinel) { - const char *label = \ - elm_flipselector_item_label_get(DATA_GET(wd->sentinel)); - - tmp = edje_object_part_text_get(wd->base, "top"); - edje_object_part_text_set(wd->base, "top", label); + const char *label = elm_object_item_text_get(DATA_GET(wd->sentinel)); + tmp = edje_object_part_text_get(wd->base, "elm.top"); + edje_object_part_text_escaped_set(wd->base, "elm.top", label); } edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh); elm_coords_finger_size_adjust(1, &minw, 2, &minh); evas_object_size_hint_min_get(obj, &w, &h); - if (wd->sentinel) - edje_object_part_text_set(wd->base, "top", tmp); + if (wd->sentinel) edje_object_part_text_escaped_set(wd->base, "elm.top", tmp); if (w > minw) minw = w; if (h > minh) minh = h; @@ -369,17 +395,14 @@ _update_view(Evas_Object *obj) Elm_Flipselector_Item *item; wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; label = NULL; item = DATA_GET(wd->current); - if (item) - label = item->label; - - edje_object_part_text_set(wd->base, "top", label ? label : ""); - edje_object_part_text_set(wd->base, "bottom", label ? label : ""); + if (item) label = item->label; + edje_object_part_text_escaped_set(wd->base, "elm.top", label ? label : ""); + edje_object_part_text_escaped_set(wd->base, "elm.bottom", label ? label : ""); edje_object_message_signal_process(wd->base); } @@ -389,11 +412,10 @@ _changed(Widget_Data *wd) Elm_Flipselector_Item *item; item = DATA_GET(wd->current); - if (!item) - return; + if (!item) return; if (item->func) - item->func((void *)item->base.data, item->base.widget, item); + item->func((void *)item->base.data, WIDGET(item), item); if (!item->deleted) evas_object_smart_callback_call(wd->self, SIG_SELECTED, item); } @@ -415,8 +437,7 @@ _flip_up(Widget_Data *wd) { Elm_Flipselector_Item *item; - if (!wd->current) - return; + if (!wd->current) return; if (wd->current == wd->items) { @@ -427,8 +448,7 @@ _flip_up(Widget_Data *wd) wd->current = eina_list_prev(wd->current); item = DATA_GET(wd->current); - if (!item) - return; + if (!item) return; _send_msg(wd, MSG_FLIP_UP, (char *)item->label); } @@ -438,8 +458,7 @@ _signal_val_up(void *data) { Widget_Data *wd = elm_widget_data_get(data); - if (!wd) - goto val_up_exit_on_error; + if (!wd) goto val_up_exit_on_error; _flipselector_walk(wd); @@ -462,13 +481,11 @@ static void _signal_val_up_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); - if (!wd) - return; + if (!wd) return; wd->interval = wd->first_interval; - if (wd->spin) - ecore_timer_del(wd->spin); + if (wd->spin) ecore_timer_del(wd->spin); wd->spin = ecore_timer_add(wd->interval, _signal_val_up, data); _signal_val_up(data); @@ -479,8 +496,7 @@ _flip_down(Widget_Data *wd) { Elm_Flipselector_Item *item; - if (!wd->current) - return; + if (!wd->current) return; wd->current = eina_list_next(wd->current); if (!wd->current) @@ -490,8 +506,7 @@ _flip_down(Widget_Data *wd) } item = DATA_GET(wd->current); - if (!item) - return; + if (!item) return; _send_msg(wd, MSG_FLIP_DOWN, (char *)item->label); } @@ -501,8 +516,7 @@ _signal_val_down(void *data) { Widget_Data *wd = elm_widget_data_get(data); - if (!wd) - goto val_down_exit_on_error; + if (!wd) goto val_down_exit_on_error; _flipselector_walk(wd); @@ -524,13 +538,11 @@ static void _signal_val_down_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); - if (!wd) - return; + if (!wd) return; wd->interval = wd->first_interval; - if (wd->spin) - ecore_timer_del(wd->spin); + if (wd->spin) ecore_timer_del(wd->spin); wd->spin = ecore_timer_add(wd->interval, _signal_val_down, data); _signal_val_down(data); @@ -540,11 +552,9 @@ static void _signal_val_change_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); - if (!wd) - return; + if (!wd) return; - if (wd->spin) - ecore_timer_del(wd->spin); + if (wd->spin) ecore_timer_del(wd->spin); wd->spin = NULL; } @@ -563,14 +573,52 @@ _callbacks_set(Evas_Object *obj) "", _signal_val_change_stop, obj); } -/** - * Add a new flipselector to the parent. - * - * @param parent The parent object - * @return The new object or NULL, if it cannot be created - * - * @ingroup Flipselector - */ +static Eina_Bool +_item_del_pre_hook(Elm_Object_Item *it) +{ + Widget_Data *wd; + Elm_Flipselector_Item *item, *item2; + Eina_List *l; + + item = (Elm_Flipselector_Item *)it; + wd = elm_widget_data_get(WIDGET(item)); + if (!wd) return EINA_FALSE; + + if (wd->walking > 0) + { + item->deleted = EINA_TRUE; + return EINA_FALSE; + } + + _flipselector_walk(wd); + + EINA_LIST_FOREACH(wd->items, l, item2) + { + if (item2 == item) + { + wd->items = eina_list_remove_list(wd->items, l); + if (wd->current == l) + { + wd->current = l->prev; + if (!wd->current) wd->current = l->next; + if (wd->current) + { + item2 = wd->current->data; + _send_msg(wd, MSG_FLIP_DOWN, (char *)item2->label); + } + else + _send_msg(wd, MSG_FLIP_DOWN, ""); + } + break; + } + } + eina_stringshare_del(item->label); + _sentinel_eval(wd); + _flipselector_unwalk(wd); + + return EINA_TRUE; +} + EAPI Evas_Object * elm_flipselector_add(Evas_Object *parent) { @@ -585,9 +633,10 @@ elm_flipselector_add(Evas_Object *parent) elm_widget_sub_object_add(parent, obj); elm_widget_data_set(obj, wd); + wd->self = obj; elm_widget_del_hook_set(obj, _del_hook); elm_widget_theme_hook_set(obj, _theme_hook); - /* TODO: elm_widget_disable_hook_set(obj, _disable_hook); */ + elm_widget_disable_hook_set(obj, _disable_hook); elm_widget_can_focus_set(obj, EINA_TRUE); elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL); @@ -606,68 +655,39 @@ elm_flipselector_add(Evas_Object *parent) return obj; } -/** - * Select next item of a flipselector. - * - * @param obj The flipselector object - * - * @ingroup Flipselector - */ EAPI void elm_flipselector_flip_next(Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; if (wd->spin) ecore_timer_del(wd->spin); + wd->spin = NULL; _flipselector_walk(wd); _flip_down(wd); _flipselector_unwalk(wd); } -/** - * Select previous item of a flipselector. - * - * @param obj The flipselector object - * - * @ingroup Flipselector - */ EAPI void elm_flipselector_flip_prev(Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; + if (!wd) return; if (wd->spin) ecore_timer_del(wd->spin); + wd->spin = NULL; _flipselector_walk(wd); _flip_up(wd); _flipselector_unwalk(wd); } -/** - * Append item to a flipselector. - * - * @param obj The flipselector object - * @param label The label of new item - * @param func Convenience function called when item selected - * @param data Data passed to @p func above - * @return A handle to the item added or NULL, on errors - * - * @note The maximum length of the label is going to be determined by - * the widget's theme. Strings larger than that value are going to be - * truncated. - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * +EAPI Elm_Object_Item * elm_flipselector_item_append(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; @@ -676,22 +696,21 @@ elm_flipselector_item_append(Evas_Object *obj, const char *label, void (*func)(v Widget_Data *wd; wd = elm_widget_data_get(obj); - if (!wd) - return NULL; + if (!wd) return NULL; item = _item_new(obj, label, func, data); - if (!item) - return NULL; + if (!item) return NULL; wd->items = eina_list_append(wd->items, item); - if (!wd->current) { + if (!wd->current) + { wd->current = wd->items; _update_view(obj); - } + } if (!wd->sentinel || - (strlen(elm_flipselector_item_label_get(item)) > - strlen(elm_flipselector_item_label_get(DATA_GET(wd->sentinel))))) + (strlen(elm_object_item_text_get((Elm_Object_Item *)item)) > + strlen(elm_object_item_text_get(DATA_GET(wd->sentinel))))) { wd->sentinel = eina_list_last(wd->items); _sizing_eval(obj); @@ -700,25 +719,10 @@ elm_flipselector_item_append(Evas_Object *obj, const char *label, void (*func)(v if (eina_list_count(wd->items) >= 2) edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm"); - return item; + return (Elm_Object_Item *)item; } -/** - * Prepend item to a flipselector. - * - * @param obj The flipselector object - * @param label The label of new item - * @param func Convenience function called when item selected - * @param data Data passed to @p func above - * @return A handle to the item added or NULL, on errors - * - * @note The maximum length of the label is going to be determined by - * the widget's theme. Strings larger than that value are going to be - * truncated. - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * +EAPI Elm_Object_Item * elm_flipselector_item_prepend(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; @@ -727,22 +731,21 @@ elm_flipselector_item_prepend(Evas_Object *obj, const char *label, void (*func)( Widget_Data *wd; wd = elm_widget_data_get(obj); - if (!wd) - return NULL; + if (!wd) return NULL; item = _item_new(obj, label, func, data); - if (!item) - return NULL; + if (!item) return NULL; wd->items = eina_list_prepend(wd->items, item); - if (!wd->current) { + if (!wd->current) + { wd->current = wd->items; _update_view(obj); - } + } if (!wd->sentinel || - (strlen(elm_flipselector_item_label_get(item)) > - strlen(elm_flipselector_item_label_get(DATA_GET(wd->sentinel))))) + (strlen(elm_object_item_text_get((Elm_Object_Item *)item)) > + strlen(elm_object_item_text_get(DATA_GET(wd->sentinel))))) { wd->sentinel = wd->items; _sizing_eval(obj); @@ -751,39 +754,20 @@ elm_flipselector_item_prepend(Evas_Object *obj, const char *label, void (*func)( if (eina_list_count(wd->items) >= 2) edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm"); - return item; + return (Elm_Object_Item *)item; } -/* TODO: account for deleted items? */ -/** - * Get a list of items in the flipselector. - * - * @param obj The flipselector object - * @return The list of items, or NULL on errors. - * - * @ingroup Flipselector - */ EAPI const Eina_List * elm_flipselector_items_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return NULL; - + if (!wd) return NULL; return wd->items; } -/** - * Get the first item in the flipselector - * - * @param obj The flipselector object - * @return The first item, or NULL if none - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * +EAPI Elm_Object_Item * elm_flipselector_first_item_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; @@ -793,29 +777,17 @@ elm_flipselector_first_item_get(const Evas_Object *obj) Eina_List *l; wd = elm_widget_data_get(obj); - if (!wd || !wd->items) - return NULL; + if (!wd || !wd->items) return NULL; EINA_LIST_FOREACH(wd->items, l, it) { - if (it->deleted) - continue; - - return it; + if (it->deleted) continue; + return (Elm_Object_Item *)it; } - return NULL; } -/** - * Get the last item in the flipselector - * - * @param obj The flipselector object - * @return The last item, or NULL if none - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * +EAPI Elm_Object_Item * elm_flipselector_last_item_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; @@ -825,70 +797,42 @@ elm_flipselector_last_item_get(const Evas_Object *obj) Eina_List *l; wd = elm_widget_data_get(obj); - if (!wd || !wd->items) - return NULL; + if (!wd || !wd->items) return NULL; EINA_LIST_REVERSE_FOREACH(wd->items, l, it) { - if (it->deleted) - continue; - - return it; + if (it->deleted) continue; + return (Elm_Object_Item *)it; } - return NULL; } -/** - * Get the selected item in a flipselector. - * - * @param obj The flipselector object - * @return The selected item, or NULL if none - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * +EAPI Elm_Object_Item * elm_flipselector_selected_item_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) NULL; Widget_Data *wd = elm_widget_data_get(obj); - if (!wd || !wd->current) - return NULL; - + if (!wd) return NULL; return DATA_GET(wd->current); } -/** - * Set the selected state of an item - * - * This sets the selected state (EINA_TRUE selected, EINA_FALSE not selected) - * of the given item @p item. - * If a new item is selected the previosly selected will be unselected. - * If the item @p item is unselected, the first item will be selected. - * - * @param item The item - * @param selected The selected state - * - * @ingroup Flipselector - */ EAPI void -elm_flipselector_item_selected_set(Elm_Flipselector_Item *item, Eina_Bool selected) +elm_flipselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected) { - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item); + ELM_OBJ_ITEM_CHECK_OR_RETURN(it); - Elm_Flipselector_Item *_item, *cur; + Elm_Flipselector_Item *item, *_item, *cur; int flipside = MSG_FLIP_UP; Widget_Data *wd; Eina_List *l; - wd = elm_widget_data_get(item->base.widget); - if (!wd) - return; + item = (Elm_Flipselector_Item *)it; + wd = elm_widget_data_get(WIDGET(item)); + if (!wd) return; cur = DATA_GET(wd->current); - if ((selected) && (cur == item)) - return; + if ((selected) && (cur == item)) return; _flipselector_walk(wd); @@ -909,8 +853,7 @@ elm_flipselector_item_selected_set(Elm_Flipselector_Item *item, Eina_Bool select EINA_LIST_FOREACH(wd->items, l, _item) { - if (_item == cur) - flipside = MSG_FLIP_DOWN; + if (_item == cur) flipside = MSG_FLIP_DOWN; if (_item == item) { @@ -923,241 +866,71 @@ elm_flipselector_item_selected_set(Elm_Flipselector_Item *item, Eina_Bool select _flipselector_unwalk(wd); } -/* - * Get the selected state of @p item. - * - * @param item The flipselector item - * @return If true, the item is selected - * - * @ingroup Flipselector - */ EAPI Eina_Bool -elm_flipselector_item_selected_get(const Elm_Flipselector_Item *item) +elm_flipselector_item_selected_get(const Elm_Object_Item *it) { - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE); + ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE); Widget_Data *wd; + Elm_Flipselector_Item *item; - wd = elm_widget_data_get(item->base.widget); + item = (Elm_Flipselector_Item *)it; + wd = elm_widget_data_get(WIDGET(item)); if (!wd) return EINA_FALSE; return (eina_list_data_get(wd->current) == item); } -/** - * Delete a given item from a flipselector. - * - * @param item The item - * - * @ingroup Flipselector - */ -EAPI void -elm_flipselector_item_del(Elm_Flipselector_Item *item) -{ - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item); - - Widget_Data *wd; - - wd = elm_widget_data_get(item->base.widget); - if (!wd) - return; - - if (wd->walking > 0) - { - item->deleted = EINA_TRUE; - return; - } - - _flipselector_walk(wd); - - wd->items = eina_list_remove(wd->items, item); - _item_free(item); - _sentinel_eval(wd); - - _flipselector_unwalk(wd); -} - -/** - * Get the label of a given flipselector item. - * - * @param item The item - * @return The label of a given item, or NULL if none - * - * @ingroup Flipselector - */ -EAPI const char * -elm_flipselector_item_label_get(const Elm_Flipselector_Item *item) +EAPI Elm_Object_Item * +elm_flipselector_item_prev_get(const Elm_Object_Item *it) { - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item, NULL); + ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); - Elm_Flipselector_Item *_item; Widget_Data *wd; Eina_List *l; + Elm_Flipselector_Item *item = (Elm_Flipselector_Item *)it; - wd = elm_widget_data_get(item->base.widget); - if ((!wd) || (!wd->items)) - return NULL; + wd = elm_widget_data_get(WIDGET(item)); + if ((!wd) || (!wd->items)) return NULL; - EINA_LIST_FOREACH(wd->items, l, _item) - if (_item == item) - return item->label; + l = eina_list_data_find_list(wd->items, it); + if (l && l->prev) return DATA_GET(l->prev); return NULL; } -/** - * Set the label of a given flipselector item. - * - * @param item The item - * @param label The text label string in UTF-8 - * - * @ingroup Flipselector - */ -EAPI void -elm_flipselector_item_label_set(Elm_Flipselector_Item *item, const char *label) +EAPI Elm_Object_Item * +elm_flipselector_item_next_get(const Elm_Object_Item *it) { - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item); + ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); Widget_Data *wd; Eina_List *l; + Elm_Flipselector_Item *item = (Elm_Flipselector_Item *)it; - if ((!item) || (!label)) - return; - - wd = elm_widget_data_get(item->base.widget); - if ((!wd) || (!wd->items)) - return; - - l = eina_list_data_find_list(wd->items, item); - if (!l) - return; - - eina_stringshare_del(item->label); - item->label = eina_stringshare_add_length(label, wd->max_len); - - if (strlen(label) > - strlen(elm_flipselector_item_label_get(DATA_GET(wd->sentinel)))) - wd->sentinel = l; - - if (wd->current == l) - { - _update_view(item->base.widget); - _sizing_eval(wd->self); - } - - return; -} + wd = elm_widget_data_get(WIDGET(item)); + if ((!wd) || (!wd->items)) return NULL; -/** - * Gets the item before @p item in a flipselector. - * - * @param item The item - * @return The item before the item @p item - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * -elm_flipselector_item_prev_get(Elm_Flipselector_Item *item) -{ - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item, NULL); - - Elm_Flipselector_Item *_item; - Widget_Data *wd; - Eina_List *l; - - wd = elm_widget_data_get(item->base.widget); - if ((!wd) || (!wd->items)) - return NULL; - - EINA_LIST_FOREACH(wd->items, l, _item) - if (_item == item) - { - l = eina_list_prev(l); - if (!l) - return NULL; - return DATA_GET(l); - } + l = eina_list_data_find_list(wd->items, it); + if (l && l->next) return DATA_GET(l->next); return NULL; } -/** - * Gets the item after @p item in a flipselector. - * - * @param item The item - * @return The item after the item @p item - * - * @ingroup Flipselector - */ -EAPI Elm_Flipselector_Item * -elm_flipselector_item_next_get(Elm_Flipselector_Item *item) -{ - ELM_FLIPSELECTOR_ITEM_CHECK_DELETED_RETURN(item, NULL); - - Elm_Flipselector_Item *_item; - Widget_Data *wd; - Eina_List *l; - - wd = elm_widget_data_get(item->base.widget); - if ((!wd) || (!wd->items)) - return NULL; - - EINA_LIST_FOREACH(wd->items, l, _item) - if (_item == item) - { - l = eina_list_next(l); - if (!l) - return NULL; - return DATA_GET(l); - } - - return NULL; -} - -/** - * Set the flipping interval for the flipselector. - * - * @param obj The flipselector object - * @param interval The interval value in seconds - * - * The interval value is decreased while the user flips the widget up - * or down repeatedly. The next interval value is the previous - * interval / 1.05, so it speeds up a bit. Default value is 0.85 - * seconds. - * - * @ingroup Flipselector - */ EAPI void -elm_flipselector_interval_set(Evas_Object *obj, double interval) +elm_flipselector_first_interval_set(Evas_Object *obj, double interval) { ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) - return; - + if (!wd) return; wd->first_interval = interval; } -/** - * Get the flipping interval of the flipselector. - * - * @param obj The flipselector object - * @return The value of the first interval in seconds - * - * The interval value is decreased while the user flips the widget up - * or down repeatedly. The next interval value is the previous - * interval / 1.05, so it speeds up a bit. Default value is 0.85 - * seconds. - * - * @ingroup Flipselector - */ EAPI double -elm_flipselector_interval_get(const Evas_Object *obj) +elm_flipselector_first_interval_get(const Evas_Object *obj) { - ELM_CHECK_WIDTYPE(obj, widtype) 0.0; + ELM_CHECK_WIDTYPE(obj, widtype) 0; Widget_Data *wd = elm_widget_data_get(obj); - - if (!wd) - return 0.0; + if (!wd) return 0; return wd->first_interval; }