aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/elm_flipselector.c
blob: f9ba061f75062d531faf9a37994b885f9b3b4f0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_ACCESS_OBJECT_PROTECTED
#define EFL_ACCESS_WIDGET_ACTION_PROTECTED

#define ELM_WIDGET_ITEM_PROTECTED
#include <Elementary.h>
#include "elm_priv.h"
#include "elm_widget_flipselector.h"

#include "elm_flipselector_eo.h"
#include "elm_flipselector_item_eo.h"

#define MY_CLASS ELM_FLIPSELECTOR_CLASS

#define MY_CLASS_NAME "Elm_Flipselector"
#define MY_CLASS_NAME_LEGACY "elm_flipselector"

/* TODO: ideally, the default theme would use map{} blocks on the TEXT
   parts to implement their fading in/out properly (as in the clock
   widget) */
/* TODO: if one ever wants to extend it to receiving generic widgets
   as items, be my guest. in this case, remember to implement the
   items tooltip infra. */
/* TODO: fix default theme image borders for looong strings as item
   labels. */
/* TODO: set text elipsis on labels if one enforces mininum size on
 * the overall widget less the required for displaying it. */
/* TODO: find a way to, in the default theme, to detect we are
 * bootstrapping (receiving the 1st message) and populate the downmost
 * TEXT parts with the same text as the upmost, where appropriate. */

#define FLIP_FIRST_INTERVAL (0.85)
#define FLIP_MIN_INTERVAL   (0.1)
#define MSG_FLIP_DOWN       (1)
#define MSG_FLIP_UP         (2)
#define MAX_LEN_DEFAULT     (50)

#define DATA_GET            eina_list_data_get

static const char SIG_SELECTED[] = "selected";
static const char SIG_UNDERFLOWED[] = "underflowed";
static const char SIG_OVERFLOWED[] = "overflowed";
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
   {SIG_SELECTED, ""},
   {SIG_UNDERFLOWED, ""},
   {SIG_OVERFLOWED, ""},
   {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
   {SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */
   {SIG_LAYOUT_FOCUSED, ""}, /**< handled by elm_layout */
   {SIG_LAYOUT_UNFOCUSED, ""}, /**< handled by elm_layout */
   {NULL, NULL}
};

static Eina_Bool _key_action_flip(Evas_Object *obj, const char *params);

static const Elm_Action key_actions[] = {
   {"flip", _key_action_flip},
   {NULL, NULL}
};

EOLIAN static void
_elm_flipselector_elm_layout_sizing_eval(Eo *obj, Elm_Flipselector_Data *sd)
{
   char *tmp = NULL;
   Evas_Coord minw = -1, minh = -1, w, h;

   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);

   if (sd->evaluating) return;

   elm_coords_finger_size_adjust(1, &minw, 2, &minh);

   sd->evaluating = EINA_TRUE;

   if (sd->sentinel)
     {
        const char *label = elm_object_item_text_get(DATA_GET(sd->sentinel));
        const char *src = elm_layout_text_get(obj, "elm.top");

        if (src)
            tmp = strdup(src);
        elm_layout_text_set(obj, "elm.top", label);
     }

   edje_object_size_min_restricted_calc
     (wd->resize_obj, &minw, &minh, minw, minh);
   elm_coords_finger_size_adjust(1, &minw, 2, &minh);
   evas_object_size_hint_combined_min_get(obj, &w, &h);

   if (sd->sentinel)
     {
        elm_layout_text_set(obj, "elm.top", tmp);
        free(tmp);
     }

   if (w > minw) minw = w;
   if (h > minh) minh = h;

   sd->evaluating = EINA_FALSE;

   evas_object_size_hint_min_set(obj, minw, minh);
}

static void
_update_view(Evas_Object *obj)
{
   const char *label;
   Elm_Object_Item *eo_item;

   ELM_FLIPSELECTOR_DATA_GET(obj, sd);
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);

   label = NULL;
   eo_item = DATA_GET(sd->current);
   ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, item);
   if (item) label = item->label;

   elm_layout_text_set(obj, "elm.top", label ? label : "");
   elm_layout_text_set(obj, "elm.bottom", label ? label : "");

   edje_object_message_signal_process(wd->resize_obj);
}

