elementary/menu, ctxpopup, index, segment_control, diskselector, multibuttonentry...
[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 void _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 void
580 _item_del_pre_hook(Elm_Object_Item *it)
581 {
582    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
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;
590
591    if (wd->walking > 0)
592      {
593         item->deleted = EINA_TRUE;
594         return;
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
624 EAPI Evas_Object *
625 elm_flipselector_add(Evas_Object *parent)
626 {
627    Evas_Object *obj;
628    Evas *e;
629    Widget_Data *wd;
630
631    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
632
633    ELM_SET_WIDTYPE(widtype, "flipselector");
634    elm_widget_type_set(obj, "flipselector");
635    elm_widget_sub_object_add(parent, obj);
636    elm_widget_data_set(obj, wd);
637
638    wd->self = obj;
639    elm_widget_del_hook_set(obj, _del_hook);
640    elm_widget_theme_hook_set(obj, _theme_hook);
641    /* TODO: elm_widget_disable_hook_set(obj, _disable_hook); */
642
643    elm_widget_can_focus_set(obj, EINA_TRUE);
644    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
645    elm_widget_event_hook_set(obj, _event_hook);
646
647    wd->base = edje_object_add(e);
648    elm_widget_resize_object_set(obj, wd->base);
649
650    _callbacks_set(obj);
651
652    wd->first_interval = FLIP_FIRST_INTERVAL;
653
654    _theme_hook(obj);
655
656    evas_object_smart_callbacks_descriptions_set(obj, _signals);
657    return obj;
658 }
659
660 EAPI void
661 elm_flipselector_flip_next(Evas_Object *obj)
662 {
663    ELM_CHECK_WIDTYPE(obj, widtype);
664
665    Widget_Data *wd = elm_widget_data_get(obj);
666    if (!wd) return;
667
668    if (wd->spin) ecore_timer_del(wd->spin);
669
670    _flipselector_walk(wd);
671    _flip_down(wd);
672    _flipselector_unwalk(wd);
673 }
674
675 EAPI void
676 elm_flipselector_flip_prev(Evas_Object *obj)
677 {
678    ELM_CHECK_WIDTYPE(obj, widtype);
679
680    Widget_Data *wd = elm_widget_data_get(obj);
681    if (!wd) return;
682
683    if (wd->spin) ecore_timer_del(wd->spin);
684
685    _flipselector_walk(wd);
686    _flip_up(wd);
687    _flipselector_unwalk(wd);
688 }
689
690 EAPI Elm_Object_Item *
691 elm_flipselector_item_append(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data)
692 {
693    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
694
695    Elm_Flipselector_Item *item;
696    Widget_Data *wd;
697
698    wd = elm_widget_data_get(obj);
699    if (!wd) return NULL;
700
701    item = _item_new(obj, label, func, data);
702    if (!item) return NULL;
703
704    wd->items = eina_list_append(wd->items, item);
705    if (!wd->current)
706      {
707         wd->current = wd->items;
708         _update_view(obj);
709      }
710
711    if (!wd->sentinel ||
712        (strlen(elm_object_item_text_get((Elm_Object_Item *) item)) >
713         strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))))
714      {
715         wd->sentinel = eina_list_last(wd->items);
716         _sizing_eval(obj);
717      }
718
719    if (eina_list_count(wd->items) >= 2)
720      edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm");
721
722    return (Elm_Object_Item *) item;
723 }
724
725 EAPI Elm_Object_Item *
726 elm_flipselector_item_prepend(Evas_Object *obj, const char *label, void (*func)(void *data, Evas_Object *obj, void *event_info), void *data)
727 {
728    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
729
730    Elm_Flipselector_Item *item;
731    Widget_Data *wd;
732
733    wd = elm_widget_data_get(obj);
734    if (!wd) return NULL;
735
736    item = _item_new(obj, label, func, data);
737    if (!item) return NULL;
738
739    wd->items = eina_list_prepend(wd->items, item);
740    if (!wd->current)
741      {
742         wd->current = wd->items;
743         _update_view(obj);
744      }
745
746    if (!wd->sentinel ||
747        (strlen(elm_object_item_text_get((Elm_Object_Item *) item)) >
748         strlen(elm_object_item_text_get(DATA_GET(wd->sentinel)))))
749      {
750         wd->sentinel = wd->items;
751         _sizing_eval(obj);
752      }
753
754    if (eina_list_count(wd->items) >= 2)
755      edje_object_signal_emit(wd->base, "elm,state,button,visible", "elm");
756
757    return (Elm_Object_Item *) item;
758 }
759
760 /* TODO: account for deleted items?  */
761 EAPI const Eina_List *
762 elm_flipselector_items_get(const Evas_Object *obj)
763 {
764    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
765
766    Widget_Data *wd = elm_widget_data_get(obj);
767    if (!wd) return NULL;
768    return wd->items;
769 }
770
771 EAPI Elm_Object_Item *
772 elm_flipselector_first_item_get(const Evas_Object *obj)
773 {
774    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
775
776    Elm_Flipselector_Item *it;
777    Widget_Data *wd;
778    Eina_List *l;
779
780    wd = elm_widget_data_get(obj);
781    if (!wd || !wd->items) return NULL;
782
783    EINA_LIST_FOREACH(wd->items, l, it)
784      {
785         if (it->deleted) continue;
786         return (Elm_Object_Item *) it;
787      }
788    return NULL;
789 }
790
791 EAPI Elm_Object_Item *
792 elm_flipselector_last_item_get(const Evas_Object *obj)
793 {
794    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
795
796    Elm_Flipselector_Item *it;
797    Widget_Data *wd;
798    Eina_List *l;
799
800    wd = elm_widget_data_get(obj);
801    if (!wd || !wd->items) return NULL;
802
803    EINA_LIST_REVERSE_FOREACH(wd->items, l, it)
804      {
805         if (it->deleted) continue;
806         return (Elm_Object_Item *) it;
807      }
808    return NULL;
809 }
810
811 EAPI Elm_Object_Item *
812 elm_flipselector_selected_item_get(const Evas_Object *obj)
813 {
814    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
815
816    Widget_Data *wd = elm_widget_data_get(obj);
817    if (!wd || !wd->current) return NULL;
818    return DATA_GET(wd->current);
819 }
820
821 EAPI void
822 elm_flipselector_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
823 {
824    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
825
826    Elm_Flipselector_Item *item, *_item, *cur;
827    int flipside = MSG_FLIP_UP;
828    Widget_Data *wd;
829    Eina_List *l;
830
831    item = (Elm_Flipselector_Item *) it;
832    wd = elm_widget_data_get(WIDGET(item));
833    if (!wd) return;
834
835    cur = DATA_GET(wd->current);
836    if ((selected) && (cur == item)) return;
837
838    _flipselector_walk(wd);
839
840    if ((!selected) && (cur == item))
841      {
842         EINA_LIST_FOREACH(wd->items, l, _item)
843           {
844              if (!_item->deleted)
845                {
846                   wd->current = l;
847                   _send_msg(wd, MSG_FLIP_UP, (char *)_item->label);
848                   break;
849                }
850           }
851         _flipselector_unwalk(wd);
852         return;
853      }
854
855    EINA_LIST_FOREACH(wd->items, l, _item)
856      {
857         if (_item == cur) flipside = MSG_FLIP_DOWN;
858
859         if (_item == item)
860           {
861              wd->current = l;
862              _send_msg(wd, flipside, (char *)item->label);
863              break;
864           }
865      }
866
867    _flipselector_unwalk(wd);
868 }
869
870 EAPI Eina_Bool
871 elm_flipselector_item_selected_get(const Elm_Object_Item *it)
872 {
873    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
874    Widget_Data *wd;
875    Elm_Flipselector_Item *item;
876
877    item = (Elm_Flipselector_Item *) it;
878    wd = elm_widget_data_get(WIDGET(item));
879    if (!wd) return EINA_FALSE;
880    return (eina_list_data_get(wd->current) == item);
881 }
882
883 EAPI void
884 elm_flipselector_item_del(Elm_Object_Item *it)
885 {
886    elm_object_item_del(it);
887 }
888
889 EAPI const char *
890 elm_flipselector_item_label_get(const Elm_Object_Item *it)
891 {
892    return _item_text_get_hook(it, NULL);
893 }
894
895 EAPI void
896 elm_flipselector_item_label_set(Elm_Object_Item *it, const char *label)
897 {
898    _item_text_set_hook(it, NULL, label);
899 }
900
901 EAPI Elm_Object_Item *
902 elm_flipselector_item_prev_get(Elm_Object_Item *it)
903 {
904    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
905
906    Elm_Flipselector_Item *item, *_item;
907    Widget_Data *wd;
908    Eina_List *l;
909
910    item = (Elm_Flipselector_Item *) it;
911    wd = elm_widget_data_get(WIDGET(item));
912    if ((!wd) || (!wd->items)) return NULL;
913
914    EINA_LIST_FOREACH(wd->items, l, _item)
915      if (_item == item)
916        {
917           l = eina_list_prev(l);
918           if (!l) return NULL;
919           return DATA_GET(l);
920        }
921    return NULL;
922 }
923
924 EAPI Elm_Object_Item *
925 elm_flipselector_item_next_get(Elm_Object_Item *it)
926 {
927    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
928
929    Elm_Flipselector_Item *item, *_item;
930    Widget_Data *wd;
931    Eina_List *l;
932
933    item = (Elm_Flipselector_Item *) it;
934    wd = elm_widget_data_get(WIDGET(item));
935    if ((!wd) || (!wd->items)) return NULL;
936
937    EINA_LIST_FOREACH(wd->items, l, _item)
938      if (_item == item)
939        {
940           l = eina_list_next(l);
941           if (!l) return NULL;
942           return DATA_GET(l);
943        }
944    return NULL;
945 }
946
947 EAPI void
948 elm_flipselector_interval_set(Evas_Object *obj, double interval)
949 {
950    ELM_CHECK_WIDTYPE(obj, widtype);
951
952    Widget_Data *wd = elm_widget_data_get(obj);
953    if (!wd) return;
954    wd->first_interval = interval;
955 }
956
957 EAPI double
958 elm_flipselector_interval_get(const Evas_Object *obj)
959 {
960    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
961
962    Widget_Data *wd = elm_widget_data_get(obj);
963    if (!wd) return 0;
964    return wd->first_interval;
965 }