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