EOLIAN static void
_elm_flipselector_item_elm_widget_item_part_text_set(Eo *eo_item,
                                                     Elm_Flipselector_Item_Data *item,
                                                     const char *part,
                                                     const char *label)
{
   Eina_List *l;

   if (!label) return;

   if (part && strcmp(part, "default")) return;

   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   if (!sd->items) return;

   l = eina_list_data_find_list(sd->items, eo_item);
   if (!l) return;

   eina_stringshare_del(item->label);
   item->label = eina_stringshare_add_length(label, sd->max_len);

   if (strlen(label) > strlen(elm_object_item_text_get(DATA_GET(sd->sentinel))))
     sd->sentinel = l;

   if (sd->current == l)
     {
        _update_view(WIDGET(item));
        elm_layout_sizing_eval(WIDGET(item));
     }
}

EOLIAN static const char *
_elm_flipselector_item_elm_widget_item_part_text_get(const Eo *eo_it EINA_UNUSED,
                                                     Elm_Flipselector_Item_Data *it,
                                                     const char *part)
{
   if (part && strcmp(part, "default")) return NULL;

   return it->label;
}

EOLIAN static void
_elm_flipselector_item_elm_widget_item_signal_emit(Eo *eo_it EINA_UNUSED,
                                                   Elm_Flipselector_Item_Data *it,
                                                   const char *emission,
                                                   const char *source)
{
   edje_object_signal_emit(VIEW(it), emission, source);
}

static inline void
_flipselector_walk(Elm_Flipselector_Data *sd)
{
   if (sd->walking < 0)
     {
        ERR("walking was negative. fixed!\n");
        sd->walking = 0;
     }
   sd->walking++;
}

static void
_sentinel_eval(Elm_Flipselector_Data *sd)
{
   Elm_Object_Item *it;
   Eina_List *l;

   if (!sd->items)
     {
        sd->sentinel = NULL;
        return;
     }

   sd->sentinel = sd->items;

   EINA_LIST_FOREACH(sd->items, l, it)
     {
        if (strlen(elm_object_item_text_get(it)) >
            strlen(elm_object_item_text_get(DATA_GET(sd->sentinel))))
          sd->sentinel = l;
     }
}

static inline void
_flipselector_unwalk(Elm_Flipselector_Data *sd)
{
   sd->walking--;

   if (sd->walking < 0)
     {
        ERR("walking became negative. fixed!\n");
        sd->walking = 0;
     }
   if (sd->walking) return;
}

static void
_on_item_changed(Elm_Flipselector_Data *sd)
{
   Elm_Object_Item *eo_item;

   eo_item = DATA_GET(sd->current);
   ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, item);
   if (!item) return;
   if (sd->deleting) return;

   if (item->func)
     item->func((void *)WIDGET_ITEM_DATA_GET(eo_item), WIDGET(item), eo_item);
   evas_object_smart_callback_call(sd->obj, "selected", eo_item);
}

static void
_send_msg(Elm_Flipselector_Data *sd,
          int flipside,
          char *label)
{
   Edje_Message_String msg;
   ELM_WIDGET_DATA_GET_OR_RETURN(sd->obj, wd);

   msg.str = label;
   edje_object_message_send
     (wd->resize_obj, EDJE_MESSAGE_STRING, flipside, &msg);
   edje_object_message_signal_process(wd->resize_obj);

   _on_item_changed(sd);
}

static void
_view_update(void *data)
{
   Evas_Object *obj = data;
   ELM_FLIPSELECTOR_DATA_GET(obj, sd);
   Elm_Object_Item *eo_item;

   sd->view_update = NULL;
   sd->need_update = EINA_FALSE;

   if (sd->current)
     {
        eo_item = sd->current->data;
        ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, item);
        _send_msg(sd, MSG_FLIP_DOWN, (char *)item->label);
     }
   else
     {
        _send_msg(sd, MSG_FLIP_DOWN, "");
        elm_layout_signal_emit(obj, "elm,state,button,hidden", "elm");
     }
}

EOLIAN static void
_elm_flipselector_item_efl_object_destructor(Eo *eo_item, Elm_Flipselector_Item_Data *item)
{
   Eina_List *l;
   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   if (sd->deleting)
     {
        eina_stringshare_del(item->label);
        sd->items = eina_list_remove(sd->items, eo_item);
        efl_destructor(efl_super(eo_item, ELM_FLIPSELECTOR_ITEM_CLASS));
        return;
     }

   if ((sd->current) && (sd->current->data == eo_item))
     {
        sd->need_update = EINA_TRUE;
        l = sd->current->prev;
        if (!l) l = sd->current->next;
        if (!l) sd->current = NULL;
        else sd->current = l;
     }

   eina_stringshare_del(item->label);
   sd->items = eina_list_remove(sd->items, eo_item);

   _sentinel_eval(sd);

   if (sd->need_update)
     {
        if (sd->view_update) ecore_job_del(sd->view_update);
        sd->view_update = ecore_job_add(_view_update, WIDGET(item));
     }

   efl_destructor(efl_super(eo_item, ELM_FLIPSELECTOR_ITEM_CLASS));
}

