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