Merge "[Genlist] _item_select migration"
[framework/uifw/elementary.git] / src / lib / elm_flipselector.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /* TODO: ideally, the default theme would use map{} blocks on the TEXT
5    parts to implement their fading in/out propertly (as in the clock
6    widget) */
7 /* TODO: if one ever wants to extend it to receiving generic widgets
8    as items, be my guest. in this case, remember to implement the
9    items tooltip infra. */
10 /* TODO: implement disabled mode -- disable_hook() and stuff. */
11 /* TODO: fix default theme image borders for looong strings as item
12    labels. */
13 /* TODO: set text elipsis on labels if one enforces mininum size on
14  * the overall widget less the required for displaying it. */
15 /* TODO: find a way to, in the default theme, to detect we are
16  * bootstrapping (receiving the 1st message) and populate the downmost
17  * TEXT parts with the same text as the upmost, where appropriate. */
18
19 #define FLIP_FIRST_INTERVAL (0.85)
20 #define FLIP_MIN_INTERVAL (0.1)
21 #define MSG_FLIP_DOWN (1)
22 #define MSG_FLIP_UP (2)
23 #define MAX_LEN_DEFAULT (50)
24
25 #define DATA_GET eina_list_data_get
26
27 struct _Elm_Flipselector_Item
28 {
29    ELM_WIDGET_ITEM;
30    const char *label;
31    Evas_Smart_Cb func;
32    void *data;
33    int deleted : 1;
34 };
35
36 typedef struct _Widget_Data Widget_Data;
37 typedef struct _Elm_Flipselector_Item Elm_Flipselector_Item;
38
39 struct _Widget_Data
40 {
41    Evas_Object *self;
42    Evas_Object *base;
43    Eina_List *items;
44    Eina_List *current;
45    Eina_List *sentinel; /* item containing the largest label string */
46    int walking;
47    unsigned int max_len;
48    Ecore_Timer *spin;
49    double interval, first_interval;
50 };
51
52 static const char *widtype = NULL;
53 static void _del_hook(Evas_Object *obj);
54 static void _theme_hook(Evas_Object *obj);
55 static void _sizing_eval(Evas_Object *obj);
56 static void _update_view(Evas_Object *obj);
57 static void _callbacks_set(Evas_Object *obj);
58 static void _flip_up(Widget_Data *wd);
59 static void _flip_down(Widget_Data *wd);
60 static Eina_Bool _item_del_pre_hook(Elm_Object_Item *it);
61
62 static const char SIG_SELECTED[] = "selected";
63 static const char SIG_UNDERFLOWED[] = "underflowed";
64 static const char SIG_OVERFLOWED[] = "overflowed";
65 static const Evas_Smart_Cb_Description _signals[] = {
66   {SIG_SELECTED, ""},
67   {SIG_UNDERFLOWED, ""},
68   {SIG_OVERFLOWED, ""},
69   {NULL, NULL}
70 };
71
72 static void
73 _item_text_set_hook(Elm_Object_Item *it,
74                     const char *part,
75                     const char *label)
76 {
77    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
78
79    Widget_Data *wd;
80    Eina_List *l;
81    Elm_Flipselector_Item *item;
82
83    if (!label) return;
84
85    if (part && strcmp(part ,"default")) return;
86
87    item = (Elm_Flipselector_Item *) it;
88    wd = elm_widget_data_get(WIDGET(item));
89    if ((!wd) || (!wd->items)) return;
90
91    l = eina_list_data_find_list(wd->items, item);
92    if (!l) return;
93
94    eina_stringshare_del(item->label);
95    item->label = eina_stringshare_add_length(label, wd->max_len);
96
97    if (strlen(label) > strlen(elm_object_item_text_get(DATA_GET(wd->sentinel))))
98      wd->sentinel = l;
99
100    if (wd->current == l)
101      {
102         _update_view(WIDGET(item));
103         _sizing_eval(wd->self);
104      }
105 }
106
107 static const char *
108 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
109 {
110    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
111
112    Elm_Flipselector_Item *item, *_item;
113    Widget_Data *wd;
114    Eina_List *l;
115
116    if (part && strcmp(part ,"default")) return NULL;
117
118    item = (Elm_Flipselector_Item *) it;
119    wd = elm_widget_data_get(WIDGET(item));
120    if ((!wd) || (!wd->items)) return NULL;
121
122    EINA_LIST_FOREACH(wd->items, l, _item)
123      if (_item == item) return item->label;
124    return NULL;
125 }
126
127 static void
128 _item_signal_emit_hook(Elm_Object_Item *it,
129                        const char *emission,
130                        const char *source)
131 {
132    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
133    Elm_Flipselector_Item *item = (Elm_Flipselector_Item *) it;
134    edje_object_signal_emit(VIEW(item), emission, source);
135 }
136
137 static Elm_Flipselector_Item *
138 _item_new(Evas_Object *obj, const char *label, Evas_Smart_Cb func, const void *data)
139 {
140    unsigned int len;
141    Elm_Flipselector_Item *it;
142    Widget_Data *wd = elm_widget_data_get(obj);
143
144    it = elm_widget_item_new(obj, Elm_Flipselector_Item);
145    if (!it) return NULL;
146
147    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
148    elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
149    elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
150    elm_widget_item_signal_emit_hook_set(it, _item_signal_emit_hook);
151
152    len = strlen(label);
153    if (len > wd->max_len)
154      len = wd->max_len;
155
156    it->label = eina_stringshare_add_length(label, len);
157    it->func = func;
158    it->base.data = data;
159
160    /* TODO: no view here, but if one desires general contents in the
161     * future... */
162    return it;
163 }
164
165 static inline void
166 _item_free(Elm_Flipselector_Item *it)
167 {
168    eina_stringshare_del(it->label);
169    elm_widget_item_free(it);
170 }
171
172 static void
173 _del_hook(Evas_Object *obj)
174 {
175    Elm_Flipselector_Item *item;
176
177    Widget_Data *wd = elm_widget_data_get(obj);
178    if (!wd) return;
179
180    if (wd->walking) ERR("flipselector deleted while walking.\n");
181
182    EINA_LIST_FREE(wd->items, item)
183      _item_free(item);
184
185    if (wd->spin) ecore_timer_del(wd->spin);
186    free(wd);
187 }
188
189 static void
190 _theme_hook(Evas_Object *obj)
191 {
192    Widget_Data *wd;
193    const char *max_len;
194
195    wd = elm_widget_data_get(obj);
196    if (!wd) return;
197
198    _elm_theme_object_set(obj, wd->base, "flipselector", "base",
199                          elm_widget_style_get(obj));
200    edje_object_scale_set(wd->base,
201                          elm_widget_scale_get(obj) * _elm_config->scale);
202
203    max_len = edje_object_data_get(wd->base, "max_len");
204    if (!max_len)
205      wd->max_len = MAX_LEN_DEFAULT;
206    else
207      {
208         wd->max_len = atoi(max_len);
209         if (!wd->max_len)
210           wd->max_len = MAX_LEN_DEFAULT;
211      }
212
213    _update_view(obj);
214    _sizing_eval(obj);
215 }
216
217 static void
218 _sentinel_eval(Widget_Data *wd)
219 {
220    Elm_Flipselector_Item *it;
221    Eina_List *l;
222
223    if (!wd->items)
224      {
225         wd->sentinel = NULL;
226         return;
227      }
228
229    wd->sentinel = wd->items;
230
231    EINA_LIST_FOREACH(wd->items, l, it)
232      {
233         if (strlen(elm_object_item_text_get((Elm_Object_Item *) it)) >
234             strlen(elm_object_item_text_get(DATA_GET(wd->sentinel))))
235           wd->sentinel = l;
236      }
237 }
238
239 /* TODO: create a flag to avoid looping here all times */
240 static void
241 _flipselector_process_deletions(Widget_Data *wd)
242 {
243    Elm_Flipselector_Item *it;
244    Eina_List *l;
245    Eina_Bool skip = EINA_TRUE;
246    Eina_Bool sentinel_eval = EINA_FALSE;
247
248    wd->walking++; /* avoid nested deletions */
249
250    EINA_LIST_FOREACH(wd->items, l, it)
251      {
252         if (!it->deleted) continue;
253
254         if (wd->current == l)
255           {
256              if (wd->current == wd->sentinel)
257                sentinel_eval = EINA_TRUE;
258              wd->current = eina_list_prev(wd->current);
259           }
260         wd->items = eina_list_remove(wd->items, it);
261
262         if (!wd->current)
263           wd->current = wd->items;
264
265         _item_free(it);
266         skip = EINA_FALSE;
267
268         if (eina_list_count(wd->items) <= 1)
269           edje_object_signal_emit(wd->base, "elm,state,button,hidden", "elm");
270         else
271           edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm");
272      }
273
274    if (!skip)
275      _update_view(wd->self);
276
277    if (sentinel_eval)
278      _sentinel_eval(wd);
279
280    wd->walking--;
281 }
282
283 static inline void
284 _flipselector_walk(Widget_Data *wd)
285 {
286    if (wd->walking < 0)
287      {
288         ERR("walking was negative. fixed!\n");
289         wd->walking = 0;
290      }
291    wd->walking++;
292 }
293
294 static inline void
295 _flipselector_unwalk(Widget_Data *wd)
296 {
297    wd->walking--;
298    if (wd->walking < 0)
299      {
300         ERR("walking became negative. fixed!\n");
301         wd->walking = 0;
302      }
303    if (wd->walking) return;
304
305    _flipselector_process_deletions(wd);
306 }
307
308 static Eina_Bool
309 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
310 {
311    Evas_Event_Key_Down *ev;
312    Widget_Data *wd;
313    Eina_Bool is_up = EINA_TRUE;
314
315    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
316
317    wd = elm_widget_data_get(obj);
318    if (!wd) return EINA_FALSE;
319
320    ev = event_info;
321    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
322
323    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
324
325    if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
326      is_up = EINA_FALSE;
327    else if ((strcmp(ev->keyname, "Up")) && (strcmp(ev->keyname, "KP_Up")))
328      return EINA_FALSE;
329
330    if (wd->spin) ecore_timer_del(wd->spin);
331
332    /* TODO: if direction setting via API is not coming in, replace
333       these calls by flip_{next,prev} */
334    _flipselector_walk(wd);
335    if (is_up) _flip_up(wd);
336    else _flip_down(wd);
337    _flipselector_unwalk(wd);
338
339    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
340    return EINA_TRUE;
341 }
342
343 static void
344 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
345 {
346    Widget_Data *wd = elm_widget_data_get(obj);
347    if (!wd) return;
348
349    /* FIXME: no treatment of this signal so far */
350    if (elm_widget_focus_get(obj))
351      {
352         edje_object_signal_emit(wd->base, "elm,action,focus", "elm");
353         evas_object_focus_set(wd->base, EINA_TRUE);
354      }
355    else
356      {
357         edje_object_signal_emit(wd->base, "elm,action,unfocus", "elm");
358         evas_object_focus_set(wd->base, EINA_FALSE);
359      }
360 }
361
362 static void
363 _sizing_eval(Evas_Object *obj)
364 {
365    Widget_Data *wd;
366    const char *tmp = NULL;
367    Evas_Coord minw = -1, minh = -1, w, h;
368
369    wd = elm_widget_data_get(obj);
370    if (!wd) return;
371
372    elm_coords_finger_size_adjust(1, &minw, 2, &minh);
373
374    if (wd->sentinel)
375      {
376         const char *label = elm_object_item_text_get(DATA_GET(wd->sentinel));
377         tmp = edje_object_part_text_get(wd->base, "top");
378         edje_object_part_text_set(wd->base, "top", label);
379      }
380
381    edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
382    elm_coords_finger_size_adjust(1, &minw, 2, &minh);
383    evas_object_size_hint_min_get(obj, &w, &h);
384
385    if (wd->sentinel) edje_object_part_text_set(wd->base, "top", tmp);
386
387    if (w > minw) minw = w;
388    if (h > minh) minh = h;
389
390    evas_object_size_hint_min_set(obj, minw, minh);
391 }
392
393 static void
394 _update_view(Evas_Object *obj)
395 {
396    Widget_Data *wd;
397    const char *label;
398    Elm_Flipselector_Item *item;
399
400    wd = elm_widget_data_get(obj);
401    if (!wd) return;
402
403    label = NULL;
404    item = DATA_GET(wd->current);
405    if (item) label = item->label;
406
407    edje_object_part_text_set(wd->base, "top", label ? label : "");
408    edje_object_part_text_set(wd->base, "bottom", label ? label : "");
409    edje_object_message_signal_process(wd->base);
410 }
411
412 static void
413 _changed(Widget_Data *wd)
414 {
415    Elm_Flipselector_Item *item;
416
417    item = DATA_GET(wd->current);
418    if (!item) return;
419
420    if (item->func)
421      item->func((void *)item->base.data, WIDGET(item), item);
422    if (!item->deleted)
423      evas_object_smart_callback_call(wd->self, SIG_SELECTED, item);
424 }
425
426 static void
427 _send_msg(Widget_Data *wd, int flipside, char *label)
428 {
429    Edje_Message_String msg;
430
431    msg.str = label;
432    edje_object_message_send(wd->base, EDJE_MESSAGE_STRING, flipside, &msg);
433    edje_object_message_signal_process(wd->base);
434
435    _changed(wd);
436 }
437
438 static void
439 _flip_up(Widget_Data *wd)
440 {
441    Elm_Flipselector_Item *item;
442
443    if (!wd->current) return;
444
445    if (wd->current == wd->items)
446      {
447         wd->current = eina_list_last(wd->items);
448         evas_object_smart_callback_call(wd->self, SIG_UNDERFLOWED, NULL);
449      }
450    else
451      wd->current = eina_list_prev(wd->current);
452
453    item = DATA_GET(wd->current);
454    if (!item) return;
455
456    _send_msg(wd, MSG_FLIP_UP, (char *)item->label);
457 }
458
459 static Eina_Bool
460 _signal_val_up(void *data)
461 {
462    Widget_Data *wd = elm_widget_data_get(data);
463
464    if (!wd) goto val_up_exit_on_error;
465
466    _flipselector_walk(wd);
467
468    if (wd->interval > FLIP_MIN_INTERVAL)
469      wd->interval = wd->interval / 1.05;
470
471    ecore_timer_interval_set(wd->spin, wd->interval);
472
473    _flip_up(wd);
474
475    _flipselector_unwalk(wd);
476
477    return ECORE_CALLBACK_RENEW;
478
479 val_up_exit_on_error:
480    return ECORE_CALLBACK_CANCEL;
481 }
482
483 static void
484 _signal_val_up_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
485 {
486    Widget_Data *wd = elm_widget_data_get(data);
487    if (!wd) return;
488
489    wd->interval = wd->first_interval;
490
491    if (wd->spin) ecore_timer_del(wd->spin);
492    wd->spin = ecore_timer_add(wd->interval, _signal_val_up, data);
493
494    _signal_val_up(data);
495 }
496
497 static void
498 _flip_down(Widget_Data *wd)
499 {
500    Elm_Flipselector_Item *item;
501
502    if (!wd->current) return;
503
504    wd->current = eina_list_next(wd->current);
505    if (!wd->current)
506      {
507         wd->current = wd->items;
508         evas_object_smart_callback_call(wd->self, SIG_OVERFLOWED, NULL);
509      }
510
511    item = DATA_GET(wd->current);
512    if (!item) return;
513
514    _send_msg(wd, MSG_FLIP_DOWN, (char *)item->label);
515 }
516
517 static Eina_Bool
518 _signal_val_down(void *data)
519 {
520    Widget_Data *wd = elm_widget_data_get(data);
521
522    if (!wd) goto val_down_exit_on_error;
523
524    _flipselector_walk(wd);
525
526    if (wd->interval > FLIP_MIN_INTERVAL)
527      wd->interval = wd->interval / 1.05;
528    ecore_timer_interval_set(wd->spin, wd->interval);
529
530    _flip_down(wd);
531
532    _flipselector_unwalk(wd);
533
534    return ECORE_CALLBACK_RENEW;
535
536 val_down_exit_on_error:
537    return ECORE_CALLBACK_CANCEL;
538 }
539
540 static void
541 _signal_val_down_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
542 {
543    Widget_Data *wd = elm_widget_data_get(data);
544    if (!wd) return;
545
546    wd->interval = wd->first_interval;
547
548    if (wd->spin) ecore_timer_del(wd->spin);
549    wd->spin = ecore_timer_add(wd->interval, _signal_val_down, data);
550
551    _signal_val_down(data);
552 }
553
554 static void
555 _signal_val_change_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
556 {
557    Widget_Data *wd = elm_widget_data_get(data);
558    if (!wd) return;
559
560    if (wd->spin) ecore_timer_del(wd->spin);
561    wd->spin = NULL;
562 }
563
564 static void
565 _callbacks_set(Evas_Object *obj)
566 {
567    Widget_Data *wd = elm_widget_data_get(obj);
568
569    edje_object_signal_callback_add(wd->base, "elm,action,up,start",
570                                    "", _signal_val_up_start, obj);
571    edje_object_signal_callback_add(wd->base, "elm,action,up,stop",
572                                    "", _signal_val_change_stop, obj);
573    edje_object_signal_callback_add(wd->base, "elm,action,down,start",
574                                    "", _signal_val_down_start, obj);
575    edje_object_signal_callback_add(wd->base, "elm,action,down,stop",
576                                    "", _signal_val_change_stop, obj);
577 }
578
579 static Eina_Bool
580 _item_del_pre_hook(Elm_Object_Item *it)
581 {
582    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
583    Widget_Data *wd;
584    Elm_Flipselector_Item *item, *item2;
585    Eina_List *l;
586
587    item = (Elm_Flipselector_Item *) it;
588    wd = elm_widget_data_get(WIDGET(item));
589    if (!wd) return EINA_FALSE;
590
591    if (wd->walking > 0)
592      {
593         item->deleted = EINA_TRUE;
594         return EINA_FALSE;
595      }
596
597    _flipselector_walk(wd);
598
599    EINA_LIST_FOREACH(wd->items, l, item2)
600      {
601         if (item2 == item)
602           {
603              wd->items = eina_list_remove_list(wd->items, l);
604              if (wd->current == l)
605                {
606                   wd->current = l->prev;
607                   if (!wd->current) wd->current = l->next;
608                   if (wd->current)
609                     {
610                        item2 = wd->current->data;
611                        _send_msg(wd, MSG_FLIP_DOWN, (char *)item2->label);
612                     }
613                   else
614                      _send_msg(wd, MSG_FLIP_DOWN, "");
615                }
616              break;
617           }
618      }
619    eina_stringshare_del(item->label);
620    _sentinel_eval(wd);
621    _flipselector_unwalk(wd);
622
623    return EINA_TRUE;
624 }
625
626 EAPI Evas_Object *
627 elm_flipselector_add(Evas_Object *parent)
628 {
629    Evas_Object *obj;
630    Evas *e;
631    Widget_Data *wd;
632
633    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
634
635    ELM_SET_WIDTYPE(widtype, "flipselector");
636    elm_widget_type_set(obj, "flipselector");
637    elm_widget_sub_object_add(parent, obj);
638    elm_widget_data_set(obj, wd);
639
640    wd->self = obj;
641    elm_widget_del_hook_set(obj, _del_hook);
642    elm_widget_theme_hook_set(obj, _theme_hook);
643    /* TODO: elm_widget_disable_hook_set(obj, _disable_hook); */
644
645    elm_widget_can_focus_set(obj, EINA_TRUE);
646    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
647    elm_widget_event_hook_set(obj, _event_hook);
648
649    wd->base = edje_object_add(e);
650    elm_widget_resize_object_set(obj, wd->base);
651
652    _callbacks_set(obj);
653
654    wd->first_interval = FLIP_FIRST_INTERVAL;
655
656    _theme_hook(obj);
657
658    evas_object_smart_callbacks_descriptions_set(obj, _signals);
659    return obj;
660 }
661
662 EAPI void
663 elm_flipselector_flip_next(Evas_Object *obj)
664 {
665    ELM_CHECK_WIDTYPE(obj, widtype);
666
667    Widget_Data *wd = elm_widget_data_get(obj);
668    if (!wd) return;
669
670    if (wd->spin) ecore_timer_del(wd->spin);
671
672    _flipselector_walk(wd);
673    _flip_down(wd);
674    _flipselector_unwalk(wd);
675 }
676
677 EAPI void
678 elm_flipselector_flip_prev(Evas_Object *obj)
679 {
680    ELM_CHECK_WIDTYPE(obj, widtype);
681
682    Widget_Data *wd = elm_widget_data_get(obj);
683    if (!wd) return;
684
685    if (wd->spin) ecore_timer_del(wd->spin);
686
687    _flipselector_walk(wd);
688    _flip_up(wd);
689    _flipselector_unwalk(wd);
690 }
691
692 EAPI Elm_Object_Item *
693 elm_flipselector_item_append(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data)
694 {
695    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
696
697    Elm_Flipselector_Item *item;
698    Widget_Data *wd;
699
700    wd = elm_widget_data_get(obj);
701    if (!wd) return NULL;
702
703    item = _item_new(obj, label, func, data);
704    if (!item) return NULL;
705
706    wd->items = eina_list_append(wd->items, item);
707    if (!wd->current)
708      {
709         wd->current = wd->items;
710         _update_view(obj);
711      }
712
713    if (!wd->sentinel ||
714        (strlen(elm_object_item_text_get((Elm_Object_Item *) item)) >
715         strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))))
716      {
717         wd->sentinel = eina_list_last(wd->items);
718         _sizing_eval(obj);
719      }
720
721    if (eina_list_count(wd->items) >= 2)
722      edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm");
723
724    return (Elm_Object_Item *) item;
725 }
726
727 EAPI Elm_Object_Item *
728 elm_flipselector_item_prepend(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data)
729 {
730    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
731
732    Elm_Flipselector_Item *item;
733    Widget_Data *wd;
734
735    wd = elm_widget_data_get(obj);
736    if (!wd) return NULL;
737
738    item = _item_new(obj, label, func, data);
739    if (!item) return NULL;
740
741    wd->items = eina_list_prepend(wd->items, item);
742    if (!wd->current)
743      {
744         wd->current = wd->items;
745         _update_view(obj);
746      }
747
748    if (!wd->sentinel ||
749        (strlen(elm_object_item_text_get((Elm_Object_Item *) item)) >
750         strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))))
751      {
752         wd->sentinel = wd->items;
753         _sizing_eval(obj);
754      }
755
756    if (eina_list_count(wd->items) >= 2)
757      edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm");
758
759    return (Elm_Object_Item *) item;
760 }
761
762 /* TODO: account for deleted items?  */
763 EAPI const Eina_List *
764 elm_flipselector_items_get(const Evas_Object *obj)
765 {
766    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
767
768    Widget_Data *wd = elm_widget_data_get(obj);
769    if (!wd) return NULL;
770    return wd->items;
771 }
772
773 EAPI Elm_Object_Item *
774 elm_flipselector_first_item_get(const Evas_Object *obj)
775 {
776    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
777
778    Elm_Flipselector_Item *it;
779    Widget_Data *wd;
780    Eina_List *l;
781
782    wd = elm_widget_data_get(obj);
783    if (!wd || !wd->items) return NULL;
784
785    EINA_LIST_FOREACH(wd->items, l, it)
786      {
787         if (it->deleted) continue;
788         return (Elm_Object_Item *) it;
789      }
790    return NULL;
791 }
792
793 EAPI Elm_Object_Item *
794 elm_flipselector_last_item_get(const Evas_Object *obj)
795 {
796    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
797
798    Elm_Flipselector_Item *it;
799    Widget_Data *wd;
800    Eina_List *l;
801
802    wd = elm_widget_data_get(obj);
803    if (!wd || !wd->items) return NULL;
804
805    EINA_LIST_REVERSE_FOREACH(wd->items, l, it)
806      {
807         if (it->deleted) continue;
808         return (Elm_Object_Item *) it;
809      }
810    return NULL;
811 }
812
813 EAPI Elm_Object_Item *
814 elm_flipselector_selected_item_get(const Evas_Object *obj)
815 {
816    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
817
818    Widget_Data *wd = elm_widget_data_get(obj);
819    if (!wd || !wd->current) return NULL;
820    return DATA_GET(wd->current);
821 }
822
823 EAPI void
824 elm_flipselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
825 {
826    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
827
828    Elm_Flipselector_Item *item, *_item, *cur;
829    int flipside = MSG_FLIP_UP;
830    Widget_Data *wd;
831    Eina_List *l;
832
833    item = (Elm_Flipselector_Item *) it;
834    wd = elm_widget_data_get(WIDGET(item));
835    if (!wd) return;
836
837    cur = DATA_GET(wd->current);
838    if ((selected) && (cur == item)) return;
839
840    _flipselector_walk(wd);
841
842    if ((!selected) && (cur == item))
843      {
844         EINA_LIST_FOREACH(wd->items, l, _item)
845           {
846              if (!_item->deleted)
847                {
848                   wd->current = l;
849                   _send_msg(wd, MSG_FLIP_UP, (char *)_item->label);
850                   break;
851                }
852           }
853         _flipselector_unwalk(wd);
854         return;
855      }
856
857    EINA_LIST_FOREACH(wd->items, l, _item)
858      {
859         if (_item == cur) flipside = MSG_FLIP_DOWN;
860
861         if (_item == item)
862           {
863              wd->current = l;
864              _send_msg(wd, flipside, (char *)item->label);
865              break;
866           }
867      }
868
869    _flipselector_unwalk(wd);
870 }
871
872 EAPI Eina_Bool
873 elm_flipselector_item_selected_get(const Elm_Object_Item *it)
874 {
875    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
876    Widget_Data *wd;
877    Elm_Flipselector_Item *item;
878
879    item = (Elm_Flipselector_Item *) it;
880    wd = elm_widget_data_get(WIDGET(item));
881    if (!wd) return EINA_FALSE;
882    return (eina_list_data_get(wd->current) == item);
883 }
884
885 EAPI void
886 elm_flipselector_item_del(Elm_Object_Item *it)
887 {
888    elm_object_item_del(it);
889 }
890
891 EAPI const char *
892 elm_flipselector_item_label_get(const Elm_Object_Item *it)
893 {
894    return _item_text_get_hook(it, NULL);
895 }
896
897 EAPI void
898 elm_flipselector_item_label_set(Elm_Object_Item *it, const char *label)
899 {
900    _item_text_set_hook(it, NULL, label);
901 }
902
903 EAPI Elm_Object_Item *
904 elm_flipselector_item_prev_get(Elm_Object_Item *it)
905 {
906    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
907
908    Elm_Flipselector_Item *item, *_item;
909    Widget_Data *wd;
910    Eina_List *l;
911
912    item = (Elm_Flipselector_Item *) it;
913    wd = elm_widget_data_get(WIDGET(item));
914    if ((!wd) || (!wd->items)) return NULL;
915
916    EINA_LIST_FOREACH(wd->items, l, _item)
917      if (_item == item)
918        {
919           l = eina_list_prev(l);
920           if (!l) return NULL;
921           return DATA_GET(l);
922        }
923    return NULL;
924 }
925
926 EAPI Elm_Object_Item *
927 elm_flipselector_item_next_get(Elm_Object_Item *it)
928 {
929    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
930
931    Elm_Flipselector_Item *item, *_item;
932    Widget_Data *wd;
933    Eina_List *l;
934
935    item = (Elm_Flipselector_Item *) it;
936    wd = elm_widget_data_get(WIDGET(item));
937    if ((!wd) || (!wd->items)) return NULL;
938
939    EINA_LIST_FOREACH(wd->items, l, _item)
940      if (_item == item)
941        {
942           l = eina_list_next(l);
943           if (!l) return NULL;
944           return DATA_GET(l);
945        }
946    return NULL;
947 }
948
949 EAPI void
950 elm_flipselector_interval_set(Evas_Object *obj, double interval)
951 {
952    ELM_CHECK_WIDTYPE(obj, widtype);
953
954    Widget_Data *wd = elm_widget_data_get(obj);
955    if (!wd) return;
956    wd->first_interval = interval;
957 }
958
959 EAPI double
960 elm_flipselector_interval_get(const Evas_Object *obj)
961 {
962    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
963
964    Widget_Data *wd = elm_widget_data_get(obj);
965    if (!wd) return 0;
966    return wd->first_interval;
967 }