EOLIAN static Eo *
_elm_flipselector_item_efl_object_constructor(Eo *obj, Elm_Flipselector_Item_Data *it)
{
   obj = efl_constructor(efl_super(obj, ELM_FLIPSELECTOR_ITEM_CLASS));
   it->base = efl_data_scope_get(obj, ELM_WIDGET_ITEM_CLASS);

   return obj;
}

static Elm_Object_Item *
_item_new(Evas_Object *obj,
          const char *label,
          Evas_Smart_Cb func,
          const void *data)
{
   unsigned int len;
   Eo *eo_item;

   ELM_FLIPSELECTOR_DATA_GET(obj, sd);

   eo_item = efl_add(ELM_FLIPSELECTOR_ITEM_CLASS, obj);
   if (!eo_item) return NULL;

   ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, it);

   len = strlen(label);
   if (len > sd->max_len) len = sd->max_len;

   it->label = eina_stringshare_add_length(label, len);
   it->func = func;
   WIDGET_ITEM_DATA_SET(eo_item, data);

   /* TODO: no view here, but if one desires general contents in the
    * future... */
   return eo_item;
}

EOLIAN static Eina_Error
_elm_flipselector_efl_ui_widget_theme_apply(Eo *obj, Elm_Flipselector_Data *sd)
{
   const char *max_len;

   Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EFL_UI_THEME_APPLY_ERROR_GENERIC);

   int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
   if (int_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return int_ret;

   max_len = edje_object_data_get(wd->resize_obj, "max_len");
   if (!max_len) sd->max_len = MAX_LEN_DEFAULT;
   else
     {
        sd->max_len = atoi(max_len);

        if (!sd->max_len) sd->max_len = MAX_LEN_DEFAULT;
     }

   _update_view(obj);
   elm_layout_sizing_eval(obj);

   return int_ret;
}

static void
_flip_up(Elm_Flipselector_Data *sd)
{
   Elm_Object_Item *eo_item;

   if (!sd->current) return;

   if (sd->deleting) return;
   if (sd->current == sd->items)
     {
        sd->current = eina_list_last(sd->items);
        efl_event_callback_legacy_call
          (sd->obj, ELM_FLIPSELECTOR_EVENT_UNDERFLOWED, NULL);
     }
   else
     sd->current = eina_list_prev(sd->current);

   eo_item = DATA_GET(sd->current);
   ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, item);
   if (!item) return;

   _send_msg(sd, MSG_FLIP_UP, (char *)item->label);
}

static void
_flip_down(Elm_Flipselector_Data *sd)
{
   Elm_Object_Item *eo_item;

   if (!sd->current) return;

   if (sd->deleting) return;
   sd->current = eina_list_next(sd->current);
   if (!sd->current)
     {
        sd->current = sd->items;
        efl_event_callback_legacy_call
          (sd->obj, ELM_FLIPSELECTOR_EVENT_OVERFLOWED, NULL);
     }

   eo_item = DATA_GET(sd->current);
   ELM_FLIPSELECTOR_ITEM_DATA_GET(eo_item, item);
   if (!item) return;

   _send_msg(sd, MSG_FLIP_DOWN, (char *)item->label);
}

static Eina_Bool
_key_action_flip(Evas_Object *obj, const char *params)
{
   ELM_FLIPSELECTOR_DATA_GET(obj, sd);
   const char *dir = params;

   ELM_SAFE_FREE(sd->spin, ecore_timer_del);

   /* TODO: if direction setting via API is not coming in, replace
      these calls by flip_{next,prev} */
   _flipselector_walk(sd);

   if (!strcmp(dir, "up")) _flip_up(sd);
   else if (!strcmp(dir, "down")) _flip_down(sd);
   else return EINA_FALSE;

   _flipselector_unwalk(sd);
   return EINA_TRUE;
}

static void
_clear_items(Evas_Object *obj)
{
   ELM_FLIPSELECTOR_DATA_GET(obj, sd);
   sd->current = NULL;
   while(sd->items)
     elm_object_item_del(DATA_GET(sd->items));
}

static void
_items_add(Evas_Object *obj)
{
   double d;
   Eina_Bool reverse;
   char buf[16];

   ELM_FLIPSELECTOR_DATA_GET(obj, sd);
   reverse = (sd->val_min > sd->val_max);
   _clear_items(obj);
   for (d = sd->val_min; d < sd->val_max;)
     {
        snprintf(buf, sizeof(buf), "%.2f", d);
        elm_flipselector_item_append(obj, buf, NULL, NULL);
        if (reverse) d = d - sd->step;
        else d = d + sd->step;
     }
   snprintf(buf, sizeof(buf), "%.2f", sd->val_max);
   elm_flipselector_item_append(obj, buf, NULL, NULL);
}

EOLIAN static void
_elm_flipselector_efl_ui_range_display_range_min_max_set(Eo *obj, Elm_Flipselector_Data *sd, double min, double max)
{
   if ((sd->val_min == min) && (sd->val_max == max)) return;

   sd->val_min = min;
   sd->val_max = max;

   _items_add(obj);
}

EOLIAN static void
_elm_flipselector_efl_ui_range_display_range_min_max_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd, double *min, double *max)
{
   if (min) *min = sd->val_min;
   if (max) *max = sd->val_max;
}

EOLIAN static void
_elm_flipselector_efl_ui_range_interactive_range_step_set(Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd, double step)
{
   if (sd->step == step) return;

   if (step == 0.0) step = 1.0;
   else if (step < 0.0) step *= -1;

   sd->step = step;
   _items_add(obj);
}

EOLIAN static double
_elm_flipselector_efl_ui_range_interactive_range_step_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return sd->step;
}

EOLIAN static double
_elm_flipselector_efl_ui_range_display_range_value_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   if (sd->val_min == 0 && sd->val_max == 0)
     {
        WRN("This API can be used only if you set min and max and flipselector values are numericals");
        return 0;
     }
   ELM_FLIPSELECTOR_ITEM_DATA_GET(sd->current->data, item);
   return atof(item->label);
}

EOLIAN static void
_elm_flipselector_efl_ui_range_display_range_value_set(Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd, double val)
{
   Eina_List *l;
   Elm_Object_Item *it;

   EINA_LIST_FOREACH(sd->items, l, it)
     {
        if (atof(elm_object_item_text_get(it)) >= val)
          break;
     }
   elm_flipselector_item_selected_set(it, EINA_TRUE);
}

static Eina_Bool
_signal_val_up(void *data)
{
   ELM_FLIPSELECTOR_DATA_GET(data, sd);

   _flipselector_walk(sd);

   if (sd->interval > FLIP_MIN_INTERVAL) sd->interval = sd->interval / 1.05;

   ecore_timer_interval_set(sd->spin, sd->interval);

   _flip_up(sd);

   _flipselector_unwalk(sd);

   return ECORE_CALLBACK_RENEW;
}

static void
_signal_val_up_start(void *data,
                     Evas_Object *obj EINA_UNUSED,
                     const char *emission EINA_UNUSED,
                     const char *source EINA_UNUSED)
{
   ELM_FLIPSELECTOR_DATA_GET(data, sd);

   sd->interval = sd->first_interval;

   ecore_timer_del(sd->spin);
   sd->spin = ecore_timer_add(sd->interval, _signal_val_up, data);

   _signal_val_up(data);
}

static Eina_Bool
_signal_val_down(void *data)
{
   ELM_FLIPSELECTOR_DATA_GET(data, sd);

   _flipselector_walk(sd);

   if (sd->interval > FLIP_MIN_INTERVAL) sd->interval = sd->interval / 1.05;
   ecore_timer_interval_set(sd->spin, sd->interval);

   _flip_down(sd);

   _flipselector_unwalk(sd);

   return ECORE_CALLBACK_RENEW;
}

static void
_signal_val_down_start(void *data,
                       Evas_Object *obj EINA_UNUSED,
                       const char *emission EINA_UNUSED,
                       const char *source EINA_UNUSED)
{
   ELM_FLIPSELECTOR_DATA_GET(data, sd);

   sd->interval = sd->first_interval;

   ecore_timer_del(sd->spin);
   sd->spin = ecore_timer_add(sd->interval, _signal_val_down, data);

   _signal_val_down(data);
}

static void
_signal_val_change_stop(void *data,
                        Evas_Object *obj EINA_UNUSED,
                        const char *emission EINA_UNUSED,
                        const char *source EINA_UNUSED)
{
   ELM_FLIPSELECTOR_DATA_GET(data, sd);

   ELM_SAFE_FREE(sd->spin, ecore_timer_del);
}

EOLIAN static void
_elm_flipselector_efl_canvas_group_group_add(Eo *obj, Elm_Flipselector_Data *priv)
{
   efl_canvas_group_add(efl_super(obj, MY_CLASS));

   if (!elm_layout_theme_set
       (obj, "flipselector", "base", elm_widget_style_get(obj)))
     CRI("Failed to set layout!");

   elm_layout_signal_callback_add
     (obj, "elm,action,up,start", "*", _signal_val_up_start, obj);
   elm_layout_signal_callback_add
     (obj, "elm,action,up,stop", "*", _signal_val_change_stop, obj);
   elm_layout_signal_callback_add
     (obj, "elm,action,down,start", "*", _signal_val_down_start, obj);
   elm_layout_signal_callback_add
     (obj, "elm,action,down,stop", "*", _signal_val_change_stop, obj);

   priv->first_interval = FLIP_FIRST_INTERVAL;
   priv->step = 1.0;

   elm_widget_can_focus_set(obj, EINA_TRUE);

   efl_ui_widget_theme_apply(obj);
}

EOLIAN static void
_elm_flipselector_efl_canvas_group_group_del(Eo *obj, Elm_Flipselector_Data *sd)
{
   sd->deleting = EINA_TRUE;

   if (sd->walking) ERR("flipselector deleted while walking.\n");

   while (sd->items)
     efl_del(DATA_GET(sd->items));

   ecore_timer_del(sd->spin);
   ecore_job_del(sd->view_update);

   efl_canvas_group_del(efl_super(obj, MY_CLASS));
}

EAPI Evas_Object *
elm_flipselector_add(Evas_Object *parent)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
   return elm_legacy_add(MY_CLASS, parent);
}

EOLIAN static Eo *
_elm_flipselector_efl_object_constructor(Eo *obj, Elm_Flipselector_Data *sd)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   sd->obj = obj;
   efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
   evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
   efl_access_object_role_set(obj, EFL_ACCESS_ROLE_LIST);
   legacy_object_focus_handle(obj);

   return obj;
}

EOLIAN static void
_elm_flipselector_flip_next(Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   ELM_SAFE_FREE(sd->spin, ecore_timer_del);

   _flipselector_walk(sd);
   _flip_down(sd);
   _flipselector_unwalk(sd);
}

EOLIAN static void
_elm_flipselector_flip_prev(Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   ELM_SAFE_FREE(sd->spin, ecore_timer_del);

   _flipselector_walk(sd);
   _flip_up(sd);
   _flipselector_unwalk(sd);
}

EOLIAN static Elm_Object_Item *
_elm_flipselector_item_append(Eo *obj, Elm_Flipselector_Data *sd, const char *label, Evas_Smart_Cb func, const void *data)
{
   Elm_Object_Item *item;

   item = _item_new(obj, label, func, data);
   if (!item) return NULL;

   sd->items = eina_list_append(sd->items, item);
   if (!sd->current)
     {
        sd->current = sd->items;
        _update_view(obj);
     }

   if (!sd->sentinel ||
       (strlen(elm_object_item_text_get(item)) >
        strlen(elm_object_item_text_get(DATA_GET(sd->sentinel)))))
     {
        sd->sentinel = eina_list_last(sd->items);
        elm_layout_sizing_eval(obj);
     }

   if (eina_list_count(sd->items) > 1)
     elm_layout_signal_emit(obj, "elm,state,button,visible", "elm");

   return item;
}

EOLIAN static Elm_Object_Item *
_elm_flipselector_item_prepend(Eo *obj, Elm_Flipselector_Data *sd, const char *label, Evas_Smart_Cb func, void *data)
{
   Elm_Object_Item *item;

   item = _item_new(obj, label, func, data);
   if (!item) return NULL;

   sd->items = eina_list_prepend(sd->items, item);
   if (!sd->current)
     {
        sd->current = sd->items;
        _update_view(obj);
     }

   if (!sd->sentinel ||
       (strlen(elm_object_item_text_get(item)) >
        strlen(elm_object_item_text_get(DATA_GET(sd->sentinel)))))
     {
        sd->sentinel = sd->items;
        elm_layout_sizing_eval(obj);
     }

   if (eina_list_count(sd->items) >= 2)
     elm_layout_signal_emit(obj, "elm,state,button,visible", "elm");

   return item;
}

EOLIAN static const Eina_List*
_elm_flipselector_items_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return sd->items;
}

EOLIAN static Elm_Object_Item*
_elm_flipselector_first_item_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return eina_list_data_get(sd->items);
}

EOLIAN static Elm_Object_Item*
_elm_flipselector_last_item_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return eina_list_last_data_get(sd->items);
}

EOLIAN static Elm_Object_Item*
_elm_flipselector_selected_item_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return DATA_GET(sd->current);
}

EOLIAN static void
_elm_flipselector_item_selected_set(Eo *eo_item,
                                    Elm_Flipselector_Item_Data *item,
                                    Eina_Bool selected)
{
   Elm_Object_Item *_eo_item, *eo_cur;
   int flipside = MSG_FLIP_UP;
   Eina_List *l;

   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   eo_cur = DATA_GET(sd->current);
   if ((selected) && (eo_cur == eo_item)) return;

   _flipselector_walk(sd);

   if ((!selected) && (eo_cur == eo_item))
     {
        EINA_LIST_FOREACH(sd->items, l, _eo_item)
          {
             ELM_FLIPSELECTOR_ITEM_DATA_GET(_eo_item, _item);
             sd->current = l;
             _send_msg(sd, MSG_FLIP_UP, (char *)_item->label);
             break;
          }
        _flipselector_unwalk(sd);
        return;
     }

   EINA_LIST_FOREACH(sd->items, l, _eo_item)
     {
        if (_eo_item == eo_cur) flipside = MSG_FLIP_DOWN;

        if (_eo_item == eo_item)
          {
             ELM_FLIPSELECTOR_ITEM_DATA_GET(_eo_item, _item);
             sd->current = l;
             _send_msg(sd, flipside, (char *)_item->label);
             break;
          }
     }

   _flipselector_unwalk(sd);
}

EOLIAN static Eina_Bool
_elm_flipselector_item_selected_get(const Eo *eo_item,
                                    Elm_Flipselector_Item_Data *item)
{
   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   return eina_list_data_get(sd->current) == eo_item;
}

EOLIAN static Elm_Object_Item *
_elm_flipselector_item_prev_get(const Eo *eo_item,
                                Elm_Flipselector_Item_Data *item)
{
   Eina_List *l;

   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   if ((!sd->items)) return NULL;

   l = eina_list_data_find_list(sd->items, eo_item);
   if (l && l->prev) return DATA_GET(l->prev);

   return NULL;
}

EOLIAN static Elm_Object_Item *
_elm_flipselector_item_next_get(const Eo *eo_item,
                                Elm_Flipselector_Item_Data *item)
{
   Eina_List *l;

   ELM_FLIPSELECTOR_DATA_GET(WIDGET(item), sd);

   if ((!sd->items)) return NULL;

   l = eina_list_data_find_list(sd->items, eo_item);
   if (l && l->next) return DATA_GET(l->next);

   return NULL;
}

EOLIAN void
_elm_flipselector_first_interval_set(Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd, double interval)
{
   sd->first_interval = interval;
}

EOLIAN double
_elm_flipselector_first_interval_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *sd)
{
   return sd->first_interval;
}

EOLIAN static void
_elm_flipselector_class_constructor(Efl_Class *klass)
{
   evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
}

EOLIAN const Efl_Access_Action_Data *
_elm_flipselector_efl_access_widget_action_elm_actions_get(const Eo *obj EINA_UNUSED, Elm_Flipselector_Data *pd EINA_UNUSED)
{
   static Efl_Access_Action_Data atspi_actions[] = {
          { "flip,up", "flip", "up", _key_action_flip},
          { "flip,down", "flip", "down", _key_action_flip},
          { NULL, NULL, NULL, NULL}
   };
   return &atspi_actions[0];
}

/* Standard widget overrides */

ELM_WIDGET_KEY_DOWN_DEFAULT_IMPLEMENT(elm_flipselector, Elm_Flipselector_Data)

/* Internal EO APIs and hidden overrides */

#define ELM_FLIPSELECTOR_EXTRA_OPS \
   ELM_LAYOUT_SIZING_EVAL_OPS(elm_flipselector), \
   EFL_CANVAS_GROUP_ADD_DEL_OPS(elm_flipselector)

#include "elm_flipselector_item_eo.c"
#include "elm_flipselector_eo.c"